From 126ca2b23857ee25c4ebd860a3b3101b4617be05 Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Sun, 11 Oct 2026 20:07:34 +1100 Subject: [PATCH 01/14] canvas: draggable relationship edges + saved layout (visual only) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two gaps against erwin's diagram editor, both visual-only and fully isolated from the model. Part A — draggable edges. A relationship's vertical segment can be dragged sideways (its x is the only free degree of freedom — ports are on card left/right only). Hovering or selecting an edge shows an ew-resize grip at the segment's midpoint; dragging slides it while both ends stay anchored. The route snaps to a 10px grid (Shift bypasses), magnetises within 6px to sibling segments and card edges, and is clamped out of both endpoint cards (forward edges to the corridor, backward edges to any x outside both). Double-click resets to automatic routing. A sub-3px press is a click (opens the editor); a real drag is swallowed. The live route is kept in local edge state and committed once on release, so a 100-entity model does not rebuild every edge per move. Geometry is a pure, unit-tested module (edgeRouting.ts); getSmoothStepPath's centerX carries the route. Part B — saved layout. Node positions and edge routes persist per view in a /.mdl/layout.json sidecar (JSON, so it stays out of every *.yaml glob). New server routes GET/PUT/DELETE /api/layout: PUT is atomic, caps the body at 1MB, drops ids not in the model, rejects non-finite/over-long keys (422), and returns 403 under read-only. Layout is never a model mutation — no fingerprint bump, no cache bust, no audit. On first write it creates .mdl/.gitignore inside a git tree so layout.json is ignored. The canvas loads saved positions over auto-layout (new entities, e.g. Copilot's, get an overlap nudge; no re-fit when a layout exists), saves on node-drag / route-commit / re-layout (debounced 800ms), and offers Reset layout in the View menu. The LayoutStore is injected like exec, so the SME/catalog shells pass none and never persist. Isolation (tested): mdl validate, drift, every emitter and /api/export are byte-identical with and without the sidecar; git status is never dirty from it and discard/propose-rollback never delete it (git clean -e). The reverse prune already excludes .mdl/ (regression test added). Tests: edgeRouting (15), RelationshipEdge component (6), layout API + isolation (14), writer-prune guard (1). npm run build, vitest (39), server pytest and ruff all green; VS Code gates unaffected. Verified live: the handle renders on select with an ew-resize cursor and a node PUT round-trips to the sidecar. --- README.md | 12 +- canvas/src/App.tsx | 6 + canvas/src/ModelCanvas.tsx | 229 +++++++++++++++++- canvas/src/RelationshipEdge.test.tsx | 82 +++++++ canvas/src/RelationshipEdge.tsx | 138 ++++++++++- canvas/src/TopBar.tsx | 27 ++- canvas/src/api.ts | 40 +++ canvas/src/edgeRouting.test.ts | 113 +++++++++ canvas/src/edgeRouting.ts | 120 +++++++++ canvas/src/layoutStore.ts | 23 ++ canvas/src/styles.css | 4 + canvas/src/test/setup.ts | 28 +++ canvas/src/types.ts | 26 ++ .../tests/test_writer_prune_windows.py | 11 + packages/server/src/mdl_server/app.py | 48 ++++ packages/server/src/mdl_server/git_api.py | 74 +++++- .../server/src/mdl_server/layout_store.py | 195 +++++++++++++++ ...m-CRUBpPVn.js => ModelDiagram-CrqdkiTB.js} | 2 +- .../mdl_server/static/assets/main-DScWOCuj.js | 2 - .../mdl_server/static/assets/main-lOq9xM1X.js | 2 + .../{sme-Zxw1Myjj.js => sme-BJx0Kpa-.js} | 4 +- .../static/assets/styles-B90OKxCj.js | 23 -- ...tyles-DxhL4SV-.css => styles-DO3eXfyX.css} | 2 +- .../static/assets/styles-SXBmvQqW.js | 23 ++ .../server/src/mdl_server/static/index.html | 6 +- .../server/src/mdl_server/static/sme.html | 6 +- packages/server/tests/test_layout_api.py | 192 +++++++++++++++ ...delith-canvas-edge-drag-and-layout-spec.md | 154 ++++++++++++ 28 files changed, 1530 insertions(+), 62 deletions(-) create mode 100644 canvas/src/RelationshipEdge.test.tsx create mode 100644 canvas/src/edgeRouting.test.ts create mode 100644 canvas/src/edgeRouting.ts create mode 100644 canvas/src/layoutStore.ts create mode 100644 packages/server/src/mdl_server/layout_store.py rename packages/server/src/mdl_server/static/assets/{ModelDiagram-CRUBpPVn.js => ModelDiagram-CrqdkiTB.js} (95%) delete mode 100644 packages/server/src/mdl_server/static/assets/main-DScWOCuj.js create mode 100644 packages/server/src/mdl_server/static/assets/main-lOq9xM1X.js rename packages/server/src/mdl_server/static/assets/{sme-Zxw1Myjj.js => sme-BJx0Kpa-.js} (99%) delete mode 100644 packages/server/src/mdl_server/static/assets/styles-B90OKxCj.js rename packages/server/src/mdl_server/static/assets/{styles-DxhL4SV-.css => styles-DO3eXfyX.css} (60%) create mode 100644 packages/server/src/mdl_server/static/assets/styles-SXBmvQqW.js create mode 100644 packages/server/tests/test_layout_api.py create mode 100644 specs/modelith-canvas-edge-drag-and-layout-spec.md diff --git a/README.md b/README.md index 02b8a02..063a4b3 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,17 @@ all first-class in the model. Relationship lines anchor to the exact columns that join, not to the entity headers, so with composite keys or several relationships between the same pair the diagram still says which columns join which; hovering an attribute highlights the relationships it takes part -in and dims the rest. +in and dims the rest. Select or hover a relationship to get a drag handle on its vertical +segment and slide the line sideways (snapping to a grid and to nearby lines) so a dense +diagram stays readable; double-click the handle to return it to automatic routing. + +**Saved layout.** Card positions and relationship routes are remembered per view in a +`/.mdl/layout.json` sidecar, so reopening the canvas or restarting `mdl serve` +restores your arrangement exactly. Layout is purely visual: it is JSON (never model YAML), +it is **git-ignored by default** (a `.mdl/.gitignore` is created on first save), and it is +invisible to `mdl validate`, drift, `mdl diff`, every emitter and the git status, so it +never shows up in a review, a diff or the generated dbt. "Reset layout" in the View menu +clears a view's saved arrangement. ![The ER canvas with a relationship line running from one entity's foreign-key attribute row to the referenced entity's primary-key row, with crow's-foot cardinality](docs/assets/canvas.png) diff --git a/canvas/src/App.tsx b/canvas/src/App.tsx index 7b475bb..9a927dd 100644 --- a/canvas/src/App.tsx +++ b/canvas/src/App.tsx @@ -8,6 +8,7 @@ import { fetchDiagnostics, fetchModel, gitStatus, + httpLayoutStore, sendCommand, } from "./api"; import { directCapabilities } from "./exec"; @@ -92,6 +93,9 @@ function Canvas() { // The architect canvas writes straight to disk; its capabilities follow the // server's read-only flag exactly. const caps = useMemo(() => directCapabilities(readOnly), [readOnly]); + // The architect canvas persists node positions + edge routes (visual only). The + // SME/catalog shells pass no store, so staged/previewed models never persist. + const layoutStore = useMemo(() => httpLayoutStore(), []); const urlParams = useMemo(() => new URLSearchParams(window.location.search), []); const minimal = urlParams.get("minimal") === "1"; // The preview pane (minimal) opens collapsed so a big warehouse is readable at a glance; @@ -267,6 +271,7 @@ function Canvas() { onToggleCollapse={() => setCollapseDetail((v) => !v)} onFitView={() => canvasRef.current?.fitView()} onRelayout={(mode, dir) => canvasRef.current?.relayout(mode, dir)} + onResetLayout={() => canvasRef.current?.resetLayout()} onRefresh={refresh} readOnly={readOnly} dirty={dirty} @@ -297,6 +302,7 @@ function Canvas() { activeAreas={activeAreas} onError={setToast} handleRef={canvasRef} + layoutStore={layoutStore} /> {!minimal && ( o.x && y < o.y + o.h + GAP && y + h + GAP > o.y; + if (overlap) { + y = o.y + o.h + GAP; // push below the card it hit + moved = true; + } + } + } + return { x, y }; +} + /** Which React Flow handle each end of a relationship anchors to (issue #5). * * Per end: if the relationship maps to an attribute that actually exists on that @@ -66,6 +94,10 @@ export interface ModelCanvasHandle { focusEntity: (id: string) => void; /** Open the New Entity modal — a shell gesture (toolbar button, `n` shortcut). */ newEntity: () => void; + /** Clear the saved layout for the current view and re-run auto-layout. */ + resetLayout: () => void; + /** Restore the positions replaced by the last Re-layout (session undo). */ + undoRelayout: () => void; } export interface ModelCanvasProps { @@ -90,6 +122,9 @@ export interface ModelCanvasProps { /** Surfaced by the shell however it likes (a toast, a banner). */ onError?: (message: string) => void; handleRef?: React.Ref; + /** Persist node positions + edge routes (visual only). Absent on the SME/catalog + * shells, so a staged or previewed model never persists layout. See layoutStore.ts. */ + layoutStore?: LayoutStore; } /** The ER canvas plus its editing surface: the graph, the inspector, and the five @@ -114,12 +149,57 @@ export function ModelCanvas({ activeAreas, onError, handleRef, + layoutStore, }: ModelCanvasProps) { const { fitView, fitBounds, getNodes } = useReactFlow(); const [nodes, setNodes] = useState[]>([]); const [edges, setEdges] = useState[]>([]); const layoutedRef = useRef(false); + // --- saved layout (visual only) ------------------------------------------- + // The view key: "__all__" for the unfiltered canvas, else "sa:" + the sorted + // active-area ids joined with "+". Each view keeps its own arrangement because + // the canvas re-lays-out the visible subset per filter. + const viewKey = useMemo(() => { + const areas = activeAreas && activeAreas.size > 0 ? [...activeAreas].sort() : null; + return areas ? "sa:" + areas.join("+") : "__all__"; + }, [activeAreas]); + // the saved arrangement for the CURRENT view; null until loaded (or when none). + const savedRef = useRef(null); + const [savedTick, setSavedTick] = useState(0); // bump to re-run the derivation after a load + // per-view in-memory cache so switching the filter back is instant and offline. + const loadedViews = useRef>(new Map()); + // Re-layout undo: the positions replaced by the last Re-layout, for a session toast. + const undoRef = useRef | null>(null); + + // Load the saved layout whenever the view changes. A missing store or a failed + // load leaves savedRef null (pure auto-layout). layoutedRef is reset so the + // derivation re-applies positions for the new view. + useEffect(() => { + if (!layoutStore) { + savedRef.current = null; + return; + } + const cached = loadedViews.current.get(viewKey); + if (cached) { + savedRef.current = cached; + layoutedRef.current = false; + setSavedTick((t) => t + 1); + return; + } + let cancelled = false; + layoutStore.load(viewKey).then((layout) => { + if (cancelled) return; + loadedViews.current.set(viewKey, layout); + savedRef.current = layout; + layoutedRef.current = false; + setSavedTick((t) => t + 1); + }); + return () => { + cancelled = true; + }; + }, [layoutStore, viewKey]); + const [alignFor, setAlignFor] = useState(null); const [mapFor, setMapFor] = useState(null); const [newEntityOpen, setNewEntityOpen] = useState(false); @@ -134,9 +214,49 @@ export function ModelCanvas({ // and canvas-local; it feeds the existing dimmed/highlighted computation. const [hoveredAttr, setHoveredAttr] = useState(null); const [hoveredEdge, setHoveredEdge] = useState(null); + // committed edge routes for the current view (relId -> routeX). The live drag + // is kept inside the edge component; this holds only committed values. + const routesRef = useRef>({}); const readOnly = !caps.canEdit; + // --- persist layout (debounced; whole view) ------------------------------- + const saveTimer = useRef | null>(null); + const saveLayout = useCallback(() => { + if (!layoutStore) return; + if (saveTimer.current) clearTimeout(saveTimer.current); + saveTimer.current = setTimeout(() => { + const posNodes: ViewLayout["nodes"] = {}; + for (const n of getNodes()) { + if (!n.hidden) posNodes[n.id] = { x: Math.round(n.position.x), y: Math.round(n.position.y) }; + } + const edgeRoutes: ViewLayout["edges"] = {}; + for (const [relId, routeX] of Object.entries(routesRef.current)) { + edgeRoutes[relId] = { routeX: Math.round(routeX) }; + } + const layout: ViewLayout = { nodes: posNodes, edges: edgeRoutes }; + loadedViews.current.set(viewKey, layout); + savedRef.current = layout; + layoutStore.save(viewKey, layout); + }, 800); + }, [layoutStore, getNodes, viewKey]); + + // Commit a dragged edge route (or null to reset to automatic). Updates the edge + // data in place (identity-preserving, so only that one edge re-renders) and saves. + const onRouteCommit = useCallback( + (relId: string, routeX: number | null) => { + if (routeX == null) delete routesRef.current[relId]; + else routesRef.current[relId] = routeX; + setEdges((prev) => + prev.map((e) => + e.id === relId ? { ...e, data: { ...e.data!, routeX: routeX ?? undefined } } : e, + ), + ); + saveLayout(); + }, + [saveLayout], + ); + const saColors = useMemo(() => { const m = new Map(); doc.subject_areas.forEach((sa, i) => m.set(sa.id, PALETTE[i % PALETTE.length])); @@ -278,6 +398,14 @@ export function ModelCanvas({ }; }); + // seed committed routes for this view from the saved layout + const saved = savedRef.current; + routesRef.current = {}; + if (saved) { + for (const [relId, r] of Object.entries(saved.edges)) routesRef.current[relId] = r.routeX; + } + + let mergedForCards: Node[] = newNodes; setNodes((prev) => { const posById = new Map(prev.map((n) => [n.id, n.position])); const known = newNodes.every((n) => posById.has(n.id)); @@ -286,21 +414,63 @@ export function ModelCanvas({ // Otherwise keep known positions so a re-derivation (search, selection) doesn't reflow. const filtering = (activeAreas?.size ?? 0) > 0; if (layoutedRef.current && known && prev.length >= newNodes.length && !filtering) { - return newNodes.map((n) => ({ ...n, position: posById.get(n.id) ?? n.position })); + const kept = newNodes.map((n) => ({ ...n, position: posById.get(n.id) ?? n.position })); + mergedForCards = kept; + return kept; } const toLay = filtering ? newNodes.filter((n) => !n.hidden) : newNodes; const laid = layoutGraph(toLay, newEdges, entityIndex, "auto", areaByEntity); const laidPos = new Map(laid.map((n) => [n.id, n.position])); + // Prefer a SAVED position over the auto-layout result. Entities without a saved + // position (new ones, e.g. just created via MCP) keep auto-layout, then get a + // simple overlap nudge so they don't land on top of an existing card. + const savedPos = saved?.nodes ?? {}; + const hasSaved = Object.keys(savedPos).length > 0; + const occupied: { x: number; y: number; w: number; h: number }[] = []; const merged = newNodes.map((n) => { + const sp = savedPos[n.id]; + if (sp) { + const pos = { x: sp.x, y: sp.y }; + occupied.push({ x: pos.x, y: pos.y, w: NODE_WIDTH, h: nodeHeight(n.data.entity) }); + return { ...n, position: pos }; + } if (laidPos.has(n.id)) return { ...n, position: laidPos.get(n.id)! }; - // a hidden node keeps its prior position (it isn't shown, so it doesn't matter) return posById.has(n.id) && layoutedRef.current ? { ...n, position: posById.get(n.id)! } : n; }); + // nudge auto-placed cards off any saved card they overlap + if (hasSaved) { + for (const n of merged) { + if (savedPos[n.id] || n.hidden) continue; + n.position = nudgeOffOverlaps(n.position, nodeHeight(n.data.entity), occupied); + occupied.push({ x: n.position.x, y: n.position.y, w: NODE_WIDTH, h: nodeHeight(n.data.entity) }); + } + } layoutedRef.current = true; - requestAnimationFrame(() => fitView({ padding: 0.15, duration: 300 })); + // Only auto-fit when there is NO saved layout — a restored arrangement must not + // be re-zoomed away. + if (!hasSaved) requestAnimationFrame(() => fitView({ padding: 0.15, duration: 300 })); + mergedForCards = merged; return merged; }); - setEdges(newEdges); + + // card rectangles (flow coords) so each edge can clamp its route out of its + // endpoint cards; attached to edge data to avoid a per-move node-store read. + const cardById = new Map(); + for (const n of mergedForCards) { + cardById.set(n.id, { left: n.position.x, right: n.position.x + NODE_WIDTH }); + } + setEdges( + newEdges.map((e) => ({ + ...e, + data: { + ...e.data!, + routeX: routesRef.current[e.id], + onRouteChange: layoutStore ? onRouteCommit : undefined, + sourceCard: cardById.get(e.source), + targetCard: cardById.get(e.target), + }, + })), + ); }, [ doc, query, @@ -316,6 +486,9 @@ export function ModelCanvas({ activeAreas, endpointAttrsByEntity, fitView, + layoutStore, + onRouteCommit, + savedTick, ]); // --- lightweight hover overlay (issue #5) --------------------------------------- @@ -449,12 +622,43 @@ export function ModelCanvas({ const relayout = useCallback( (mode: LayoutMode = "auto", dir: LayoutDir = "LR") => { + // Re-layout is destructive of manual placement; remember the positions it + // replaces so the session can offer Undo, then persist the new arrangement. + undoRef.current = Object.fromEntries( + getNodes().map((n) => [n.id, { x: n.position.x, y: n.position.y }]), + ); setNodes((prev) => layoutGraph(prev, edges, entityIndex, mode, areaByEntity, dir)); requestAnimationFrame(() => fitView({ padding: 0.15, duration: 300 })); + saveLayout(); }, - [edges, entityIndex, areaByEntity, fitView], + [edges, entityIndex, areaByEntity, fitView, getNodes, saveLayout], ); + const undoRelayout = useCallback(() => { + const prevPos = undoRef.current; + if (!prevPos) return; + setNodes((prev) => + prev.map((n) => (prevPos[n.id] ? { ...n, position: prevPos[n.id] } : n)), + ); + undoRef.current = null; + saveLayout(); + }, [saveLayout]); + + const resetLayout = useCallback(() => { + layoutStore?.reset(viewKey); + loadedViews.current.delete(viewKey); + savedRef.current = null; + routesRef.current = {}; + layoutedRef.current = false; + // re-run auto-layout for the current view and drop all edge routes + setEdges((prev) => prev.map((e) => ({ ...e, data: { ...e.data!, routeX: undefined } }))); + setNodes((prev) => { + const laid = layoutGraph(prev, edges, entityIndex, "auto", areaByEntity); + requestAnimationFrame(() => fitView({ padding: 0.15, duration: 300 })); + return laid; + }); + }, [layoutStore, viewKey, edges, entityIndex, areaByEntity, fitView]); + const focusEntity = useCallback( (id: string) => { onSelect(id); @@ -474,8 +678,10 @@ export function ModelCanvas({ fitView: () => fitView({ padding: 0.15, duration: 300 }), focusEntity, newEntity: () => setNewEntityOpen(true), + resetLayout, + undoRelayout, }), - [relayout, fitView, focusEntity], + [relayout, fitView, focusEntity, resetLayout, undoRelayout], ); const onConnect = useCallback( @@ -528,9 +734,10 @@ export function ModelCanvas({ onSelect(null); setRelEdit(null); }} - onNodeDragStop={(_, n) => - setNodes((prev) => prev.map((p) => (p.id === n.id ? { ...p, position: n.position } : p))) - } + onNodeDragStop={(_, n) => { + setNodes((prev) => prev.map((p) => (p.id === n.id ? { ...p, position: n.position } : p))); + saveLayout(); + }} onConnect={onConnect} nodesConnectable={!readOnly} minZoom={0.05} diff --git a/canvas/src/RelationshipEdge.test.tsx b/canvas/src/RelationshipEdge.test.tsx new file mode 100644 index 0000000..107a4ac --- /dev/null +++ b/canvas/src/RelationshipEdge.test.tsx @@ -0,0 +1,82 @@ +import { fireEvent, render } from "@testing-library/react"; +import { Position, ReactFlowProvider, type EdgeProps } from "reactflow"; +import { describe, expect, it, vi } from "vitest"; +import { RelationshipEdge, type RelationshipEdgeData } from "./RelationshipEdge"; +import type { Relationship } from "./types"; + +const REL: Relationship = { + id: "01REL00000000000000000000", + name: "ae_for_subject", + from: { entity: "01FROM0000000000000000000", attributes: [] }, + to: { entity: "01TO000000000000000000000", attributes: [] }, + cardinality: "many_to_one", + identifying: false, + optionality: "mandatory", + verb_phrase: "experiences", +}; + +/** Render the edge component directly with EdgeProps, inside an svg + provider (so + * useReactFlow resolves). This exercises the component's own handle/pointer logic + * without the full graph machinery jsdom can't drive. */ +function renderEdge(data: Partial, selected = false) { + const props = { + id: REL.id, + source: REL.from.entity, + target: REL.to.entity, + sourceX: 0, + sourceY: 0, + targetX: 400, + targetY: 0, + sourcePosition: Position.Right, + targetPosition: Position.Left, + selected, + data: { relationship: REL, dimmed: false, ...data }, + } as unknown as EdgeProps; + return render( + + + + + , + ); +} + +describe("RelationshipEdge drag handle", () => { + it("shows the grip when selected and draggable", () => { + const { container } = renderEdge({ onRouteChange: vi.fn() }, true); + expect(container.querySelector(".rel-handle")).not.toBeNull(); + expect(container.querySelector(".rel-grip")).not.toBeNull(); + }); + + it("hides the grip when not selected", () => { + const { container } = renderEdge({ onRouteChange: vi.fn() }, false); + expect(container.querySelector(".rel-handle")).toBeNull(); + }); + + it("is not draggable (no handle) when onRouteChange is absent", () => { + const { container } = renderEdge({}, true); + expect(container.querySelector(".rel-handle")).toBeNull(); + }); + + it("double-clicking the handle resets routing (onRouteChange with null)", () => { + const onRouteChange = vi.fn(); + const { container } = renderEdge({ onRouteChange, routeX: 200 }, true); + fireEvent.doubleClick(container.querySelector(".rel-handle")!); + expect(onRouteChange).toHaveBeenCalledWith(REL.id, null); + }); + + it("a plain pointerdown without movement does not commit a route", () => { + const onRouteChange = vi.fn(); + const { container } = renderEdge({ onRouteChange }, true); + const handle = container.querySelector(".rel-handle")!; + fireEvent.pointerDown(handle, { button: 0, clientX: 100, clientY: 100, pointerId: 1 }); + fireEvent.pointerUp(window, { clientX: 100, clientY: 100, pointerId: 1 }); + expect(onRouteChange).not.toHaveBeenCalled(); + }); + + it("positions the label at routeX when a route is set", () => { + const { container } = renderEdge({ onRouteChange: vi.fn(), routeX: 250 }, true); + const label = container.querySelector(".rel-label"); + expect(label?.getAttribute("x")).toBe("250"); + }); +}); diff --git a/canvas/src/RelationshipEdge.tsx b/canvas/src/RelationshipEdge.tsx index bce96fe..36ef6e2 100644 --- a/canvas/src/RelationshipEdge.tsx +++ b/canvas/src/RelationshipEdge.tsx @@ -1,5 +1,5 @@ -import { memo } from "react"; -import { getSmoothStepPath, Position, type EdgeProps } from "reactflow"; +import { memo, useCallback, useRef, useState } from "react"; +import { getSmoothStepPath, Position, useReactFlow, type EdgeProps } from "reactflow"; import type { Relationship } from "./types"; export interface RelationshipEdgeData { @@ -9,8 +9,22 @@ export interface RelationshipEdgeData { memberCount?: number; /** hover the line -> the canvas highlights both endpoint attribute rows */ onHoverEdge?: (relId: string | null) => void; + /** the x of the vertical segment, in flow coords. Undefined = automatic routing. */ + routeX?: number; + /** commit a new route (or null to reset to automatic). Absent = not draggable. */ + onRouteChange?: (relId: string, routeX: number | null) => void; + /** endpoint card rectangles (flow coords), for clamping the route out of cards */ + sourceCard?: { left: number; right: number }; + targetCard?: { left: number; right: number }; } +// Keep in sync with edgeRouting.ts; imported there, inlined here to avoid a cycle +// of concerns (this file owns the pointer handling, edgeRouting owns the math). +import { adjustRouteX } from "./edgeRouting"; + +/** a press that moves less than this many px counts as a click, not a drag */ +const CLICK_SLOP = 3; + /** * Crow's-foot notation (erwin-style), drawn as small glyph groups at each end of * a smooth-step path. Layout is left-to-right with ports on node sides, so edge @@ -21,6 +35,11 @@ export interface RelationshipEdgeData { * * identifying (IDEF1X): the parent's key is part of the child's identity, drawn * as a SOLID line; non-identifying is DASHED. erwin draws the same distinction. + * + * The vertical segment is draggable: its x (`routeX`) is the only free degree of + * freedom (ports are on the left/right of a card only). A handle appears on hover + * or select; dragging slides the segment while both ends stay glued to their + * attribute handles. See edgeRouting.ts for the snap/magnet/clamp geometry. */ export const RelationshipEdge = memo(function RelationshipEdge({ id, @@ -33,7 +52,20 @@ export const RelationshipEdge = memo(function RelationshipEdge({ data, selected, }: EdgeProps) { - const [path] = getSmoothStepPath({ + const { screenToFlowPosition } = useReactFlow(); + // while dragging, the live route is kept here so we do NOT rebuild all edges + // per move; the committed value rides in data.routeX. + const [dragX, setDragX] = useState(null); + const draggingRef = useRef(false); + const movedRef = useRef(0); + + const onRouteChange = data?.onRouteChange; + const draggable = !!onRouteChange; + + // effective vertical-segment x: live drag wins, else the committed route. + const routeX = dragX ?? data?.routeX; + + const [path, autoLabelX, autoLabelY] = getSmoothStepPath({ sourceX, sourceY, sourcePosition, @@ -41,6 +73,7 @@ export const RelationshipEdge = memo(function RelationshipEdge({ targetY, targetPosition, borderRadius: 10, + ...(routeX != null ? { centerX: routeX } : {}), }); const rel = data?.relationship; @@ -57,6 +90,82 @@ export const RelationshipEdge = memo(function RelationshipEdge({ const composite = (data?.memberCount ?? 0) > 1; const onHover = data?.onHoverEdge; + // handle sits at the mid-height of the vertical segment, at its x. + const handleX = routeX ?? (sourceX + targetX) / 2; + const handleY = (sourceY + targetY) / 2; + // labels follow the vertical segment once a route is set, else the smooth-step's + // own label point. + const labelX = routeX != null ? routeX : autoLabelX; + const labelY = routeX != null ? handleY : autoLabelY; + + const commit = useCallback( + (x: number | null) => onRouteChange && rel && onRouteChange(rel.id, x), + [onRouteChange, rel], + ); + + const onPointerDown = useCallback( + (e: React.PointerEvent) => { + if (!draggable || e.button !== 0) return; + e.stopPropagation(); + (e.target as Element).setPointerCapture?.(e.pointerId); + draggingRef.current = true; + movedRef.current = 0; + const start = screenToFlowPosition({ x: e.clientX, y: e.clientY }); + const startX = start.x; + let raf = 0; + let latest = routeX ?? handleX; + + const onMove = (ev: PointerEvent) => { + const p = screenToFlowPosition({ x: ev.clientX, y: ev.clientY }); + movedRef.current = Math.max(movedRef.current, Math.abs(p.x - startX)); + latest = adjustRouteX(p.x, { + shift: ev.shiftKey, + source: data?.sourceCard ?? { left: sourceX, right: sourceX }, + target: data?.targetCard ?? { left: targetX, right: targetX }, + }); + if (!raf) { + raf = requestAnimationFrame(() => { + raf = 0; + setDragX(latest); + }); + } + }; + const onUp = () => { + window.removeEventListener("pointermove", onMove); + window.removeEventListener("pointerup", onUp); + if (raf) cancelAnimationFrame(raf); + draggingRef.current = false; + setDragX(null); + if (movedRef.current >= CLICK_SLOP) commit(latest); + // a sub-slop press is a click; swallow the click that follows a real drag + }; + window.addEventListener("pointermove", onMove); + window.addEventListener("pointerup", onUp); + }, + [draggable, screenToFlowPosition, routeX, handleX, data, sourceX, targetX, commit], + ); + + // Swallow the click that fires right after a real drag, so it does not open the + // edit modal (a true click — sub-slop press — is allowed through). + const onClickCapture = useCallback( + (e: React.MouseEvent) => { + if (movedRef.current >= CLICK_SLOP) { + e.stopPropagation(); + movedRef.current = 0; + } + }, + [], + ); + + const onDoubleClick = useCallback( + (e: React.MouseEvent) => { + if (!draggable) return; + e.stopPropagation(); + commit(null); // reset to automatic routing + }, + [draggable, commit], + ); + return ( + {/* drag handle on the vertical segment — only when draggable and hovered/selected */} + {draggable && (selected || dragX != null) && ( + + {/* a fat transparent target around the grip for easy grabbing */} + + + + )} {(selected || composite) && rel && ( - + {/* erwin verb phrase reads " "; fall back to the name */} {selected ? rel.verb_phrase || rel.name : ""} {composite ? `${selected ? " " : ""}(${data!.memberCount})` : ""} diff --git a/canvas/src/TopBar.tsx b/canvas/src/TopBar.tsx index 628d486..8affe51 100644 --- a/canvas/src/TopBar.tsx +++ b/canvas/src/TopBar.tsx @@ -36,6 +36,7 @@ export function TopBar({ onToggleCollapse, onFitView, onRelayout, + onResetLayout, onRefresh, readOnly, dirty, @@ -61,6 +62,8 @@ export function TopBar({ onToggleCollapse: () => void; onFitView: () => void; onRelayout: (mode?: LayoutMode, dir?: LayoutDir) => void; + /** clear the saved layout for the current view and re-run auto-layout */ + onResetLayout?: () => void; onRefresh: () => void; readOnly: boolean; dirty: boolean; @@ -215,7 +218,7 @@ export function TopBar({ > - + + {onReset && ( + <> +
+ + + )}
)} diff --git a/canvas/src/api.ts b/canvas/src/api.ts index ce123c3..655572a 100644 --- a/canvas/src/api.ts +++ b/canvas/src/api.ts @@ -18,7 +18,10 @@ import type { StackDoc, TermCard, TermDetail, + LayoutDoc, + ViewLayout, } from "./types"; +import type { LayoutStore } from "./layoutStore"; /** API base prefix. The same canvas bundle is served both at `/` (private `mdl serve`) * and under `/view//` (a catalog-materialised model). When mounted under `/view/`, @@ -253,3 +256,40 @@ export const expandSubjectArea = ( id: string, body: { seeds: string[]; direction: string; levels: number }, ) => post(`/api/glossary/subject-area/${id}/expand`, body); + +/** + * HTTP-backed layout store (the architect app). Saves are fire-and-forget: a + * failure (e.g. 403 under read-only) resolves without surfacing an error, so the + * canvas falls back to session-only layout. Load tolerates a missing/empty file. + */ +export function httpLayoutStore(): LayoutStore { + return { + async load(view: string): Promise { + try { + const d = await get(`/api/layout?view=${encodeURIComponent(view)}`); + return { nodes: d.nodes ?? {}, edges: d.edges ?? {} }; + } catch { + return { nodes: {}, edges: {} }; + } + }, + async save(view: string, layout: ViewLayout): Promise { + try { + await fetch(url("/api/layout"), { + method: "PUT", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ view, nodes: layout.nodes, edges: layout.edges }), + }); + } catch { + // session-only: a save failure is never an error to the user + } + }, + async reset(view?: string): Promise { + try { + const q = view ? `?view=${encodeURIComponent(view)}` : ""; + await fetch(url(`/api/layout${q}`), { method: "DELETE" }); + } catch { + // ignore + } + }, + }; +} diff --git a/canvas/src/edgeRouting.test.ts b/canvas/src/edgeRouting.test.ts new file mode 100644 index 0000000..4c7a2f1 --- /dev/null +++ b/canvas/src/edgeRouting.test.ts @@ -0,0 +1,113 @@ +import { describe, expect, it } from "vitest"; +import { + CARD_MARGIN, + GRID, + MAGNET, + adjustRouteX, + clampRouteX, + magnetise, + snapRouteX, + type CardX, +} from "./edgeRouting"; + +describe("snapRouteX", () => { + it("snaps to the grid", () => { + expect(snapRouteX(483, false)).toBe(480); + expect(snapRouteX(486, false)).toBe(490); + expect(snapRouteX(485, false)).toBe(490); // round half up + }); + it("is a no-op when shift is held", () => { + expect(snapRouteX(483, true)).toBe(483); + expect(snapRouteX(486.4, true)).toBe(486.4); + }); + it("grid is 10", () => { + expect(GRID).toBe(10); + }); +}); + +describe("magnetise", () => { + it("snaps to another segment within MAGNET px", () => { + expect(magnetise(484, [480], [])).toBe(480); // 4px away -> snap + }); + it("does not snap when outside MAGNET px", () => { + expect(magnetise(487, [480], [])).toBe(487); // 7px away -> keep + }); + it("snaps to a card edge plus margin", () => { + const card: CardX = { left: 100, right: 364 }; + // right edge + margin = 388; x=390 is 2px away + expect(magnetise(390, [], [card])).toBe(364 + CARD_MARGIN); + // left edge - margin = 76; x=74 is 2px away + expect(magnetise(74, [], [card])).toBe(100 - CARD_MARGIN); + }); + it("the closest candidate wins", () => { + expect(magnetise(483, [480, 485], [])).toBe(485); // 2px vs 3px + }); + it("MAGNET is 6", () => { + expect(MAGNET).toBe(6); + }); +}); + +describe("clampRouteX", () => { + // forward: source entirely left of target with a wide corridor + const sFwd: CardX = { left: 0, right: 264 }; + const tFwd: CardX = { left: 600, right: 864 }; + + it("forward edge keeps the run in the corridor", () => { + // corridor is [264+24, 600-24] = [288, 576] + expect(clampRouteX(400, sFwd, tFwd)).toBe(400); // already inside + expect(clampRouteX(100, sFwd, tFwd)).toBe(288); // inside source -> clamp lo + expect(clampRouteX(700, sFwd, tFwd)).toBe(576); // inside target -> clamp hi + expect(clampRouteX(280, sFwd, tFwd)).toBe(288); // in source margin -> lo + }); + + it("backward edge allows any x outside both cards", () => { + // target left of source + const s: CardX = { left: 600, right: 864 }; + const t: CardX = { left: 0, right: 264 }; + expect(clampRouteX(950, s, t)).toBe(950); // right of both -> allowed + expect(clampRouteX(-50, s, t)).toBe(-50); // left of both -> allowed + expect(clampRouteX(400, s, t)).toBe(400); // between the cards -> allowed + }); + + it("backward edge pushes an x that landed inside a card to its outer edge", () => { + const s: CardX = { left: 600, right: 864 }; + const t: CardX = { left: 0, right: 264 }; + // x=800 is inside source(600..864); nearer right edge (64 vs 200) -> 864+24 + expect(clampRouteX(800, s, t)).toBe(864 + CARD_MARGIN); + // x=620 is inside source; nearer left edge (20 vs 244) -> 600-24 + expect(clampRouteX(620, s, t)).toBe(600 - CARD_MARGIN); + // x=100 is inside target(0..264); nearer right edge (164 vs 100... left) -> 0-24 + expect(clampRouteX(100, s, t)).toBe(0 - CARD_MARGIN); + }); + + it("no corridor (cards too close) falls back to outside-both", () => { + const s: CardX = { left: 0, right: 264 }; + const t: CardX = { left: 280, right: 544 }; // gap 16 < 2*margin + // x inside the tiny gap but inside neither card is allowed + expect(clampRouteX(272, s, t)).toBe(272); + // x inside source -> nearest outer edge + expect(clampRouteX(10, s, t)).toBe(0 - CARD_MARGIN); + }); +}); + +describe("adjustRouteX", () => { + const source: CardX = { left: 0, right: 264 }; + const target: CardX = { left: 600, right: 864 }; + + it("snaps, magnetises, then clamps", () => { + // 403 -> snap 400 -> no magnet -> inside corridor -> 400 + expect(adjustRouteX(403, { shift: false, source, target })).toBe(400); + }); + + it("clamp still applies even with shift (free placement, but legal)", () => { + // shift bypasses snap+magnet but a drop inside the source card is still illegal + expect(adjustRouteX(100, { shift: true, source, target })).toBe(288); + }); + + it("magnetises to a sibling segment when close", () => { + // 483 -> snap 480 -> sibling at 490 is 10px away, no magnet; sibling at 482 snaps + expect(adjustRouteX(483, { shift: false, source, target, otherSegmentXs: [478] })).toBe( + 478, + ); + }); +}); diff --git a/canvas/src/edgeRouting.ts b/canvas/src/edgeRouting.ts new file mode 100644 index 0000000..3ecac30 --- /dev/null +++ b/canvas/src/edgeRouting.ts @@ -0,0 +1,120 @@ +/** + * Pure geometry for draggable relationship edges (no React, no reactflow). + * + * An edge's only adjustable degree of freedom is the x of its vertical segment + * (`routeX`) — the canvas has ports on the left and right of a card only + * (EntityNode.tsx), so there is nothing to drag but that one vertical run. + * + * All coordinates are flow coordinates. These helpers are unit-tested directly + * (edgeRouting.test.ts); keep them free of side effects so they stay testable. + */ + +/** Grid step for snapping the vertical segment. */ +export const GRID = 10; +/** A segment within this many px of another segment / card edge magnetises to it. */ +export const MAGNET = 6; +/** Keep the vertical segment at least this far outside a card's horizontal extent. */ +export const CARD_MARGIN = 24; + +/** A card's horizontal extent in flow coordinates. */ +export interface CardX { + left: number; + right: number; +} + +/** Snap `x` to the GRID, unless `shift` is held (free placement). */ +export function snapRouteX(x: number, shift: boolean): number { + if (shift) return x; + return Math.round(x / GRID) * GRID; +} + +/** + * Magnetise `x` to the nearest candidate within MAGNET px: another edge's + * segment x, or a card's left/right edge (± CARD_MARGIN so aligned lines sit + * just off the card, matching the clamp). Returns the snapped x, or `x` if + * nothing is close enough. The closest candidate wins. + */ +export function magnetise(x: number, segmentXs: number[], cards: CardX[]): number { + const candidates: number[] = [...segmentXs]; + for (const c of cards) { + candidates.push(c.left - CARD_MARGIN, c.right + CARD_MARGIN); + } + let best = x; + let bestDist = MAGNET; // only snap when strictly within MAGNET + for (const cand of candidates) { + const d = Math.abs(cand - x); + if (d < bestDist) { + bestDist = d; + best = cand; + } + } + return best; +} + +/** True when `x` falls within a card's horizontal extent (its forbidden zone). */ +function insideCard(x: number, card: CardX): boolean { + return x > card.left && x < card.right; +} + +/** + * Keep the vertical segment out of both endpoint cards' horizontal extents. + * + * - Forward edge (source left of target) with room between the cards: clamp to + * `[sourceRight + CARD_MARGIN, targetLeft - CARD_MARGIN]` so the run sits in + * the corridor between them. + * - Otherwise (backward edge, or overlapping cards with no corridor): allow any + * x that is outside BOTH cards; if the proposed x landed inside a card, push + * it to that card's nearest outer edge ± CARD_MARGIN. + * + * `source`/`target` are the two endpoint cards. Returns a safe x. + */ +export function clampRouteX(x: number, source: CardX, target: CardX): number { + const forward = source.right <= target.left; + if (forward) { + const lo = source.right + CARD_MARGIN; + const hi = target.left - CARD_MARGIN; + if (lo <= hi) { + // There is a corridor between the cards — keep the run inside it. + return Math.min(Math.max(x, lo), hi); + } + // Cards too close for a corridor; fall through to the outside-both rule. + } + // Backward edge, or no corridor: any x outside both cards is allowed. + if (!insideCard(x, source) && !insideCard(x, target)) return x; + // Landed inside a card — move to the nearest outer edge of whichever card + // contains it (prefer the one it is actually inside). + const offender = insideCard(x, source) ? source : target; + const toLeft = x - (offender.left - CARD_MARGIN); + const toRight = offender.right + CARD_MARGIN - x; + const candidate = + toRight <= toLeft ? offender.right + CARD_MARGIN : offender.left - CARD_MARGIN; + // The nudged candidate might now sit inside the OTHER card; if so, bounce to + // that card's far side instead. + const other = offender === source ? target : source; + if (insideCard(candidate, other)) { + return candidate <= other.left ? other.left - CARD_MARGIN : other.right + CARD_MARGIN; + } + return candidate; +} + +/** + * Full adjustment applied while dragging and on release: snap to grid (unless + * Shift), magnetise to nearby segments/cards, then clamp out of the endpoint + * cards. Clamp runs last so the result is always legal. + */ +export function adjustRouteX( + x: number, + opts: { + shift: boolean; + source: CardX; + target: CardX; + otherSegmentXs?: number[]; + otherCards?: CardX[]; + }, +): number { + const snapped = snapRouteX(x, opts.shift); + const magnetised = opts.shift + ? snapped + : magnetise(snapped, opts.otherSegmentXs ?? [], opts.otherCards ?? []); + return clampRouteX(magnetised, opts.source, opts.target); +} diff --git a/canvas/src/layoutStore.ts b/canvas/src/layoutStore.ts new file mode 100644 index 0000000..8ffd4d2 --- /dev/null +++ b/canvas/src/layoutStore.ts @@ -0,0 +1,23 @@ +import type { ViewLayout } from "./types"; + +/** + * The layout-persistence seam, injected the same way `exec` is (see exec.ts). + * + * The canvas never calls the API directly: it is handed a `LayoutStore` and does + * not know or care whether it is HTTP-backed (the architect app) or absent (the + * SME / catalog shells, which never persist a staged or previewed model's layout). + * + * Layout is VISUAL only. A `save` that fails (e.g. 403 under read-only) must be a + * quiet no-op from the canvas's point of view — session-only layout, never an error. + */ +export interface LayoutStore { + /** Load one view's saved arrangement; empty maps when absent. */ + load(view: string): Promise; + /** Persist one whole view. Fire-and-forget; resolves/rejects are the store's concern. */ + save(view: string, layout: ViewLayout): Promise; + /** Remove one view, or (no arg) all saved layout. */ + reset(view?: string): Promise; +} + +/** An empty arrangement — what `load` returns when nothing is saved. */ +export const EMPTY_LAYOUT: ViewLayout = { nodes: {}, edges: {} }; diff --git a/canvas/src/styles.css b/canvas/src/styles.css index dd31906..d47b9e4 100644 --- a/canvas/src/styles.css +++ b/canvas/src/styles.css @@ -255,6 +255,10 @@ body { font-family: var(--font); background: var(--bg); color: var(--text); } .rel-edge:hover .rel-glyph, .rel-edge.selected .rel-glyph { stroke: var(--accent); } .rel-edge.dimmed { opacity: 0.12; } .rel-label { fill: var(--text); font-size: 11px; text-anchor: middle; paint-order: stroke; stroke: var(--bg); stroke-width: 4px; } +/* draggable edge route handle (grip on the vertical segment) */ +.rel-handle .rel-grip { fill: var(--accent); stroke: var(--bg); stroke-width: 1; opacity: 0.9; } +.rel-handle:hover .rel-grip { opacity: 1; } +.layout-menu-sep { height: 1px; margin: 4px 0; background: var(--border); } /* ---------- detail panel ---------- */ .detail-panel { diff --git a/canvas/src/test/setup.ts b/canvas/src/test/setup.ts index f149f27..26e6381 100644 --- a/canvas/src/test/setup.ts +++ b/canvas/src/test/setup.ts @@ -1 +1,29 @@ import "@testing-library/jest-dom/vitest"; + +// jsdom lacks APIs React Flow touches at mount. Shim the minimum so an edge/canvas +// component can render in a test (the geometry itself is unit-tested separately). +class ResizeObserverStub { + observe() {} + unobserve() {} + disconnect() {} +} +if (!("ResizeObserver" in globalThis)) { + (globalThis as unknown as { ResizeObserver: unknown }).ResizeObserver = ResizeObserverStub; +} + +if (!(Element.prototype as unknown as { hasPointerCapture?: unknown }).hasPointerCapture) { + Element.prototype.hasPointerCapture = () => false; + Element.prototype.setPointerCapture = () => {}; + Element.prototype.releasePointerCapture = () => {}; +} + +// React Flow reads getBoundingClientRect for the flow<->screen transform; jsdom +// returns zeros, which is fine for our assertions (we test callback wiring, not pixels). +if (!(globalThis as unknown as { DOMMatrixReadOnly?: unknown }).DOMMatrixReadOnly) { + class DOMMatrixReadOnlyStub { + m22 = 1; + constructor(_t?: string) {} + } + (globalThis as unknown as { DOMMatrixReadOnly: unknown }).DOMMatrixReadOnly = + DOMMatrixReadOnlyStub; +} diff --git a/canvas/src/types.ts b/canvas/src/types.ts index 5a7d1dd..00e0543 100644 --- a/canvas/src/types.ts +++ b/canvas/src/types.ts @@ -479,3 +479,29 @@ export interface ExpandDoc { added: string[]; error?: string; } + +// --- visual layout (node positions + edge routes), persisted per canvas view -- + +/** One saved node position (flow coordinates). */ +export interface NodePos { + x: number; + y: number; +} + +/** One saved edge route: the x of its draggable vertical segment. */ +export interface EdgeRoute { + routeX: number; +} + +/** One view's saved arrangement. `__all__` is the unfiltered canvas; a filtered + * view is keyed `sa:` + the sorted active-area ids joined with `+`. */ +export interface ViewLayout { + nodes: Record; + edges: Record; +} + +/** The `GET /api/layout?view=` response. */ +export interface LayoutDoc extends ViewLayout { + version: number; + view: string; +} diff --git a/packages/reverse/tests/test_writer_prune_windows.py b/packages/reverse/tests/test_writer_prune_windows.py index a2168a2..99179a3 100644 --- a/packages/reverse/tests/test_writer_prune_windows.py +++ b/packages/reverse/tests/test_writer_prune_windows.py @@ -27,6 +27,17 @@ def test_write_model_keeps_every_file_it_wrote(tmp_path): assert len(files) == 52, "write_model must leave all 52 entity files on disk" +def test_prune_never_touches_mdl_layout_sidecar(tmp_path): + """The reverse prune only sweeps the owned object dirs; the visual layout + sidecar under .mdl/ must survive a re-reverse. Guards the isolation guarantee.""" + (tmp_path / ".mdl").mkdir(parents=True, exist_ok=True) + layout = tmp_path / ".mdl" / "layout.json" + layout.write_text('{"version": 1, "views": {}}', encoding="utf-8") + write_model(_model(3), tmp_path) # a fresh write that prunes stale files + assert layout.exists(), "re-reverse must not delete .mdl/layout.json" + assert layout.read_text(encoding="utf-8") == '{"version": 1, "views": {}}' + + def test_prune_stale_would_fail_with_naive_separator(tmp_path): """Directly prove the fix: build the prune comparison the OLD way (str with the OS separator) vs the NEW way (as_posix), against a forward-slash `written` set. On a diff --git a/packages/server/src/mdl_server/app.py b/packages/server/src/mdl_server/app.py index 9b12e05..ace6d80 100644 --- a/packages/server/src/mdl_server/app.py +++ b/packages/server/src/mdl_server/app.py @@ -157,6 +157,54 @@ def preview(body: dict) -> JSONResponse: doc["read_only"] = read_only return JSONResponse(doc) + # --- visual layout sidecar (.mdl/layout.json) ---------------------------- + # Node positions + edge routes, per canvas view. VISUAL ONLY: never a model + # mutation — these routes do not go through apply_command, do not bump the + # fingerprint, do not clear the repo cache, and write no audit record. The + # GET is always available (a readable model always returns 200, empty when + # absent); PUT/DELETE are gated under the read_only block below. + + @app.get("/api/layout") + def get_layout(view: str = "__all__") -> JSONResponse: + from mdl_server import layout_store + + return JSONResponse(layout_store.get_view(model_dir, view)) + + @app.put("/api/layout") + def put_layout(body: dict, request: Request) -> JSONResponse: + """Replace one view's node positions + edge routes. 403 under read_only + (the canvas treats that as 'session only', no error). Not a model write: + no fingerprint bump, no cache bust, no audit.""" + from mdl_server import layout_store + + if read_only: + return JSONResponse({"ok": False, "error": "read-only"}, status_code=403) + clen = request.headers.get("content-length") + if clen and clen.isdigit() and int(clen) > layout_store.MAX_BYTES: + return JSONResponse({"ok": False, "error": "layout too large"}, status_code=422) + model = _load().model + try: + layout_store.put_view( + model_dir, + body.get("view") or "", + body.get("nodes"), + body.get("edges"), + entity_ids={e.id for e in model.logical_entities.values()}, + relationship_ids=set(model.relationships), + ) + except layout_store.LayoutError as e: + return JSONResponse({"ok": False, "error": str(e)}, status_code=422) + return JSONResponse({"ok": True}) + + @app.delete("/api/layout") + def delete_layout(view: str | None = None) -> JSONResponse: + from mdl_server import layout_store + + if read_only: + return JSONResponse({"ok": False, "error": "read-only"}, status_code=403) + layout_store.delete_view(model_dir, view) + return JSONResponse({"ok": True}) + # --- ER interchange import/export (Model-tab toolbar) --------------------- # Reads: always available. Export writes nothing; import returns a change list # the client previews and proposes (it does not write the model itself). diff --git a/packages/server/src/mdl_server/git_api.py b/packages/server/src/mdl_server/git_api.py index 9619dc7..4303bf2 100644 --- a/packages/server/src/mdl_server/git_api.py +++ b/packages/server/src/mdl_server/git_api.py @@ -42,6 +42,62 @@ def _git(model_dir: Path, *args: str, timeout: int = 30) -> tuple[int, str]: return proc.returncode, out.strip() +# The visual layout sidecar is not a model change: it must never make the tree +# look "dirty" (which would block propose/commit), and it must never be removed +# on a discard/revert. `git status --porcelain` paths here are model-dir-relative +# (the calls are scoped with `-- .`), so the sidecar shows as `.mdl/layout.json`. +_LAYOUT_REL = ".mdl/layout.json" +# The layout feature also auto-creates .mdl/.gitignore (ignoring layout.json). Until +# a user commits it, it reads as untracked; it is our own isolation artifact, not a +# model change, so filter it too. When the WHOLE .mdl/ dir is new, porcelain collapses +# it to `?? .mdl/` — treat that as layout-only iff the dir holds nothing but these two. +_LAYOUT_ARTIFACTS = frozenset({_LAYOUT_REL, ".mdl/.gitignore"}) + + +def _porcelain_lines(out: str, model_dir: Path | None = None) -> list[str]: + """Non-blank porcelain lines with the layout sidecar (and its auto-created + .gitignore) filtered out. A porcelain line is `XY ` (path at column 3); + a rename is `XY old -> new`. A collapsed `?? .mdl/` is dropped only when the + directory contains nothing but the layout artifacts (so real decisions.yaml / + state changes under .mdl/ still read as dirty).""" + lines: list[str] = [] + for line in out.splitlines(): + if not line.strip(): + continue + path = line[3:].strip() + if " -> " in path: # rename/copy: the destination is what counts + path = path.split(" -> ", 1)[1].strip() + # porcelain may quote paths with odd chars; strip surrounding quotes + if path.startswith('"') and path.endswith('"'): + path = path[1:-1] + if path in _LAYOUT_ARTIFACTS: + continue + if path == ".mdl/" and model_dir is not None and _mdl_only_layout(model_dir): + continue + lines.append(line) + return lines + + +def _mdl_only_layout(model_dir: Path) -> bool: + """True when `.mdl/` holds nothing but the layout artifacts — so a collapsed + `?? .mdl/` is purely layout and can be ignored.""" + mdl = model_dir / ".mdl" + try: + present = {p.name for p in mdl.iterdir()} + except OSError: + return False + return present.issubset({"layout.json", "layout.json.tmp", ".gitignore"}) + + +def _is_dirty(model_dir: Path) -> bool: + """True when the model dir has uncommitted changes OTHER than the layout + sidecar. Mirrors `git status --porcelain -- .` but ignores `.mdl/layout.json`.""" + code, out = _git(model_dir, "status", "--porcelain", "--", ".") + if code != 0: + return False + return bool(_porcelain_lines(out, model_dir)) + + class CommitBody(BaseModel): message: str @@ -632,8 +688,7 @@ def _context_response(model_dir: Path, user: str, *, read_only: bool) -> dict: branch = _current_branch(model_dir) base = _base_branch(model_dir) - code, dirty_out = _git(model_dir, "status", "--porcelain", "--", ".") - dirty = bool(dirty_out.strip()) if code == 0 else False + dirty = _is_dirty(model_dir) # ignores the .mdl/layout.json sidecar has_remote, remote = _git(model_dir, "remote", "get-url", "origin") ahead, behind = (0, 0) if branch and branch != base: @@ -794,9 +849,8 @@ def status() -> JSONResponse: if code != 0: return JSONResponse({"git": False, "dirty": [], "error": out}) dirty = [] - for line in out.splitlines(): - if not line.strip(): - continue + # the .mdl/layout.json sidecar is visual-only; it must never read as dirty + for line in _porcelain_lines(out, model_dir): state, path = line[:2].strip() or "??", line[3:].strip() dirty.append({"state": state, "path": path}) return JSONResponse({"git": True, "dirty": dirty, "clean": not dirty}) @@ -900,7 +954,9 @@ def discard(ident: Identity = Depends(_identity)) -> JSONResponse: return JSONResponse({"ok": False, "error": denied}, status_code=403) # revert tracked edits + remove untracked files, model dir only code1, out1 = _git(model_dir, "checkout", "--", ".") - code2, out2 = _git(model_dir, "clean", "-fd", "--", ".") + # -e keeps the visual layout sidecar: discard reverts the MODEL, not + # the user's canvas arrangement. + code2, out2 = _git(model_dir, "clean", "-fd", "-e", _LAYOUT_REL, "--", ".") ok = code1 == 0 and code2 == 0 _audit("discard", ident, "working-tree", "ok" if ok else "error") return JSONResponse({"ok": ok, "error": None if ok else f"{out1}\n{out2}"}) @@ -966,8 +1022,8 @@ def propose( ) # Refuse to run on a dirty tree — we branch from a clean base. - code, dirty = _git(model_dir, "status", "--porcelain", "--", ".") - if code == 0 and dirty: + # The .mdl/layout.json sidecar does not count as dirty. + if _is_dirty(model_dir): return JSONResponse( { "ok": False, @@ -1002,7 +1058,7 @@ def propose( applied += 1 except CommandError as e: _git(model_dir, "checkout", "--", ".") - _git(model_dir, "clean", "-fd", "--", ".") + _git(model_dir, "clean", "-fd", "-e", _LAYOUT_REL, "--", ".") # a failed propose must be a complete no-op _git(model_dir, "checkout", starting_branch) _git(model_dir, "branch", "-D", branch_name) diff --git a/packages/server/src/mdl_server/layout_store.py b/packages/server/src/mdl_server/layout_store.py new file mode 100644 index 0000000..bebf089 --- /dev/null +++ b/packages/server/src/mdl_server/layout_store.py @@ -0,0 +1,195 @@ +"""Visual layout sidecar — node positions and edge routes, per canvas view. + +Layout is a VISUAL concern only. It must never appear in the model, drift, +validation, exports, diffs, proposals or dbt output. It lives in +`/.mdl/layout.json` — JSON, not YAML, so it stays out of every +`*.yaml` glob (dir_fingerprint, ModelRepo.load, status, the reverse prune) by +construction, and it is git-ignored by default. + +The file is read-modify-write safe: unknown top-level keys and a higher +`version` are preserved, and a corrupt file is treated as empty (logged once) +rather than crashing the server. Writes are atomic (temp file + os.replace). +""" + +from __future__ import annotations + +import json +import logging +import math +import os +from pathlib import Path +from typing import Any + +log = logging.getLogger("mdl.layout") + +LAYOUT_REL = ".mdl/layout.json" +VERSION = 1 +MAX_BYTES = 1_000_000 # 1 MB body cap (enforced by the route; a guard here too) +MAX_KEY_LEN = 64 + +# log a corrupt-file warning at most once per process so a bad file is not noisy +_warned_corrupt: set[str] = set() + + +def _path(model_dir: Path) -> Path: + return model_dir / LAYOUT_REL + + +def _read_doc(model_dir: Path) -> dict[str, Any]: + """The whole layout document, or a fresh empty one. Never raises: a missing + or corrupt file yields an empty doc (the corrupt case is logged once).""" + p = _path(model_dir) + if not p.exists(): + return {"version": VERSION, "views": {}} + try: + doc = json.loads(p.read_text(encoding="utf-8")) + if not isinstance(doc, dict): + raise ValueError("layout.json is not an object") + doc.setdefault("version", VERSION) + if not isinstance(doc.get("views"), dict): + doc["views"] = {} + return doc + except (OSError, ValueError, json.JSONDecodeError) as e: + key = str(p) + if key not in _warned_corrupt: + _warned_corrupt.add(key) + log.warning("ignoring unreadable layout file %s: %s", p, e) + return {"version": VERSION, "views": {}} + + +def _write_doc(model_dir: Path, doc: dict[str, Any]) -> None: + """Write the document atomically with a stable, diff-friendly shape: + sorted keys, 1-space indent, trailing newline.""" + base = model_dir / ".mdl" + base.mkdir(parents=True, exist_ok=True) + target = base / "layout.json" + tmp = base / "layout.json.tmp" + text = json.dumps(doc, indent=1, sort_keys=True) + "\n" + tmp.write_text(text, encoding="utf-8") + os.replace(tmp, target) # atomic within the same directory + + +def get_view(model_dir: Path, view: str) -> dict[str, Any]: + """The one view's maps (empty when absent). Shape: + `{version, view, nodes: {ulid: {x, y}}, edges: {ulid: {routeX}}}`.""" + doc = _read_doc(model_dir) + v = doc.get("views", {}).get(view) or {} + nodes = v.get("nodes") if isinstance(v.get("nodes"), dict) else {} + edges = v.get("edges") if isinstance(v.get("edges"), dict) else {} + return {"version": doc.get("version", VERSION), "view": view, "nodes": nodes, "edges": edges} + + +class LayoutError(ValueError): + """A layout payload the route should reject with 422.""" + + +def _finite(x: Any) -> bool: + return isinstance(x, (int, float)) and not isinstance(x, bool) and math.isfinite(x) + + +def _clean_nodes(nodes: Any, valid_ids: set[str]) -> dict[str, dict[str, int]]: + out: dict[str, dict[str, int]] = {} + if not isinstance(nodes, dict): + return out + for nid, pos in nodes.items(): + if len(nid) > MAX_KEY_LEN: + raise LayoutError(f"node id too long: {nid[:16]}…") + if nid not in valid_ids: + continue # drop dead ids so the file does not accumulate them + if not isinstance(pos, dict) or not _finite(pos.get("x")) or not _finite(pos.get("y")): + raise LayoutError(f"node {nid}: x and y must be finite numbers") + out[nid] = {"x": round(pos["x"]), "y": round(pos["y"])} + return out + + +def _clean_edges(edges: Any, valid_ids: set[str]) -> dict[str, dict[str, int]]: + out: dict[str, dict[str, int]] = {} + if not isinstance(edges, dict): + return out + for eid, route in edges.items(): + if len(eid) > MAX_KEY_LEN: + raise LayoutError(f"edge id too long: {eid[:16]}…") + if eid not in valid_ids: + continue + if not isinstance(route, dict) or not _finite(route.get("routeX")): + raise LayoutError(f"edge {eid}: routeX must be a finite number") + out[eid] = {"routeX": round(route["routeX"])} + return out + + +def put_view( + model_dir: Path, + view: str, + nodes: Any, + edges: Any, + *, + entity_ids: set[str], + relationship_ids: set[str], +) -> None: + """Replace one view. Drops ids not present in the model. Raises LayoutError + (→ 422) on a bad view key, over-long id, or non-finite number.""" + if not view or len(view) > MAX_KEY_LEN: + raise LayoutError("view key missing or too long") + clean_nodes = _clean_nodes(nodes, entity_ids) + clean_edges = _clean_edges(edges, relationship_ids) + doc = _read_doc(model_dir) + doc.setdefault("version", VERSION) + doc.setdefault("views", {}) + doc["views"][view] = {"nodes": clean_nodes, "edges": clean_edges} + _write_doc(model_dir, doc) + _ensure_gitignore(model_dir) + + +def delete_view(model_dir: Path, view: str | None) -> None: + """Remove one view, or the whole file when `view` is None (reset all).""" + p = _path(model_dir) + if view is None: + if p.exists(): + try: + p.unlink() + except OSError as e: # noqa: BLE001 - best effort; never fatal + log.warning("could not remove layout file %s: %s", p, e) + return + doc = _read_doc(model_dir) + if view in doc.get("views", {}): + del doc["views"][view] + _write_doc(model_dir, doc) + + +def _ensure_gitignore(model_dir: Path) -> None: + """On first write, make sure layout.json is git-ignored. Create + `/.mdl/.gitignore` with `layout.json` when it is not already + ignored. Only inside a git work tree, and never beyond creating this file.""" + mdl = model_dir / ".mdl" + gi = mdl / ".gitignore" + if gi.exists(): + try: + if "layout.json" in gi.read_text(encoding="utf-8").splitlines(): + return + except OSError: + return + # a .gitignore exists but does not list layout.json — do not edit the + # user's file beyond appending our one line + try: + with gi.open("a", encoding="utf-8") as f: + f.write("layout.json\n") + except OSError: + pass + return + # no .gitignore yet: only create one if we are inside a git work tree + if not _in_git_tree(model_dir): + return + try: + gi.write_text("layout.json\n", encoding="utf-8") + except OSError: + pass + + +def _in_git_tree(model_dir: Path) -> bool: + """True when `model_dir` sits inside a git work tree (a `.git` exists at or + above it). Cheap walk-up; no subprocess.""" + p = model_dir.resolve() + for d in (p, *p.parents): + if (d / ".git").exists(): + return True + return False diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-CRUBpPVn.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-CrqdkiTB.js similarity index 95% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-CRUBpPVn.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-CrqdkiTB.js index 2d6de82..0c33152 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-CRUBpPVn.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-CrqdkiTB.js @@ -1 +1 @@ -import{r,j as s}from"./client-DOmNpTln.js";import{f as T,u as _,v as O,w as R,E as D,B as P,C as z,x as A}from"./styles-B90OKxCj.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; +import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-SXBmvQqW.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; diff --git a/packages/server/src/mdl_server/static/assets/main-DScWOCuj.js b/packages/server/src/mdl_server/static/assets/main-DScWOCuj.js deleted file mode 100644 index 08556aa..0000000 --- a/packages/server/src/mdl_server/static/assets/main-DScWOCuj.js +++ /dev/null @@ -1,2 +0,0 @@ -import{j as e,r as a,c as ie,R as oe}from"./client-DOmNpTln.js";import{I as le,R as de,P as Y,f as J,a as Z,g as ee,s as he,A as ue,b as xe,M as je,S as pe}from"./styles-B90OKxCj.js";function me(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function l({size:s=16,children:i}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:i})}const fe=s=>e.jsx(l,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),ge=s=>e.jsx(l,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),ye=s=>e.jsxs(l,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),be=s=>e.jsxs(l,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),we=s=>e.jsxs(l,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),ve=s=>e.jsx(l,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Me=s=>e.jsxs(l,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ce=s=>e.jsxs(l,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),Ne=s=>e.jsx(l,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Ee=s=>e.jsxs(l,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),ke=s=>e.jsxs(l,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Se=s=>e.jsxs(l,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Ie=s=>e.jsxs(l,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Le=s=>e.jsxs(l,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),Re=s=>e.jsxs(l,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),Te=s=>e.jsx(l,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),ze=s=>e.jsxs(l,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),De=s=>e.jsx(l,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Be=s=>e.jsx(l,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Fe({doc:s,saColors:i,countByArea:f,activeAreas:d,onSetActive:g,open:v,onClose:y}){const x=s.subject_areas,j=d.size>0,m=c=>g(new Set([c])),M=c=>{const p=new Set(d);p.has(c)?p.delete(c):p.add(c),g(p)},o=f.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(v?" open":""),"aria-hidden":!v,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(ze,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:y,title:"Close","aria-label":"Close drawer",children:e.jsx(De,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:j?`Showing ${d.size} of ${x.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(j?"":" active"),onClick:()=>g(new Set),disabled:!j,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[x.map(c=>{const p=d.has(c.id),D=f.get(c.id)??c.member_count??0;return e.jsxs("div",{className:"sa-row"+(p?" active":""),onClick:()=>m(c.id),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),m(c.id))},title:`Focus ${c.name}`,children:[e.jsx("input",{type:"checkbox",checked:p,onClick:w=>w.stopPropagation(),onChange:()=>M(c.id),"aria-label":`Include ${c.name}`}),e.jsx("span",{className:"sa-chip",style:{background:i.get(c.id)}}),e.jsx("span",{className:"sa-name",children:c.name}),e.jsx("span",{className:"sa-count",children:D})]},c.id)}),o>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:o})]})]})]})}function Pe({doc:s,diagnostics:i,query:f,onQuery:d,onSubmitQuery:g,showTypes:v,onToggleTypes:y,collapseDetail:x,onToggleCollapse:j,onFitView:m,onRelayout:M,onRefresh:o,readOnly:c,dirty:p,panelTab:D,onPanelTab:w,onNewEntity:Q,exec:A,onImported:S,onImportBatch:I,openImport:_,onToggleDrawer:$,drawerOpen:k,filterCount:K}){const B=(i==null?void 0:i.items.filter(u=>u.severity==="error").length)??0,C=(i==null?void 0:i.items.filter(u=>u.severity==="warning").length)??0,L=(u,b,R,F,q)=>e.jsxs("button",{className:"grp-btn"+(D===u?" active":""),onClick:()=>w(u),title:F,children:[b,e.jsx("span",{children:R}),q&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(k?" active":""),onClick:$,title:k?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":k,children:[e.jsx(Te,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),c&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:f,onChange:u=>d(u.target.value),onKeyDown:u=>{u.key==="Enter"&&g()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(ke,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Se,{size:14}),s.counts.relationships]}),i&&e.jsx("span",{className:"diag-chip"+(B?" err":C?" warn":" ok"),title:i.items.map(u=>`${u.code} ${u.message}`).join(` -`)||"model valid",children:B?e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),B]}):C?e.jsxs(e.Fragment,{children:[e.jsx(Le,{size:14}),C]}):e.jsxs(e.Fragment,{children:[e.jsx(Ie,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!c&&e.jsxs("button",{className:"tool-btn primary",onClick:Q,title:"New entity (n)",children:[e.jsx(fe,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),L("ontology",e.jsx(ge,{size:15}),"Ontology","Ontology browser"),L("layers",e.jsx(ye,{size:15}),"Layers","Four-layer stack & coverage"),L("changes",e.jsx(be,{size:15}),"Changes",p?"Uncommitted changes":"Changes",p),L("decisions",e.jsx(we,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(v?" active":""),onClick:y,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(ve,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(x?" active":""),onClick:j,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Me,{size:15})}),e.jsx(_e,{onRelayout:M}),e.jsx("button",{className:"grp-btn icon-only",onClick:m,title:"Fit view","aria-label":"Fit view",children:e.jsx(Ne,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:o,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Ee,{size:15})}),e.jsx(le,{exec:A,canEdit:!c,onImported:S,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:I,openImport:_})]})]})]})}const O=["LR","TB","RL","BT"],Ae={LR:0,TB:90,RL:180,BT:270},se={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function _e({onRelayout:s}){const[i,f]=a.useState(!1),[d,g]=a.useState("LR"),[v,y]=a.useState("auto"),x=a.useRef(null);a.useEffect(()=>{if(!i)return;const o=c=>{x.current&&!x.current.contains(c.target)&&f(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[i]);const j=o=>{y(o),s(o,d)},m=o=>{j(o),f(!1)},M=()=>{const o=O[(O.indexOf(d)+1)%O.length];g(o),s(v,o)};return e.jsxs("div",{className:"layout-picker",ref:x,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>j("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(i?" active":""),onClick:()=>f(o=>!o),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:M,title:`Flow direction: ${se[d]} (click to rotate)`,"aria-label":`Flow direction: ${se[d]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${Ae[d]}deg)`},children:e.jsx(Be,{size:15})})}),i&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>m("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>m("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>m("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>m("grid"),children:"Grid"})]})]})}function $e(){const[s,i]=a.useState(null),[f,d]=a.useState(null),[g,v]=a.useState(null),[y,x]=a.useState(null),[j,m]=a.useState(""),[M,o]=a.useState(!0),[c,p]=a.useState(!1),[D,w]=a.useState(()=>new Set),[Q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[k,K]=a.useState(()=>new Set),[B,C]=a.useState(!1),[L,u]=a.useState(0),b=a.useRef(null),R=a.useRef(""),F=a.useRef(!1),q=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((r,n)=>t.set(r.id,Y[n%Y.length])),t},[s]),U=a.useMemo(()=>{const t=new Map;if(!s)return t;const r=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(h=>r.set(h,n.id))}),s.entities.forEach(n=>{var E,V,X;const P=((E=n.conceptual)!=null&&E.id?r.get(n.conceptual.id):void 0)??((X=(V=n.conceptual)==null?void 0:V.subject_area)==null?void 0:X.id)??"";t.set(n.id,P)}),t},[s]),te=a.useMemo(()=>{const t=new Map;return U.forEach(r=>t.set(r,(t.get(r)??0)+1)),t},[U]),T=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>me(T),[T]),H=a.useMemo(()=>new URLSearchParams(window.location.search),[]),z=H.get("minimal")==="1";a.useEffect(()=>{z&&p(!0)},[z]);const ae=a.useCallback(t=>{w(r=>{const n=new Set(r);return n.has(t)?n.delete(t):n.add(t),n})},[]),re=H.get("import")==="1",W=a.useRef(!1),N=a.useCallback(()=>{J().then(i).catch(t=>v(String(t))),Z().then(d).catch(()=>d(null)),ee().then(t=>C(!!(t.git&&!t.clean))).catch(()=>C(!1)),u(t=>t+1)},[]);a.useEffect(N,[N]),a.useEffect(()=>{const t=setInterval(()=>{J().then(r=>{i(n=>n&&r.fingerprint===n.fingerprint?n:(F.current||(R.current=r.fingerprint),z||(Z().then(d).catch(()=>d(null)),ee().then(h=>C(!!(h.git&&!h.clean))).catch(()=>C(!1))),u(h=>h+1),r))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[z]),a.useEffect(()=>{s!=null&&s.fingerprint&&(R.current=s.fingerprint)},[s]);const G=a.useCallback(async(t,r)=>{if(s){F.current=!0;try{const n=await he(t,r,R.current||s.fingerprint);return n!=null&&n.fingerprint&&(R.current=n.fingerprint),N(),n}catch(n){throw n instanceof ue&&n.status===409?(x("Model changed on disk — view refreshed, please retry."),N()):x(n instanceof Error?n.message:String(n)),n}finally{F.current=!1}}},[s,N]);a.useEffect(()=>{if(!y)return;const t=setTimeout(()=>x(null),5e3);return()=>clearTimeout(t)},[y]),a.useEffect(()=>{if(!s||W.current)return;const t=H.get("focus");if(!t)return;const r=s.entities.find(n=>{var h;return n.name===t||((h=n.conceptual)==null?void 0:h.name)===t});r&&(W.current=!0,requestAnimationFrame(()=>{var n;return(n=b.current)==null?void 0:n.focusEntity(r.id)}))},[s,H]);const ce=a.useCallback(()=>{var n;if(!s)return;const t=j.trim().toLowerCase();if(!t)return;const r=s.entities.find(h=>{var E;return(h.name.toLowerCase()+" "+(((E=h.conceptual)==null?void 0:E.name.toLowerCase())??"")+" "+h.attributes.map(V=>V.name.toLowerCase()).join(" ")).includes(t)});r&&((n=b.current)==null||n.focusEntity(r.id))},[s,j]);return a.useEffect(()=>{const t=r=>{var h,P,E;const n=(h=document.activeElement)==null?void 0:h.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(r.key==="/"&&(r.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),r.key==="n"&&!T&&((E=b.current)==null||E.newEntity()),r.key==="Escape"&&(A(null),m(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[T]),g?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:g}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!z&&e.jsx(Pe,{doc:s,diagnostics:f,query:j,onQuery:m,onSubmitQuery:ce,showTypes:M,onToggleTypes:()=>o(t=>!t),collapseDetail:c,onToggleCollapse:()=>p(t=>!t),onFitView:()=>{var t;return(t=b.current)==null?void 0:t.fitView()},onRelayout:(t,r)=>{var n;return(n=b.current)==null?void 0:n.relayout(t,r)},onRefresh:N,readOnly:T,dirty:B,panelTab:S,onPanelTab:t=>I(r=>r===t?null:t),onNewEntity:()=>{var t;return(t=b.current)==null?void 0:t.newEntity()},exec:G,onImported:N,onImportBatch:xe,openImport:re,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:k.size}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(je,{doc:s,caps:ne,exec:G,selectedId:S?null:Q,onSelect:A,query:j,showTypes:M,collapseDetail:c,expandedEntities:D,onToggleExpand:ae,activeAreas:k,onError:x,handleRef:b}),!z&&e.jsx(Fe,{doc:s,saColors:q,countByArea:te,activeAreas:k,onSetActive:K,open:_,onClose:()=>$(!1)}),S&&e.jsx(pe,{tab:S,onClose:()=>I(null),readOnly:T,refreshKey:L,onModelChanged:N,onFocusEntity:t=>{var r;I(null),(r=b.current)==null||r.focusEntity(t)}}),y&&e.jsx("div",{className:"toast",children:y})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ke(){return e.jsx(de,{children:e.jsx($e,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(oe.StrictMode,{children:e.jsx(Ke,{})})); diff --git a/packages/server/src/mdl_server/static/assets/main-lOq9xM1X.js b/packages/server/src/mdl_server/static/assets/main-lOq9xM1X.js new file mode 100644 index 0000000..a016a29 --- /dev/null +++ b/packages/server/src/mdl_server/static/assets/main-lOq9xM1X.js @@ -0,0 +1,2 @@ +import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-SXBmvQqW.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` +`)||"model valid",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),M]}):F?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14}),F]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!u&&e.jsxs("button",{className:"tool-btn primary",onClick:A,title:"New entity (n)",children:[e.jsx(ye,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),E("ontology",e.jsx(be,{size:15}),"Ontology","Ontology browser"),E("layers",e.jsx(we,{size:15}),"Layers","Four-layer stack & coverage"),E("changes",e.jsx(ve,{size:15}),"Changes",k?"Uncommitted changes":"Changes",k),E("decisions",e.jsx(Me,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(w?" active":""),onClick:g,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(m?" active":""),onClick:p,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Ne,{size:15})}),e.jsx(Ke,{onRelayout:f,onReset:v}),e.jsx("button",{className:"grp-btn icon-only",onClick:y,title:"Fit view","aria-label":"Fit view",children:e.jsx(ke,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:r,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Se,{size:15})}),e.jsx(de,{exec:S,canEdit:!u,onImported:I,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:_,openImport:$})]})]})]})}const U=["LR","TB","RL","BT"],$e={LR:0,TB:90,RL:180,BT:270},se={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function Ke({onRelayout:s,onReset:l}){const[j,h]=a.useState(!1),[x,w]=a.useState("LR"),[g,m]=a.useState("auto"),p=a.useRef(null);a.useEffect(()=>{if(!j)return;const r=u=>{p.current&&!p.current.contains(u.target)&&h(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[j]);const y=r=>{m(r),s(r,x)},f=r=>{y(r),h(!1)},v=()=>{const r=U[(U.indexOf(x)+1)%U.length];w(r),s(g,r)};return e.jsxs("div",{className:"layout-picker",ref:p,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>y("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ee,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(j?" active":""),onClick:()=>h(r=>!r),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:v,title:`Flow direction: ${se[x]} (click to rotate)`,"aria-label":`Flow direction: ${se[x]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${$e[x]}deg)`},children:e.jsx(Pe,{size:15})})}),j&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>f("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>f("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>f("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>f("grid"),children:"Grid"}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"layout-menu-sep",role:"separator"}),e.jsx("button",{onClick:()=>{l(),h(!1)},title:"Clear saved positions and routes for this view",children:"Reset layout"})]})]})]})}function He(){const[s,l]=a.useState(null),[j,h]=a.useState(null),[x,w]=a.useState(null),[g,m]=a.useState(null),[p,y]=a.useState(""),[f,v]=a.useState(!0),[r,u]=a.useState(!1),[k,b]=a.useState(()=>new Set),[q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[z,D]=a.useState(()=>new Set),[K,M]=a.useState(!1),[F,E]=a.useState(0),o=a.useRef(null),L=a.useRef(""),B=a.useRef(!1),O=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((c,n)=>t.set(c.id,Y[n%Y.length])),t},[s]),H=a.useMemo(()=>{const t=new Map;if(!s)return t;const c=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(d=>c.set(d,n.id))}),s.entities.forEach(n=>{var N,Q,X;const P=((N=n.conceptual)!=null&&N.id?c.get(n.conceptual.id):void 0)??((X=(Q=n.conceptual)==null?void 0:Q.subject_area)==null?void 0:X.id)??"";t.set(n.id,P)}),t},[s]),te=a.useMemo(()=>{const t=new Map;return H.forEach(c=>t.set(c,(t.get(c)??0)+1)),t},[H]),R=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>ge(R),[R]),ae=a.useMemo(()=>ue(),[]),V=a.useMemo(()=>new URLSearchParams(window.location.search),[]),T=V.get("minimal")==="1";a.useEffect(()=>{T&&u(!0)},[T]);const re=a.useCallback(t=>{b(c=>{const n=new Set(c);return n.has(t)?n.delete(t):n.add(t),n})},[]),ce=V.get("import")==="1",W=a.useRef(!1),C=a.useCallback(()=>{J().then(l).catch(t=>w(String(t))),Z().then(h).catch(()=>h(null)),ee().then(t=>M(!!(t.git&&!t.clean))).catch(()=>M(!1)),E(t=>t+1)},[]);a.useEffect(C,[C]),a.useEffect(()=>{const t=setInterval(()=>{J().then(c=>{l(n=>n&&c.fingerprint===n.fingerprint?n:(B.current||(L.current=c.fingerprint),T||(Z().then(h).catch(()=>h(null)),ee().then(d=>M(!!(d.git&&!d.clean))).catch(()=>M(!1))),E(d=>d+1),c))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[T]),a.useEffect(()=>{s!=null&&s.fingerprint&&(L.current=s.fingerprint)},[s]);const G=a.useCallback(async(t,c)=>{if(s){B.current=!0;try{const n=await xe(t,c,L.current||s.fingerprint);return n!=null&&n.fingerprint&&(L.current=n.fingerprint),C(),n}catch(n){throw n instanceof pe&&n.status===409?(m("Model changed on disk — view refreshed, please retry."),C()):m(n instanceof Error?n.message:String(n)),n}finally{B.current=!1}}},[s,C]);a.useEffect(()=>{if(!g)return;const t=setTimeout(()=>m(null),5e3);return()=>clearTimeout(t)},[g]),a.useEffect(()=>{if(!s||W.current)return;const t=V.get("focus");if(!t)return;const c=s.entities.find(n=>{var d;return n.name===t||((d=n.conceptual)==null?void 0:d.name)===t});c&&(W.current=!0,requestAnimationFrame(()=>{var n;return(n=o.current)==null?void 0:n.focusEntity(c.id)}))},[s,V]);const oe=a.useCallback(()=>{var n;if(!s)return;const t=p.trim().toLowerCase();if(!t)return;const c=s.entities.find(d=>{var N;return(d.name.toLowerCase()+" "+(((N=d.conceptual)==null?void 0:N.name.toLowerCase())??"")+" "+d.attributes.map(Q=>Q.name.toLowerCase()).join(" ")).includes(t)});c&&((n=o.current)==null||n.focusEntity(c.id))},[s,p]);return a.useEffect(()=>{const t=c=>{var d,P,N;const n=(d=document.activeElement)==null?void 0:d.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(c.key==="/"&&(c.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),c.key==="n"&&!R&&((N=o.current)==null||N.newEntity()),c.key==="Escape"&&(A(null),y(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[R]),x?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:x}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!T&&e.jsx(_e,{doc:s,diagnostics:j,query:p,onQuery:y,onSubmitQuery:oe,showTypes:f,onToggleTypes:()=>v(t=>!t),collapseDetail:r,onToggleCollapse:()=>u(t=>!t),onFitView:()=>{var t;return(t=o.current)==null?void 0:t.fitView()},onRelayout:(t,c)=>{var n;return(n=o.current)==null?void 0:n.relayout(t,c)},onResetLayout:()=>{var t;return(t=o.current)==null?void 0:t.resetLayout()},onRefresh:C,readOnly:R,dirty:K,panelTab:S,onPanelTab:t=>I(c=>c===t?null:t),onNewEntity:()=>{var t;return(t=o.current)==null?void 0:t.newEntity()},exec:G,onImported:C,onImportBatch:je,openImport:ce,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:z.size}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(me,{doc:s,caps:ne,exec:G,selectedId:S?null:q,onSelect:A,query:p,showTypes:f,collapseDetail:r,expandedEntities:k,onToggleExpand:re,activeAreas:z,onError:m,handleRef:o,layoutStore:ae}),!T&&e.jsx(Ae,{doc:s,saColors:O,countByArea:te,activeAreas:z,onSetActive:D,open:_,onClose:()=>$(!1)}),S&&e.jsx(fe,{tab:S,onClose:()=>I(null),readOnly:R,refreshKey:F,onModelChanged:C,onFocusEntity:t=>{var c;I(null),(c=o.current)==null||c.focusEntity(t)}}),g&&e.jsx("div",{className:"toast",children:g})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ve(){return e.jsx(he,{children:e.jsx(He,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(le.StrictMode,{children:e.jsx(Ve,{})})); diff --git a/packages/server/src/mdl_server/static/assets/sme-Zxw1Myjj.js b/packages/server/src/mdl_server/static/assets/sme-BJx0Kpa-.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-Zxw1Myjj.js rename to packages/server/src/mdl_server/static/assets/sme-BJx0Kpa-.js index 1da7f69..cca39ab 100644 --- a/packages/server/src/mdl_server/static/assets/sme-Zxw1Myjj.js +++ b/packages/server/src/mdl_server/static/assets/sme-BJx0Kpa-.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-CRUBpPVn.js","assets/client-DOmNpTln.js","assets/styles-B90OKxCj.js","assets/styles-DxhL4SV-.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,h as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,i as Qe,j as Xe,A as Ze,k as es,l as ss,m as ns,o as ts,n as as,s as rs,f as ie,q as is,r as ls,t as cs,b as os}from"./styles-B90OKxCj.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-CRUBpPVn.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-CrqdkiTB.js","assets/client-DOmNpTln.js","assets/styles-SXBmvQqW.js","assets/styles-DO3eXfyX.css"])))=>i.map(i=>d[i]); +import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-SXBmvQqW.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-CrqdkiTB.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); diff --git a/packages/server/src/mdl_server/static/assets/styles-B90OKxCj.js b/packages/server/src/mdl_server/static/assets/styles-B90OKxCj.js deleted file mode 100644 index 6cbaefa..0000000 --- a/packages/server/src/mdl_server/static/assets/styles-B90OKxCj.js +++ /dev/null @@ -1,23 +0,0 @@ -var tl=Object.defineProperty;var nl=(e,t,n)=>t in e?tl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ue=(e,t,n)=>nl(e,typeof t!="symbol"?t+"":t,n);import{r as w,g as fi,R as M,j as h}from"./client-DOmNpTln.js";function ye(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?ul:cl;gi.useSyncExternalStore=Et.useSyncExternalStore!==void 0?Et.useSyncExternalStore:dl;pi.exports=gi;var fl=pi.exports;/** - * @license React - * use-sync-external-store-shim/with-selector.production.js - * - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var kn=w,hl=fl;function ml(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var pl=typeof Object.is=="function"?Object.is:ml,gl=hl.useSyncExternalStore,yl=kn.useRef,xl=kn.useEffect,wl=kn.useMemo,bl=kn.useDebugValue;mi.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=yl(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=wl(function(){function l(f){if(!c){if(c=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var x=o.value;if(s(x,f))return d=x}return d=f}if(x=d,pl(u,f))return x;var y=r(f);return s!==void 0&&s(x,y)?(u=f,x):(u=f,d=y)}var c=!1,u,d,m=n===void 0?null:n;return[function(){return l(t())},m===null?void 0:function(){return l(m())}]},[t,n,r,s]);var a=gl(e,i[0],i[1]);return xl(function(){o.hasValue=!0,o.value=a},[a]),bl(a),a};hi.exports=mi;var vl=hi.exports;const _l=fi(vl),El={},Wr=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(x=>x(t,f))}},s=()=>t,l={setState:r,getState:s,getInitialState:()=>c,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(El?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},c=t=e(r,s,l);return l},Nl=e=>e?Wr(e):Wr,{useDebugValue:Sl}=M,{useSyncExternalStoreWithSelector:kl}=_l,jl=e=>e;function yi(e,t=jl,n){const r=kl(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Sl(r),r}const Ur=(e,t)=>{const n=Nl(e),r=(s,i=t)=>yi(n,s,i);return Object.assign(r,n),r},Cl=(e,t)=>e?Ur(e,t):Ur;function ge(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var $l={value:()=>{}};function jn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}cn.prototype=jn.prototype={constructor:cn,on:function(e,t){var n=this._,r=Ml(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),qr.hasOwnProperty(t)?{space:qr[t],local:e}:e}function Il(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===nr&&t.documentElement.namespaceURI===nr?t.createElement(e):t.createElementNS(n,e)}}function Rl(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function xi(e){var t=Cn(e);return(t.local?Rl:Il)(t)}function Tl(){}function wr(e){return e==null?Tl:function(){return this.querySelector(e)}}function Ol(e){typeof e!="function"&&(e=wr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=$&&($=E+1);!(A=v[$])&&++$=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function oc(e){e||(e=ac);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function lc(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function cc(){return Array.from(this)}function uc(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?vc:typeof t=="function"?Ec:_c)(e,t,n??"")):Nt(this.node(),e)}function Nt(e,t){return e.style.getPropertyValue(t)||Ei(e).getComputedStyle(e,null).getPropertyValue(t)}function Sc(e){return function(){delete this[e]}}function kc(e,t){return function(){this[e]=t}}function jc(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Cc(e,t){return arguments.length>1?this.each((t==null?Sc:typeof t=="function"?jc:kc)(e,t)):this.node()[e]}function Ni(e){return e.trim().split(/^|\s+/)}function br(e){return e.classList||new Si(e)}function Si(e){this._node=e,this._names=Ni(e.getAttribute("class")||"")}Si.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function ki(e,t){for(var n=br(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function nu(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function rr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:l,dy:c,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:c,enumerable:!0,configurable:!0},_:{value:u}})}rr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function fu(e){return!e.ctrlKey&&!e.button}function hu(){return this.parentNode}function mu(e,t){return t??{x:e.x,y:e.y}}function pu(){return navigator.maxTouchPoints||"ontouchstart"in this}function gu(){var e=fu,t=hu,n=mu,r=pu,s={},i=jn("start","drag","end"),o=0,a,l,c,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",p,du).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,A){if(!(u||!e.call(this,b,A))){var j=$(this,t.call(this,b,A),b,A,"mouse");j&&(Ne(b.view).on("mousemove.drag",x,zt).on("mouseup.drag",y,zt),Mi(b.view),Hn(b),c=!1,a=b.clientX,l=b.clientY,j("start",b))}}function x(b){if(wt(b),!c){var A=b.clientX-a,j=b.clientY-l;c=A*A+j*j>d}s.mouse("drag",b)}function y(b){Ne(b.view).on("mousemove.drag mouseup.drag",null),Ai(b.view,c),wt(b),s.mouse("end",b)}function v(b,A){if(e.call(this,b,A)){var j=b.changedTouches,_=t.call(this,b,A),I=j.length,S,D;for(S=0;S>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Jt(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Jt(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=xu.exec(e))?new ve(t[1],t[2],t[3],1):(t=wu.exec(e))?new ve(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=bu.exec(e))?Jt(t[1],t[2],t[3],t[4]):(t=vu.exec(e))?Jt(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=_u.exec(e))?ns(t[1],t[2]/100,t[3]/100,1):(t=Eu.exec(e))?ns(t[1],t[2]/100,t[3]/100,t[4]):Kr.hasOwnProperty(e)?Jr(Kr[e]):e==="transparent"?new ve(NaN,NaN,NaN,0):null}function Jr(e){return new ve(e>>16&255,e>>8&255,e&255,1)}function Jt(e,t,n,r){return r<=0&&(e=t=n=NaN),new ve(e,t,n,r)}function ku(e){return e instanceof Xt||(e=Vt(e)),e?(e=e.rgb(),new ve(e.r,e.g,e.b,e.opacity)):new ve}function sr(e,t,n,r){return arguments.length===1?ku(e):new ve(e,t,n,r??1)}function ve(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}vr(ve,sr,Ii(Xt,{brighter(e){return e=e==null?mn:Math.pow(mn,e),new ve(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Ht:Math.pow(Ht,e),new ve(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new ve(at(this.r),at(this.g),at(this.b),pn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:es,formatHex:es,formatHex8:ju,formatRgb:ts,toString:ts}));function es(){return`#${it(this.r)}${it(this.g)}${it(this.b)}`}function ju(){return`#${it(this.r)}${it(this.g)}${it(this.b)}${it((isNaN(this.opacity)?1:this.opacity)*255)}`}function ts(){const e=pn(this.opacity);return`${e===1?"rgb(":"rgba("}${at(this.r)}, ${at(this.g)}, ${at(this.b)}${e===1?")":`, ${e})`}`}function pn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function at(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function it(e){return e=at(e),(e<16?"0":"")+e.toString(16)}function ns(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Me(e,t,n,r)}function Ri(e){if(e instanceof Me)return new Me(e.h,e.s,e.l,e.opacity);if(e instanceof Xt||(e=Vt(e)),!e)return new Me;if(e instanceof Me)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,l=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&l<1?0:o,new Me(o,a,l,e.opacity)}function Cu(e,t,n,r){return arguments.length===1?Ri(e):new Me(e,t,n,r??1)}function Me(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}vr(Me,Cu,Ii(Xt,{brighter(e){return e=e==null?mn:Math.pow(mn,e),new Me(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Ht:Math.pow(Ht,e),new Me(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new ve(Fn(e>=240?e-240:e+120,s,r),Fn(e,s,r),Fn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Me(rs(this.h),en(this.s),en(this.l),pn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=pn(this.opacity);return`${e===1?"hsl(":"hsla("}${rs(this.h)}, ${en(this.s)*100}%, ${en(this.l)*100}%${e===1?")":`, ${e})`}`}}));function rs(e){return e=(e||0)%360,e<0?e+360:e}function en(e){return Math.max(0,Math.min(1,e||0))}function Fn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Ti=e=>()=>e;function $u(e,t){return function(n){return e+n*t}}function Mu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Au(e){return(e=+e)==1?Oi:function(t,n){return n-t?Mu(t,n,e):Ti(isNaN(t)?n:t)}}function Oi(e,t){var n=t-e;return n?$u(e,n):Ti(isNaN(e)?t:e)}const ss=function e(t){var n=Au(t);function r(s,i){var o=n((s=sr(s)).r,(i=sr(i)).r),a=n(s.g,i.g),l=n(s.b,i.b),c=Oi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=l(u),s.opacity=c(u),s+""}}return r.gamma=e,r}(1);function Ue(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var ir=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Vn=new RegExp(ir.source,"g");function Iu(e){return function(){return e}}function Ru(e){return function(t){return e(t)+""}}function Tu(e,t){var n=ir.lastIndex=Vn.lastIndex=0,r,s,i,o=-1,a=[],l=[];for(e=e+"",t=t+"";(r=ir.exec(e))&&(s=Vn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,l.push({i:o,x:Ue(r,s)})),n=Vn.lastIndex;return n180?u+=360:u-c>180&&(c+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:Ue(c,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(c,u,d,m){c!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:Ue(c,u)}):u&&d.push(s(d)+"skewX("+u+r)}function l(c,u,d,m,f,x){if(c!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");x.push({i:y-4,x:Ue(c,d)},{i:y-2,x:Ue(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(c,u){var d=[],m=[];return c=e(c),u=e(u),i(c.translateX,c.translateY,u.translateX,u.translateY,d,m),o(c.rotate,u.rotate,d,m),a(c.skewX,u.skewX,d,m),l(c.scaleX,c.scaleY,u.scaleX,u.scaleY,d,m),c=u=null,function(f){for(var x=-1,y=m.length,v;++x=0&&e._call.call(void 0,t),e=e._next;--St}function as(){ct=(yn=Bt.now())+$n,St=Ot=0;try{Gu()}finally{St=0,Wu(),ct=0}}function Yu(){var e=Bt.now(),t=e-yn;t>Pi&&($n-=t,yn=e)}function Wu(){for(var e,t=gn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:gn=n);Dt=e,ar(r)}function ar(e){if(!St){Ot&&(Ot=clearTimeout(Ot));var t=e-ct;t>24?(e<1/0&&(Ot=setTimeout(as,e-Bt.now()-$n)),Mt&&(Mt=clearInterval(Mt))):(Mt||(yn=Bt.now(),Mt=setInterval(Yu,Pi)),St=1,zi(as))}}function ls(e,t,n){var r=new xn;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Uu=jn("start","end","cancel","interrupt"),Xu=[],Fi=0,cs=1,lr=2,un=3,us=4,cr=5,dn=6;function Mn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;qu(e,n,{name:t,index:r,group:s,on:Uu,tween:Xu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Fi})}function Er(e,t){var n=Ae(e,t);if(n.state>Fi)throw new Error("too late; already scheduled");return n}function Oe(e,t){var n=Ae(e,t);if(n.state>un)throw new Error("too late; already running");return n}function Ae(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function qu(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=Hi(i,0,n.time);function i(c){n.state=cs,n.timer.restart(o,n.delay,n.time),n.delay<=c&&o(c-n.delay)}function o(c){var u,d,m,f;if(n.state!==cs)return l();for(u in r)if(f=r[u],f.name===n.name){if(f.state===un)return ls(o);f.state===us?(f.state=dn,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+ulr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function Sd(e,t,n){var r,s,i=Nd(t)?Er:Oe;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function kd(e,t){var n=this._id;return arguments.length<2?Ae(this.node(),n).on.on(e):this.each(Sd(n,e,t))}function jd(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Cd(){return this.on("end.remove",jd(this._id))}function $d(e){var t=this._name,n=this._id;typeof e!="function"&&(e=wr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function ef(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function He(e,t,n){this.k=e,this.x=t,this.y=n}He.prototype={constructor:He,scale:function(e){return e===1?this:new He(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new He(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Fe=new He(1,0,0);He.prototype;function Bn(e){e.stopImmediatePropagation()}function At(e){e.preventDefault(),e.stopImmediatePropagation()}function tf(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function nf(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ds(){return this.__zoom||Fe}function rf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function sf(){return navigator.maxTouchPoints||"ontouchstart"in this}function of(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function Yi(){var e=tf,t=nf,n=of,r=rf,s=sf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,l=Vu,c=jn("start","zoom","end"),u,d,m,f=500,x=150,y=0,v=10;function p(g){g.property("__zoom",ds).on("wheel.zoom",I,{passive:!1}).on("mousedown.zoom",S).on("dblclick.zoom",D).filter(s).on("touchstart.zoom",P).on("touchmove.zoom",V).on("touchend.zoom touchcancel.zoom",F).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}p.transform=function(g,C,N,R){var H=g.selection?g.selection():g;H.property("__zoom",ds),g!==H?A(g,C,N,R):H.interrupt().each(function(){j(this,arguments).event(R).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},p.scaleBy=function(g,C,N,R){p.scaleTo(g,function(){var H=this.__zoom.k,k=typeof C=="function"?C.apply(this,arguments):C;return H*k},N,R)},p.scaleTo=function(g,C,N,R){p.transform(g,function(){var H=t.apply(this,arguments),k=this.__zoom,T=N==null?b(H):typeof N=="function"?N.apply(this,arguments):N,L=k.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n($(E(k,z),T,L),H,o)},N,R)},p.translateBy=function(g,C,N,R){p.transform(g,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof N=="function"?N.apply(this,arguments):N),t.apply(this,arguments),o)},null,R)},p.translateTo=function(g,C,N,R,H){p.transform(g,function(){var k=t.apply(this,arguments),T=this.__zoom,L=R==null?b(k):typeof R=="function"?R.apply(this,arguments):R;return n(Fe.translate(L[0],L[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof N=="function"?-N.apply(this,arguments):-N),k,o)},R,H)};function E(g,C){return C=Math.max(i[0],Math.min(i[1],C)),C===g.k?g:new He(C,g.x,g.y)}function $(g,C,N){var R=C[0]-N[0]*g.k,H=C[1]-N[1]*g.k;return R===g.x&&H===g.y?g:new He(g.k,R,H)}function b(g){return[(+g[0][0]+ +g[1][0])/2,(+g[0][1]+ +g[1][1])/2]}function A(g,C,N,R){g.on("start.zoom",function(){j(this,arguments).event(R).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(R).end()}).tween("zoom",function(){var H=this,k=arguments,T=j(H,k).event(R),L=t.apply(H,k),z=N==null?b(L):typeof N=="function"?N.apply(H,k):N,Y=Math.max(L[1][0]-L[0][0],L[1][1]-L[0][1]),G=H.__zoom,K=typeof C=="function"?C.apply(H,k):C,J=l(G.invert(z).concat(Y/G.k),K.invert(z).concat(Y/K.k));return function(ee){if(ee===1)ee=K;else{var ie=J(ee),te=Y/ie[2];ee=new He(te,z[0]-ie[0]*te,z[1]-ie[1]*te)}T.zoom(null,ee)}})}function j(g,C,N){return!N&&g.__zooming||new _(g,C)}function _(g,C){this.that=g,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(g,C),this.taps=0}_.prototype={event:function(g){return g&&(this.sourceEvent=g),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(g,C){return this.mouse&&g!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&g!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&g!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(g){var C=Ne(this.that).datum();c.call(g,this.that,new ef(g,{sourceEvent:this.sourceEvent,target:p,transform:this.that.__zoom,dispatch:c}),C)}};function I(g,...C){if(!e.apply(this,arguments))return;var N=j(this,C).event(g),R=this.__zoom,H=Math.max(i[0],Math.min(i[1],R.k*Math.pow(2,r.apply(this,arguments)))),k=$e(g);if(N.wheel)(N.mouse[0][0]!==k[0]||N.mouse[0][1]!==k[1])&&(N.mouse[1]=R.invert(N.mouse[0]=k)),clearTimeout(N.wheel);else{if(R.k===H)return;N.mouse=[k,R.invert(k)],fn(this),N.start()}At(g),N.wheel=setTimeout(T,x),N.zoom("mouse",n($(E(R,H),N.mouse[0],N.mouse[1]),N.extent,o));function T(){N.wheel=null,N.end()}}function S(g,...C){if(m||!e.apply(this,arguments))return;var N=g.currentTarget,R=j(this,C,!0).event(g),H=Ne(g.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",Y,!0),k=$e(g,N),T=g.clientX,L=g.clientY;Mi(g.view),Bn(g),R.mouse=[k,this.__zoom.invert(k)],fn(this),R.start();function z(G){if(At(G),!R.moved){var K=G.clientX-T,J=G.clientY-L;R.moved=K*K+J*J>y}R.event(G).zoom("mouse",n($(R.that.__zoom,R.mouse[0]=$e(G,N),R.mouse[1]),R.extent,o))}function Y(G){H.on("mousemove.zoom mouseup.zoom",null),Ai(G.view,R.moved),At(G),R.event(G).end()}}function D(g,...C){if(e.apply(this,arguments)){var N=this.__zoom,R=$e(g.changedTouches?g.changedTouches[0]:g,this),H=N.invert(R),k=N.k*(g.shiftKey?.5:2),T=n($(E(N,k),R,H),t.apply(this,C),o);At(g),a>0?Ne(this).transition().duration(a).call(A,T,R,g):Ne(this).call(p.transform,T,R,g)}}function P(g,...C){if(e.apply(this,arguments)){var N=g.touches,R=N.length,H=j(this,C,g.changedTouches.length===R).event(g),k,T,L,z;for(Bn(g),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},Wi=Be.error001();function ae(e,t){const n=w.useContext(An);if(n===null)throw new Error(Wi);return yi(n,e,t)}const pe=()=>{const e=w.useContext(An);if(e===null)throw new Error(Wi);return w.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},lf=e=>e.userSelectionActive?"none":"all";function Sr({position:e,children:t,className:n,style:r,...s}){const i=ae(lf),o=`${e}`.split("-");return M.createElement("div",{className:ye(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function cf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:M.createElement(Sr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},M.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const uf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:l,className:c,...u})=>{const d=w.useRef(null),[m,f]=w.useState({x:0,y:0,width:0,height:0}),x=ye(["react-flow__edge-textwrapper",c]);return w.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:M.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:x,visibility:m.width?"visible":"hidden",...u},s&&M.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),M.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),l)};var df=w.memo(uf);const kr=e=>({width:e.offsetWidth,height:e.offsetHeight}),kt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),jr=(e={x:0,y:0},t)=>({x:kt(e.x,t[0][0],t[1][0]),y:kt(e.y,t[0][1],t[1][1])}),fs=(e,t,n)=>en?-kt(Math.abs(e-n),1,50)/50:0,Ui=(e,t)=>{const n=fs(e.x,35,t.width-35)*20,r=fs(e.y,35,t.height-35)*20;return[n,r]},Xi=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},qi=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Gt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),Ki=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),hs=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),ff=(e,t)=>Ki(qi(Gt(e),Gt(t))),ur=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},hf=e=>Se(e.width)&&Se(e.height)&&Se(e.x)&&Se(e.y),Se=e=>!isNaN(e)&&isFinite(e),le=Symbol.for("internals"),Zi=["Enter"," ","Escape"],mf=(e,t)=>{},pf=e=>"nativeEvent"in e;function dr(e){var s,i;const t=pf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const Qi=e=>"clientX"in e,Ze=(e,t)=>{var i,o;const n=Qi(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},wn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},qt=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>M.createElement(M.Fragment,null,M.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&M.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Se(n)&&Se(r)?M.createElement(df,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c}):null);qt.displayName="BaseEdge";function It(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function Ji({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[v,p,E]=to({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return M.createElement(qt,{path:v,labelX:p,labelY:E,label:o,labelStyle:a,labelShowBg:l,labelBgStyle:c,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:x,interactionWidth:y})});Cr.displayName="SimpleBezierEdge";const ps={[Z.Left]:{x:-1,y:0},[Z.Right]:{x:1,y:0},[Z.Top]:{x:0,y:-1},[Z.Bottom]:{x:0,y:1}},gf=({source:e,sourcePosition:t=Z.Bottom,target:n})=>t===Z.Left||t===Z.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function yf({source:e,sourcePosition:t=Z.Bottom,target:n,targetPosition:r=Z.Top,center:s,offset:i}){const o=ps[t],a=ps[r],l={x:e.x+o.x*i,y:e.y+o.y*i},c={x:n.x+a.x*i,y:n.y+a.y*i},u=gf({source:l,sourcePosition:t,target:c}),d=u.x!==0?"x":"y",m=u[d];let f=[],x,y;const v={x:0,y:0},p={x:0,y:0},[E,$,b,A]=Ji({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){x=s.x??E,y=s.y??$;const _=[{x,y:l.y},{x,y:c.y}],I=[{x:l.x,y},{x:c.x,y}];o[d]===m?f=d==="x"?_:I:f=d==="x"?I:_}else{const _=[{x:l.x,y:c.y}],I=[{x:c.x,y:l.y}];if(d==="x"?f=o.x===m?I:_:f=o.y===m?_:I,t===r){const F=Math.abs(e[d]-n[d]);if(F<=i){const g=Math.min(i-1,i-F);o[d]===m?v[d]=(l[d]>e[d]?-1:1)*g:p[d]=(c[d]>n[d]?-1:1)*g}}if(t!==r){const F=d==="x"?"y":"x",g=o[d]===a[F],C=l[F]>c[F],N=l[F]=V?(x=(S.x+D.x)/2,y=f[0].y):(x=f[0].x,y=(S.y+D.y)/2)}return[[e,{x:l.x+v.x,y:l.y+v.y},...f,{x:c.x+p.x,y:c.y+p.y},n],x,y,b,A]}function xf(e,t,n,r){const s=Math.min(gs(e,t)/2,gs(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const c=e.x{let $="";return E>0&&E{const[p,E,$]=vn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return M.createElement(qt,{path:p,labelX:E,labelY:$,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c,style:u,markerEnd:f,markerStart:x,interactionWidth:v})});In.displayName="SmoothStepEdge";const $r=w.memo(e=>{var t;return M.createElement(In,{...e,pathOptions:w.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});$r.displayName="StepEdge";function wf({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=Ji({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const Mr=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[x,y,v]=wf({sourceX:e,sourceY:t,targetX:n,targetY:r});return M.createElement(qt,{path:x,labelX:y,labelY:v,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});Mr.displayName="StraightEdge";function rn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function ys({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case Z.Left:return[t-rn(t-r,i),n];case Z.Right:return[t+rn(r-t,i),n];case Z.Top:return[t,n-rn(n-s,i)];case Z.Bottom:return[t,n+rn(s-n,i)]}}function no({sourceX:e,sourceY:t,sourcePosition:n=Z.Bottom,targetX:r,targetY:s,targetPosition:i=Z.Top,curvature:o=.25}){const[a,l]=ys({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[c,u]=ys({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,x]=eo({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:l,targetControlX:c,targetControlY:u});return[`M${e},${t} C${a},${l} ${c},${u} ${r},${s}`,d,m,f,x]}const _n=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=Z.Bottom,targetPosition:i=Z.Top,label:o,labelStyle:a,labelShowBg:l,labelBgStyle:c,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:x,pathOptions:y,interactionWidth:v})=>{const[p,E,$]=no({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return M.createElement(qt,{path:p,labelX:E,labelY:$,label:o,labelStyle:a,labelShowBg:l,labelBgStyle:c,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:x,interactionWidth:v})});_n.displayName="BezierEdge";const Ar=w.createContext(null),bf=Ar.Provider;Ar.Consumer;const vf=()=>w.useContext(Ar),_f=e=>"id"in e&&"source"in e&&"target"in e,Ef=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,fr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Nf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),Sf=(e,t)=>{if(!e.source||!e.target)return t;let n;return _f(e)?n={...e}:n={...e,id:Ef(e)},Nf(n,t)?t:t.concat(n)},hr=({x:e,y:t},[n,r,s],i,[o,a])=>{const l={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(l.x/o),y:a*Math.round(l.y/a)}:l},ro=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),lt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},Kt=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=lt(s,t).positionAbsolute;return qi(r,Gt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Ki(n)},kf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),Kt(e,t)),so=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const l={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},c=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:x=!1}=u;if(o&&!f||x)return!1;const{positionAbsolute:y}=lt(u,a),v={x:y.x,y:y.y,width:d||0,height:m||0},p=ur(l,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,$=i&&p>0,b=(d||0)*(m||0);(E||$||p>=b||u.dragging)&&c.push(u)}),c},io=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},oo=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),l=Math.min(o,a),c=kt(l,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*c,f=n/2-d*c;return{x:m,y:f,zoom:c}},st=(e,t=0)=>e.transition().duration(t);function xs(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function jf(e,t,n,r,s,i){const{x:o,y:a}=Ze(e),c=t.elementsFromPoint(o,a).find(x=>x.classList.contains("react-flow__handle"));if(c){const x=c.getAttribute("data-nodeid");if(x){const y=Ir(void 0,c),v=c.getAttribute("data-handleid"),p=i({nodeId:x,id:v,type:y});if(p){const E=s.find($=>$.nodeId===x&&$.type===y&&$.id===v);return{handle:{id:v,type:y,nodeId:x,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:p}}}}let u=[],d=1/0;if(s.forEach(x=>{const y=Math.sqrt((x.x-n.x)**2+(x.y-n.y)**2);if(y<=r){const v=i(x);y<=d&&(yx.isValid),f=u.some(({handle:x})=>x.type==="target");return u.find(({handle:x,validHandleResult:y})=>f?x.type==="target":m?y.isValid:!0)||u[0]}const Cf={source:null,target:null,sourceHandle:null,targetHandle:null},ao=()=>({handleDomNode:null,isValid:!1,connection:Cf,endHandle:null});function lo(e,t,n,r,s,i,o){const a=s==="target",l=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),c={...ao(),handleDomNode:l};if(l){const u=Ir(void 0,l),d=l.getAttribute("data-nodeid"),m=l.getAttribute("data-handleid"),f=l.classList.contains("connectable"),x=l.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};c.connection=y,f&&x&&(t===ut.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(c.endHandle={nodeId:d,handleId:m,type:u},c.isValid=i(y))}return c}function $f({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[le]){const{handleBounds:o}=i[le];let a=[],l=[];o&&(a=xs(i,o,"source",`${t}-${n}-${r}`),l=xs(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...l)}return s},[])}function Ir(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Gn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Mf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function co({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:l,onReconnectEnd:c}){const u=Xi(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:x,onConnectStart:y,panBy:v,getNodes:p,cancelConnection:E}=i();let $=0,b;const{x:A,y:j}=Ze(e),_=u==null?void 0:u.elementFromPoint(A,j),I=Ir(l,_),S=m==null?void 0:m.getBoundingClientRect();if(!S||!I)return;let D,P=Ze(e,S),V=!1,F=null,g=!1,C=null;const N=$f({nodes:p(),nodeId:n,handleId:t,handleType:I}),R=()=>{if(!f)return;const[T,L]=Ui(P,S);v({x:T,y:L}),$=requestAnimationFrame(R)};o({connectionPosition:P,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:I,connectionStartHandle:{nodeId:n,handleId:t,type:I},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:I});function H(T){const{transform:L}=i();P=Ze(T,S);const{handle:z,validHandleResult:Y}=jf(T,u,hr(P,L,!1,[1,1]),x,N,G=>lo(G,d,n,t,s?"target":"source",a,u));if(b=z,V||(R(),V=!0),C=Y.handleDomNode,F=Y.connection,g=Y.isValid,o({connectionPosition:b&&g?ro({x:b.x,y:b.y},L):P,connectionStatus:Mf(!!b,g),connectionEndHandle:Y.endHandle}),!b&&!g&&!C)return Gn(D);F.source!==F.target&&C&&(Gn(D),D=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",g),C.classList.toggle("react-flow__handle-valid",g))}function k(T){var L,z;(b||C)&&F&&g&&(r==null||r(F)),(z=(L=i()).onConnectEnd)==null||z.call(L,T),l&&(c==null||c(T)),Gn(D),E(),cancelAnimationFrame($),V=!1,g=!1,F=null,C=null,u.removeEventListener("mousemove",H),u.removeEventListener("mouseup",k),u.removeEventListener("touchmove",H),u.removeEventListener("touchend",k)}u.addEventListener("mousemove",H),u.addEventListener("mouseup",k),u.addEventListener("touchmove",H),u.addEventListener("touchend",k)}const ws=()=>!0,Af=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),If=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},uo=w.forwardRef(({type:e="source",position:t=Z.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:l,className:c,onMouseDown:u,onTouchStart:d,...m},f)=>{var S,D;const x=o||null,y=e==="target",v=pe(),p=vf(),{connectOnClick:E,noPanClassName:$}=ae(Af,ge),{connecting:b,clickConnecting:A}=ae(If(p,x,e),ge);p||(D=(S=v.getState()).onError)==null||D.call(S,"010",Be.error010());const j=P=>{const{defaultEdgeOptions:V,onConnect:F,hasDefaultEdges:g}=v.getState(),C={...V,...P};if(g){const{edges:N,setEdges:R}=v.getState();R(Sf(C,N))}F==null||F(C),a==null||a(C)},_=P=>{if(!p)return;const V=Qi(P);s&&(V&&P.button===0||!V)&&co({event:P,handleId:x,nodeId:p,onConnect:j,isTarget:y,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||ws}),V?u==null||u(P):d==null||d(P)},I=P=>{const{onClickConnectStart:V,onClickConnectEnd:F,connectionClickStartHandle:g,connectionMode:C,isValidConnection:N}=v.getState();if(!p||!g&&!s)return;if(!g){V==null||V(P,{nodeId:p,handleId:x,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:p,type:e,handleId:x}});return}const R=Xi(P.target),H=n||N||ws,{connection:k,isValid:T}=lo({nodeId:p,id:x,type:e},C,g.nodeId,g.handleId||null,g.type,H,R);T&&j(k),F==null||F(P),v.setState({connectionClickStartHandle:null})};return M.createElement("div",{"data-handleid":x,"data-nodeid":p,"data-handlepos":t,"data-id":`${p}-${x}-${e}`,className:ye(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",$,c,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:A,connectionindicator:r&&(s&&!b||i&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?I:void 0,ref:f,...m},l)});uo.displayName="Handle";var Ke=w.memo(uo);const fo=({data:e,isConnectable:t,targetPosition:n=Z.Top,sourcePosition:r=Z.Bottom})=>M.createElement(M.Fragment,null,M.createElement(Ke,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,M.createElement(Ke,{type:"source",position:r,isConnectable:t}));fo.displayName="DefaultNode";var mr=w.memo(fo);const ho=({data:e,isConnectable:t,sourcePosition:n=Z.Bottom})=>M.createElement(M.Fragment,null,e==null?void 0:e.label,M.createElement(Ke,{type:"source",position:n,isConnectable:t}));ho.displayName="InputNode";var mo=w.memo(ho);const po=({data:e,isConnectable:t,targetPosition:n=Z.Top})=>M.createElement(M.Fragment,null,M.createElement(Ke,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);po.displayName="OutputNode";var go=w.memo(po);const Rr=()=>null;Rr.displayName="GroupNode";const Rf=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),sn=e=>e.id;function Tf(e,t){return ge(e.selectedNodes.map(sn),t.selectedNodes.map(sn))&&ge(e.selectedEdges.map(sn),t.selectedEdges.map(sn))}const yo=w.memo(({onSelectionChange:e})=>{const t=pe(),{selectedNodes:n,selectedEdges:r}=ae(Rf,Tf);return w.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});yo.displayName="SelectionListener";const Of=e=>!!e.onSelectionChange;function Df({onSelectionChange:e}){const t=ae(Of);return e||t?M.createElement(yo,{onSelectionChange:e}):null}const Lf=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function mt(e,t){w.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ne(e,t,n){w.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Pf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:l,nodesDraggable:c,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:x,minZoom:y,maxZoom:v,nodeExtent:p,onNodesChange:E,onEdgesChange:$,elementsSelectable:b,connectionMode:A,snapGrid:j,snapToGrid:_,translateExtent:I,connectOnClick:S,defaultEdgeOptions:D,fitView:P,fitViewOptions:V,onNodesDelete:F,onEdgesDelete:g,onNodeDrag:C,onNodeDragStart:N,onNodeDragStop:R,onSelectionDrag:H,onSelectionDragStart:k,onSelectionDragStop:T,noPanClassName:L,nodeOrigin:z,rfId:Y,autoPanOnConnect:G,autoPanOnNodeDrag:K,onError:J,connectionRadius:ee,isValidConnection:ie,nodeDragThreshold:te})=>{const{setNodes:re,setEdges:fe,setDefaultNodesAndEdges:B,setMinZoom:q,setMaxZoom:W,setTranslateExtent:Q,setNodeExtent:U,reset:X}=ae(Lf,ge),O=pe();return w.useEffect(()=>{const se=r==null?void 0:r.map(ce=>({...ce,...D}));return B(n,se),()=>{X()}},[]),ne("defaultEdgeOptions",D,O.setState),ne("connectionMode",A,O.setState),ne("onConnect",s,O.setState),ne("onConnectStart",i,O.setState),ne("onConnectEnd",o,O.setState),ne("onClickConnectStart",a,O.setState),ne("onClickConnectEnd",l,O.setState),ne("nodesDraggable",c,O.setState),ne("nodesConnectable",u,O.setState),ne("nodesFocusable",d,O.setState),ne("edgesFocusable",m,O.setState),ne("edgesUpdatable",f,O.setState),ne("elementsSelectable",b,O.setState),ne("elevateNodesOnSelect",x,O.setState),ne("snapToGrid",_,O.setState),ne("snapGrid",j,O.setState),ne("onNodesChange",E,O.setState),ne("onEdgesChange",$,O.setState),ne("connectOnClick",S,O.setState),ne("fitViewOnInit",P,O.setState),ne("fitViewOnInitOptions",V,O.setState),ne("onNodesDelete",F,O.setState),ne("onEdgesDelete",g,O.setState),ne("onNodeDrag",C,O.setState),ne("onNodeDragStart",N,O.setState),ne("onNodeDragStop",R,O.setState),ne("onSelectionDrag",H,O.setState),ne("onSelectionDragStart",k,O.setState),ne("onSelectionDragStop",T,O.setState),ne("noPanClassName",L,O.setState),ne("nodeOrigin",z,O.setState),ne("rfId",Y,O.setState),ne("autoPanOnConnect",G,O.setState),ne("autoPanOnNodeDrag",K,O.setState),ne("onError",J,O.setState),ne("connectionRadius",ee,O.setState),ne("isValidConnection",ie,O.setState),ne("nodeDragThreshold",te,O.setState),mt(e,re),mt(t,fe),mt(y,q),mt(v,W),mt(I,Q),mt(p,U),null},bs={display:"none"},zf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},xo="react-flow__node-desc",wo="react-flow__edge-desc",Hf="react-flow__aria-live",Ff=e=>e.ariaLiveMessage;function Vf({rfId:e}){const t=ae(Ff);return M.createElement("div",{id:`${Hf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:zf},t)}function Bf({rfId:e,disableKeyboardA11y:t}){return M.createElement(M.Fragment,null,M.createElement("div",{id:`${xo}-${e}`,style:bs},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),M.createElement("div",{id:`${wo}-${e}`,style:bs},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&M.createElement(Vf,{rfId:e}))}var Wt=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=w.useState(!1),s=w.useRef(!1),i=w.useRef(new Set([])),[o,a]=w.useMemo(()=>{if(e!==null){const c=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=c.reduce((d,m)=>d.concat(...m),[]);return[c,u]}return[[],[]]},[e]);return w.useEffect(()=>{const l=typeof document<"u"?document:null,c=(t==null?void 0:t.target)||l;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&dr(f))return!1;const y=_s(f.code,a);i.current.add(f[y]),vs(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&dr(f))return!1;const y=_s(f.code,a);vs(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return c==null||c.addEventListener("keydown",u),c==null||c.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{c==null||c.removeEventListener("keydown",u),c==null||c.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function vs(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function _s(e,t){return t.includes(e)?"code":"key"}function bo(e,t,n,r){var a,l;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=lt(i,r);return bo(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[le])==null?void 0:a.z)??0)>(n.z??0)?((l=i[le])==null?void 0:l.z)??0:n.z??0},r)}function vo(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:l}=bo(r,e,{...r.position,z:((i=r[le])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[le].z=l,n!=null&&n[r.id]&&(r[le].isParent=!0)}})}function Yn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const l=(Se(a.zIndex)?a.zIndex:0)+(a.selected?o:0),c=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(c==null?void 0:c.type)&&(c==null?void 0:c.type)!==a.type;Object.defineProperty(u,le,{enumerable:!1,value:{handleBounds:m||(f=c==null?void 0:c[le])==null?void 0:f.handleBounds,z:l}}),s.set(a.id,u)}),vo(s,n,i),s}function _o(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:l,fitViewOnInitDone:c,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!c&&u;if(a&&l&&(m||!t.initial)){const x=n().filter(v=>{var E;const p=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?p&&t.nodes.some($=>$.id===v.id):p}),y=x.every(v=>v.width&&v.height);if(x.length>0&&y){const v=Kt(x,d),{x:p,y:E,zoom:$}=oo(v,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),b=Fe.translate(p,E).scale($);return typeof t.duration=="number"&&t.duration>0?a.transform(st(l,t.duration),b):a.transform(l,b),!0}}return!1}function Gf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[le]:r[le],selected:n.selected})}),new Map(t)}function Yf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function on({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:l,hasDefaultEdges:c}=n();e!=null&&e.length&&(l&&r({nodeInternals:Gf(e,s)}),o==null||o(e)),t!=null&&t.length&&(c&&r({edges:Yf(t,i)}),a==null||a(t))}const pt=()=>{},Wf={zoomIn:pt,zoomOut:pt,zoomTo:pt,getZoom:()=>1,setViewport:pt,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:pt,fitBounds:pt,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Uf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Xf=()=>{const e=pe(),{d3Zoom:t,d3Selection:n}=ae(Uf,ge);return w.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(st(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(st(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(st(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,l]=e.getState().transform,c=Fe.translate(s.x??o,s.y??a).scale(s.zoom??l);t.transform(st(n,i==null?void 0:i.duration),c)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>_o(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:l,maxZoom:c}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:c,d=a/2-s*u,m=l/2-i*u,f=Fe.translate(d,m).scale(u);t.transform(st(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:l,maxZoom:c}=e.getState(),{x:u,y:d,zoom:m}=oo(s,o,a,l,c,(i==null?void 0:i.padding)??.1),f=Fe.translate(u,d).scale(m);t.transform(st(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),hr(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:l}=e.getState();if(!l)return s;const{x:c,y:u}=l.getBoundingClientRect(),d={x:s.x-c,y:s.y-u};return hr(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:l}=o.getBoundingClientRect(),c=ro(s,i);return{x:c.x+a,y:c.y+l}},viewportInitialized:!0}:Wf,[t,n])};function Rn(){const e=Xf(),t=pe(),n=w.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=w.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=w.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(v=>({...v}))},[]),i=w.useCallback(y=>{const{edges:v=[]}=t.getState();return v.find(p=>p.id===y)},[]),o=w.useCallback(y=>{const{getNodes:v,setNodes:p,hasDefaultNodes:E,onNodesChange:$}=t.getState(),b=v(),A=typeof y=="function"?y(b):y;if(E)p(A);else if($){const j=A.length===0?b.map(_=>({type:"remove",id:_.id})):A.map(_=>({item:_,type:"reset"}));$(j)}},[]),a=w.useCallback(y=>{const{edges:v=[],setEdges:p,hasDefaultEdges:E,onEdgesChange:$}=t.getState(),b=typeof y=="function"?y(v):y;if(E)p(b);else if($){const A=b.length===0?v.map(j=>({type:"remove",id:j.id})):b.map(j=>({item:j,type:"reset"}));$(A)}},[]),l=w.useCallback(y=>{const v=Array.isArray(y)?y:[y],{getNodes:p,setNodes:E,hasDefaultNodes:$,onNodesChange:b}=t.getState();if($){const j=[...p(),...v];E(j)}else if(b){const A=v.map(j=>({item:j,type:"add"}));b(A)}},[]),c=w.useCallback(y=>{const v=Array.isArray(y)?y:[y],{edges:p=[],setEdges:E,hasDefaultEdges:$,onEdgesChange:b}=t.getState();if($)E([...p,...v]);else if(b){const A=v.map(j=>({item:j,type:"add"}));b(A)}},[]),u=w.useCallback(()=>{const{getNodes:y,edges:v=[],transform:p}=t.getState(),[E,$,b]=p;return{nodes:y().map(A=>({...A})),edges:v.map(A=>({...A})),viewport:{x:E,y:$,zoom:b}}},[]),d=w.useCallback(({nodes:y,edges:v})=>{const{nodeInternals:p,getNodes:E,edges:$,hasDefaultNodes:b,hasDefaultEdges:A,onNodesDelete:j,onEdgesDelete:_,onNodesChange:I,onEdgesChange:S}=t.getState(),D=(y||[]).map(C=>C.id),P=(v||[]).map(C=>C.id),V=E().reduce((C,N)=>{const R=N.parentNode||N.parentId,H=!D.includes(N.id)&&R&&C.find(T=>T.id===R);return(typeof N.deletable=="boolean"?N.deletable:!0)&&(D.includes(N.id)||H)&&C.push(N),C},[]),F=$.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),g=F.filter(C=>P.includes(C.id));if(V||g){const C=io(V,F),N=[...g,...C],R=N.reduce((H,k)=>(H.includes(k.id)||H.push(k.id),H),[]);if((A||b)&&(A&&t.setState({edges:$.filter(H=>!R.includes(H.id))}),b&&(V.forEach(H=>{p.delete(H.id)}),t.setState({nodeInternals:new Map(p)}))),R.length>0&&(_==null||_(N),S&&S(R.map(H=>({id:H,type:"remove"})))),V.length>0&&(j==null||j(V),I)){const H=V.map(k=>({id:k.id,type:"remove"}));I(H)}}},[]),m=w.useCallback(y=>{const v=hf(y),p=v?null:t.getState().nodeInternals.get(y.id);return!v&&!p?[null,null,v]:[v?y:hs(p),p,v]},[]),f=w.useCallback((y,v=!0,p)=>{const[E,$,b]=m(y);return E?(p||t.getState().getNodes()).filter(A=>{if(!b&&(A.id===$.id||!A.positionAbsolute))return!1;const j=hs(A),_=ur(j,E);return v&&_>0||_>=E.width*E.height}):[]},[]),x=w.useCallback((y,v,p=!0)=>{const[E]=m(y);if(!E)return!1;const $=ur(E,v);return p&&$>0||$>=E.width*E.height},[]);return w.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:l,addEdges:c,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:x}),[e,n,r,s,i,o,a,l,c,u,d,f,x])}const qf={actInsideInputWithModifier:!1};var Kf=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=pe(),{deleteElements:r}=Rn(),s=Wt(e,qf),i=Wt(t);w.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),l=a().filter(u=>u.selected),c=o.filter(u=>u.selected);r({nodes:l,edges:c}),n.setState({nodesSelectionActive:!1})}},[s]),w.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function Zf(e){const t=pe();w.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=kr(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",Be.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Tr={position:"absolute",width:"100%",height:"100%",top:0,left:0},Qf=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,an=e=>({x:e.x,y:e.y,zoom:e.k}),gt=(e,t)=>e.target.closest(`.${t}`),Es=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Ns=e=>{const t=e.ctrlKey&&wn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},Jf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),eh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:l=ot.Free,zoomOnDoubleClick:c=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:x,maxZoom:y,zoomActivationKeyCode:v,preventScrolling:p=!0,children:E,noWheelClassName:$,noPanClassName:b})=>{const A=w.useRef(),j=pe(),_=w.useRef(!1),I=w.useRef(!1),S=w.useRef(null),D=w.useRef({x:0,y:0,zoom:0}),{d3Zoom:P,d3Selection:V,d3ZoomHandler:F,userSelectionActive:g}=ae(Jf,ge),C=Wt(v),N=w.useRef(0),R=w.useRef(!1),H=w.useRef();return Zf(S),w.useEffect(()=>{if(S.current){const k=S.current.getBoundingClientRect(),T=Yi().scaleExtent([x,y]).translateExtent(f),L=Ne(S.current).call(T),z=Fe.translate(m.x,m.y).scale(kt(m.zoom,x,y)),Y=[[0,0],[k.width,k.height]],G=T.constrain()(z,Y,f);T.transform(L,G),T.wheelDelta(Ns),j.setState({d3Zoom:T,d3Selection:L,d3ZoomHandler:L.on("wheel.zoom"),transform:[G.x,G.y,G.k],domNode:S.current.closest(".react-flow")})}},[]),w.useEffect(()=>{V&&P&&(o&&!C&&!g?V.on("wheel.zoom",k=>{if(gt(k,$))return!1;k.preventDefault(),k.stopImmediatePropagation();const T=V.property("__zoom").k||1;if(k.ctrlKey&&i){const ie=$e(k),te=Ns(k),re=T*Math.pow(2,te);P.scaleTo(V,re,ie,k);return}const L=k.deltaMode===1?20:1;let z=l===ot.Vertical?0:k.deltaX*L,Y=l===ot.Horizontal?0:k.deltaY*L;!wn()&&k.shiftKey&&l!==ot.Vertical&&(z=k.deltaY*L,Y=0),P.translateBy(V,-(z/T)*a,-(Y/T)*a,{internal:!0});const G=an(V.property("__zoom")),{onViewportChangeStart:K,onViewportChange:J,onViewportChangeEnd:ee}=j.getState();clearTimeout(H.current),R.current||(R.current=!0,t==null||t(k,G),K==null||K(G)),R.current&&(e==null||e(k,G),J==null||J(G),H.current=setTimeout(()=>{n==null||n(k,G),ee==null||ee(G),R.current=!1},150))},{passive:!1}):typeof F<"u"&&V.on("wheel.zoom",function(k,T){if(!p&&k.type==="wheel"&&!k.ctrlKey||gt(k,$))return null;k.preventDefault(),F.call(this,k,T)},{passive:!1}))},[g,o,l,V,P,F,C,i,p,$,t,e,n]),w.useEffect(()=>{P&&P.on("start",k=>{var z,Y;if(!k.sourceEvent||k.sourceEvent.internal)return null;N.current=(z=k.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=j.getState(),L=an(k.transform);_.current=!0,D.current=L,((Y=k.sourceEvent)==null?void 0:Y.type)==="mousedown"&&j.setState({paneDragging:!0}),T==null||T(L),t==null||t(k.sourceEvent,L)})},[P,t]),w.useEffect(()=>{P&&(g&&!_.current?P.on("zoom",null):g||P.on("zoom",k=>{var L;const{onViewportChange:T}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),I.current=!!(r&&Es(d,N.current??0)),(e||T)&&!((L=k.sourceEvent)!=null&&L.internal)){const z=an(k.transform);T==null||T(z),e==null||e(k.sourceEvent,z)}}))},[g,P,e,d,r]),w.useEffect(()=>{P&&P.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=j.getState();if(_.current=!1,j.setState({paneDragging:!1}),r&&Es(d,N.current??0)&&!I.current&&r(k.sourceEvent),I.current=!1,(n||T)&&Qf(D.current,k.transform)){const L=an(k.transform);D.current=L,clearTimeout(A.current),A.current=setTimeout(()=>{T==null||T(L),n==null||n(k.sourceEvent,L)},o?150:0)}})},[P,o,d,n,r]),w.useEffect(()=>{P&&P.filter(k=>{const T=C||s,L=i&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(gt(k,"react-flow__node")||gt(k,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!c&&!i||g||!c&&k.type==="dblclick"||gt(k,$)&&k.type==="wheel"||gt(k,b)&&(k.type!=="wheel"||o&&k.type==="wheel"&&!C)||!i&&k.ctrlKey&&k.type==="wheel"||!T&&!o&&!L&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&z})},[g,P,s,i,o,c,d,u,C]),M.createElement("div",{className:"react-flow__renderer",ref:S,style:Tr},E)},th=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function nh(){const{userSelectionActive:e,userSelectionRect:t}=ae(th,ge);return e&&t?M.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Ss(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function rh(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&Ss(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&Ss(r,o);break}case"remove":return r}return r.push(o),r},n)}function sh(e,t){return rh(e,t)}const Xe=(e,t)=>({id:e,type:"select",selected:t});function xt(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(Xe(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(Xe(r.id,!1))),n},[])}const Wn=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},ih=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Eo=w.memo(({isSelecting:e,selectionMode:t=Yt.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:l,onPaneMouseMove:c,onPaneMouseLeave:u,children:d})=>{const m=w.useRef(null),f=pe(),x=w.useRef(0),y=w.useRef(0),v=w.useRef(),{userSelectionActive:p,elementsSelectable:E,dragging:$}=ae(ih,ge),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),x.current=0,y.current=0},A=F=>{i==null||i(F),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=F=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){F.preventDefault();return}o==null||o(F)},_=a?F=>a(F):void 0,I=F=>{const{resetSelectedElements:g,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||F.button!==0||F.target!==m.current||!v.current)return;const{x:N,y:R}=Ze(F,v.current);g(),f.setState({userSelectionRect:{width:0,height:0,startX:N,startY:R,x:N,y:R}}),r==null||r(F)},S=F=>{const{userSelectionRect:g,nodeInternals:C,edges:N,transform:R,onNodesChange:H,onEdgesChange:k,nodeOrigin:T,getNodes:L}=f.getState();if(!e||!v.current||!g)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=Ze(F,v.current),Y=g.startX??0,G=g.startY??0,K={...g,x:z.xre.id),te=ee.map(re=>re.id);if(x.current!==te.length){x.current=te.length;const re=xt(J,te);re.length&&(H==null||H(re))}if(y.current!==ie.length){y.current=ie.length;const re=xt(N,ie);re.length&&(k==null||k(re))}f.setState({userSelectionRect:K})},D=F=>{if(F.button!==0)return;const{userSelectionRect:g}=f.getState();!p&&g&&F.target===m.current&&(A==null||A(F)),f.setState({nodesSelectionActive:x.current>0}),b(),s==null||s(F)},P=F=>{p&&(f.setState({nodesSelectionActive:x.current>0}),s==null||s(F)),b()},V=E&&(e||p);return M.createElement("div",{className:ye(["react-flow__pane",{dragging:$,selection:e}]),onClick:V?void 0:Wn(A,m),onContextMenu:Wn(j,m),onWheel:Wn(_,m),onMouseEnter:V?void 0:l,onMouseDown:V?I:void 0,onMouseMove:V?S:c,onMouseUp:V?D:void 0,onMouseLeave:V?P:u,ref:m,style:Tr},d,M.createElement(nh,null))});Eo.displayName="Pane";function No(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:No(r,t):!1}function ks(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function oh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!No(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function ah(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function So(e,t,n,r,s=[0,0],i){const o=ah(e,e.extent||r);let a=o;const l=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(l&&e.width&&e.height){const d=n.get(l),{x:m,y:f}=lt(d,s).positionAbsolute;a=d&&Se(m)&&Se(f)&&Se(d.width)&&Se(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",Be.error005()),a=o;else if(e.extent&&l&&e.extent!=="parent"){const d=n.get(l),{x:m,y:f}=lt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let c={x:0,y:0};if(l){const d=n.get(l);c=lt(d,s).positionAbsolute}const u=a&&a!=="parent"?jr(t,a):t;return{position:{x:u.x-c.x,y:u.y-c.y},positionAbsolute:u}}function Un({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const js=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(l=>{const c=l.getBoundingClientRect();return{id:l.getAttribute("data-handleid"),position:l.getAttribute("data-handlepos"),x:(c.left-o.left-a.x)/n,y:(c.top-o.top-a.y)/n,...kr(l)}})};function Rt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function pr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:l}=t.getState(),c=a.get(e);if(!c){l==null||l("012",Be.error012(e));return}t.setState({nodesSelectionActive:!1}),c.selected?(n||c.selected&&o)&&(i({nodes:[c],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function lh(){const e=pe();return w.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,l={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(l.x/s[0]):l.x,ySnapped:i?s[1]*Math.round(l.y/s[1]):l.y,...l}},[])}function Xn(e){return(t,n,r)=>e==null?void 0:e(t,r)}function ko({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=pe(),[l,c]=w.useState(!1),u=w.useRef([]),d=w.useRef({x:null,y:null}),m=w.useRef(0),f=w.useRef(null),x=w.useRef({x:0,y:0}),y=w.useRef(null),v=w.useRef(!1),p=w.useRef(!1),E=w.useRef(!1),$=lh();return w.useEffect(()=>{if(e!=null&&e.current){const b=Ne(e.current),A=({x:I,y:S})=>{const{nodeInternals:D,onNodeDrag:P,onSelectionDrag:V,updateNodePositions:F,nodeExtent:g,snapGrid:C,snapToGrid:N,nodeOrigin:R,onError:H}=a.getState();d.current={x:I,y:S};let k=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&g){const z=Kt(u.current,R);T=Gt(z)}if(u.current=u.current.map(z=>{const Y={x:I-z.distance.x,y:S-z.distance.y};N&&(Y.x=C[0]*Math.round(Y.x/C[0]),Y.y=C[1]*Math.round(Y.y/C[1]));const G=[[g[0][0],g[0][1]],[g[1][0],g[1][1]]];u.current.length>1&&g&&!z.extent&&(G[0][0]=z.positionAbsolute.x-T.x+g[0][0],G[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+g[1][0],G[0][1]=z.positionAbsolute.y-T.y+g[0][1],G[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+g[1][1]);const K=So(z,Y,D,G,R,H);return k=k||z.position.x!==K.position.x||z.position.y!==K.position.y,z.position=K.position,z.positionAbsolute=K.positionAbsolute,z}),!k)return;F(u.current,!0,!0),c(!0);const L=s?P:Xn(V);if(L&&y.current){const[z,Y]=Un({nodeId:s,dragItems:u.current,nodeInternals:D});L(y.current,z,Y)}},j=()=>{if(!f.current)return;const[I,S]=Ui(x.current,f.current);if(I!==0||S!==0){const{transform:D,panBy:P}=a.getState();d.current.x=(d.current.x??0)-I/D[2],d.current.y=(d.current.y??0)-S/D[2],P({x:I,y:S})&&A(d.current)}m.current=requestAnimationFrame(j)},_=I=>{var R;const{nodeInternals:S,multiSelectionActive:D,nodesDraggable:P,unselectNodesAndEdges:V,onNodeDragStart:F,onSelectionDragStart:g}=a.getState();p.current=!0;const C=s?F:Xn(g);(!o||!i)&&!D&&s&&((R=S.get(s))!=null&&R.selected||V()),s&&i&&o&&pr({id:s,store:a,nodeRef:e});const N=$(I);if(d.current=N,u.current=oh(S,P,N,s),C&&u.current){const[H,k]=Un({nodeId:s,dragItems:u.current,nodeInternals:S});C(I.sourceEvent,H,k)}};if(t)b.on(".drag",null);else{const I=gu().on("start",S=>{const{domNode:D,nodeDragThreshold:P}=a.getState();P===0&&_(S),E.current=!1;const V=$(S);d.current=V,f.current=(D==null?void 0:D.getBoundingClientRect())||null,x.current=Ze(S.sourceEvent,f.current)}).on("drag",S=>{var F,g;const D=$(S),{autoPanOnNodeDrag:P,nodeDragThreshold:V}=a.getState();if(S.sourceEvent.type==="touchmove"&&S.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&p.current&&P&&(v.current=!0,j()),!p.current){const C=D.xSnapped-(((F=d==null?void 0:d.current)==null?void 0:F.x)??0),N=D.ySnapped-(((g=d==null?void 0:d.current)==null?void 0:g.y)??0);Math.sqrt(C*C+N*N)>V&&_(S)}(d.current.x!==D.xSnapped||d.current.y!==D.ySnapped)&&u.current&&p.current&&(y.current=S.sourceEvent,x.current=Ze(S.sourceEvent,f.current),A(D))}}).on("end",S=>{if(!(!p.current||E.current)&&(c(!1),v.current=!1,p.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:D,nodeInternals:P,onNodeDragStop:V,onSelectionDragStop:F}=a.getState(),g=s?V:Xn(F);if(D(u.current,!1,!1),g){const[C,N]=Un({nodeId:s,dragItems:u.current,nodeInternals:P});g(S.sourceEvent,C,N)}}}).filter(S=>{const D=S.target;return!S.button&&(!n||!ks(D,`.${n}`,e))&&(!r||ks(D,r,e))});return b.call(I),()=>{b.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,$]),l}function jo(){const e=pe();return w.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:l,onError:c,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?l[0]:5,f=a?l[1]:5,x=n.isShiftPressed?4:1,y=n.x*m*x,v=n.y*f*x,p=d.map(E=>{if(E.positionAbsolute){const $={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+v};a&&($.x=l[0]*Math.round($.x/l[0]),$.y=l[1]*Math.round($.y/l[1]));const{positionAbsolute:b,position:A}=So(E,$,r,s,void 0,c);E.position=A,E.positionAbsolute=b}return E});i(p,!0,!1)},[])}const vt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Tt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:l,selected:c,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:x,onDoubleClick:y,style:v,className:p,isDraggable:E,isSelectable:$,isConnectable:b,isFocusable:A,selectNodesOnDrag:j,sourcePosition:_,targetPosition:I,hidden:S,resizeObserver:D,dragHandle:P,zIndex:V,isParent:F,noDragClassName:g,noPanClassName:C,initialized:N,disableKeyboardA11y:R,ariaLabel:H,rfId:k,hasHandleBounds:T})=>{const L=pe(),z=w.useRef(null),Y=w.useRef(null),G=w.useRef(_),K=w.useRef(I),J=w.useRef(r),ee=$||E||u||d||m||f,ie=jo(),te=Rt(n,L.getState,d),re=Rt(n,L.getState,m),fe=Rt(n,L.getState,f),B=Rt(n,L.getState,x),q=Rt(n,L.getState,y),W=X=>{const{nodeDragThreshold:O}=L.getState();if($&&(!j||!E||O>0)&&pr({id:n,store:L,nodeRef:z}),u){const se=L.getState().nodeInternals.get(n);se&&u(X,{...se})}},Q=X=>{if(!dr(X)&&!R)if(Zi.includes(X.key)&&$){const O=X.key==="Escape";pr({id:n,store:L,unselect:O,nodeRef:z})}else E&&c&&Object.prototype.hasOwnProperty.call(vt,X.key)&&(L.setState({ariaLiveMessage:`Moved selected node ${X.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),ie({x:vt[X.key].x,y:vt[X.key].y,isShiftPressed:X.shiftKey}))};w.useEffect(()=>()=>{Y.current&&(D==null||D.unobserve(Y.current),Y.current=null)},[]),w.useEffect(()=>{if(z.current&&!S){const X=z.current;(!N||!T||Y.current!==X)&&(Y.current&&(D==null||D.unobserve(Y.current)),D==null||D.observe(X),Y.current=X)}},[S,N,T]),w.useEffect(()=>{const X=J.current!==r,O=G.current!==_,se=K.current!==I;z.current&&(X||O||se)&&(X&&(J.current=r),O&&(G.current=_),se&&(K.current=I),L.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,I]);const U=ko({nodeRef:z,disabled:S||!E,noDragClassName:g,handleSelector:P,nodeId:n,isSelectable:$,selectNodesOnDrag:j});return S?null:M.createElement("div",{className:ye(["react-flow__node",`react-flow__node-${r}`,{[C]:E},p,{selected:c,selectable:$,parent:F,dragging:U}]),ref:z,style:{zIndex:V,transform:`translate(${a}px,${l}px)`,pointerEvents:ee?"all":"none",visibility:N?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:te,onMouseMove:re,onMouseLeave:fe,onContextMenu:B,onClick:W,onDoubleClick:q,onKeyDown:A?Q:void 0,tabIndex:A?0:void 0,role:A?"button":void 0,"aria-describedby":R?void 0:`${xo}-${k}`,"aria-label":H},M.createElement(bf,{value:n},M.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:c,isConnectable:b,sourcePosition:_,targetPosition:I,dragging:U,dragHandle:P,zIndex:V})))};return t.displayName="NodeWrapper",w.memo(t)};const ch=e=>{const t=e.getNodes().filter(n=>n.selected);return{...Kt(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function uh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=pe(),{width:s,height:i,x:o,y:a,transformString:l,userSelectionActive:c}=ae(ch,ge),u=jo(),d=w.useRef(null);if(w.useEffect(()=>{var x;n||(x=d.current)==null||x.focus({preventScroll:!0})},[n]),ko({nodeRef:d}),c||!s||!i)return null;const m=e?x=>{const y=r.getState().getNodes().filter(v=>v.selected);e(x,y)}:void 0,f=x=>{Object.prototype.hasOwnProperty.call(vt,x.key)&&u({x:vt[x.key].x,y:vt[x.key].y,isShiftPressed:x.shiftKey})};return M.createElement("div",{className:ye(["react-flow__nodesselection","react-flow__container",t]),style:{transform:l}},M.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var dh=w.memo(uh);const fh=e=>e.nodesSelectionActive,Co=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:l,onMoveStart:c,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:x,onSelectionEnd:y,multiSelectionKeyCode:v,panActivationKeyCode:p,zoomActivationKeyCode:E,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:A,panOnScroll:j,panOnScrollSpeed:_,panOnScrollMode:I,zoomOnDoubleClick:S,panOnDrag:D,defaultViewport:P,translateExtent:V,minZoom:F,maxZoom:g,preventScrolling:C,onSelectionContextMenu:N,noWheelClassName:R,noPanClassName:H,disableKeyboardA11y:k})=>{const T=ae(fh),L=Wt(d),z=Wt(p),Y=z||D,G=z||j,K=L||m&&Y!==!0;return Kf({deleteKeyCode:a,multiSelectionKeyCode:v}),M.createElement(eh,{onMove:l,onMoveStart:c,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:A,panOnScroll:G,panOnScrollSpeed:_,panOnScrollMode:I,zoomOnDoubleClick:S,panOnDrag:!L&&Y,defaultViewport:P,translateExtent:V,minZoom:F,maxZoom:g,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:R,noPanClassName:H},M.createElement(Eo,{onSelectionStart:x,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:Y,isSelecting:!!K,selectionMode:f},e,T&&M.createElement(dh,{onSelectionContextMenu:N,noPanClassName:H,disableKeyboardA11y:k})))};Co.displayName="FlowRenderer";var hh=w.memo(Co);function mh(e){return ae(w.useCallback(n=>e?so(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function ph(e){const t={input:Tt(e.input||mo),default:Tt(e.default||mr),output:Tt(e.output||go),group:Tt(e.group||Rr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Tt(e[i]||mr),s),n);return{...t,...r}}const gh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},yh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),$o=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=ae(yh,ge),a=mh(e.onlyRenderVisibleElements),l=w.useRef(),c=w.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return l.current=u,u},[]);return w.useEffect(()=>()=>{var u;(u=l==null?void 0:l.current)==null||u.disconnect()},[]),M.createElement("div",{className:"react-flow__nodes",style:Tr},a.map(u=>{var A,j,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",Be.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),x=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),v=!!(u.focusable||r&&typeof u.focusable>"u"),p=e.nodeExtent?jr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(p==null?void 0:p.x)??0,$=(p==null?void 0:p.y)??0,b=gh({x:E,y:$,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return M.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||Z.Bottom,targetPosition:u.targetPosition||Z.Top,hidden:u.hidden,xPos:E,yPos:$,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:x,isConnectable:y,isFocusable:v,resizeObserver:c,dragHandle:u.dragHandle,zIndex:((A=u[le])==null?void 0:A.z)??0,isParent:!!((j=u[le])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[le])!=null&&_.handleBounds)})}))};$o.displayName="NodeRenderer";var xh=w.memo($o);const wh=(e,t,n)=>n===Z.Left?e-t:n===Z.Right?e+t:e,bh=(e,t,n)=>n===Z.Top?e-t:n===Z.Bottom?e+t:e,Cs="react-flow__edgeupdater",$s=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>M.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:ye([Cs,`${Cs}-${a}`]),cx:wh(t,r,e),cy:bh(n,r,e),r,stroke:"transparent",fill:"transparent"}),vh=()=>!0;var yt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:l,animated:c,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:y,style:v,source:p,target:E,sourceX:$,sourceY:b,targetX:A,targetY:j,sourcePosition:_,targetPosition:I,elementsSelectable:S,hidden:D,sourceHandleId:P,targetHandleId:V,onContextMenu:F,onMouseEnter:g,onMouseMove:C,onMouseLeave:N,reconnectRadius:R,onReconnect:H,onReconnectStart:k,onReconnectEnd:T,markerEnd:L,markerStart:z,rfId:Y,ariaLabel:G,isFocusable:K,isReconnectable:J,pathOptions:ee,interactionWidth:ie,disableKeyboardA11y:te})=>{const re=w.useRef(null),[fe,B]=w.useState(!1),[q,W]=w.useState(!1),Q=pe(),U=w.useMemo(()=>`url('#${fr(z,Y)}')`,[z,Y]),X=w.useMemo(()=>`url('#${fr(L,Y)}')`,[L,Y]);if(D)return null;const O=xe=>{var Re;const{edges:Ce,addSelectedEdges:Je,unselectNodesAndEdges:et,multiSelectionActive:tt}=Q.getState(),De=Ce.find(Ct=>Ct.id===n);De&&(S&&(Q.setState({nodesSelectionActive:!1}),De.selected&&tt?(et({nodes:[],edges:[De]}),(Re=re.current)==null||Re.blur()):Je([n])),o&&o(xe,De))},se=It(n,Q.getState,a),ce=It(n,Q.getState,F),me=It(n,Q.getState,g),we=It(n,Q.getState,C),be=It(n,Q.getState,N),Ee=(xe,Ce)=>{if(xe.button!==0)return;const{edges:Je,isValidConnection:et}=Q.getState(),tt=Ce?E:p,De=(Ce?V:P)||null,Re=Ce?"target":"source",Ct=et||vh,Dn=Ce,$t=Je.find(nt=>nt.id===n);W(!0),k==null||k(xe,$t,Re);const Ln=nt=>{W(!1),T==null||T(nt,$t,Re)};co({event:xe,handleId:De,nodeId:tt,onConnect:nt=>H==null?void 0:H($t,nt),isTarget:Dn,getState:Q.getState,setState:Q.setState,isValidConnection:Ct,edgeUpdaterType:Re,onReconnectEnd:Ln})},Ye=xe=>Ee(xe,!0),oe=xe=>Ee(xe,!1),Qe=()=>B(!0),ft=()=>B(!1),ht=!S&&!o,jt=xe=>{var Ce;if(!te&&Zi.includes(xe.key)&&S){const{unselectNodesAndEdges:Je,addSelectedEdges:et,edges:tt}=Q.getState();xe.key==="Escape"?((Ce=re.current)==null||Ce.blur(),Je({edges:[tt.find(Re=>Re.id===n)]})):et([n])}};return M.createElement("g",{className:ye(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:l,animated:c,inactive:ht,updating:fe}]),onClick:O,onDoubleClick:se,onContextMenu:ce,onMouseEnter:me,onMouseMove:we,onMouseLeave:be,onKeyDown:K?jt:void 0,tabIndex:K?0:void 0,role:K?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":G===null?void 0:G||`Edge from ${p} to ${E}`,"aria-describedby":K?`${wo}-${Y}`:void 0,ref:re},!q&&M.createElement(e,{id:n,source:p,target:E,selected:l,animated:c,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:y,data:i,style:v,sourceX:$,sourceY:b,targetX:A,targetY:j,sourcePosition:_,targetPosition:I,sourceHandleId:P,targetHandleId:V,markerStart:U,markerEnd:X,pathOptions:ee,interactionWidth:ie}),J&&M.createElement(M.Fragment,null,(J==="source"||J===!0)&&M.createElement($s,{position:_,centerX:$,centerY:b,radius:R,onMouseDown:Ye,onMouseEnter:Qe,onMouseOut:ft,type:"source"}),(J==="target"||J===!0)&&M.createElement($s,{position:I,centerX:A,centerY:j,radius:R,onMouseDown:oe,onMouseEnter:Qe,onMouseOut:ft,type:"target"})))};return t.displayName="EdgeWrapper",w.memo(t)};function _h(e){const t={default:yt(e.default||_n),straight:yt(e.bezier||Mr),step:yt(e.step||$r),smoothstep:yt(e.step||In),simplebezier:yt(e.simplebezier||Cr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=yt(e[i]||_n),s),n);return{...t,...r}}function Ms(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case Z.Top:return{x:r+i/2,y:s};case Z.Right:return{x:r+i,y:s+o/2};case Z.Bottom:return{x:r+i/2,y:s+o};case Z.Left:return{x:r,y:s+o/2}}}function As(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const Eh=(e,t,n,r,s,i)=>{const o=Ms(n,e,t),a=Ms(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Nh({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:l}){const c={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};c.x===c.x2&&(c.x2+=1),c.y===c.y2&&(c.y2+=1);const u=Gt({x:(0-l[0])/l[2],y:(0-l[1])/l[2],width:o/l[2],height:a/l[2]}),d=Math.max(0,Math.min(u.x2,c.x2)-Math.max(u.x,c.x)),m=Math.max(0,Math.min(u.y2,c.y2)-Math.max(u.y,c.y));return Math.ceil(d*m)>0}function Is(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[le])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const Sh=[{level:0,isMaxLevel:!0,edges:[]}];function kh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const l=Se(a.zIndex);let c=l?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),x=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[le])==null?void 0:u.z)||0,((d=m==null?void 0:m[le])==null?void 0:d.z)||0,1e3);c=(l?a.zIndex:0)+(x?y:0)}return o[c]?o[c].push(a):o[c]=[a],r=c>r?c:r,o},{}),i=Object.entries(s).map(([o,a])=>{const l=+o;return{edges:a,level:l,isMaxLevel:l===r}});return i.length===0?Sh:i}function jh(e,t,n){const r=ae(w.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Nh({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return kh(r,t,n)}const Ch=({color:e="none",strokeWidth:t=1})=>M.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),$h=({color:e="none",strokeWidth:t=1})=>M.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Rs={[bn.Arrow]:Ch,[bn.ArrowClosed]:$h};function Mh(e){const t=pe();return w.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(Rs,e)?Rs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",Be.error009(e)),null)},[e])}const Ah=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const l=Mh(t);return l?M.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},M.createElement(l,{color:n,strokeWidth:o})):null},Ih=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=fr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},Mo=({defaultColor:e,rfId:t})=>{const n=ae(w.useCallback(Ih({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return M.createElement("defs",null,n.map(r=>M.createElement(Ah,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};Mo.displayName="MarkerDefinitions";var Rh=w.memo(Mo);const Th=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ao=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:l,onEdgeMouseLeave:c,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:x,reconnectRadius:y,children:v,disableKeyboardA11y:p})=>{const{edgesFocusable:E,edgesUpdatable:$,elementsSelectable:b,width:A,height:j,connectionMode:_,nodeInternals:I,onError:S}=ae(Th,ge),D=jh(t,I,n);return A?M.createElement(M.Fragment,null,D.map(({level:P,edges:V,isMaxLevel:F})=>M.createElement("svg",{key:P,style:{zIndex:P},width:A,height:j,className:"react-flow__edges react-flow__container"},F&&M.createElement(Rh,{defaultColor:e,rfId:r}),M.createElement("g",null,V.map(g=>{const[C,N,R]=Is(I.get(g.source)),[H,k,T]=Is(I.get(g.target));if(!R||!T)return null;let L=g.type||"default";s[L]||(S==null||S("011",Be.error011(L)),L="default");const z=s[L]||s.default,Y=_===ut.Strict?k.target:(k.target??[]).concat(k.source??[]),G=As(N.source,g.sourceHandle),K=As(Y,g.targetHandle),J=(G==null?void 0:G.position)||Z.Bottom,ee=(K==null?void 0:K.position)||Z.Top,ie=!!(g.focusable||E&&typeof g.focusable>"u"),te=g.reconnectable||g.updatable,re=typeof m<"u"&&(te||$&&typeof te>"u");if(!G||!K)return S==null||S("008",Be.error008(G,g)),null;const{sourceX:fe,sourceY:B,targetX:q,targetY:W}=Eh(C,G,J,H,K,ee);return M.createElement(z,{key:g.id,id:g.id,className:ye([g.className,i]),type:L,data:g.data,selected:!!g.selected,animated:!!g.animated,hidden:!!g.hidden,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,style:g.style,source:g.source,target:g.target,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerEnd:g.markerEnd,markerStart:g.markerStart,sourceX:fe,sourceY:B,targetX:q,targetY:W,sourcePosition:J,targetPosition:ee,elementsSelectable:b,onContextMenu:o,onMouseEnter:a,onMouseMove:l,onMouseLeave:c,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:x,reconnectRadius:y,rfId:r,ariaLabel:g.ariaLabel,isFocusable:ie,isReconnectable:re,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth,disableKeyboardA11y:p})})))),v):null};Ao.displayName="EdgeRenderer";var Oh=w.memo(Ao);const Dh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Lh({children:e}){const t=ae(Dh);return M.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Ph(e){const t=Rn(),n=w.useRef(!1);w.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const zh={[Z.Left]:Z.Right,[Z.Right]:Z.Left,[Z.Top]:Z.Bottom,[Z.Bottom]:Z.Top},Io=({nodeId:e,handleType:t,style:n,type:r=qe.Bezier,CustomComponent:s,connectionStatus:i})=>{var j,_,I;const{fromNode:o,handleId:a,toX:l,toY:c,connectionMode:u}=ae(w.useCallback(S=>({fromNode:S.nodeInternals.get(e),handleId:S.connectionHandleId,toX:(S.connectionPosition.x-S.transform[0])/S.transform[2],toY:(S.connectionPosition.y-S.transform[1])/S.transform[2],connectionMode:S.connectionMode}),[e]),ge),d=(j=o==null?void 0:o[le])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(u===ut.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(S=>S.id===a):m[0],x=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,v=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+x,p=(((I=o.positionAbsolute)==null?void 0:I.y)??0)+y,E=f==null?void 0:f.position,$=E?zh[E]:null;if(!E||!$)return null;if(s)return M.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:v,fromY:p,toX:l,toY:c,fromPosition:E,toPosition:$,connectionStatus:i});let b="";const A={sourceX:v,sourceY:p,sourcePosition:E,targetX:l,targetY:c,targetPosition:$};return r===qe.Bezier?[b]=no(A):r===qe.Step?[b]=vn({...A,borderRadius:0}):r===qe.SmoothStep?[b]=vn(A):r===qe.SimpleBezier?[b]=to(A):b=`M${v},${p} ${l},${c}`,M.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Io.displayName="ConnectionLine";const Hh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Fh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:l,connectionStatus:c}=ae(Hh,ge);return!(s&&i&&a&&o)?null:M.createElement("svg",{style:e,width:a,height:l,className:"react-flow__edges react-flow__connectionline react-flow__container"},M.createElement("g",{className:ye(["react-flow__connection",c])},M.createElement(Io,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:c})))}function Ts(e,t){return w.useRef(null),pe(),w.useMemo(()=>t(e),[e])}const Ro=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:l,onEdgeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:x,onSelectionStart:y,onSelectionEnd:v,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:$,connectionLineContainerStyle:b,selectionKeyCode:A,selectionOnDrag:j,selectionMode:_,multiSelectionKeyCode:I,panActivationKeyCode:S,zoomActivationKeyCode:D,deleteKeyCode:P,onlyRenderVisibleElements:V,elementsSelectable:F,selectNodesOnDrag:g,defaultViewport:C,translateExtent:N,minZoom:R,maxZoom:H,preventScrolling:k,defaultMarkerColor:T,zoomOnScroll:L,zoomOnPinch:z,panOnScroll:Y,panOnScrollSpeed:G,panOnScrollMode:K,zoomOnDoubleClick:J,panOnDrag:ee,onPaneClick:ie,onPaneMouseEnter:te,onPaneMouseMove:re,onPaneMouseLeave:fe,onPaneScroll:B,onPaneContextMenu:q,onEdgeContextMenu:W,onEdgeMouseEnter:Q,onEdgeMouseMove:U,onEdgeMouseLeave:X,onReconnect:O,onReconnectStart:se,onReconnectEnd:ce,reconnectRadius:me,noDragClassName:we,noWheelClassName:be,noPanClassName:Ee,elevateEdgesOnSelect:Ye,disableKeyboardA11y:oe,nodeOrigin:Qe,nodeExtent:ft,rfId:ht})=>{const jt=Ts(e,ph),xe=Ts(t,_h);return Ph(i),M.createElement(hh,{onPaneClick:ie,onPaneMouseEnter:te,onPaneMouseMove:re,onPaneMouseLeave:fe,onPaneContextMenu:q,onPaneScroll:B,deleteKeyCode:P,selectionKeyCode:A,selectionOnDrag:j,selectionMode:_,onSelectionStart:y,onSelectionEnd:v,multiSelectionKeyCode:I,panActivationKeyCode:S,zoomActivationKeyCode:D,elementsSelectable:F,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:L,zoomOnPinch:z,zoomOnDoubleClick:J,panOnScroll:Y,panOnScrollSpeed:G,panOnScrollMode:K,panOnDrag:ee,defaultViewport:C,translateExtent:N,minZoom:R,maxZoom:H,onSelectionContextMenu:x,preventScrolling:k,noDragClassName:we,noWheelClassName:be,noPanClassName:Ee,disableKeyboardA11y:oe},M.createElement(Lh,null,M.createElement(Oh,{edgeTypes:xe,onEdgeClick:a,onEdgeDoubleClick:c,onlyRenderVisibleElements:V,onEdgeContextMenu:W,onEdgeMouseEnter:Q,onEdgeMouseMove:U,onEdgeMouseLeave:X,onReconnect:O,onReconnectStart:se,onReconnectEnd:ce,reconnectRadius:me,defaultMarkerColor:T,noPanClassName:Ee,elevateEdgesOnSelect:!!Ye,disableKeyboardA11y:oe,rfId:ht},M.createElement(Fh,{style:E,type:p,component:$,containerStyle:b})),M.createElement("div",{className:"react-flow__edgelabel-renderer"}),M.createElement(xh,{nodeTypes:jt,onNodeClick:o,onNodeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:g,onlyRenderVisibleElements:V,noPanClassName:Ee,noDragClassName:we,disableKeyboardA11y:oe,nodeOrigin:Qe,nodeExtent:ft,rfId:ht})))};Ro.displayName="GraphView";var Vh=w.memo(Ro);const gr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],We={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:gr,nodeExtent:gr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:ut.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:mf,isValidConnection:void 0},Bh=()=>Cl((e,t)=>({...We,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Yn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Yn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:l,nodeOrigin:c}=t(),u=l==null?void 0:l.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,v)=>{const p=s.get(v.id);if(p!=null&&p.hidden)s.set(p.id,{...p,[le]:{...p[le],handleBounds:void 0}});else if(p){const E=kr(v.nodeElement);!!(E.width&&E.height&&(p.width!==E.width||p.height!==E.height||v.forceUpdate))&&(s.set(p.id,{...p,[le]:{...p[le],handleBounds:{source:js(".source",v.nodeElement,m,c),target:js(".target",v.nodeElement,m,c)}},...E}),y.push({id:p.id,type:"dimensions",dimensions:E}))}return y},[]);vo(s,c);const x=o||i&&!o&&_o(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:x}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const l={id:a.id,type:"position",dragging:s};return r&&(l.positionAbsolute=a.positionAbsolute,l.position=a.position),l});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:l}=t();if(n!=null&&n.length){if(i){const c=sh(n,a()),u=Yn(c,s,o,l);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(l=>Xe(l,!0)):(o=xt(i(),n),a=xt(s,[])),on({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(l=>Xe(l,!0)):(o=xt(s,n),a=xt(i(),[])),on({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,l=o.map(u=>(u.selected=!1,Xe(u.id,!1))),c=a.map(u=>Xe(u.id,!1));on({changedNodes:l,changedEdges:c,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>Xe(a.id,!1)),o=n.filter(a=>a.selected).map(a=>Xe(a.id,!1));on({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=jr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:l}=t();if(!o||!a||!n.x&&!n.y)return!1;const c=Fe.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(c,u,l);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:We.connectionNodeId,connectionHandleId:We.connectionHandleId,connectionHandleType:We.connectionHandleType,connectionStatus:We.connectionStatus,connectionStartHandle:We.connectionStartHandle,connectionEndHandle:We.connectionEndHandle}),reset:()=>e({...We})}),Object.is),To=({children:e})=>{const t=w.useRef(null);return t.current||(t.current=Bh()),M.createElement(af,{value:t.current},e)};To.displayName="ReactFlowProvider";const Oo=({children:e})=>w.useContext(An)?M.createElement(M.Fragment,null,e):M.createElement(To,null,e);Oo.displayName="ReactFlowWrapper";const Gh={input:mo,default:mr,output:go,group:Rr},Yh={default:_n,straight:Mr,step:$r,smoothstep:In,simplebezier:Cr},Wh=[0,0],Uh=[15,15],Xh={x:0,y:0,zoom:1},qh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Do=w.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Gh,edgeTypes:o=Yh,onNodeClick:a,onEdgeClick:l,onInit:c,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:x,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:A,onNodeDoubleClick:j,onNodeDragStart:_,onNodeDrag:I,onNodeDragStop:S,onNodesDelete:D,onEdgesDelete:P,onSelectionChange:V,onSelectionDragStart:F,onSelectionDrag:g,onSelectionDragStop:C,onSelectionContextMenu:N,onSelectionStart:R,onSelectionEnd:H,connectionMode:k=ut.Strict,connectionLineType:T=qe.Bezier,connectionLineStyle:L,connectionLineComponent:z,connectionLineContainerStyle:Y,deleteKeyCode:G="Backspace",selectionKeyCode:K="Shift",selectionOnDrag:J=!1,selectionMode:ee=Yt.Full,panActivationKeyCode:ie="Space",multiSelectionKeyCode:te=wn()?"Meta":"Control",zoomActivationKeyCode:re=wn()?"Meta":"Control",snapToGrid:fe=!1,snapGrid:B=Uh,onlyRenderVisibleElements:q=!1,selectNodesOnDrag:W=!0,nodesDraggable:Q,nodesConnectable:U,nodesFocusable:X,nodeOrigin:O=Wh,edgesFocusable:se,edgesUpdatable:ce,elementsSelectable:me,defaultViewport:we=Xh,minZoom:be=.5,maxZoom:Ee=2,translateExtent:Ye=gr,preventScrolling:oe=!0,nodeExtent:Qe,defaultMarkerColor:ft="#b1b1b7",zoomOnScroll:ht=!0,zoomOnPinch:jt=!0,panOnScroll:xe=!1,panOnScrollSpeed:Ce=.5,panOnScrollMode:Je=ot.Free,zoomOnDoubleClick:et=!0,panOnDrag:tt=!0,onPaneClick:De,onPaneMouseEnter:Re,onPaneMouseMove:Ct,onPaneMouseLeave:Dn,onPaneScroll:$t,onPaneContextMenu:Ln,children:Vr,onEdgeContextMenu:nt,onEdgeDoubleClick:_a,onEdgeMouseEnter:Ea,onEdgeMouseMove:Na,onEdgeMouseLeave:Sa,onEdgeUpdate:ka,onEdgeUpdateStart:ja,onEdgeUpdateEnd:Ca,onReconnect:$a,onReconnectStart:Ma,onReconnectEnd:Aa,reconnectRadius:Ia=10,edgeUpdaterRadius:Ra=10,onNodesChange:Ta,onEdgesChange:Oa,noDragClassName:Da="nodrag",noWheelClassName:La="nowheel",noPanClassName:Br="nopan",fitView:Pa=!1,fitViewOptions:za,connectOnClick:Ha=!0,attributionPosition:Fa,proOptions:Va,defaultEdgeOptions:Ba,elevateNodesOnSelect:Ga=!0,elevateEdgesOnSelect:Ya=!1,disableKeyboardA11y:Gr=!1,autoPanOnConnect:Wa=!0,autoPanOnNodeDrag:Ua=!0,connectionRadius:Xa=20,isValidConnection:qa,onError:Ka,style:Za,id:Yr,nodeDragThreshold:Qa,...Ja},el)=>{const Pn=Yr||"1";return M.createElement("div",{...Ja,style:{...Za,...qh},ref:el,className:ye(["react-flow",s]),"data-testid":"rf__wrapper",id:Yr},M.createElement(Oo,null,M.createElement(Vh,{onInit:c,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:l,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:A,onNodeDoubleClick:j,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:L,connectionLineComponent:z,connectionLineContainerStyle:Y,selectionKeyCode:K,selectionOnDrag:J,selectionMode:ee,deleteKeyCode:G,multiSelectionKeyCode:te,panActivationKeyCode:ie,zoomActivationKeyCode:re,onlyRenderVisibleElements:q,selectNodesOnDrag:W,defaultViewport:we,translateExtent:Ye,minZoom:be,maxZoom:Ee,preventScrolling:oe,zoomOnScroll:ht,zoomOnPinch:jt,zoomOnDoubleClick:et,panOnScroll:xe,panOnScrollSpeed:Ce,panOnScrollMode:Je,panOnDrag:tt,onPaneClick:De,onPaneMouseEnter:Re,onPaneMouseMove:Ct,onPaneMouseLeave:Dn,onPaneScroll:$t,onPaneContextMenu:Ln,onSelectionContextMenu:N,onSelectionStart:R,onSelectionEnd:H,onEdgeContextMenu:nt,onEdgeDoubleClick:_a,onEdgeMouseEnter:Ea,onEdgeMouseMove:Na,onEdgeMouseLeave:Sa,onReconnect:$a??ka,onReconnectStart:Ma??ja,onReconnectEnd:Aa??Ca,reconnectRadius:Ia??Ra,defaultMarkerColor:ft,noDragClassName:Da,noWheelClassName:La,noPanClassName:Br,elevateEdgesOnSelect:Ya,rfId:Pn,disableKeyboardA11y:Gr,nodeOrigin:O,nodeExtent:Qe}),M.createElement(Pf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:x,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,nodesDraggable:Q,nodesConnectable:U,nodesFocusable:X,edgesFocusable:se,edgesUpdatable:ce,elementsSelectable:me,elevateNodesOnSelect:Ga,minZoom:be,maxZoom:Ee,nodeExtent:Qe,onNodesChange:Ta,onEdgesChange:Oa,snapToGrid:fe,snapGrid:B,connectionMode:k,translateExtent:Ye,connectOnClick:Ha,defaultEdgeOptions:Ba,fitView:Pa,fitViewOptions:za,onNodesDelete:D,onEdgesDelete:P,onNodeDragStart:_,onNodeDrag:I,onNodeDragStop:S,onSelectionDrag:g,onSelectionDragStart:F,onSelectionDragStop:C,noPanClassName:Br,nodeOrigin:O,rfId:Pn,autoPanOnConnect:Wa,autoPanOnNodeDrag:Ua,onError:Ka,connectionRadius:Xa,isValidConnection:qa,nodeDragThreshold:Qa}),M.createElement(Df,{onSelectionChange:V}),Vr,M.createElement(cf,{proOptions:Va,position:Fa}),M.createElement(Bf,{rfId:Pn,disableKeyboardA11y:Gr})))});Do.displayName="ReactFlow";const Lo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:l,className:c,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:x,backgroundColor:y}=i||{},v=o||x||y;return M.createElement("rect",{className:ye(["react-flow__minimap-node",{selected:f},c]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:v,stroke:a,strokeWidth:l,shapeRendering:d,onClick:m?p=>m(p,e):void 0})};Lo.displayName="MiniMapNode";var Kh=w.memo(Lo);const Zh=e=>e.nodeOrigin,Qh=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),qn=e=>e instanceof Function?e:()=>e;function Jh({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=Kh,onClick:o}){const a=ae(Qh,ge),l=ae(Zh),c=qn(t),u=qn(e),d=qn(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return M.createElement(M.Fragment,null,a.map(f=>{const{x,y}=lt(f,l).positionAbsolute;return M.createElement(i,{key:f.id,x,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:c(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var em=w.memo(Jh);const tm=200,nm=150,rm=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?ff(Kt(t,e.nodeOrigin),n):n,rfId:e.rfId}},sm="react-flow__minimap-desc";function Po({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:l="rgb(240, 240, 240, 0.6)",maskStrokeColor:c="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:x=!1,zoomable:y=!1,ariaLabel:v="React Flow mini map",inversePan:p=!1,zoomStep:E=10,offsetScale:$=5}){const b=pe(),A=w.useRef(null),{boundingRect:j,viewBB:_,rfId:I}=ae(rm,ge),S=(e==null?void 0:e.width)??tm,D=(e==null?void 0:e.height)??nm,P=j.width/S,V=j.height/D,F=Math.max(P,V),g=F*S,C=F*D,N=$*F,R=j.x-(g-j.width)/2-N,H=j.y-(C-j.height)/2-N,k=g+N*2,T=C+N*2,L=`${sm}-${I}`,z=w.useRef(0);z.current=F,w.useEffect(()=>{if(A.current){const K=Ne(A.current),J=te=>{const{transform:re,d3Selection:fe,d3Zoom:B}=b.getState();if(te.sourceEvent.type!=="wheel"||!fe||!B)return;const q=-te.sourceEvent.deltaY*(te.sourceEvent.deltaMode===1?.05:te.sourceEvent.deltaMode?1:.002)*E,W=re[2]*Math.pow(2,q);B.scaleTo(fe,W)},ee=te=>{const{transform:re,d3Selection:fe,d3Zoom:B,translateExtent:q,width:W,height:Q}=b.getState();if(te.sourceEvent.type!=="mousemove"||!fe||!B)return;const U=z.current*Math.max(1,re[2])*(p?-1:1),X={x:re[0]-te.sourceEvent.movementX*U,y:re[1]-te.sourceEvent.movementY*U},O=[[0,0],[W,Q]],se=Fe.translate(X.x,X.y).scale(re[2]),ce=B.constrain()(se,O,q);B.transform(fe,ce)},ie=Yi().on("zoom",x?ee:null).on("zoom.wheel",y?J:null);return K.call(ie),()=>{K.on("zoom",null)}}},[x,y,p,E]);const Y=m?K=>{const J=$e(K);m(K,{x:J[0],y:J[1]})}:void 0,G=f?(K,J)=>{const ee=b.getState().nodeInternals.get(J);f(K,ee)}:void 0;return M.createElement(Sr,{position:d,style:e,className:ye(["react-flow__minimap",t]),"data-testid":"rf__minimap"},M.createElement("svg",{width:S,height:D,viewBox:`${R} ${H} ${k} ${T}`,role:"img","aria-labelledby":L,ref:A,onClick:Y},v&&M.createElement("title",{id:L},v),M.createElement(em,{onClick:G,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),M.createElement("path",{className:"react-flow__minimap-mask",d:`M${R-N},${H-N}h${k+N*2}v${T+N*2}h${-k-N*2}z - M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:l,fillRule:"evenodd",stroke:c,strokeWidth:u,pointerEvents:"none"})))}Po.displayName="MiniMap";var im=w.memo(Po);function om(){return M.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},M.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function am(){return M.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},M.createElement("path",{d:"M0 0h32v4.2H0z"}))}function lm(){return M.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},M.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function cm(){return M.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},M.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function um(){return M.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},M.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Lt=({children:e,className:t,...n})=>M.createElement("button",{type:"button",className:ye(["react-flow__controls-button",t]),...n},e);Lt.displayName="ControlButton";const dm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),zo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:l,className:c,children:u,position:d="bottom-left"})=>{const m=pe(),[f,x]=w.useState(!1),{isInteractive:y,minZoomReached:v,maxZoomReached:p}=ae(dm,ge),{zoomIn:E,zoomOut:$,fitView:b}=Rn();if(w.useEffect(()=>{x(!0)},[]),!f)return null;const A=()=>{E(),i==null||i()},j=()=>{$(),o==null||o()},_=()=>{b(s),a==null||a()},I=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),l==null||l(!y)};return M.createElement(Sr,{className:ye(["react-flow__controls",c]),position:d,style:e,"data-testid":"rf__controls"},t&&M.createElement(M.Fragment,null,M.createElement(Lt,{onClick:A,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:p},M.createElement(om,null)),M.createElement(Lt,{onClick:j,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},M.createElement(am,null))),n&&M.createElement(Lt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},M.createElement(lm,null)),r&&M.createElement(Lt,{className:"react-flow__controls-interactive",onClick:I,title:"toggle interactivity","aria-label":"toggle interactivity"},y?M.createElement(um,null):M.createElement(cm,null)),u)};zo.displayName="Controls";var fm=w.memo(zo),ke;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(ke||(ke={}));function hm({color:e,dimensions:t,lineWidth:n}){return M.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function mm({color:e,radius:t}){return M.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const pm={[ke.Dots]:"#91919a",[ke.Lines]:"#eee",[ke.Cross]:"#e2e2e2"},gm={[ke.Dots]:1,[ke.Lines]:1,[ke.Cross]:6},ym=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Ho({id:e,variant:t=ke.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:l}){const c=w.useRef(null),{transform:u,patternId:d}=ae(ym,ge),m=o||pm[t],f=r||gm[t],x=t===ke.Dots,y=t===ke.Cross,v=Array.isArray(n)?n:[n,n],p=[v[0]*u[2]||1,v[1]*u[2]||1],E=f*u[2],$=y?[E,E]:p,b=x?[E/i,E/i]:[$[0]/i,$[1]/i];return M.createElement("svg",{className:ye(["react-flow__background",l]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:c,"data-testid":"rf__background"},M.createElement("pattern",{id:d+e,x:u[0]%p[0],y:u[1]%p[1],width:p[0],height:p[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},x?M.createElement(mm,{color:m,radius:E/i}):M.createElement(hm,{dimensions:$,color:m,lineWidth:s})),M.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}Ho.displayName="Background";var xm=w.memo(Ho);const Or=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Fo(e){return Or+e}async function de(e){const t=await fetch(Fo(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function Ge(e,t){const n=await fetch(Fo(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new Vo(r.error??`${e}: ${n.status}`,n.status);return r}class Vo extends Error{constructor(n,r){super(n);ue(this,"status");this.status=r}}const xx=e=>de(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),wx=()=>de("/api/diagnostics"),Bo=(e,t)=>de(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Go=()=>de("/api/ontology/ontologies"),wm=e=>de(`/api/ontology/term?ref=${encodeURIComponent(e)}`),bm=()=>de("/api/ontology/stack"),vm=()=>de("/api/ontology/coverage"),_m=(e,t,n)=>Ge("/api/command",{op:e,payload:t,fingerprint:n??""}),Em=()=>de("/api/git/status"),Nm=()=>de("/api/git/diff"),Sm=e=>Ge("/api/git/commit",{message:e}),km=()=>Ge("/api/git/discard",{}),jm=()=>de("/api/decisions"),Os=(e,t)=>Ge(`/api/decisions/${e}/verdict`,{verdict:t}),bx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),de(`/api/glossary/terms?${t.toString()}`)},vx=()=>de("/api/glossary/config"),_x=e=>Ge("/api/git/propose",e),Ex=(e="HEAD")=>de(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Nx=(e="HEAD")=>de(`/api/git/classify?base=${encodeURIComponent(e)}`),Sx=e=>Ge("/api/git/classify",{changes:e}),kx=e=>de(`/api/git/conflicts?base=${encodeURIComponent(e)}`),jx=(e="")=>de(`/api/git/context?user=${encodeURIComponent(e)}`),Cx=(e="")=>de(`/api/git/proposals?user=${encodeURIComponent(e)}`),Cm=()=>de("/api/export"),$m=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Or}/api/export/${encodeURIComponent(e)}${n}`},Mm=(e,t,n)=>Ge("/api/import",{format:e,content:t,dialect:n}),Am=(e,t)=>Ge("/api/import/preview",{format:e,content:t}),$x=e=>de(`/api/import/stash/${encodeURIComponent(e)}`),Mx=async(e,t=!1)=>{for(const n of e)try{await _m(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Ax=(e,t,n)=>fetch(`${Or}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new Vo(await r.text(),r.status);return await r.json()}),Ix=()=>de("/api/glossary/subject-areas"),Rx=e=>de(`/api/glossary/subject-area/${e}`),Tx=(e,t)=>Ge(`/api/glossary/subject-area/${e}/expand`,t),Im={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Rm(e){return e??""}const Dr="__entity_source",Lr="__entity_target",Tm=w.memo(function({data:t,selected:n}){var j;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:l,expanded:c,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:x}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,I)=>({a:_,i:I})).sort((_,I)=>y(_.a)-y(I.a)||_.i-I.i).map(_=>_.a),p=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const $=!!l&&!c;let b=0;if($){const _=E.filter(I=>d==null?void 0:d.has(I.id));b=E.length-_.length,E=_}const A=(_,I)=>{const S="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:S,onMouseEnter:x?()=>x(_.id):void 0,onMouseLeave:x?()=>x(null):void 0,children:[h.jsx(Ke,{id:_.id,type:"target",position:Z.Left,className:"port attr-port"}),h.jsx(Ke,{id:_.id,type:"source",position:Z.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Im[_.role]}),h.jsx("span",{className:"attr-name"+(I?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Rm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(Ke,{id:Lr,type:"target",position:Z.Left,className:"port"}),h.jsx(Ke,{id:Dr,type:"source",position:Z.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((j=r.conceptual)==null?void 0:j.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var S;const _=(((S=r.conceptual)==null?void 0:S.ontology_refs)??[]).filter(D=>D.uri);if(_.length===0)return null;const I=_.map(D=>D.uri).join(` -`);return h.jsxs("span",{className:"badge ontology",title:I,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),p.length>0&&h.jsx("div",{className:"attr-section keys",children:p.map(_=>A(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>A(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),c&&!!l&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),Om=["string","integer","bigint","decimal","boolean","date","timestamp"];function Dm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,x,y,v,p,E,$,b,A,j,_,I;const l=!n.canEdit,c=e.conceptual,u=t.relationships.filter(S=>S.from.entity===e.id||S.to.entity===e.id),d=S=>{var D;return((D=t.entities.find(P=>P.id===S))==null?void 0:D.name)??S};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Pe,{value:e.name,className:"entity-title-input",readOnly:l,onCommit:S=>r("rename_entity",{id:e.id,name:S})}),(e.physical_name||!l)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Pe,{value:e.physical_name??"",className:"physical-name-input",placeholder:l?"—":"physical table name…",readOnly:l,onCommit:S=>r("rename_entity",{id:e.id,physical_name:S})})]}),h.jsxs("div",{children:[h.jsx(Pm,{entity:e,doc:t,readOnly:l,exec:r}),h.jsx(Hm,{entity:e,readOnly:l,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Pe,{value:((m=c==null?void 0:c.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:l?"—":"add a business definition…",className:"definition-input",readOnly:l,onCommit:S=>r("set_definition",{id:e.id,definition:S})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!l&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=c==null?void 0:c.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((x=c==null?void 0:c.ontology_refs)==null?void 0:x.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(c==null?void 0:c.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${c.ontology_layer}`,children:c.ontology_layer}),c.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Lm,{entityId:e.id,refs:(c==null?void 0:c.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!l&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((p=e.term_map)==null?void 0:p.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),($=e.term_map)!=null&&$.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[((A=e.term_map)==null?void 0:A.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Pe,{value:((_=c==null?void 0:c.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:l,onCommit:S=>{var D;return r("set_stewardship",{id:e.id,owner:S,steward:((D=c==null?void 0:c.stewardship)==null?void 0:D.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Pe,{value:((I=c==null?void 0:c.stewardship)==null?void 0:I.steward)??"",placeholder:"—",readOnly:l,onCommit:S=>{var D;return r("set_stewardship",{id:e.id,owner:((D=c==null?void 0:c.stewardship)==null?void 0:D.owner)??null,steward:S})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(S=>h.jsx(Vm,{a:S,entity:e,doc:t,readOnly:l,exec:r},S.id))})}),!l&&h.jsx(Bm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(S=>{const D=S.members.map(P=>{var V;return((V=e.attributes.find(F=>F.id===P))==null?void 0:V.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+S.type,children:S.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:S.name}),h.jsx("span",{className:"key-cols",children:D})]},S.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([S,D])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:S}),h.jsx("td",{className:"udp-val",children:String(D)})]},S))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(S=>{const D=S.from.entity===e.id?S.to.entity:S.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(D),children:[h.jsx("span",{className:"rel-card",children:Gm(S,e.id)}),d(D)]}),(S.verb_phrase||S.inverse_verb_phrase||!l)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Pe,{value:S.verb_phrase??"",className:"verb-input",placeholder:l?"":"verb phrase…",readOnly:l,onCommit:P=>r("update_relationship",{id:S.id,verb_phrase:P})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Pe,{value:S.inverse_verb_phrase??"",className:"verb-input",placeholder:l?"":"inverse…",readOnly:l,onCommit:P=>r("update_relationship",{id:S.id,inverse_verb_phrase:P})})]})]}),!l&&h.jsx("button",{className:"mini-btn danger",title:`delete ${S.name}`,onClick:()=>r("delete_relationship",{id:S.id}),children:"✕"})]},S.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var S;return(S=navigator.clipboard)==null?void 0:S.writeText(e.id)},children:e.id}),!l&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Lm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const l=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(l?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(l?"proposed":"accepted"),children:l?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[l&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Pe({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=w.useState(e);w.useEffect(()=>a(e),[e]);const l=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:c=>a(c.target.value),onBlur:l}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:c=>a(c.target.value),onBlur:l,onKeyDown:c=>c.key==="Enter"&&c.target.blur()})}function Pm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:l=>r("set_subject_area",{id:e.id,subject_area:l.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(l=>h.jsx("option",{value:l.id,children:l.name},l.id))]})}const zm=["","scd2","hub","link","satellite","bridge"];function Hm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:zm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Fm=["attribute","business_key","measure","surrogate_key"];function Vm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Pe,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Pe,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...Om,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Fm.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Bm({entity:e,exec:t}){const[n,r]=w.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Gm(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var Ym="\0",rt="\0",Ds="";let Wm=class{constructor(t){ue(this,"_isDirected",!0);ue(this,"_isMultigraph",!1);ue(this,"_isCompound",!1);ue(this,"_label");ue(this,"_defaultNodeLabelFn",()=>{});ue(this,"_defaultEdgeLabelFn",()=>{});ue(this,"_nodes",{});ue(this,"_in",{});ue(this,"_preds",{});ue(this,"_out",{});ue(this,"_sucs",{});ue(this,"_edgeObjs",{});ue(this,"_edgeLabels",{});ue(this,"_nodeCount",0);ue(this,"_edgeCount",0);ue(this,"_parent");ue(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[rt]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=rt,this._children[t]={},this._children[rt][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=rt;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==rt)return n}}children(t=rt){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===rt)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Pt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var l=Um(this._isDirected,t,n,r);return t=l.v,n=l.w,Object.freeze(l),this._edgeObjs[a]=l,Ls(this._preds[n],t),Ls(this._sucs[t],n),this._in[n][a]=l,this._out[t][a]=l,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?Kn(this._isDirected,arguments[0]):Pt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?Kn(this._isDirected,arguments[0]):Pt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?Kn(this._isDirected,arguments[0]):Pt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Ps(this._preds[n],t),Ps(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Ls(e,t){e[t]?e[t]++:e[t]=1}function Ps(e,t){--e[t]||delete e[t]}function Pt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Ds+i+Ds+(r===void 0?Ym:r)}function Um(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function Kn(e,t){return Pt(e,t.v,t.w,t.name)}var Pr=Wm,Xm="2.2.4",qm={Graph:Pr,version:Xm},Km=Pr,Zm={write:Qm,read:tp};function Qm(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Jm(e),edges:ep(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function Jm(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function ep(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function tp(e){var t=new Km(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var np=rp;function rp(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let sp=class{constructor(){ue(this,"_arr",[]);ue(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function ap(e,t,n,r){return lp(e,String(t),n||op,r||function(s){return e.outEdges(s)})}function lp(e,t,n,r){var s={},i=new ip,o,a,l=function(c){var u=c.v!==o?c.v:c.w,d=s[u],m=n(c),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+c+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(l);return s}var cp=Wo,up=dp;function dp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=cp(e,s,t,n),r},{})}var Uo=fp;function fp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var l=[],c;do c=n.pop(),r[c].onStack=!1,l.push(c);while(o!==c);s.push(l)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var hp=Uo,mp=pp;function pp(e){return hp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var gp=xp,yp=()=>1;function xp(e,t,n){return wp(e,t||yp,n||function(r){return e.outEdges(r)})}function wp(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,l=t(o);r[i][a]={distance:l,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var l=r[a];s.forEach(function(c){var u=l[i],d=o[c],m=l[c],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?Ep:Np,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function Ep(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),Zo(t(i[0]),o=>s.push([o,!1])))}}function Np(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),Zo(t(i),o=>s.push(o)))}}function Zo(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var Sp=Ko,kp=jp;function jp(e,t){return Sp(e,t,"post")}var Cp=Ko,$p=Mp;function Mp(e,t){return Cp(e,t,"pre")}var Ap=Pr,Ip=Yo,Rp=Tp;function Tp(e,t){var n=new Ap,r={},s=new Ip,i;function o(l){var c=l.v===i?l.w:l.v,u=s.priority(c);if(u!==void 0){var d=t(l);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var Op={components:np,dijkstra:Wo,dijkstraAll:up,findCycles:mp,floydWarshall:gp,isAcyclic:bp,postorder:kp,preorder:$p,prim:Rp,tarjan:Uo,topsort:qo},Hs=qm,Ie={Graph:Hs.Graph,json:Zm,alg:Op,version:Hs.version};let Dp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Fs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Fs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Lp)),r=r._prev;return"["+t.join(", ")+"]"}};function Fs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Lp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Pp=Dp;let zp=Ie.Graph,Hp=Pp;var Fp=Bp;let Vp=()=>1;function Bp(e,t){if(e.nodeCount()<=1)return[];let n=Yp(e,t||Vp);return Gp(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Gp(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)Zn(e,t,n,o);for(;o=s.dequeue();)Zn(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(Zn(e,t,n,o,!0));break}}}return r}function Zn(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),l=e.node(o.v);s&&i.push({v:o.v,w:o.w}),l.out-=a,xr(t,n,l)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),l=o.w,c=e.node(l);c.in-=a,xr(t,n,c)}),e.removeNode(r.v),i}function Yp(e,t){let n=new zp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let l=n.edge(a.v,a.w)||0,c=t(a),u=l+c;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=c),r=Math.max(r,n.node(a.w).in+=c)});let i=Wp(s+r+3).map(()=>new Hp),o=r+1;return n.nodes().forEach(a=>{xr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function xr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Wp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Xp(e){let t=new Qo({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function qp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return zr(e.nodes(),t)}function Kp(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return zr(e.nodes(),t)}function Zp(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let l,c;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),l=a*s/i,c=a):(s<0&&(o=-o),l=o,c=o*i/s),{x:n+l,y:r+c}}function Qp(e){let t=ra(ta(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function Jp(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Tn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function eg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Tn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(l=>e.node(l).rank+=s)})}function tg(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),Jo(e,"border",s,t)}function ng(e,t=ea){const n=[];for(let r=0;rea){const n=ng(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function ta(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Tn(Math.max,n)}function rg(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function sg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function ig(e,t){return t()}let og=0;function na(e){var t=++og;return e+(""+t)}function ra(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function zr(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let cg=Fp,ug=he.uniqueId;var dg={run:fg,undo:mg};function fg(e){(e.graph().acyclicer==="greedy"?cg(e,n(e)):hg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,ug("rev"))});function n(r){return s=>r.edge(s).weight}}function hg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function mg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let pg=he;var gg={run:yg,undo:wg};function yg(e){e.graph().dummyChains=[],e.edges().forEach(t=>xg(e,t))}function xg(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),l=a.labelRank;if(i===r+1)return;e.removeEdge(t);let c,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:bg}=he;var On={longestPath:vg,slack:_g};function vg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=bg(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function _g(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var Eg=Ie.Graph,En=On.slack,sa=Ng;function Ng(e){var t=new Eg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;Sg(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!En(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function kg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=En(t,s)),it.node(r).rank+=n)}var Cg=sa,Vs=On.slack,$g=On.longestPath,Mg=Ie.alg.preorder,Ag=Ie.alg.postorder,Ig=he.simplify,Rg=dt;dt.initLowLimValues=Fr;dt.initCutValues=Hr;dt.calcCutValue=ia;dt.leaveEdge=aa;dt.enterEdge=la;dt.exchangeEdges=ca;function dt(e){e=Ig(e),$g(e);var t=Cg(e);Fr(t),Hr(t,e);for(var n,r;n=aa(t);)r=la(t,e,n),ca(t,e,n,r)}function Hr(e,t){var n=Ag(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Tg(e,t,r))}function Tg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ia(e,t,n)}function ia(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(l=>{var c=l.v===n,u=c?l.w:l.v;if(u!==s){var d=c===i,m=t.edge(l).weight;if(a+=d?m:-m,Dg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Fr(e,t){arguments.length<2&&(t=e.nodes()[0]),oa(e,{},1,t)}function oa(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=oa(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function aa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function la(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,l=!1;i.lim>o.lim&&(a=o,l=!0);var c=t.edges().filter(u=>l===Bs(e,e.node(u.v),a)&&l!==Bs(e,e.node(u.w),a));return c.reduce((u,d)=>Vs(t,d)!t.node(s).parent),r=Mg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Dg(e,t,n){return e.hasEdge(t,n)}function Bs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Lg=On,ua=Lg.longestPath,Pg=sa,zg=Rg,Hg=Fg;function Fg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Gs(e);break;case"tight-tree":Bg(e);break;case"longest-path":Vg(e);break;case"none":break;default:Gs(e)}}var Vg=ua;function Bg(e){ua(e),Pg(e)}function Gs(e){zg(e)}var Gg=Yg;function Yg(e){let t=Ug(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Wg(e,t,s.v,s.w),o=i.path,a=i.lca,l=0,c=o[l],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(c=o[l])!==a&&e.node(c).maxRanko||a>t[l].lim));for(c=l,l=r;(l=e.parent(l))!==c;)i.push(l);return{path:s.concat(i.reverse()),lca:c}}function Ug(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Nn=he;var Xg={run:qg,cleanup:Qg};function qg(e){let t=Nn.addDummyNode(e,"root",{},"_root"),n=Kg(e),r=Object.values(n),s=Nn.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=Zg(e)+1;e.children().forEach(a=>da(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function da(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let l=Nn.addBorderNode(e,"_bt"),c=Nn.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(l,o),u.borderTop=l,e.setParent(c,o),u.borderBottom=c,a.forEach(d=>{da(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,x=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,v=f!==x?1:s-i[o]+1;e.setEdge(l,f,{weight:y,minlen:v,nestingEdge:!0}),e.setEdge(x,c,{weight:y,minlen:v,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,l,{weight:0,minlen:s+i[o]})}function Kg(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function Zg(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function Qg(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let Jg=he;var e0=t0;function t0(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iWs(e.node(t))),e.edges().forEach(t=>Ws(e.edge(t)))}function Ws(e){let t=e.width;e.width=e.height,e.height=t}function i0(e){e.nodes().forEach(t=>Qn(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(Qn),Object.hasOwn(n,"y")&&Qn(n)})}function Qn(e){e.y=-e.y}function o0(e){e.nodes().forEach(t=>Jn(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(Jn),Object.hasOwn(n,"x")&&Jn(n)})}function Jn(e){let t=e.x;e.x=e.y,e.y=t}let Us=he;var a0=l0;function l0(e){let t={},n=e.nodes().filter(l=>!e.children(l).length),r=n.map(l=>e.node(l).rank),s=Us.applyWithChunking(Math.max,r),i=Us.range(s+1).map(()=>[]);function o(l){if(t[l])return;t[l]=!0;let c=e.node(l);i[c.rank].push(l),e.successors(l).forEach(o)}return n.sort((l,c)=>e.node(l).rank-e.node(c).rank).forEach(o),i}let c0=he.zipObject;var u0=d0;function d0(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(c=>e.outEdges(c).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=c.pos+i;a[u]+=c.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=c.weight;l+=c.weight*d}),l}var h0=m0;function m0(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),l=e.node(o.v);return{sum:i.sum+a.weight*l.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let p0=he;var g0=y0;function y0(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return x0(r)}function x0(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&w0(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>p0.pick(s,["vs","i","barycenter","weight"]))}function w0(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let b0=he;var v0=_0;function _0(e,t){let n=b0.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,l=0;r.sort(E0(!!t)),l=Xs(i,s,l),r.forEach(u=>{l+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,l=Xs(i,s,l)});let c={vs:i.flat(!0)};return a&&(c.barycenter=o/a,c.weight=a),c}function Xs(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function E0(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let N0=h0,S0=g0,k0=v0;var j0=ha;function ha(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,l={};o&&(s=s.filter(m=>m!==o&&m!==a));let c=N0(e,s);c.forEach(m=>{if(e.children(m.v).length){let f=ha(e,m.v,n,r);l[m.v]=f,Object.hasOwn(f,"barycenter")&&$0(m,f)}});let u=S0(c,n);C0(u,l);let d=k0(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function C0(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function $0(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let M0=Ie.Graph,A0=he;var I0=R0;function R0(e,t,n,r){r||(r=e.nodes());let s=T0(e),i=new M0({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),l=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,l||s),e[n](o).forEach(c=>{let u=c.v===o?c.w:c.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(c).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function T0(e){for(var t;e.hasNode(t=A0.uniqueId("_root")););return t}var O0=D0;function D0(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,l;for(;o;){if(a=e.parent(o),a?(l=r[a],r[a]=o):(l=s,s=o),l&&l!==o){t.setEdge(l,o);return}o=a}})}let L0=a0,P0=u0,z0=j0,H0=I0,F0=O0,V0=Ie.Graph,ln=he;var B0=ma;function ma(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,ma);return}let n=ln.maxRank(e),r=qs(e,ln.range(1,n+1),"inEdges"),s=qs(e,ln.range(n-1,-1,-1),"outEdges"),i=L0(e);if(Ks(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let l=0,c=0;c<4;++l,++c){G0(l%2?r:s,l%4>=2),i=ln.buildLayerMatrix(e);let u=P0(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return H0(e,i,n,r.get(i)||[])})}function G0(e,t){let n=new V0;e.forEach(function(r){let s=r.graph().root,i=z0(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),F0(r,n,i.vs)})}function Ks(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let Y0=Ie.Graph,ze=he;var W0={positionX:ry};function U0(e,t){let n={};function r(s,i){let o=0,a=0,l=s.length,c=i[i.length-1];return i.forEach((u,d)=>{let m=q0(e,u),f=m?e.node(m).order:l;(m||u===c)&&(i.slice(a,d+1).forEach(x=>{e.predecessors(x).forEach(y=>{let v=e.node(y),p=v.order;(p{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderc)&&pa(n,m,u)})})}function s(i,o){let a=-1,l,c=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(l=e.node(m[0]).order,r(o,c,d,a,l),c=d,a=l)}r(o,c,o.length,l,i.length)}),o}return t.length&&t.reduce(s),n}function q0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function pa(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function K0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function Z0(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((l,c)=>{s[l]=l,i[l]=l,o[l]=c})}),t.forEach(a=>{let l=-1;a.forEach(c=>{let u=r(c);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let x=u[m];i[c]===c&&lMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((x,y)=>Math.min(x,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return l(c,o.predecessors.bind(o)),l(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function J0(e,t,n,r){let s=new Y0,i=e.graph(),o=sy(i.nodesep,i.edgesep,r);return t.forEach(a=>{let l;a.forEach(c=>{let u=n[c];if(s.setNode(u),l){var d=n[l],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,c,l),m||0))}l=c})}),s}function ey(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,l])=>{let c=iy(e,a)/2;s=Math.max(l+c,s),i=Math.min(l-c,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,l=e[a];if(l===t)return;let c=Object.values(l),u=r-ze.applyWithChunking(Math.min,c);o!=="l"&&(u=s-ze.applyWithChunking(Math.max,c)),u&&(e[a]=ze.mapValues(l,d=>d+u))})})}function ny(e,t){return ze.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function ry(e){let t=ze.buildLayerMatrix(e),n=Object.assign(U0(e,t),X0(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let l=(o==="u"?e.predecessors:e.successors).bind(e),c=Z0(e,s,n,l),u=Q0(e,s,c.root,c.align,a==="r");a==="r"&&(u=ze.mapValues(u,d=>-d)),r[o+a]=u})});let i=ey(e,r);return ty(r,i),ny(r,e.graph().align)}function sy(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),l=0,c;if(l+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":c=-o.width/2;break;case"r":c=o.width/2;break}if(c&&(l+=n?c:-c),c=0,l+=(o.dummy?t:e)/2,l+=(a.dummy?t:e)/2,l+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":c=a.width/2;break;case"r":c=-a.width/2;break}return c&&(l+=n?c:-c),c=0,l}}function iy(e,t){return e.node(t).width}let ga=he,oy=W0.positionX;var ay=ly;function ly(e){e=ga.asNonCompoundGraph(e),cy(e),Object.entries(oy(e)).forEach(([t,n])=>e.node(t).x=n)}function cy(e){let t=ga.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const l=e.node(a).height;return o>l?o:l},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let Zs=dg,Qs=gg,uy=Hg,dy=he.normalizeRanks,fy=Gg,hy=he.removeEmptyRanks,Js=Xg,my=e0,ei=n0,py=B0,gy=ay,je=he,yy=Ie.Graph;var xy=wy;function wy(e,t){let n=t&&t.debugTiming?je.time:je.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>$y(e));n(" runLayout",()=>by(r,n,t)),n(" updateInputGraph",()=>vy(e,r))})}function by(e,t,n){t(" makeSpaceForEdgeLabels",()=>My(e)),t(" removeSelfEdges",()=>zy(e)),t(" acyclic",()=>Zs.run(e)),t(" nestingGraph.run",()=>Js.run(e)),t(" rank",()=>uy(je.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Ay(e)),t(" removeEmptyRanks",()=>hy(e)),t(" nestingGraph.cleanup",()=>Js.cleanup(e)),t(" normalizeRanks",()=>dy(e)),t(" assignRankMinMax",()=>Iy(e)),t(" removeEdgeLabelProxies",()=>Ry(e)),t(" normalize.run",()=>Qs.run(e)),t(" parentDummyChains",()=>fy(e)),t(" addBorderSegments",()=>my(e)),t(" order",()=>py(e,n)),t(" insertSelfEdges",()=>Hy(e)),t(" adjustCoordinateSystem",()=>ei.adjust(e)),t(" position",()=>gy(e)),t(" positionSelfEdges",()=>Fy(e)),t(" removeBorderNodes",()=>Py(e)),t(" normalize.undo",()=>Qs.undo(e)),t(" fixupEdgeLabelCoords",()=>Dy(e)),t(" undoCoordinateSystem",()=>ei.undo(e)),t(" translateGraph",()=>Ty(e)),t(" assignNodeIntersects",()=>Oy(e)),t(" reversePoints",()=>Ly(e)),t(" acyclic.undo",()=>Zs.undo(e))}function vy(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let _y=["nodesep","edgesep","ranksep","marginx","marginy"],Ey={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Ny=["acyclicer","ranker","rankdir","align"],Sy=["width","height","rank"],ti={width:0,height:0},ky=["minlen","weight","width","height","labeloffset"],jy={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Cy=["labelpos"];function $y(e){let t=new yy({multigraph:!0,compound:!0}),n=tr(e.graph());return t.setGraph(Object.assign({},Ey,er(n,_y),je.pick(n,Ny))),e.nodes().forEach(r=>{let s=tr(e.node(r));const i=er(s,Sy);Object.keys(ti).forEach(o=>{i[o]===void 0&&(i[o]=ti[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=tr(e.edge(r));t.setEdge(r,Object.assign({},jy,er(s,ky),je.pick(s,Cy)))}),t}function My(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Ay(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};je.addDummyNode(e,"edge-proxy",i,"_ep")}})}function Iy(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Ry(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Ty(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function l(c){let u=c.x,d=c.y,m=c.width,f=c.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(c=>l(e.node(c))),e.edges().forEach(c=>{let u=e.edge(c);Object.hasOwn(u,"x")&&l(u)}),t-=o,r-=a,e.nodes().forEach(c=>{let u=e.node(c);u.x-=t,u.y-=r}),e.edges().forEach(c=>{let u=e.edge(c);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function Oy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(je.intersectRect(r,i)),n.points.push(je.intersectRect(s,o))})}function Dy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Ly(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Py(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function zy(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Hy(e){var t=je.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{je.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Fy(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function er(e,t){return je.mapValues(je.pick(e,t),Number)}function tr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Vy=he,By=Ie.Graph;var Gy={debugOrdering:Yy};function Yy(e){let t=Vy.buildLayerMatrix(e),n=new By({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var Wy="1.1.8",Uy={graphlib:Ie,layout:xy,debug:Gy,util:{time:he.time,notime:he.notime},version:Wy};const ni=fi(Uy),_t=264,Xy=44,qy=26,Ky=14;function Sn(e){const t=Math.max(e.attributes.length,1);return Xy+t*qy+Ky}const Zy=40;function ri(e,t,n,r="auto",s,i="LR"){const o=Qy(n,s);return r==="grid"?ai(e,n,o):r==="clustered"?oi(e,t,n,o,i):r==="hierarchical"||e.length<=Zy?si(e,t,n,i):new Set(e.map(l=>o(l.id)).filter(Boolean)).size>1?oi(e,t,n,o,i):ai(e,n,o)}function Qy(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function ya(e,t,n,r=!1,s="LR"){const i=new ni.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:_t,height:d?Sn(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ni.layout(i);let a=0,l=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?Sn(m):120,x=d.x-_t/2,y=d.y-f/2;return a=Math.max(a,x+_t),l=Math.max(l,y+f),{...u,position:{x,y}}}),width:a,height:l}}function si(e,t,n,r="LR"){return ya(e,t,n,!1,r).nodes}function Jy(e,t){const n=a=>{const l=t.get(a);return l?Sn(l):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(_t+xa);s.push({...c,position:{x:d,y:i}}),o=Math.max(o,d+_t)}),i+=Math.max(...l.map(c=>n(c.id)))+wa}return{nodes:s,width:o,height:i}}const ii=120;function oi(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),x=new Set(f.map(E=>E.id));let y=0;for(const E of t)x.has(E.source)&&x.has(E.target)&&y++;const p=f.length<=8&&y>=f.length-1?ya(f,t,n,!0,s):Jy(f,n);return{name:m,...p}}),l=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),c=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const xa=40,wa=40;function ai(e,t,n){const r=c=>{const u=t.get(c);return u?Sn(u):120},s=[...e].sort((c,u)=>{var y,v;const d=n(c.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(c.id))==null?void 0:y.name)??c.id,x=((v=t.get(u.id))==null?void 0:v.name)??u.id;return f.localeCompare(x)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(c,u)=>u*(_t+xa)),a=new Map;let l=0;for(let c=0;ca.set(m.id,{x:o[f],y:l}));const d=Math.max(...u.map(m=>r(m.id)));l+=d+wa}return e.map(c=>({...c,position:a.get(c.id)??c.position}))}function Zt({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const ex=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],ba=["industry","core","domain","specialised"];function tx({entity:e,exec:t,onClose:n}){var b,A;const[r,s]=w.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[i,o]=w.useState([]),[a,l]=w.useState(null),[c,u]=w.useState(null),[d,m]=w.useState("skos:exactMatch"),[f,x]=w.useState(((A=e.conceptual)==null?void 0:A.ontology_layer)??"core"),[y,v]=w.useState([]),[p,E]=w.useState("");w.useEffect(()=>{Go().then(j=>v(j.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return o([]);Bo(r,p||void 0).then(_=>{o(_.results),l(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(j)},[r,p]);const $=()=>{c&&t("set_alignment",{id:e.id,aligns_to:c.prefixed,alignment:d,layer:f,resolved_via:c.source}).then(n)};return h.jsxs(Zt,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(p===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(j=>h.jsx("button",{className:"src-chip"+(p===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:p?`Search within ${p}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(j=>h.jsxs("button",{className:"term-card"+((c==null?void 0:c.iri)===j.iri?" picked":""),onClick:()=>u(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:ex.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>x(j.target.value),children:ba.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!c,onClick:$,children:["Align",c?` to ${c.label}`:""]})]})]})}function nx({entity:e,doc:t,exec:n,onClose:r}){var b,A,j;const[s,i]=w.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[o,a]=w.useState(((A=e.term_map)==null?void 0:A.class_iri)??""),l=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!l.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},x=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${x}:`,v=(j=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:j.members.map(_=>{var I;return(I=e.attributes.find(S=>S.id===_))==null?void 0:I.name}).filter(Boolean),p=v&&v.length?`${y}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,$=s.trim()||p;return h.jsxs(Zt,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",$]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function rx({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=w.useState(""),[o,a]=w.useState(""),[l,c]=w.useState(""),[u,d]=w.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:l||null,layer:u||null}).then(f=>{const x=f==null?void 0:f.created_id;n(),x&&r(x)})};return h.jsxs(Zt,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:l,onChange:f=>c(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),ba.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const va=["many_to_one","one_to_many","one_to_one","many_to_many"];function sx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(b=>b.id===t),l=e.entities.find(b=>b.id===n),c=w.useMemo(()=>l==null?void 0:l.attributes.find(b=>b.role==="business_key"),[l]),[u,d]=w.useState(r??""),[m,f]=w.useState(s??(c==null?void 0:c.id)??""),[x,y]=w.useState("many_to_one"),[v,p]=w.useState("mandatory");if(!a||!l)return null;const E=u==="__new__",$=()=>i("create_relationship",{from_entity:a.id,to_entity:l.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:x,optionality:v}).then(o);return h.jsxs(Zt,{title:`${a.name} → ${l.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",l.name,")",h.jsx("select",{value:x,onChange:b=>y(b.target.value),children:va.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",c?` "${c.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",l.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),l.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>p(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:$,children:"Create relationship"})})]})}function ix({rel:e,doc:t,exec:n,onClose:r}){const s=p=>{var E;return((E=t.entities.find($=>$.id===p))==null?void 0:E.name)??"?"},[i,o]=w.useState(e.name),[a,l]=w.useState(e.cardinality),[c,u]=w.useState(e.optionality),[d,m]=w.useState(e.identifying),[f,x]=w.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||c!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:c,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(Zt,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:p=>o(p.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:p=>l(p.target.value),children:va.map(p=>h.jsx("option",{children:p},p))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:c,onChange:p=>u(p.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:p=>m(p.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>x(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const ox=w.memo(function({id:t,sourceX:n,sourceY:r,targetX:s,targetY:i,sourcePosition:o,targetPosition:a,data:l,selected:c}){const[u]=vn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10}),d=l==null?void 0:l.relationship,m=(l==null?void 0:l.dimmed)??!1,f=(d==null?void 0:d.cardinality)??"many_to_one",x=(d==null?void 0:d.optionality)==="optional",y=(d==null?void 0:d.identifying)??!1,v=f==="many_to_one"||f==="many_to_many",p=f==="one_to_many"||f==="many_to_many",E="rel-edge"+(c?" selected":"")+(m?" dimmed":""),$=((l==null?void 0:l.memberCount)??0)>1,b=l==null?void 0:l.onHoverEdge;return h.jsxs("g",{className:E,children:[h.jsx("path",{id:t,className:"rel-path",d:u,fill:"none",strokeDasharray:y?void 0:"6 4"}),h.jsx("path",{d:u,fill:"none",strokeWidth:14,stroke:"transparent",onMouseEnter:b?()=>b(d.id):void 0,onMouseLeave:b?()=>b(null):void 0}),h.jsx(li,{x:n,y:r,side:o,many:v,optional:x}),h.jsx(li,{x:s,y:i,side:a,many:p,optional:!1}),(c||$)&&d&&h.jsxs("text",{className:"rel-label",x:(n+s)/2,y:(r+i)/2-8,children:[c?d.verb_phrase||d.name:"",$?`${c?" ":""}(${l.memberCount})`:""]})]})});function li({x:e,y:t,side:n,many:r,optional:s}){const i=n===Z.Left?-1:1,o=7,a=12,l=[];return r?l.push(h.jsx("path",{className:"rel-glyph",d:`M ${e+i*a} ${t} L ${e} ${t-o} M ${e+i*a} ${t} L ${e} ${t} M ${e+i*a} ${t} L ${e} ${t+o}`,fill:"none"},"foot")):l.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a-3),y1:t-o,x2:e+i*(a-3),y2:t+o},"one")),s?l.push(h.jsx("circle",{className:"rel-glyph ring",cx:e+i*(a+6),cy:t,r:4},"opt")):l.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a+5),y1:t-o,x2:e+i*(a+5),y2:t+o},"mand")),h.jsx(h.Fragment,{children:l})}const ax={entity:Tm},lx={relationship:ox},ci=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],ui="#8a7d6a";function cx(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(l=>l.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Dr,targetHandle:n(e.to.entity,s)?s:Lr}}function Px({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:l,onToggleExpand:c,activeAreas:u,onError:d,handleRef:m}){const{fitView:f,fitBounds:x,getNodes:y}=Rn(),[v,p]=w.useState([]),[E,$]=w.useState([]),b=w.useRef(!1),[A,j]=w.useState(null),[_,I]=w.useState(null),[S,D]=w.useState(!1),[P,V]=w.useState(null),[F,g]=w.useState(null),[C,N]=w.useState(null),[R,H]=w.useState(null),k=!t.canEdit,T=w.useMemo(()=>{const B=new Map;return e.subject_areas.forEach((q,W)=>B.set(q.id,ci[W%ci.length])),B},[e]),L=w.useMemo(()=>{const B=new Map;return e.entities.forEach(q=>B.set(q.id,q)),B},[e]),z=w.useMemo(()=>{const B=new Map,q=new Map;return e.subject_areas.forEach(W=>{(W.members??[]).forEach(Q=>q.set(Q,{id:W.id,name:W.name}))}),e.entities.forEach(W=>{var O,se;const Q=(O=W.conceptual)!=null&&O.id?q.get(W.conceptual.id):void 0,U=(se=W.conceptual)==null?void 0:se.subject_area,X=Q??(U?{id:U.id,name:U.name??U.id}:void 0);X&&B.set(W.id,X)}),B},[e]),Y=w.useCallback(B=>{var W;if(!u||u.size===0)return!1;const q=(W=z.get(B))==null?void 0:W.id;return!(q&&u.has(q))},[u,z]),G=w.useMemo(()=>{const B=new Map,q=(W,Q)=>{if(!Q.length)return;const U=B.get(W)??new Set;Q.forEach(X=>U.add(X)),B.set(W,U)};for(const W of e.relationships)q(W.from.entity,W.from.attributes),q(W.to.entity,W.to.attributes);return B},[e]);w.useEffect(()=>{var X;const B=i.trim().toLowerCase(),q=new Set;if(B)for(const O of e.entities)(O.name.toLowerCase()+" "+(((X=O.conceptual)==null?void 0:X.name.toLowerCase())??"")+" "+O.attributes.map(ce=>ce.name.toLowerCase()).join(" ")).includes(B)&&q.add(O.id);const W=new Set;if(r){W.add(r);for(const O of e.relationships)O.from.entity===r&&W.add(O.to.entity),O.to.entity===r&&W.add(O.from.entity)}const Q=e.entities.map(O=>{const se=B!==""&&!q.has(O.id),ce=r!==null&&!W.has(O.id);return{id:O.id,type:"entity",position:{x:0,y:0},hidden:Y(O.id),data:{entity:O,color:(()=>{const me=z.get(O.id);return me?T.get(me.id)??ui:ui})(),dimmed:se||ce,highlighted:B!==""&&q.has(O.id),showTypes:o,collapseDetail:a,expanded:(l==null?void 0:l.has(O.id))??!1,onToggleExpand:c,endpointAttrs:G.get(O.id),highlightAttrs:void 0,onHoverAttr:N}}}),U=e.relationships.filter(O=>L.has(O.from.entity)&&L.has(O.to.entity)).map(O=>{const{sourceHandle:se,targetHandle:ce}=cx(O,L),me=r!==null&&O.from.entity!==r&&O.to.entity!==r;return{id:O.id,source:O.from.entity,target:O.to.entity,sourceHandle:se,targetHandle:ce,type:"relationship",data:{relationship:O,dimmed:me,memberCount:Math.max(O.from.attributes.length,O.to.attributes.length),onHoverEdge:H}}});p(O=>{const se=new Map(O.map(oe=>[oe.id,oe.position])),ce=Q.every(oe=>se.has(oe.id)),me=((u==null?void 0:u.size)??0)>0;if(b.current&&ce&&O.length>=Q.length&&!me)return Q.map(oe=>({...oe,position:se.get(oe.id)??oe.position}));const we=me?Q.filter(oe=>!oe.hidden):Q,be=ri(we,U,L,"auto",z),Ee=new Map(be.map(oe=>[oe.id,oe.position])),Ye=Q.map(oe=>Ee.has(oe.id)?{...oe,position:Ee.get(oe.id)}:se.has(oe.id)&&b.current?{...oe,position:se.get(oe.id)}:oe);return b.current=!0,requestAnimationFrame(()=>f({padding:.15,duration:300})),Ye}),$(U)},[e,i,r,o,a,l,c,T,L,z,Y,u,G,f]);const K=w.useMemo(()=>{const B=new Set,q=new Set,W=new Map,Q=(U,X)=>{if(!X.length)return;const O=W.get(U)??new Set;X.forEach(se=>O.add(se)),W.set(U,O)};if(C)for(const U of e.relationships)(U.from.attributes.includes(C)||U.to.attributes.includes(C))&&(B.add(U.id),q.add(U.from.entity),q.add(U.to.entity),Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes));if(R){const U=e.relationships.find(X=>X.id===R);U&&(Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes))}return{active:C!==null,relsForAttr:B,entsForAttr:q,hitAttrsByEntity:W}},[e,C,R]);w.useEffect(()=>{var Q;const B=i.trim().toLowerCase(),q=new Set;if(B)for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(O=>O.name.toLowerCase()).join(" ")).includes(B)&&q.add(U.id);const W=new Set;if(r){W.add(r);for(const U of e.relationships)U.from.entity===r&&W.add(U.to.entity),U.to.entity===r&&W.add(U.from.entity)}p(U=>U.map(X=>{const O=B!==""&&!q.has(X.id),se=r!==null&&!W.has(X.id),ce=K.active&&!K.entsForAttr.has(X.id),me=O||se||ce,we=B!==""&&q.has(X.id)||K.active&&K.entsForAttr.has(X.id),be=K.hitAttrsByEntity.get(X.id);return X.data.dimmed===me&&X.data.highlighted===we&&X.data.highlightAttrs===be?X:{...X,data:{...X.data,dimmed:me,highlighted:we,highlightAttrs:be}}})),$(U=>U.map(X=>{var we,be;const O=(we=X.data)==null?void 0:we.relationship,se=r!==null&&O!==void 0&&O.from.entity!==r&&O.to.entity!==r,ce=K.active&&!K.relsForAttr.has(X.id),me=se||ce;return((be=X.data)==null?void 0:be.dimmed)===me?X:{...X,data:{...X.data,dimmed:me}}}))},[K,i,r,e]),w.useEffect(()=>{var Q;const B=i.trim().toLowerCase();if(!B)return;const q=new Set;for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(O=>O.name.toLowerCase()).join(" ")).includes(B)&&q.add(U.id);if(!q.size)return;const W=requestAnimationFrame(()=>{const U=y().filter(O=>q.has(O.id));if(!U.length)return;const X=kf(U);x(X,{padding:.35,duration:400})});return()=>cancelAnimationFrame(W)},[i,e,y,x]);const J=w.useCallback((B="auto",q="LR")=>{p(W=>ri(W,E,L,B,z,q)),requestAnimationFrame(()=>f({padding:.15,duration:300}))},[E,L,z,f]),ee=w.useCallback(B=>{s(B),p(q=>(q.find(Q=>Q.id===B)&&requestAnimationFrame(()=>f({nodes:[{id:B}],padding:.4,duration:400})),q))},[f,s]);w.useImperativeHandle(m,()=>({relayout:J,fitView:()=>f({padding:.15,duration:300}),focusEntity:ee,newEntity:()=>D(!0)}),[J,f,ee]);const ie=w.useCallback(B=>{if(k||!B.source||!B.target||B.source===B.target)return;const q=B.sourceHandle&&B.sourceHandle!==Dr?B.sourceHandle:void 0,W=B.targetHandle&&B.targetHandle!==Lr?B.targetHandle:void 0;V({from:B.source,to:B.target,fromAttr:q,toAttr:W})},[k]),te=w.useCallback(async(B,q)=>{try{return await n(B,q)}catch(W){throw d==null||d(W instanceof Error?W.message:String(W)),W}},[n,d]),re=r?L.get(r)??null:null,fe=e.relationships.find(B=>B.id===F)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Do,{nodes:v,edges:E,nodeTypes:ax,edgeTypes:lx,onNodeClick:(B,q)=>s(q.id),onEdgeClick:(B,q)=>!k&&g(q.id),onPaneClick:()=>{s(null),g(null)},onNodeDragStop:(B,q)=>p(W=>W.map(Q=>Q.id===q.id?{...Q,position:q.position}:Q)),onConnect:ie,nodesConnectable:!k,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(xm,{variant:ke.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(im,{pannable:!0,zoomable:!0,nodeColor:B=>{var q;return((q=B.data)==null?void 0:q.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(fm,{showInteractive:!1})]}),re&&h.jsx(Dm,{entity:re,doc:e,caps:t,exec:te,onClose:()=>s(null),onFocusEntity:ee,onAlign:j,onEditMapping:I}),A&&h.jsx(tx,{entity:A,exec:te,onClose:()=>j(null)}),_&&h.jsx(nx,{entity:_,doc:e,exec:te,onClose:()=>I(null)}),S&&h.jsx(rx,{doc:e,exec:te,onClose:()=>D(!1),onCreated:ee}),P&&h.jsx(sx,{doc:e,fromId:P.from,toId:P.to,initialFromAttr:P.fromAttr,initialToAttr:P.toAttr,exec:te,onClose:()=>V(null)}),fe&&h.jsx(ix,{rel:fe,doc:e,exec:te,onClose:()=>g(null)})]})}function zx({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(ux,{}),e==="layers"&&h.jsx(fx,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(hx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(mx,{readOnly:n})]})}function ux(){const[e,t]=w.useState(""),[n,r]=w.useState([]),[s,i]=w.useState({loaded:0,vocabs:[]}),[o,a]=w.useState(null),[l,c]=w.useState([]),[u,d]=w.useState("");w.useEffect(()=>{Go().then(f=>c(f.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const f=setTimeout(()=>{Bo(e||"a",u||void 0).then(x=>{r(e?x.results:[]),i({loaded:x.loaded_terms,vocabs:x.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=w.useCallback(f=>{wm(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[l.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),l.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:l.length>0?`${l.length} source${l.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const dx=["industry","core","domain","specialised"];function fx({refreshKey:e,onFocusEntity:t}){const[n,r]=w.useState(null),[s,i]=w.useState(null);if(w.useEffect(()=>{bm().then(r).catch(()=>{}),vm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),dx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(l=>{var c;return h.jsxs("button",{className:"stack-term"+(o.has(l.name)?" uncovered":""),title:l.definition??void 0,onClick:()=>t(l.id),children:[l.name,(l.aligned_refs??(l.aligned_to?[l.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!l.aligned_to&&(((c=l.aligned_refs)==null?void 0:c.length)??0)===0&&!l.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},l.id)})]},a))]})}function hx({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=w.useState(null),[i,o]=w.useState(""),[a,l]=w.useState(""),[c,u]=w.useState(!1),d=w.useCallback(()=>{Em().then(s).catch(()=>s(null)),Nm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` - -`))).catch(()=>o(""))},[]);return w.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:i.split(` -`).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` -`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>l(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:c,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(u(!0),km().then(()=>{u(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:c||!a.trim(),onClick:()=>{u(!0),Sm(a).then(()=>{u(!1),l(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function mx({readOnly:e}){const[t,n]=w.useState([]),r=w.useCallback(()=>{jm().then(i=>n(i.decisions)).catch(()=>n([]))},[]);if(w.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(i=>h.jsxs("div",{className:"decision "+i.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[i.verdict]}),h.jsx("span",{className:"chip",children:i.confidence}),h.jsx("span",{className:"chip",children:i.signal})]}),h.jsx("p",{className:"decision-subject",children:i.subject}),!e&&i.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Os(i.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Os(i.signal_key,"rejected").then(r),children:"Reject"})]})]},i.signal_key))})}function Hx({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:i,openImport:o=!1,prefillImport:a="",onPreview:l}){const[c,u]=w.useState(o&&t?"import":null),[d,m]=w.useState([]),[f,x]=w.useState("postgres"),y=w.useRef(null);w.useEffect(()=>{Cm().then(p=>m(p.formats)).catch(()=>m([]))},[]),w.useEffect(()=>{if(!c)return;const p=E=>{y.current&&!y.current.contains(E.target)&&u(null)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[c]);const v=d.find(p=>p.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:y,children:[h.jsxs("button",{className:s+(c==="export"?" on":""),onClick:()=>u(c==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(c==="import"?" on":""),onClick:()=>u(c==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),c==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(v==null?void 0:v.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:p=>x(p.target.value),children:v.dialects.map(p=>h.jsx("option",{value:p,children:p},p))})]}),d.map(p=>h.jsx("a",{className:"ie-item",href:$m(p.id,p.id==="sql"?f:void 0),download:!0,onClick:()=>u(null),children:p.label},p.id))]}),c==="import"&&h.jsx(px,{exec:e,submitLabel:r,buttonClass:s,applyBatch:i,onClose:()=>u(null),onImported:p=>{u(null),n==null||n(p)},onPreview:l,prefillImport:a})]})}const di=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function px({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:i,onPreview:o,prefillImport:a}){var j;const[l,c]=w.useState(o?"erwin":"sql"),[u,d]=w.useState("postgres"),[m,f]=w.useState(a??""),[x,y]=w.useState(!1),[v,p]=w.useState(null),[E,$]=w.useState([]);w.useEffect(()=>{a&&f(a)},[a]);const b=_=>{_&&_.text().then(f).catch(()=>p("could not read that file"))},A=async()=>{y(!0),p(null),$([]);try{if(o&&l==="erwin"){const I=await Am(l,m);if(!I.changes.length){p(I.warnings[0]??"nothing to import from that document"),y(!1);return}s(),o(I),y(!1);return}const _=await Mm(l,m,l==="sql"?u:void 0);if(!_.changes.length){p(_.warnings[0]??"nothing to import from that document"),y(!1);return}if(r)await r(_.changes);else for(const I of _.changes)await e(I.op,I.payload);$(_.warnings),i(_.tables)}catch(_){p(_ instanceof Error?_.message:String(_))}finally{y(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:di.map(_=>h.jsx("button",{className:"ie-tab"+(l===_.id?" active":""),onClick:()=>c(_.id),children:_.label},_.id))}),h.jsx("p",{className:"ie-hint",children:(j=di.find(_=>_.id===l))==null?void 0:j.hint}),l==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:u,onChange:_=>d(_.target.value),children:["postgres","snowflake","mysql","duckdb"].map(_=>h.jsx("option",{children:_},_))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${l} here, or choose a file…`,value:m,onChange:_=>f(_.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:_=>{var I;return b(((I=_.target.files)==null?void 0:I[0])??null)}}),l==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((_,I)=>h.jsx("p",{className:"ie-warn",children:_},I)),v&&h.jsx("p",{className:"ie-error",children:v}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:x||!m.trim(),onClick:A,children:x?"Importing…":t})]})]})}export{Vo as A,xm as B,fm as C,Tm as E,Hx as I,fx as L,Px as M,ux as O,ci as P,To as R,zx as S,wx as a,Mx as b,jx as c,Ix as d,Rx as e,xx as f,Em as g,Tx as h,Cx as i,_x as j,Ex as k,Nx as l,kx as m,$x as n,Bo as o,Ax as p,Sx as q,bx as r,_m as s,vx as t,ri as u,Do as v,ox as w,im as x}; diff --git a/packages/server/src/mdl_server/static/assets/styles-DxhL4SV-.css b/packages/server/src/mdl_server/static/assets/styles-DO3eXfyX.css similarity index 60% rename from packages/server/src/mdl_server/static/assets/styles-DxhL4SV-.css rename to packages/server/src/mdl_server/static/assets/styles-DO3eXfyX.css index 442fd83..bf0c725 100644 --- a/packages/server/src/mdl_server/static/assets/styles-DxhL4SV-.css +++ b/packages/server/src/mdl_server/static/assets/styles-DO3eXfyX.css @@ -1 +1 @@ -.react-flow{direction:ltr}.react-flow__container{position:absolute;width:100%;height:100%;top:0;left:0}.react-flow__pane{z-index:1;cursor:-webkit-grab;cursor:grab}.react-flow__pane.selection{cursor:pointer}.react-flow__pane.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__viewport{transform-origin:0 0;z-index:2;pointer-events:none}.react-flow__renderer{z-index:4}.react-flow__selection{z-index:6}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible{outline:none}.react-flow .react-flow__edges{pointer-events:none;overflow:visible}.react-flow__edge-path,.react-flow__connection-path{stroke:#b1b1b7;stroke-width:1;fill:none}.react-flow__edge{pointer-events:visibleStroke;cursor:pointer}.react-flow__edge.animated path{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__edge.animated path.react-flow__edge-interaction{stroke-dasharray:none;-webkit-animation:none;animation:none}.react-flow__edge.inactive{pointer-events:none}.react-flow__edge.selected,.react-flow__edge:focus,.react-flow__edge:focus-visible{outline:none}.react-flow__edge.selected .react-flow__edge-path,.react-flow__edge:focus .react-flow__edge-path,.react-flow__edge:focus-visible .react-flow__edge-path{stroke:#555}.react-flow__edge-textwrapper{pointer-events:all}.react-flow__edge-textbg{fill:#fff}.react-flow__edge .react-flow__edge-text{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__connection{pointer-events:none}.react-flow__connection .animated{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__connectionline{z-index:1001}.react-flow__nodes{pointer-events:none;transform-origin:0 0}.react-flow__node{position:absolute;-webkit-user-select:none;-moz-user-select:none;user-select:none;pointer-events:all;transform-origin:0 0;box-sizing:border-box;cursor:-webkit-grab;cursor:grab}.react-flow__node.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__nodesselection{z-index:3;transform-origin:left top;pointer-events:none}.react-flow__nodesselection-rect{position:absolute;pointer-events:all;cursor:-webkit-grab;cursor:grab}.react-flow__handle{position:absolute;pointer-events:none;min-width:5px;min-height:5px;width:6px;height:6px;background:#1a192b;border:1px solid white;border-radius:100%}.react-flow__handle.connectionindicator{pointer-events:all;cursor:crosshair}.react-flow__handle-bottom{top:auto;left:50%;bottom:-4px;transform:translate(-50%)}.react-flow__handle-top{left:50%;top:-4px;transform:translate(-50%)}.react-flow__handle-left{top:50%;left:-4px;transform:translateY(-50%)}.react-flow__handle-right{right:-4px;top:50%;transform:translateY(-50%)}.react-flow__edgeupdater{cursor:move;pointer-events:all}.react-flow__panel{position:absolute;z-index:5;margin:15px}.react-flow__panel.top{top:0}.react-flow__panel.bottom{bottom:0}.react-flow__panel.left{left:0}.react-flow__panel.right{right:0}.react-flow__panel.center{left:50%;transform:translate(-50%)}.react-flow__attribution{font-size:10px;background:#ffffff80;padding:2px 3px;margin:0}.react-flow__attribution a{text-decoration:none;color:#999}@-webkit-keyframes dashdraw{0%{stroke-dashoffset:10}}@keyframes dashdraw{0%{stroke-dashoffset:10}}.react-flow__edgelabel-renderer{position:absolute;width:100%;height:100%;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__edge.updating .react-flow__edge-path{stroke:#777}.react-flow__edge-text{font-size:10px}.react-flow__node.selectable:focus,.react-flow__node.selectable:focus-visible{outline:none}.react-flow__node-default,.react-flow__node-input,.react-flow__node-output,.react-flow__node-group{padding:10px;border-radius:3px;width:150px;font-size:12px;color:#222;text-align:center;border-width:1px;border-style:solid;border-color:#1a192b;background-color:#fff}.react-flow__node-default.selectable:hover,.react-flow__node-input.selectable:hover,.react-flow__node-output.selectable:hover,.react-flow__node-group.selectable:hover{box-shadow:0 1px 4px 1px #00000014}.react-flow__node-default.selectable.selected,.react-flow__node-default.selectable:focus,.react-flow__node-default.selectable:focus-visible,.react-flow__node-input.selectable.selected,.react-flow__node-input.selectable:focus,.react-flow__node-input.selectable:focus-visible,.react-flow__node-output.selectable.selected,.react-flow__node-output.selectable:focus,.react-flow__node-output.selectable:focus-visible,.react-flow__node-group.selectable.selected,.react-flow__node-group.selectable:focus,.react-flow__node-group.selectable:focus-visible{box-shadow:0 0 0 .5px #1a192b}.react-flow__node-group{background-color:#f0f0f040}.react-flow__nodesselection-rect,.react-flow__selection{background:#0059dc14;border:1px dotted rgba(0,89,220,.8)}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible,.react-flow__selection:focus,.react-flow__selection:focus-visible{outline:none}.react-flow__controls{box-shadow:0 0 2px 1px #00000014}.react-flow__controls-button{border:none;background:#fefefe;border-bottom:1px solid #eee;box-sizing:content-box;display:flex;justify-content:center;align-items:center;width:16px;height:16px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;padding:5px}.react-flow__controls-button:hover{background:#f4f4f4}.react-flow__controls-button svg{width:100%;max-width:12px;max-height:12px}.react-flow__controls-button:disabled{pointer-events:none}.react-flow__controls-button:disabled svg{fill-opacity:.4}.react-flow__minimap{background-color:#fff}.react-flow__minimap svg{display:block}.react-flow__resize-control{position:absolute}.react-flow__resize-control.left,.react-flow__resize-control.right{cursor:ew-resize}.react-flow__resize-control.top,.react-flow__resize-control.bottom{cursor:ns-resize}.react-flow__resize-control.top.left,.react-flow__resize-control.bottom.right{cursor:nwse-resize}.react-flow__resize-control.bottom.left,.react-flow__resize-control.top.right{cursor:nesw-resize}.react-flow__resize-control.handle{width:4px;height:4px;border:1px solid #fff;border-radius:1px;background-color:#3367d9;transform:translate(-50%,-50%)}.react-flow__resize-control.handle.left{left:0;top:50%}.react-flow__resize-control.handle.right{left:100%;top:50%}.react-flow__resize-control.handle.top{left:50%;top:0}.react-flow__resize-control.handle.bottom{left:50%;top:100%}.react-flow__resize-control.handle.top.left,.react-flow__resize-control.handle.bottom.left{left:0}.react-flow__resize-control.handle.top.right,.react-flow__resize-control.handle.bottom.right{left:100%}.react-flow__resize-control.line{border-color:#3367d9;border-width:0;border-style:solid}.react-flow__resize-control.line.left,.react-flow__resize-control.line.right{width:1px;transform:translate(-50%);top:0;height:100%}.react-flow__resize-control.line.left{left:0;border-left-width:1px}.react-flow__resize-control.line.right{left:100%;border-right-width:1px}.react-flow__resize-control.line.top,.react-flow__resize-control.line.bottom{height:1px;transform:translateY(-50%);left:0;width:100%}.react-flow__resize-control.line.top{top:0;border-top-width:1px}.react-flow__resize-control.line.bottom{border-bottom-width:1px;top:100%}.ie-wrap{position:relative;display:inline-flex;gap:6px}.erd-ico{font-size:13px;line-height:1;opacity:.85;margin-right:1px}.ie-wrap button:hover .erd-ico,.ie-wrap button.on .erd-ico,.ie-wrap button.active .erd-ico{opacity:1}.erd-caret{opacity:.55;margin-left:1px}.ie-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:30;min-width:220px;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:6px;box-shadow:0 12px 32px #00000073;display:flex;flex-direction:column;gap:2px}.ie-item{display:block;padding:8px 10px;border-radius:6px;color:var(--text);text-decoration:none;font-size:13px;cursor:pointer}.ie-item:hover{background:#5eead424;color:var(--accent)}.ie-dialect{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 10px 8px;margin-bottom:4px;border-bottom:1px solid var(--border);font-size:12px;color:var(--text-dim)}.ie-dialect select{background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;padding:3px 6px;font-size:12px}.ie-import{width:380px;padding:12px;gap:8px}.ie-tabs{display:flex;gap:4px}.ie-tab{flex:1;padding:6px 8px;border-radius:6px;font-size:12px;cursor:pointer;background:none;border:1px solid var(--border);color:var(--text-dim)}.ie-tab.active{border-color:var(--accent);color:var(--accent);background:#5eead41a}.ie-hint{font-size:11px;color:var(--text-dim);margin:0}.ie-textarea{width:100%;font-family:var(--mono);font-size:12px;resize:vertical;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:8px;padding:8px;box-sizing:border-box}.ie-textarea:focus{border-color:var(--accent);outline:none}.ie-file{font-size:11px;color:var(--text-dim)}.ie-warn{font-size:11px;color:var(--pk);margin:0}.ie-error{font-size:12px;color:var(--err);margin:0}.ie-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:4px}:root{--bg: #14110f;--bg-raised: #1c1815;--bg-card: #221d19;--border: #33291f;--border-strong: #4a3c2c;--text: #ece6dd;--text-dim: #a89a86;--accent: #e0a63a;--accent-soft: rgba(224, 166, 58, .15);--accent-ink: #241a08;--pk: #f2c14e;--err: #f0857a;--warn: #e6a94a;--ok: #6cbf73;--font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;--mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace}*{box-sizing:border-box}html,body,#root{height:100%;margin:0}body{font-family:var(--font);background:var(--bg);color:var(--text)}.app{display:flex;flex-direction:column;height:100%}.canvas-wrap{flex:1;position:relative;min-height:0}.react-flow{background:var(--bg)}.topbar{display:flex;flex-direction:column;padding:8px 16px 0;background:var(--bg-raised);border-bottom:1px solid var(--border);z-index:10}.topbar-row{display:flex;align-items:center;gap:14px}.topbar-row.context{padding-bottom:8px}.topbar-row.actions{gap:10px;padding-bottom:8px;flex-wrap:wrap}.brand{display:flex;align-items:baseline;gap:8px;white-space:nowrap}.logo{color:var(--accent);font-size:18px}.brand-name{font-weight:700;letter-spacing:.02em}.project-name{color:var(--text-dim);font-size:13px}.search{flex:0 1 300px;margin-left:auto;padding:7px 12px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-size:13px;outline:none}.search:focus{border-color:var(--accent)}.stats{display:flex;align-items:center;gap:12px;font-size:12px;color:var(--text-dim)}.stat-item{display:inline-flex;align-items:center;gap:5px}.stat-item svg{color:var(--text-dim)}.diag-chip{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:99px;font-weight:600}.diag-chip.ok{background:#34d39926;color:var(--ok)}.diag-chip.warn{background:#fbbf2426;color:var(--warn)}.diag-chip.err{background:#f8717126;color:var(--err)}.hamburger{position:relative;display:inline-flex;align-items:center;justify-content:center;padding:6px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer}.hamburger:hover{color:var(--text);border-color:var(--border-strong)}.hamburger.active{color:var(--accent);border-color:var(--accent)}.hamburger-badge{position:absolute;top:-6px;right:-6px;min-width:15px;height:15px;padding:0 3px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-size:10px;font-weight:700;line-height:15px;text-align:center}.btn-group{display:inline-flex;align-items:center;gap:2px;background:var(--bg-card);border:1px solid var(--border);border-radius:9px;padding:2px}.grp-tag{font-size:10px;color:var(--text-dim);opacity:.75;padding:0 6px 0 4px;letter-spacing:.03em;text-transform:none;white-space:nowrap}.grp-btn{display:inline-flex;align-items:center;gap:5px;padding:5px 9px;border-radius:6px;border:none;background:transparent;color:var(--text-dim);cursor:pointer;font-size:12px;white-space:nowrap}.grp-btn.icon-only{padding:5px 7px}.grp-btn:hover{color:var(--text);background:#ffffff0d}.grp-btn.active{color:var(--accent)}.grp-btn.active svg{color:var(--accent)}.grp-badge{width:6px;height:6px;border-radius:50%;background:var(--warn);display:inline-block;margin-left:1px}.dir-arrow{display:inline-flex;transition:transform .15s ease}.tool-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 11px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.tool-btn:hover{color:var(--text);border-color:var(--border-strong)}.tool-btn.active{color:var(--accent);border-color:var(--accent)}.tool-btn.primary{color:var(--accent);border-color:#e0a63a66;font-weight:600}.layout-picker{position:relative;display:inline-flex;gap:2px}.layout-picker .caret{font-size:10px}.layout-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:20;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:8px;padding:4px;min-width:150px;box-shadow:0 8px 24px #0006}.layout-menu button{display:block;width:100%;text-align:left;padding:7px 10px;border:0;border-radius:6px;background:transparent;color:var(--text-dim);cursor:pointer;font-size:13px}.layout-menu button:hover{background:var(--bg-card);color:var(--text)}.canvas-drawer{position:absolute;top:12px;left:12px;bottom:12px;width:300px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:16px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080;display:flex;flex-direction:column;gap:10px;transform:translate(calc(-100% - 16px));opacity:0;pointer-events:none;transition:transform .2s ease,opacity .2s ease}.canvas-drawer.open{transform:translate(0);opacity:1;pointer-events:auto}.drawer-header{display:flex;align-items:center;justify-content:space-between}.drawer-header h2{margin:0;font-size:15px;display:inline-flex;align-items:center;gap:7px}.drawer-header h2 svg{color:var(--accent)}.drawer-hint{font-size:11px;color:var(--text-dim);line-height:1.4}.sa-all{align-self:flex-start;padding:4px 10px;border-radius:7px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.sa-all:hover:not(:disabled){color:var(--text);border-color:var(--border-strong)}.sa-all.active{color:var(--accent);border-color:var(--accent)}.sa-all:disabled{opacity:.5;cursor:default}.sa-list{display:flex;flex-direction:column;gap:3px;margin-top:2px}.sa-row{display:flex;align-items:center;gap:9px;padding:7px 8px;border-radius:8px;cursor:pointer;border:1px solid transparent;-webkit-user-select:none;user-select:none}.sa-row:hover{background:var(--bg-card)}.sa-row.active{background:var(--accent-soft);border-color:#e0a63a66}.sa-row.muted{cursor:default;opacity:.7}.sa-row.muted:hover{background:transparent}.sa-row input[type=checkbox]{accent-color:var(--accent);cursor:pointer}.sa-chip{width:12px;height:12px;border-radius:3px;flex:0 0 auto}.sa-chip.none{background:repeating-linear-gradient(45deg,#4a3c2c,#4a3c2c 2px,transparent 2px,transparent 4px)}.sa-name{flex:1;font-size:13px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.sa-row.muted .sa-name{color:var(--text-dim)}.sa-count{font-size:11px;color:var(--text-dim);background:var(--bg-card);padding:1px 7px;border-radius:99px;flex:0 0 auto}.entity-node{width:264px;background:var(--bg-card);border:1px solid var(--border);border-top:3px solid var(--accent);border-radius:10px;overflow:hidden;box-shadow:0 4px 18px #00000059;font-size:12px;transition:opacity .15s,box-shadow .15s,border-color .15s}.entity-node.selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent),0 8px 24px #00000080}.entity-node.highlighted{box-shadow:0 0 0 2px var(--pk),0 8px 24px #00000080}.entity-node.dimmed{opacity:.18}.entity-header{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#ffffff08;border-bottom:1px solid var(--border)}.entity-name{font-weight:700;font-size:13px;letter-spacing:.01em}.entity-badges{display:flex;gap:4px}.badge{font-size:10px;padding:1px 6px;border-radius:99px;background:var(--accent-soft);color:var(--accent);text-transform:uppercase;letter-spacing:.05em}.badge.ontology{background:#93c5fd1f;color:#93c5fd}.attr-section{padding:4px 0}.attr-section.keys{border-bottom:1px solid var(--border);background:#fcd34d0a}.attr-row{display:flex;align-items:center;gap:6px;padding:3px 12px;height:26px;line-height:20px;position:relative}.attr-row.empty{color:var(--text-dim);font-style:italic}.attr-row.more{color:var(--text-dim);font-style:italic;cursor:pointer;justify-content:center;height:22px;font-size:11px}.attr-row.more:hover{color:var(--accent);background:var(--accent-soft)}.attr-row.rel-hit{background:var(--accent-soft);box-shadow:inset 2px 0 0 var(--accent)}.attr-row.rel-hit .attr-name{color:var(--accent);font-weight:600}.attr-row.rel-dim{opacity:.35}.attr-row.endpoint .attr-name{font-style:normal}.attr-port{width:8px!important;height:8px!important;opacity:0;top:50%!important}.attr-port.react-flow__handle-left{left:-5px!important}.attr-port.react-flow__handle-right{right:-5px!important}.entity-node:hover .attr-port{opacity:.5}.attr-row:hover .attr-port{opacity:1!important;background:var(--accent)!important}.attr-icon{width:14px;text-align:center;font-size:10px;flex:none}.attr-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attr-name.pk{color:var(--pk);font-weight:600}.attr-type{color:var(--text-dim);font-family:var(--mono);font-size:10px;flex:none}.attr-notnull{color:var(--text-dim);font-size:8px;flex:none}.port{width:11px!important;height:11px!important;background:var(--border-strong)!important;border:2px solid var(--bg)!important;opacity:.55;transition:transform .12s ease,background .12s ease,opacity .12s ease}.entity-node:hover .port{opacity:1;background:var(--accent)!important;transform:scale(1.25);box-shadow:0 0 0 4px var(--accent-soft);cursor:crosshair}.port:hover{transform:scale(1.6)!important;cursor:crosshair}.entity-node:hover{border-color:var(--accent);box-shadow:0 0 0 1px #e0a63a40}.react-flow__connectionline .react-flow__edge-path,.react-flow__connection-path{stroke:var(--accent)!important;stroke-width:2!important}.rel-path{stroke:var(--border-strong);stroke-width:1.6}.rel-edge{cursor:pointer}.rel-glyph{stroke:var(--border-strong);stroke-width:1.6;fill:none}.rel-glyph.ring{fill:var(--bg)}.rel-edge:hover .rel-path,.rel-edge.selected .rel-path,.rel-edge:hover .rel-glyph,.rel-edge.selected .rel-glyph{stroke:var(--accent)}.rel-edge.dimmed{opacity:.12}.rel-label{fill:var(--text);font-size:11px;text-anchor:middle;paint-order:stroke;stroke:var(--bg);stroke-width:4px}.detail-panel{position:absolute;top:12px;right:12px;bottom:12px;width:340px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.detail-header{display:flex;justify-content:space-between;align-items:flex-start}.detail-header h2{margin:0 0 6px;font-size:18px}.icon-btn{background:none;border:none;color:var(--text-dim);cursor:pointer;font-size:14px}.icon-btn:hover{color:var(--text)}.definition{color:var(--text-dim);font-size:13px;line-height:1.5}.detail-panel section{margin-top:18px}.detail-panel h3{margin:0 0 8px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.kv{display:flex;gap:8px;margin:4px 0;font-size:12px;align-items:baseline}.kv .k{color:var(--text-dim);min-width:72px}.kv .v{word-break:break-all}.chip{display:inline-block;font-size:11px;padding:2px 8px;margin:2px 4px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim)}.chip.pattern{background:var(--accent-soft);color:var(--accent)}.chip.layer-industry{background:#93c5fd26;color:#93c5fd}.chip.layer-core{background:var(--accent-soft);color:var(--accent)}.chip.layer-domain{background:#f0abfc26;color:#f0abfc}.chip.layer-specialised{background:#fcd34d26;color:var(--pk)}.cat-badge{font-size:10px;font-weight:700;margin-left:6px;padding:2px 8px;border-radius:5px;cursor:help}.cat-badge.supertype{background:#a78bfa2e;color:#a78bfa}.cat-badge.subtype{background:var(--accent-soft);color:var(--accent)}.udp-row td{padding:3px 6px;border-bottom:1px solid var(--border);font-size:12px}.udp-key{color:var(--text-dim);font-family:var(--mono);font-size:11px}.udp-val{color:var(--text)}.enum-badge{font-size:8px;font-weight:700;margin-left:6px;padding:1px 5px;border-radius:4px;background:#a78bfa2e;color:#a78bfa;vertical-align:middle;cursor:help}.key-row{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:12px}.key-badge{font-size:9px;font-weight:700;padding:2px 6px;border-radius:5px;background:#94a3b826;color:var(--text-dim);flex:none}.key-badge.pk{background:#fcd34d2e;color:var(--pk)}.key-badge.unique,.key-badge.alternate{background:var(--accent-soft);color:var(--accent)}.key-name{font-weight:600}.key-cols{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}.attr-table td{padding:4px 6px;border-bottom:1px solid var(--border)}.attr-table td:first-child{width:100%}.attr-table td:first-child .edit-input{min-width:120px}.attr-table td.pk{color:var(--pk);font-weight:600}.attr-table td.type{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table td.null{color:var(--text-dim);font-size:10px;text-align:right}.rel-link{display:flex;gap:8px;align-items:center;width:100%;background:var(--bg-card);border:1px solid var(--border);border-radius:8px;color:var(--text);padding:7px 10px;margin:4px 0;cursor:pointer;font-size:12px;text-align:left}.rel-link:hover{border-color:var(--accent)}.rel-card{color:var(--text-dim);font-family:var(--mono);font-size:11px}.ulid{font-family:var(--mono);font-size:11px;color:var(--text-dim);cursor:copy;word-break:break-all}.ulid:hover{color:var(--accent)}.splash{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--text-dim)}.splash.error pre{background:var(--bg-card);padding:12px 16px;border-radius:8px;max-width:640px;overflow:auto;color:var(--err);font-size:12px}.react-flow__minimap{background:var(--bg-raised)!important;border-radius:10px}.react-flow__controls{border-radius:10px;overflow:hidden;box-shadow:none!important}.react-flow__controls-button{background:var(--bg-raised)!important;border-bottom:1px solid var(--border)!important;fill:var(--text-dim)!important}.react-flow__controls-button:hover{fill:var(--text)!important}.edit-input{width:100%;padding:6px 9px;border-radius:7px;font-size:12px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-family:var(--font);outline:none}.edit-input:focus{border-color:var(--accent)}.entity-title-input{font-size:17px;font-weight:700;background:transparent;border-color:transparent;padding-left:0}.entity-title-input:hover,.entity-title-input:focus{border-color:var(--border);background:var(--bg-card);padding-left:9px}.definition-input{color:var(--text-dim);line-height:1.5;resize:vertical}.chip-select,.cell-select{font-size:11px;padding:2px 6px;margin:2px 6px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim);border:1px solid transparent;outline:none}.chip-select:hover,.cell-select:hover{border-color:var(--border-strong);color:var(--text)}.cell-select{border-radius:6px;background:transparent;max-width:110px}.mini-btn{font-size:11px;padding:3px 9px;border-radius:7px;cursor:pointer;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim)}.mini-btn:hover{color:var(--accent);border-color:var(--accent)}.mini-btn.danger:hover{color:var(--err);border-color:var(--err)}.h3-actions{float:right;display:inline-flex;gap:6px}.empty-hint{color:var(--text-dim);font-size:12px;font-style:italic}.add-attr{display:flex;gap:6px;margin-top:8px}.rel-row{display:flex;gap:6px;align-items:flex-start}.rel-row .rel-main{flex:1}.verb-phrases{display:flex;align-items:center;gap:4px;margin-top:2px;padding-left:4px}.verb-phrases .verb-input{font-size:11px;font-style:italic;color:var(--text-dim);min-width:40px}.verb-phrases .verb-sep{color:var(--text-dim);font-size:11px}.physical-name-row{display:flex;align-items:center;gap:6px;margin-top:2px}.physical-name-row .physical-label{font-size:9px;text-transform:uppercase;color:var(--text-dim);letter-spacing:.04em}.physical-name-input{font-size:12px;color:var(--text-dim)}.physical-col{display:block;font-size:10px;color:var(--text-dim);font-family:var(--mono, monospace)}.physical-col-input{display:block;font-size:10px;color:var(--text-dim)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#05080db3;z-index:50;display:flex;align-items:center;justify-content:center}.modal{width:440px;max-height:80vh;overflow-y:auto;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:14px;padding:20px;box-shadow:0 24px 80px #0009}.modal.wide{width:600px}.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}.modal-header h2{margin:0;font-size:16px}.modal-search{margin-bottom:10px}.modal-footer{display:flex;gap:10px;justify-content:flex-end;align-items:center;margin-top:14px}.modal-footer label{font-size:11px;color:var(--text-dim);display:flex;flex-direction:column;gap:3px}.modal-footer select,.form-row select{background:var(--bg-card);color:var(--text);border:1px solid var(--border);border-radius:7px;padding:5px 8px;font-size:12px}.primary-btn{padding:8px 16px;border-radius:8px;border:none;cursor:pointer;background:var(--accent);color:var(--accent-ink);font-weight:700;font-size:13px}.primary-btn:disabled{opacity:.4;cursor:default}.danger-btn{padding:8px 16px;border-radius:8px;border:1px solid var(--err);cursor:pointer;background:#f8717124;color:var(--err);font-weight:700;font-size:13px}.form-row{display:flex;flex-direction:column;gap:4px;margin-bottom:14px;font-size:12px;color:var(--text-dim)}.form-row>label{font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:10px}.form-error{color:var(--err);font-size:11px}.form-preview{color:var(--text-dim);font-size:11px;word-break:break-all;opacity:.85}.form-preview:before{content:""}.form-hint{color:var(--text-dim);font-size:11px;font-style:italic;opacity:.75;word-break:break-word}.term-results{display:flex;flex-direction:column;gap:8px;max-height:44vh;overflow-y:auto}.term-card{text-align:left;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:10px 12px;cursor:pointer;color:var(--text)}.term-card:hover{border-color:var(--border-strong)}.term-card.picked{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}.term-head{display:flex;justify-content:space-between;align-items:baseline}.term-label{font-weight:600;font-size:13px}.term-source{font-size:10px;color:var(--text-dim);text-transform:uppercase;letter-spacing:.06em}.term-iri{font-size:10px;color:var(--accent);display:block;margin:2px 0;word-break:break-all}.term-def{font-size:11px;color:var(--text-dim);margin:4px 0 0;line-height:1.45}.kind-badge{font-size:8px;padding:1px 5px;margin-right:6px;border-radius:999px;background:#f0abfc26;color:#f0abfc;letter-spacing:.04em}.src-picker{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}.src-chip{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:3px 9px;border-radius:999px;background:var(--bg);border:1px solid var(--border);color:var(--text-dim);cursor:pointer}.src-chip:hover{border-color:var(--border-strong);color:var(--text)}.src-chip.active{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}.src-layer{font-size:8px;padding:0 5px;border-radius:999px;text-transform:uppercase;letter-spacing:.04em}.side-panel{position:absolute;top:12px;right:12px;bottom:12px;width:380px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.side-panel h2{margin:0;font-size:16px}.side-panel h4{margin:10px 0 6px;font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.panel-body{margin-top:12px}.panel-body.ok{color:var(--ok)}.meta-line{font-size:10px;color:var(--text-dim);margin:6px 0 10px}.coverage-banner{font-size:12px;padding:8px 12px;border-radius:9px;margin-bottom:12px;background:#34d3991a;color:var(--ok)}.coverage-banner.warn{background:#fbbf241a;color:var(--warn)}.layer-band{border:1px dashed var(--border);border-radius:10px;padding:8px 12px 10px;margin-bottom:10px}.layer-band.external{border-style:solid;background:#93c5fd0a}.stack-term{display:flex;justify-content:space-between;align-items:baseline;gap:8px;width:100%;background:var(--bg-card);border:1px solid var(--border);color:var(--text);border-radius:7px;padding:5px 10px;margin:4px 0;font-size:12px;cursor:pointer;text-align:left}div.stack-term{cursor:default}.stack-term:hover{border-color:var(--border-strong)}.stack-term.uncovered{border-color:var(--err)}.align-arrow{font-size:10px;color:var(--accent);white-space:nowrap}.align-arrow.unresolved{color:var(--warn)}.align-arrow.missing{color:var(--err);font-style:italic}.align-arrow.proposed{color:var(--warn);font-style:italic}.ref-list{display:flex;flex-direction:column;gap:6px;margin-top:4px}.ref-card{border:1px solid var(--border);border-radius:8px;padding:6px 8px;background:var(--bg)}.ref-card.proposed{border-color:var(--warn)}.ref-head{display:flex;align-items:baseline;gap:8px;justify-content:space-between}.ref-uri{font-family:var(--mono);font-size:12px;word-break:break-all}.ref-status{font-size:9px;text-transform:uppercase;letter-spacing:.04em}.ref-status.accepted{color:var(--accent)}.ref-status.proposed{color:var(--warn)}.ref-meta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:5px}.ref-pill{font-size:10px;padding:1px 6px;border-radius:999px;background:var(--accent-soft);color:var(--accent)}.ref-via{font-size:10px;color:var(--text-dim)}.ref-actions{display:flex;gap:6px;margin-top:6px}.dirty-list{list-style:none;padding:0;margin:0 0 10px;font-size:12px}.dirty-list li{padding:2px 0}.dirty-state{color:var(--warn);margin-right:6px;font-family:var(--mono)}.diff-view{background:var(--bg);border:1px solid var(--border);border-radius:9px;padding:10px;font-size:10.5px;line-height:1.5;overflow:auto;max-height:42vh;font-family:var(--mono);white-space:pre;margin-bottom:10px}.diff-add{color:var(--ok)}.diff-del{color:var(--err)}.diff-hunk{color:#93c5fd}.decision{border:1px solid var(--border);border-radius:9px;padding:8px 12px;margin-bottom:8px}.decision.accepted{opacity:.65}.decision.rejected{opacity:.45}.decision-head{display:flex;gap:6px;align-items:center}.decision-mark{font-weight:700}.decision-subject{font-size:12px;margin:6px 0}.decision-actions{display:flex;gap:6px}.toast{position:absolute;bottom:20px;left:50%;transform:translate(-50%);background:var(--bg-raised);border:1px solid var(--warn);color:var(--text);border-radius:10px;padding:10px 18px;font-size:12px;z-index:60;box-shadow:0 10px 30px #00000080} +.react-flow{direction:ltr}.react-flow__container{position:absolute;width:100%;height:100%;top:0;left:0}.react-flow__pane{z-index:1;cursor:-webkit-grab;cursor:grab}.react-flow__pane.selection{cursor:pointer}.react-flow__pane.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__viewport{transform-origin:0 0;z-index:2;pointer-events:none}.react-flow__renderer{z-index:4}.react-flow__selection{z-index:6}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible{outline:none}.react-flow .react-flow__edges{pointer-events:none;overflow:visible}.react-flow__edge-path,.react-flow__connection-path{stroke:#b1b1b7;stroke-width:1;fill:none}.react-flow__edge{pointer-events:visibleStroke;cursor:pointer}.react-flow__edge.animated path{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__edge.animated path.react-flow__edge-interaction{stroke-dasharray:none;-webkit-animation:none;animation:none}.react-flow__edge.inactive{pointer-events:none}.react-flow__edge.selected,.react-flow__edge:focus,.react-flow__edge:focus-visible{outline:none}.react-flow__edge.selected .react-flow__edge-path,.react-flow__edge:focus .react-flow__edge-path,.react-flow__edge:focus-visible .react-flow__edge-path{stroke:#555}.react-flow__edge-textwrapper{pointer-events:all}.react-flow__edge-textbg{fill:#fff}.react-flow__edge .react-flow__edge-text{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__connection{pointer-events:none}.react-flow__connection .animated{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__connectionline{z-index:1001}.react-flow__nodes{pointer-events:none;transform-origin:0 0}.react-flow__node{position:absolute;-webkit-user-select:none;-moz-user-select:none;user-select:none;pointer-events:all;transform-origin:0 0;box-sizing:border-box;cursor:-webkit-grab;cursor:grab}.react-flow__node.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__nodesselection{z-index:3;transform-origin:left top;pointer-events:none}.react-flow__nodesselection-rect{position:absolute;pointer-events:all;cursor:-webkit-grab;cursor:grab}.react-flow__handle{position:absolute;pointer-events:none;min-width:5px;min-height:5px;width:6px;height:6px;background:#1a192b;border:1px solid white;border-radius:100%}.react-flow__handle.connectionindicator{pointer-events:all;cursor:crosshair}.react-flow__handle-bottom{top:auto;left:50%;bottom:-4px;transform:translate(-50%)}.react-flow__handle-top{left:50%;top:-4px;transform:translate(-50%)}.react-flow__handle-left{top:50%;left:-4px;transform:translateY(-50%)}.react-flow__handle-right{right:-4px;top:50%;transform:translateY(-50%)}.react-flow__edgeupdater{cursor:move;pointer-events:all}.react-flow__panel{position:absolute;z-index:5;margin:15px}.react-flow__panel.top{top:0}.react-flow__panel.bottom{bottom:0}.react-flow__panel.left{left:0}.react-flow__panel.right{right:0}.react-flow__panel.center{left:50%;transform:translate(-50%)}.react-flow__attribution{font-size:10px;background:#ffffff80;padding:2px 3px;margin:0}.react-flow__attribution a{text-decoration:none;color:#999}@-webkit-keyframes dashdraw{0%{stroke-dashoffset:10}}@keyframes dashdraw{0%{stroke-dashoffset:10}}.react-flow__edgelabel-renderer{position:absolute;width:100%;height:100%;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__edge.updating .react-flow__edge-path{stroke:#777}.react-flow__edge-text{font-size:10px}.react-flow__node.selectable:focus,.react-flow__node.selectable:focus-visible{outline:none}.react-flow__node-default,.react-flow__node-input,.react-flow__node-output,.react-flow__node-group{padding:10px;border-radius:3px;width:150px;font-size:12px;color:#222;text-align:center;border-width:1px;border-style:solid;border-color:#1a192b;background-color:#fff}.react-flow__node-default.selectable:hover,.react-flow__node-input.selectable:hover,.react-flow__node-output.selectable:hover,.react-flow__node-group.selectable:hover{box-shadow:0 1px 4px 1px #00000014}.react-flow__node-default.selectable.selected,.react-flow__node-default.selectable:focus,.react-flow__node-default.selectable:focus-visible,.react-flow__node-input.selectable.selected,.react-flow__node-input.selectable:focus,.react-flow__node-input.selectable:focus-visible,.react-flow__node-output.selectable.selected,.react-flow__node-output.selectable:focus,.react-flow__node-output.selectable:focus-visible,.react-flow__node-group.selectable.selected,.react-flow__node-group.selectable:focus,.react-flow__node-group.selectable:focus-visible{box-shadow:0 0 0 .5px #1a192b}.react-flow__node-group{background-color:#f0f0f040}.react-flow__nodesselection-rect,.react-flow__selection{background:#0059dc14;border:1px dotted rgba(0,89,220,.8)}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible,.react-flow__selection:focus,.react-flow__selection:focus-visible{outline:none}.react-flow__controls{box-shadow:0 0 2px 1px #00000014}.react-flow__controls-button{border:none;background:#fefefe;border-bottom:1px solid #eee;box-sizing:content-box;display:flex;justify-content:center;align-items:center;width:16px;height:16px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;padding:5px}.react-flow__controls-button:hover{background:#f4f4f4}.react-flow__controls-button svg{width:100%;max-width:12px;max-height:12px}.react-flow__controls-button:disabled{pointer-events:none}.react-flow__controls-button:disabled svg{fill-opacity:.4}.react-flow__minimap{background-color:#fff}.react-flow__minimap svg{display:block}.react-flow__resize-control{position:absolute}.react-flow__resize-control.left,.react-flow__resize-control.right{cursor:ew-resize}.react-flow__resize-control.top,.react-flow__resize-control.bottom{cursor:ns-resize}.react-flow__resize-control.top.left,.react-flow__resize-control.bottom.right{cursor:nwse-resize}.react-flow__resize-control.bottom.left,.react-flow__resize-control.top.right{cursor:nesw-resize}.react-flow__resize-control.handle{width:4px;height:4px;border:1px solid #fff;border-radius:1px;background-color:#3367d9;transform:translate(-50%,-50%)}.react-flow__resize-control.handle.left{left:0;top:50%}.react-flow__resize-control.handle.right{left:100%;top:50%}.react-flow__resize-control.handle.top{left:50%;top:0}.react-flow__resize-control.handle.bottom{left:50%;top:100%}.react-flow__resize-control.handle.top.left,.react-flow__resize-control.handle.bottom.left{left:0}.react-flow__resize-control.handle.top.right,.react-flow__resize-control.handle.bottom.right{left:100%}.react-flow__resize-control.line{border-color:#3367d9;border-width:0;border-style:solid}.react-flow__resize-control.line.left,.react-flow__resize-control.line.right{width:1px;transform:translate(-50%);top:0;height:100%}.react-flow__resize-control.line.left{left:0;border-left-width:1px}.react-flow__resize-control.line.right{left:100%;border-right-width:1px}.react-flow__resize-control.line.top,.react-flow__resize-control.line.bottom{height:1px;transform:translateY(-50%);left:0;width:100%}.react-flow__resize-control.line.top{top:0;border-top-width:1px}.react-flow__resize-control.line.bottom{border-bottom-width:1px;top:100%}.ie-wrap{position:relative;display:inline-flex;gap:6px}.erd-ico{font-size:13px;line-height:1;opacity:.85;margin-right:1px}.ie-wrap button:hover .erd-ico,.ie-wrap button.on .erd-ico,.ie-wrap button.active .erd-ico{opacity:1}.erd-caret{opacity:.55;margin-left:1px}.ie-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:30;min-width:220px;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:6px;box-shadow:0 12px 32px #00000073;display:flex;flex-direction:column;gap:2px}.ie-item{display:block;padding:8px 10px;border-radius:6px;color:var(--text);text-decoration:none;font-size:13px;cursor:pointer}.ie-item:hover{background:#5eead424;color:var(--accent)}.ie-dialect{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 10px 8px;margin-bottom:4px;border-bottom:1px solid var(--border);font-size:12px;color:var(--text-dim)}.ie-dialect select{background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;padding:3px 6px;font-size:12px}.ie-import{width:380px;padding:12px;gap:8px}.ie-tabs{display:flex;gap:4px}.ie-tab{flex:1;padding:6px 8px;border-radius:6px;font-size:12px;cursor:pointer;background:none;border:1px solid var(--border);color:var(--text-dim)}.ie-tab.active{border-color:var(--accent);color:var(--accent);background:#5eead41a}.ie-hint{font-size:11px;color:var(--text-dim);margin:0}.ie-textarea{width:100%;font-family:var(--mono);font-size:12px;resize:vertical;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:8px;padding:8px;box-sizing:border-box}.ie-textarea:focus{border-color:var(--accent);outline:none}.ie-file{font-size:11px;color:var(--text-dim)}.ie-warn{font-size:11px;color:var(--pk);margin:0}.ie-error{font-size:12px;color:var(--err);margin:0}.ie-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:4px}:root{--bg: #14110f;--bg-raised: #1c1815;--bg-card: #221d19;--border: #33291f;--border-strong: #4a3c2c;--text: #ece6dd;--text-dim: #a89a86;--accent: #e0a63a;--accent-soft: rgba(224, 166, 58, .15);--accent-ink: #241a08;--pk: #f2c14e;--err: #f0857a;--warn: #e6a94a;--ok: #6cbf73;--font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;--mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace}*{box-sizing:border-box}html,body,#root{height:100%;margin:0}body{font-family:var(--font);background:var(--bg);color:var(--text)}.app{display:flex;flex-direction:column;height:100%}.canvas-wrap{flex:1;position:relative;min-height:0}.react-flow{background:var(--bg)}.topbar{display:flex;flex-direction:column;padding:8px 16px 0;background:var(--bg-raised);border-bottom:1px solid var(--border);z-index:10}.topbar-row{display:flex;align-items:center;gap:14px}.topbar-row.context{padding-bottom:8px}.topbar-row.actions{gap:10px;padding-bottom:8px;flex-wrap:wrap}.brand{display:flex;align-items:baseline;gap:8px;white-space:nowrap}.logo{color:var(--accent);font-size:18px}.brand-name{font-weight:700;letter-spacing:.02em}.project-name{color:var(--text-dim);font-size:13px}.search{flex:0 1 300px;margin-left:auto;padding:7px 12px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-size:13px;outline:none}.search:focus{border-color:var(--accent)}.stats{display:flex;align-items:center;gap:12px;font-size:12px;color:var(--text-dim)}.stat-item{display:inline-flex;align-items:center;gap:5px}.stat-item svg{color:var(--text-dim)}.diag-chip{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:99px;font-weight:600}.diag-chip.ok{background:#34d39926;color:var(--ok)}.diag-chip.warn{background:#fbbf2426;color:var(--warn)}.diag-chip.err{background:#f8717126;color:var(--err)}.hamburger{position:relative;display:inline-flex;align-items:center;justify-content:center;padding:6px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer}.hamburger:hover{color:var(--text);border-color:var(--border-strong)}.hamburger.active{color:var(--accent);border-color:var(--accent)}.hamburger-badge{position:absolute;top:-6px;right:-6px;min-width:15px;height:15px;padding:0 3px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-size:10px;font-weight:700;line-height:15px;text-align:center}.btn-group{display:inline-flex;align-items:center;gap:2px;background:var(--bg-card);border:1px solid var(--border);border-radius:9px;padding:2px}.grp-tag{font-size:10px;color:var(--text-dim);opacity:.75;padding:0 6px 0 4px;letter-spacing:.03em;text-transform:none;white-space:nowrap}.grp-btn{display:inline-flex;align-items:center;gap:5px;padding:5px 9px;border-radius:6px;border:none;background:transparent;color:var(--text-dim);cursor:pointer;font-size:12px;white-space:nowrap}.grp-btn.icon-only{padding:5px 7px}.grp-btn:hover{color:var(--text);background:#ffffff0d}.grp-btn.active{color:var(--accent)}.grp-btn.active svg{color:var(--accent)}.grp-badge{width:6px;height:6px;border-radius:50%;background:var(--warn);display:inline-block;margin-left:1px}.dir-arrow{display:inline-flex;transition:transform .15s ease}.tool-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 11px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.tool-btn:hover{color:var(--text);border-color:var(--border-strong)}.tool-btn.active{color:var(--accent);border-color:var(--accent)}.tool-btn.primary{color:var(--accent);border-color:#e0a63a66;font-weight:600}.layout-picker{position:relative;display:inline-flex;gap:2px}.layout-picker .caret{font-size:10px}.layout-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:20;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:8px;padding:4px;min-width:150px;box-shadow:0 8px 24px #0006}.layout-menu button{display:block;width:100%;text-align:left;padding:7px 10px;border:0;border-radius:6px;background:transparent;color:var(--text-dim);cursor:pointer;font-size:13px}.layout-menu button:hover{background:var(--bg-card);color:var(--text)}.canvas-drawer{position:absolute;top:12px;left:12px;bottom:12px;width:300px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:16px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080;display:flex;flex-direction:column;gap:10px;transform:translate(calc(-100% - 16px));opacity:0;pointer-events:none;transition:transform .2s ease,opacity .2s ease}.canvas-drawer.open{transform:translate(0);opacity:1;pointer-events:auto}.drawer-header{display:flex;align-items:center;justify-content:space-between}.drawer-header h2{margin:0;font-size:15px;display:inline-flex;align-items:center;gap:7px}.drawer-header h2 svg{color:var(--accent)}.drawer-hint{font-size:11px;color:var(--text-dim);line-height:1.4}.sa-all{align-self:flex-start;padding:4px 10px;border-radius:7px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.sa-all:hover:not(:disabled){color:var(--text);border-color:var(--border-strong)}.sa-all.active{color:var(--accent);border-color:var(--accent)}.sa-all:disabled{opacity:.5;cursor:default}.sa-list{display:flex;flex-direction:column;gap:3px;margin-top:2px}.sa-row{display:flex;align-items:center;gap:9px;padding:7px 8px;border-radius:8px;cursor:pointer;border:1px solid transparent;-webkit-user-select:none;user-select:none}.sa-row:hover{background:var(--bg-card)}.sa-row.active{background:var(--accent-soft);border-color:#e0a63a66}.sa-row.muted{cursor:default;opacity:.7}.sa-row.muted:hover{background:transparent}.sa-row input[type=checkbox]{accent-color:var(--accent);cursor:pointer}.sa-chip{width:12px;height:12px;border-radius:3px;flex:0 0 auto}.sa-chip.none{background:repeating-linear-gradient(45deg,#4a3c2c,#4a3c2c 2px,transparent 2px,transparent 4px)}.sa-name{flex:1;font-size:13px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.sa-row.muted .sa-name{color:var(--text-dim)}.sa-count{font-size:11px;color:var(--text-dim);background:var(--bg-card);padding:1px 7px;border-radius:99px;flex:0 0 auto}.entity-node{width:264px;background:var(--bg-card);border:1px solid var(--border);border-top:3px solid var(--accent);border-radius:10px;overflow:hidden;box-shadow:0 4px 18px #00000059;font-size:12px;transition:opacity .15s,box-shadow .15s,border-color .15s}.entity-node.selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent),0 8px 24px #00000080}.entity-node.highlighted{box-shadow:0 0 0 2px var(--pk),0 8px 24px #00000080}.entity-node.dimmed{opacity:.18}.entity-header{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#ffffff08;border-bottom:1px solid var(--border)}.entity-name{font-weight:700;font-size:13px;letter-spacing:.01em}.entity-badges{display:flex;gap:4px}.badge{font-size:10px;padding:1px 6px;border-radius:99px;background:var(--accent-soft);color:var(--accent);text-transform:uppercase;letter-spacing:.05em}.badge.ontology{background:#93c5fd1f;color:#93c5fd}.attr-section{padding:4px 0}.attr-section.keys{border-bottom:1px solid var(--border);background:#fcd34d0a}.attr-row{display:flex;align-items:center;gap:6px;padding:3px 12px;height:26px;line-height:20px;position:relative}.attr-row.empty{color:var(--text-dim);font-style:italic}.attr-row.more{color:var(--text-dim);font-style:italic;cursor:pointer;justify-content:center;height:22px;font-size:11px}.attr-row.more:hover{color:var(--accent);background:var(--accent-soft)}.attr-row.rel-hit{background:var(--accent-soft);box-shadow:inset 2px 0 0 var(--accent)}.attr-row.rel-hit .attr-name{color:var(--accent);font-weight:600}.attr-row.rel-dim{opacity:.35}.attr-row.endpoint .attr-name{font-style:normal}.attr-port{width:8px!important;height:8px!important;opacity:0;top:50%!important}.attr-port.react-flow__handle-left{left:-5px!important}.attr-port.react-flow__handle-right{right:-5px!important}.entity-node:hover .attr-port{opacity:.5}.attr-row:hover .attr-port{opacity:1!important;background:var(--accent)!important}.attr-icon{width:14px;text-align:center;font-size:10px;flex:none}.attr-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attr-name.pk{color:var(--pk);font-weight:600}.attr-type{color:var(--text-dim);font-family:var(--mono);font-size:10px;flex:none}.attr-notnull{color:var(--text-dim);font-size:8px;flex:none}.port{width:11px!important;height:11px!important;background:var(--border-strong)!important;border:2px solid var(--bg)!important;opacity:.55;transition:transform .12s ease,background .12s ease,opacity .12s ease}.entity-node:hover .port{opacity:1;background:var(--accent)!important;transform:scale(1.25);box-shadow:0 0 0 4px var(--accent-soft);cursor:crosshair}.port:hover{transform:scale(1.6)!important;cursor:crosshair}.entity-node:hover{border-color:var(--accent);box-shadow:0 0 0 1px #e0a63a40}.react-flow__connectionline .react-flow__edge-path,.react-flow__connection-path{stroke:var(--accent)!important;stroke-width:2!important}.rel-path{stroke:var(--border-strong);stroke-width:1.6}.rel-edge{cursor:pointer}.rel-glyph{stroke:var(--border-strong);stroke-width:1.6;fill:none}.rel-glyph.ring{fill:var(--bg)}.rel-edge:hover .rel-path,.rel-edge.selected .rel-path,.rel-edge:hover .rel-glyph,.rel-edge.selected .rel-glyph{stroke:var(--accent)}.rel-edge.dimmed{opacity:.12}.rel-label{fill:var(--text);font-size:11px;text-anchor:middle;paint-order:stroke;stroke:var(--bg);stroke-width:4px}.rel-handle .rel-grip{fill:var(--accent);stroke:var(--bg);stroke-width:1;opacity:.9}.rel-handle:hover .rel-grip{opacity:1}.layout-menu-sep{height:1px;margin:4px 0;background:var(--border)}.detail-panel{position:absolute;top:12px;right:12px;bottom:12px;width:340px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.detail-header{display:flex;justify-content:space-between;align-items:flex-start}.detail-header h2{margin:0 0 6px;font-size:18px}.icon-btn{background:none;border:none;color:var(--text-dim);cursor:pointer;font-size:14px}.icon-btn:hover{color:var(--text)}.definition{color:var(--text-dim);font-size:13px;line-height:1.5}.detail-panel section{margin-top:18px}.detail-panel h3{margin:0 0 8px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.kv{display:flex;gap:8px;margin:4px 0;font-size:12px;align-items:baseline}.kv .k{color:var(--text-dim);min-width:72px}.kv .v{word-break:break-all}.chip{display:inline-block;font-size:11px;padding:2px 8px;margin:2px 4px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim)}.chip.pattern{background:var(--accent-soft);color:var(--accent)}.chip.layer-industry{background:#93c5fd26;color:#93c5fd}.chip.layer-core{background:var(--accent-soft);color:var(--accent)}.chip.layer-domain{background:#f0abfc26;color:#f0abfc}.chip.layer-specialised{background:#fcd34d26;color:var(--pk)}.cat-badge{font-size:10px;font-weight:700;margin-left:6px;padding:2px 8px;border-radius:5px;cursor:help}.cat-badge.supertype{background:#a78bfa2e;color:#a78bfa}.cat-badge.subtype{background:var(--accent-soft);color:var(--accent)}.udp-row td{padding:3px 6px;border-bottom:1px solid var(--border);font-size:12px}.udp-key{color:var(--text-dim);font-family:var(--mono);font-size:11px}.udp-val{color:var(--text)}.enum-badge{font-size:8px;font-weight:700;margin-left:6px;padding:1px 5px;border-radius:4px;background:#a78bfa2e;color:#a78bfa;vertical-align:middle;cursor:help}.key-row{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:12px}.key-badge{font-size:9px;font-weight:700;padding:2px 6px;border-radius:5px;background:#94a3b826;color:var(--text-dim);flex:none}.key-badge.pk{background:#fcd34d2e;color:var(--pk)}.key-badge.unique,.key-badge.alternate{background:var(--accent-soft);color:var(--accent)}.key-name{font-weight:600}.key-cols{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}.attr-table td{padding:4px 6px;border-bottom:1px solid var(--border)}.attr-table td:first-child{width:100%}.attr-table td:first-child .edit-input{min-width:120px}.attr-table td.pk{color:var(--pk);font-weight:600}.attr-table td.type{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table td.null{color:var(--text-dim);font-size:10px;text-align:right}.rel-link{display:flex;gap:8px;align-items:center;width:100%;background:var(--bg-card);border:1px solid var(--border);border-radius:8px;color:var(--text);padding:7px 10px;margin:4px 0;cursor:pointer;font-size:12px;text-align:left}.rel-link:hover{border-color:var(--accent)}.rel-card{color:var(--text-dim);font-family:var(--mono);font-size:11px}.ulid{font-family:var(--mono);font-size:11px;color:var(--text-dim);cursor:copy;word-break:break-all}.ulid:hover{color:var(--accent)}.splash{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--text-dim)}.splash.error pre{background:var(--bg-card);padding:12px 16px;border-radius:8px;max-width:640px;overflow:auto;color:var(--err);font-size:12px}.react-flow__minimap{background:var(--bg-raised)!important;border-radius:10px}.react-flow__controls{border-radius:10px;overflow:hidden;box-shadow:none!important}.react-flow__controls-button{background:var(--bg-raised)!important;border-bottom:1px solid var(--border)!important;fill:var(--text-dim)!important}.react-flow__controls-button:hover{fill:var(--text)!important}.edit-input{width:100%;padding:6px 9px;border-radius:7px;font-size:12px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-family:var(--font);outline:none}.edit-input:focus{border-color:var(--accent)}.entity-title-input{font-size:17px;font-weight:700;background:transparent;border-color:transparent;padding-left:0}.entity-title-input:hover,.entity-title-input:focus{border-color:var(--border);background:var(--bg-card);padding-left:9px}.definition-input{color:var(--text-dim);line-height:1.5;resize:vertical}.chip-select,.cell-select{font-size:11px;padding:2px 6px;margin:2px 6px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim);border:1px solid transparent;outline:none}.chip-select:hover,.cell-select:hover{border-color:var(--border-strong);color:var(--text)}.cell-select{border-radius:6px;background:transparent;max-width:110px}.mini-btn{font-size:11px;padding:3px 9px;border-radius:7px;cursor:pointer;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim)}.mini-btn:hover{color:var(--accent);border-color:var(--accent)}.mini-btn.danger:hover{color:var(--err);border-color:var(--err)}.h3-actions{float:right;display:inline-flex;gap:6px}.empty-hint{color:var(--text-dim);font-size:12px;font-style:italic}.add-attr{display:flex;gap:6px;margin-top:8px}.rel-row{display:flex;gap:6px;align-items:flex-start}.rel-row .rel-main{flex:1}.verb-phrases{display:flex;align-items:center;gap:4px;margin-top:2px;padding-left:4px}.verb-phrases .verb-input{font-size:11px;font-style:italic;color:var(--text-dim);min-width:40px}.verb-phrases .verb-sep{color:var(--text-dim);font-size:11px}.physical-name-row{display:flex;align-items:center;gap:6px;margin-top:2px}.physical-name-row .physical-label{font-size:9px;text-transform:uppercase;color:var(--text-dim);letter-spacing:.04em}.physical-name-input{font-size:12px;color:var(--text-dim)}.physical-col{display:block;font-size:10px;color:var(--text-dim);font-family:var(--mono, monospace)}.physical-col-input{display:block;font-size:10px;color:var(--text-dim)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#05080db3;z-index:50;display:flex;align-items:center;justify-content:center}.modal{width:440px;max-height:80vh;overflow-y:auto;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:14px;padding:20px;box-shadow:0 24px 80px #0009}.modal.wide{width:600px}.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}.modal-header h2{margin:0;font-size:16px}.modal-search{margin-bottom:10px}.modal-footer{display:flex;gap:10px;justify-content:flex-end;align-items:center;margin-top:14px}.modal-footer label{font-size:11px;color:var(--text-dim);display:flex;flex-direction:column;gap:3px}.modal-footer select,.form-row select{background:var(--bg-card);color:var(--text);border:1px solid var(--border);border-radius:7px;padding:5px 8px;font-size:12px}.primary-btn{padding:8px 16px;border-radius:8px;border:none;cursor:pointer;background:var(--accent);color:var(--accent-ink);font-weight:700;font-size:13px}.primary-btn:disabled{opacity:.4;cursor:default}.danger-btn{padding:8px 16px;border-radius:8px;border:1px solid var(--err);cursor:pointer;background:#f8717124;color:var(--err);font-weight:700;font-size:13px}.form-row{display:flex;flex-direction:column;gap:4px;margin-bottom:14px;font-size:12px;color:var(--text-dim)}.form-row>label{font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:10px}.form-error{color:var(--err);font-size:11px}.form-preview{color:var(--text-dim);font-size:11px;word-break:break-all;opacity:.85}.form-preview:before{content:""}.form-hint{color:var(--text-dim);font-size:11px;font-style:italic;opacity:.75;word-break:break-word}.term-results{display:flex;flex-direction:column;gap:8px;max-height:44vh;overflow-y:auto}.term-card{text-align:left;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:10px 12px;cursor:pointer;color:var(--text)}.term-card:hover{border-color:var(--border-strong)}.term-card.picked{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}.term-head{display:flex;justify-content:space-between;align-items:baseline}.term-label{font-weight:600;font-size:13px}.term-source{font-size:10px;color:var(--text-dim);text-transform:uppercase;letter-spacing:.06em}.term-iri{font-size:10px;color:var(--accent);display:block;margin:2px 0;word-break:break-all}.term-def{font-size:11px;color:var(--text-dim);margin:4px 0 0;line-height:1.45}.kind-badge{font-size:8px;padding:1px 5px;margin-right:6px;border-radius:999px;background:#f0abfc26;color:#f0abfc;letter-spacing:.04em}.src-picker{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}.src-chip{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:3px 9px;border-radius:999px;background:var(--bg);border:1px solid var(--border);color:var(--text-dim);cursor:pointer}.src-chip:hover{border-color:var(--border-strong);color:var(--text)}.src-chip.active{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}.src-layer{font-size:8px;padding:0 5px;border-radius:999px;text-transform:uppercase;letter-spacing:.04em}.side-panel{position:absolute;top:12px;right:12px;bottom:12px;width:380px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.side-panel h2{margin:0;font-size:16px}.side-panel h4{margin:10px 0 6px;font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.panel-body{margin-top:12px}.panel-body.ok{color:var(--ok)}.meta-line{font-size:10px;color:var(--text-dim);margin:6px 0 10px}.coverage-banner{font-size:12px;padding:8px 12px;border-radius:9px;margin-bottom:12px;background:#34d3991a;color:var(--ok)}.coverage-banner.warn{background:#fbbf241a;color:var(--warn)}.layer-band{border:1px dashed var(--border);border-radius:10px;padding:8px 12px 10px;margin-bottom:10px}.layer-band.external{border-style:solid;background:#93c5fd0a}.stack-term{display:flex;justify-content:space-between;align-items:baseline;gap:8px;width:100%;background:var(--bg-card);border:1px solid var(--border);color:var(--text);border-radius:7px;padding:5px 10px;margin:4px 0;font-size:12px;cursor:pointer;text-align:left}div.stack-term{cursor:default}.stack-term:hover{border-color:var(--border-strong)}.stack-term.uncovered{border-color:var(--err)}.align-arrow{font-size:10px;color:var(--accent);white-space:nowrap}.align-arrow.unresolved{color:var(--warn)}.align-arrow.missing{color:var(--err);font-style:italic}.align-arrow.proposed{color:var(--warn);font-style:italic}.ref-list{display:flex;flex-direction:column;gap:6px;margin-top:4px}.ref-card{border:1px solid var(--border);border-radius:8px;padding:6px 8px;background:var(--bg)}.ref-card.proposed{border-color:var(--warn)}.ref-head{display:flex;align-items:baseline;gap:8px;justify-content:space-between}.ref-uri{font-family:var(--mono);font-size:12px;word-break:break-all}.ref-status{font-size:9px;text-transform:uppercase;letter-spacing:.04em}.ref-status.accepted{color:var(--accent)}.ref-status.proposed{color:var(--warn)}.ref-meta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:5px}.ref-pill{font-size:10px;padding:1px 6px;border-radius:999px;background:var(--accent-soft);color:var(--accent)}.ref-via{font-size:10px;color:var(--text-dim)}.ref-actions{display:flex;gap:6px;margin-top:6px}.dirty-list{list-style:none;padding:0;margin:0 0 10px;font-size:12px}.dirty-list li{padding:2px 0}.dirty-state{color:var(--warn);margin-right:6px;font-family:var(--mono)}.diff-view{background:var(--bg);border:1px solid var(--border);border-radius:9px;padding:10px;font-size:10.5px;line-height:1.5;overflow:auto;max-height:42vh;font-family:var(--mono);white-space:pre;margin-bottom:10px}.diff-add{color:var(--ok)}.diff-del{color:var(--err)}.diff-hunk{color:#93c5fd}.decision{border:1px solid var(--border);border-radius:9px;padding:8px 12px;margin-bottom:8px}.decision.accepted{opacity:.65}.decision.rejected{opacity:.45}.decision-head{display:flex;gap:6px;align-items:center}.decision-mark{font-weight:700}.decision-subject{font-size:12px;margin:6px 0}.decision-actions{display:flex;gap:6px}.toast{position:absolute;bottom:20px;left:50%;transform:translate(-50%);background:var(--bg-raised);border:1px solid var(--warn);color:var(--text);border-radius:10px;padding:10px 18px;font-size:12px;z-index:60;box-shadow:0 10px 30px #00000080} diff --git a/packages/server/src/mdl_server/static/assets/styles-SXBmvQqW.js b/packages/server/src/mdl_server/static/assets/styles-SXBmvQqW.js new file mode 100644 index 0000000..d07c7ab --- /dev/null +++ b/packages/server/src/mdl_server/static/assets/styles-SXBmvQqW.js @@ -0,0 +1,23 @@ +var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var be=(e,t,n)=>oc(e,typeof t!="symbol"?t+"":t,n);import{r as x,g as vi,R as A,j as h}from"./client-DOmNpTln.js";function je(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?mc:hc;Si.useSyncExternalStore=At.useSyncExternalStore!==void 0?At.useSyncExternalStore:pc;Ni.exports=Si;var gc=Ni.exports;/** + * @license React + * use-sync-external-store-shim/with-selector.production.js + * + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var Dn=x,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=Dn.useRef,_c=Dn.useEffect,Ec=Dn.useMemo,Nc=Dn.useDebugValue;Ei.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var y=o.value;if(s(y,f))return d=y}return d=f}if(y=d,wc(u,f))return y;var w=r(f);return s!==void 0&&s(y,w)?(u=f,y):(u=f,d=w)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};_i.exports=Ei;var Sc=_i.exports;const kc=vi(Sc),jc={},es=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(y=>y(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?es(e):es,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function ki(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const ts=(e,t)=>{const n=Cc(e),r=(s,i=t)=>ki(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?ts(e,t):ts;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rs.hasOwnProperty(t)?{space:rs[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===dr&&t.documentElement.namespaceURI===dr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ji(e){var t=zn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function Cr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=Cr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=M&&(M=E+1);!(C=v[M])&&++M=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Rt(this.node(),e)}function Rt(e,t){return e.style.getPropertyValue(t)||Ri(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ii(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Ti(e)}function Ti(e){this._node=e,this._names=Ii(e.getAttribute("class")||"")}Ti.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Oi(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function fr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}fr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Pn("start","drag","end"),o=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",p,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,C){if(!(u||!e.call(this,b,C))){var j=M(this,t.call(this,b,C),b,C,"mouse");j&&(Te(b.view).on("mousemove.drag",y,Ut).on("mouseup.drag",w,Ut),zi(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,j("start",b))}}function y(b){if(Ct(b),!l){var C=b.clientX-a,j=b.clientY-c;l=C*C+j*j>d}s.mouse("drag",b)}function w(b){Te(b.view).on("mousemove.drag mouseup.drag",null),Hi(b.view,l),Ct(b),s.mouse("end",b)}function v(b,C){if(e.call(this,b,C)){var j=b.changedTouches,_=t.call(this,b,C),R=j.length,S,O;for(S=0;S>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?un(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?un(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Me(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Me(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?un(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?un(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?us(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?us(t[1],t[2]/100,t[3]/100,t[4]):ss.hasOwnProperty(e)?as(ss[e]):e==="transparent"?new Me(NaN,NaN,NaN,0):null}function as(e){return new Me(e>>16&255,e>>8&255,e&255,1)}function un(e,t,n,r){return r<=0&&(e=t=n=NaN),new Me(e,t,n,r)}function Mu(e){return e instanceof rn||(e=Zt(e)),e?(e=e.rgb(),new Me(e.r,e.g,e.b,e.opacity)):new Me}function hr(e,t,n,r){return arguments.length===1?Mu(e):new Me(e,t,n,r??1)}function Me(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Mr(Me,hr,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Me(yt(this.r),yt(this.g),yt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:cs,formatHex:cs,formatHex8:Au,formatRgb:ls,toString:ls}));function cs(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function ls(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function us(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new He(e,t,n,r)}function Vi(e){if(e instanceof He)return new He(e.h,e.s,e.l,e.opacity);if(e instanceof rn||(e=Zt(e)),!e)return new He;if(e instanceof He)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new He(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Vi(e):new He(e,t,n,r??1)}function He(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Mr(He,Ru,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new He(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new He(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Me(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new He(ds(this.h),dn(this.s),dn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${ds(this.h)}, ${dn(this.s)*100}%, ${dn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ds(e){return e=(e||0)%360,e<0?e+360:e}function dn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Bi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Gi:function(t,n){return n-t?Tu(t,n,e):Bi(isNaN(t)?n:t)}}function Gi(e,t){var n=t-e;return n?Iu(e,n):Bi(isNaN(e)?t:e)}const fs=function e(t){var n=Ou(t);function r(s,i){var o=n((s=hr(s)).r,(i=hr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Gi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function it(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var mr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(mr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=mr.lastIndex=Kn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=mr.exec(e))&&(s=Kn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:it(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:it(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:it(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,y){if(l!==d||u!==m){var w=f.push(s(f)+"scale(",null,",",null,")");y.push({i:w-4,x:it(l,d)},{i:w-2,x:it(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var y=-1,w=m.length,v;++y=0&&e._call.call(void 0,t),e=e._next;--It}function ps(){bt=(Cn=Qt.now())+Hn,It=Gt=0;try{Uu()}finally{It=0,Ku(),bt=0}}function qu(){var e=Qt.now(),t=e-Cn;t>Wi&&(Hn-=t,Cn=e)}function Ku(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Yt=e,gr(r)}function gr(e){if(!It){Gt&&(Gt=clearTimeout(Gt));var t=e-bt;t>24?(e<1/0&&(Gt=setTimeout(ps,e-Qt.now()-Hn)),zt&&(zt=clearInterval(zt))):(zt||(Cn=Qt.now(),zt=setInterval(qu,Wi)),It=1,Ui(ps))}}function gs(e,t,n){var r=new $n;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Pn("start","end","cancel","interrupt"),Qu=[],Ki=0,ys=1,yr=2,vn=3,xs=4,xr=5,_n=6;function Fn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Ki})}function Rr(e,t){var n=Fe(e,t);if(n.state>Ki)throw new Error("too late; already scheduled");return n}function Xe(e,t){var n=Fe(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Fe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=qi(i,0,n.time);function i(l){n.state=ys,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ys)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return gs(o);f.state===xs?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uyr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Rr:Xe;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Fe(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Cr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Qe(e,t,n){this.k=e,this.x=t,this.y=n}Qe.prototype={constructor:Qe,scale:function(e){return e===1?this:new Qe(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Qe(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Je=new Qe(1,0,0);Qe.prototype;function Zn(e){e.stopImmediatePropagation()}function Ht(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ws(){return this.__zoom||Je}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function eo(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Xu,l=Pn("start","zoom","end"),u,d,m,f=500,y=150,w=0,v=10;function p(g){g.property("__zoom",ws).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",S).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",D).on("touchmove.zoom",V).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}p.transform=function(g,$,N,I){var L=g.selection?g.selection():g;L.property("__zoom",ws),g!==L?C(g,$,N,I):L.interrupt().each(function(){j(this,arguments).event(I).start().zoom(null,typeof $=="function"?$.apply(this,arguments):$).end()})},p.scaleBy=function(g,$,N,I){p.scaleTo(g,function(){var L=this.__zoom.k,k=typeof $=="function"?$.apply(this,arguments):$;return L*k},N,I)},p.scaleTo=function(g,$,N,I){p.transform(g,function(){var L=t.apply(this,arguments),k=this.__zoom,T=N==null?b(L):typeof N=="function"?N.apply(this,arguments):N,P=k.invert(T),z=typeof $=="function"?$.apply(this,arguments):$;return n(M(E(k,z),T,P),L,o)},N,I)},p.translateBy=function(g,$,N,I){p.transform(g,function(){return n(this.__zoom.translate(typeof $=="function"?$.apply(this,arguments):$,typeof N=="function"?N.apply(this,arguments):N),t.apply(this,arguments),o)},null,I)},p.translateTo=function(g,$,N,I,L){p.transform(g,function(){var k=t.apply(this,arguments),T=this.__zoom,P=I==null?b(k):typeof I=="function"?I.apply(this,arguments):I;return n(Je.translate(P[0],P[1]).scale(T.k).translate(typeof $=="function"?-$.apply(this,arguments):-$,typeof N=="function"?-N.apply(this,arguments):-N),k,o)},I,L)};function E(g,$){return $=Math.max(i[0],Math.min(i[1],$)),$===g.k?g:new Qe($,g.x,g.y)}function M(g,$,N){var I=$[0]-N[0]*g.k,L=$[1]-N[1]*g.k;return I===g.x&&L===g.y?g:new Qe(g.k,I,L)}function b(g){return[(+g[0][0]+ +g[1][0])/2,(+g[0][1]+ +g[1][1])/2]}function C(g,$,N,I){g.on("start.zoom",function(){j(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(I).end()}).tween("zoom",function(){var L=this,k=arguments,T=j(L,k).event(I),P=t.apply(L,k),z=N==null?b(P):typeof N=="function"?N.apply(L,k):N,B=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),X=L.__zoom,K=typeof $=="function"?$.apply(L,k):$,Q=c(X.invert(z).concat(B/X.k),K.invert(z).concat(B/K.k));return function(te){if(te===1)te=K;else{var oe=Q(te),ne=B/oe[2];te=new Qe(ne,z[0]-oe[0]*ne,z[1]-oe[1]*ne)}T.zoom(null,te)}})}function j(g,$,N){return!N&&g.__zooming||new _(g,$)}function _(g,$){this.that=g,this.args=$,this.active=0,this.sourceEvent=null,this.extent=t.apply(g,$),this.taps=0}_.prototype={event:function(g){return g&&(this.sourceEvent=g),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(g,$){return this.mouse&&g!=="mouse"&&(this.mouse[1]=$.invert(this.mouse[0])),this.touch0&&g!=="touch"&&(this.touch0[1]=$.invert(this.touch0[0])),this.touch1&&g!=="touch"&&(this.touch1[1]=$.invert(this.touch1[0])),this.that.__zoom=$,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(g){var $=Te(this.that).datum();l.call(g,this.that,new sf(g,{sourceEvent:this.sourceEvent,target:p,transform:this.that.__zoom,dispatch:l}),$)}};function R(g,...$){if(!e.apply(this,arguments))return;var N=j(this,$).event(g),I=this.__zoom,L=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,r.apply(this,arguments)))),k=ze(g);if(N.wheel)(N.mouse[0][0]!==k[0]||N.mouse[0][1]!==k[1])&&(N.mouse[1]=I.invert(N.mouse[0]=k)),clearTimeout(N.wheel);else{if(I.k===L)return;N.mouse=[k,I.invert(k)],En(this),N.start()}Ht(g),N.wheel=setTimeout(T,y),N.zoom("mouse",n(M(E(I,L),N.mouse[0],N.mouse[1]),N.extent,o));function T(){N.wheel=null,N.end()}}function S(g,...$){if(m||!e.apply(this,arguments))return;var N=g.currentTarget,I=j(this,$,!0).event(g),L=Te(g.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",B,!0),k=ze(g,N),T=g.clientX,P=g.clientY;zi(g.view),Zn(g),I.mouse=[k,this.__zoom.invert(k)],En(this),I.start();function z(X){if(Ht(X),!I.moved){var K=X.clientX-T,Q=X.clientY-P;I.moved=K*K+Q*Q>w}I.event(X).zoom("mouse",n(M(I.that.__zoom,I.mouse[0]=ze(X,N),I.mouse[1]),I.extent,o))}function B(X){L.on("mousemove.zoom mouseup.zoom",null),Hi(X.view,I.moved),Ht(X),I.event(X).end()}}function O(g,...$){if(e.apply(this,arguments)){var N=this.__zoom,I=ze(g.changedTouches?g.changedTouches[0]:g,this),L=N.invert(I),k=N.k*(g.shiftKey?.5:2),T=n(M(E(N,k),I,L),t.apply(this,$),o);Ht(g),a>0?Te(this).transition().duration(a).call(C,T,I,g):Te(this).call(p.transform,T,I,g)}}function D(g,...$){if(e.apply(this,arguments)){var N=g.touches,I=N.length,L=j(this,$,g.changedTouches.length===I).event(g),k,T,P,z;for(Zn(g),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},to=tt.error001();function de(e,t){const n=x.useContext(Vn);if(n===null)throw new Error(to);return ki(n,e,t)}const Ee=()=>{const e=x.useContext(Vn);if(e===null)throw new Error(to);return x.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Tr({position:e,children:t,className:n,style:r,...s}){const i=de(ff),o=`${e}`.split("-");return A.createElement("div",{className:je(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Tr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=x.useRef(null),[m,f]=x.useState({x:0,y:0,width:0,height:0}),y=je(["react-flow__edge-textwrapper",l]);return x.useEffect(()=>{if(d.current){const w=d.current.getBBox();f({x:w.x,y:w.y,width:w.width,height:w.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:y,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=x.memo(mf);const Or=e=>({width:e.offsetWidth,height:e.offsetHeight}),Tt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Lr=(e={x:0,y:0},t)=>({x:Tt(e.x,t[0][0],t[1][0]),y:Tt(e.y,t[0][1],t[1][1])}),bs=(e,t,n)=>en?-Tt(Math.abs(e-n),1,50)/50:0,no=(e,t)=>{const n=bs(e.x,35,t.width-35)*20,r=bs(e.y,35,t.height-35)*20;return[n,r]},ro=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},so=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Jt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),io=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),vs=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>io(so(Jt(e),Jt(t))),wr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Oe(e.width)&&Oe(e.height)&&Oe(e.x)&&Oe(e.y),Oe=e=>!isNaN(e)&&isFinite(e),xe=Symbol.for("internals"),oo=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function br(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const ao=e=>"clientX"in e,lt=(e,t)=>{var i,o;const n=ao(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Mn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},sn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Oe(n)&&Oe(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);sn.displayName="BaseEdge";function Ft(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function co({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[v,p,E]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(sn,{path:v,labelX:p,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:y,interactionWidth:w})});Dr.displayName="SimpleBezierEdge";const Es={[q.Left]:{x:-1,y:0},[q.Right]:{x:1,y:0},[q.Top]:{x:0,y:-1},[q.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=q.Bottom,target:n})=>t===q.Left||t===q.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=q.Bottom,target:n,targetPosition:r=q.Top,center:s,offset:i}){const o=Es[t],a=Es[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],y,w;const v={x:0,y:0},p={x:0,y:0},[E,M,b,C]=co({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){y=s.x??E,w=s.y??M;const _=[{x:y,y:c.y},{x:y,y:l.y}],R=[{x:c.x,y:w},{x:l.x,y:w}];o[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?R:_:f=o.y===m?_:R,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const g=Math.min(i-1,i-H);o[d]===m?v[d]=(c[d]>e[d]?-1:1)*g:p[d]=(l[d]>n[d]?-1:1)*g}}if(t!==r){const H=d==="x"?"y":"x",g=o[d]===a[H],$=c[H]>l[H],N=c[H]=V?(y=(S.x+O.x)/2,w=f[0].y):(y=f[0].x,w=(S.y+O.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:l.x+p.x,y:l.y+p.y},n],y,w,b,C]}function _f(e,t,n,r){const s=Math.min(Ns(e,t)/2,Ns(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let M="";return E>0&&E{const[p,E,M]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:w==null?void 0:w.borderRadius,offset:w==null?void 0:w.offset});return A.createElement(sn,{path:p,labelX:E,labelY:M,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:y,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const Pr=x.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:x.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Pr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=co({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const zr=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[y,w,v]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(sn,{path:y,labelX:w,labelY:v,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});zr.displayName="StraightEdge";function mn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Ss({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case q.Left:return[t-mn(t-r,i),n];case q.Right:return[t+mn(r-t,i),n];case q.Top:return[t,n-mn(n-s,i)];case q.Bottom:return[t,n+mn(s-n,i)]}}function fo({sourceX:e,sourceY:t,sourcePosition:n=q.Bottom,targetX:r,targetY:s,targetPosition:i=q.Top,curvature:o=.25}){const[a,c]=Ss({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Ss({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,y]=lo({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,y]}const In=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=q.Bottom,targetPosition:i=q.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:y,pathOptions:w,interactionWidth:v})=>{const[p,E,M]=fo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:w==null?void 0:w.curvature});return A.createElement(sn,{path:p,labelX:E,labelY:M,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:y,interactionWidth:v})});In.displayName="BezierEdge";const Hr=x.createContext(null),Nf=Hr.Provider;Hr.Consumer;const Sf=()=>x.useContext(Hr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,vr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},_r=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},ho=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},on=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return so(r,Jt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return io(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),on(e,t)),mo=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:y=!1}=u;if(o&&!f||y)return!1;const{positionAbsolute:w}=xt(u,a),v={x:w.x,y:w.y,width:d||0,height:m||0},p=wr(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,M=i&&p>0,b=(d||0)*(m||0);(E||M||p>=b||u.dragging)&&l.push(u)}),l},po=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},go=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Tt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function ks(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=lt(e),l=t.elementsFromPoint(o,a).find(y=>y.classList.contains("react-flow__handle"));if(l){const y=l.getAttribute("data-nodeid");if(y){const w=Fr(void 0,l),v=l.getAttribute("data-handleid"),p=i({nodeId:y,id:v,type:w});if(p){const E=s.find(M=>M.nodeId===y&&M.type===w&&M.id===v);return{handle:{id:v,type:w,nodeId:y,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:p}}}}let u=[],d=1/0;if(s.forEach(y=>{const w=Math.sqrt((y.x-n.x)**2+(y.y-n.y)**2);if(w<=r){const v=i(y);w<=d&&(wy.isValid),f=u.some(({handle:y})=>y.type==="target");return u.find(({handle:y,validHandleResult:w})=>f?y.type==="target":m?w.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},yo=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function xo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...yo(),handleDomNode:c};if(c){const u=Fr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),y=c.classList.contains("connectableend"),w={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=w,f&&y&&(t===vt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(w))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[xe]){const{handleBounds:o}=i[xe];let a=[],c=[];o&&(a=ks(i,o,"source",`${t}-${n}-${r}`),c=ks(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Fr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function wo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ro(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:y,onConnectStart:w,panBy:v,getNodes:p,cancelConnection:E}=i();let M=0,b;const{x:C,y:j}=lt(e),_=u==null?void 0:u.elementFromPoint(C,j),R=Fr(c,_),S=m==null?void 0:m.getBoundingClientRect();if(!S||!R)return;let O,D=lt(e,S),V=!1,H=null,g=!1,$=null;const N=If({nodes:p(),nodeId:n,handleId:t,handleType:R}),I=()=>{if(!f)return;const[T,P]=no(D,S);v({x:T,y:P}),M=requestAnimationFrame(I)};o({connectionPosition:D,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),w==null||w(e,{nodeId:n,handleId:t,handleType:R});function L(T){const{transform:P}=i();D=lt(T,S);const{handle:z,validHandleResult:B}=Af(T,u,_r(D,P,!1,[1,1]),y,N,X=>xo(X,d,n,t,s?"target":"source",a,u));if(b=z,V||(I(),V=!0),$=B.handleDomNode,H=B.connection,g=B.isValid,o({connectionPosition:b&&g?ho({x:b.x,y:b.y},P):D,connectionStatus:Tf(!!b,g),connectionEndHandle:B.endHandle}),!b&&!g&&!$)return Qn(O);H.source!==H.target&&$&&(Qn(O),O=$,$.classList.add("connecting","react-flow__handle-connecting"),$.classList.toggle("valid",g),$.classList.toggle("react-flow__handle-valid",g))}function k(T){var P,z;(b||$)&&H&&g&&(r==null||r(H)),(z=(P=i()).onConnectEnd)==null||z.call(P,T),c&&(l==null||l(T)),Qn(O),E(),cancelAnimationFrame(M),V=!1,g=!1,H=null,$=null,u.removeEventListener("mousemove",L),u.removeEventListener("mouseup",k),u.removeEventListener("touchmove",L),u.removeEventListener("touchend",k)}u.addEventListener("mousemove",L),u.addEventListener("mouseup",k),u.addEventListener("touchmove",L),u.addEventListener("touchend",k)}const js=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},bo=x.forwardRef(({type:e="source",position:t=q.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var S,O;const y=o||null,w=e==="target",v=Ee(),p=Sf(),{connectOnClick:E,noPanClassName:M}=de(Of,ke),{connecting:b,clickConnecting:C}=de(Lf(p,y,e),ke);p||(O=(S=v.getState()).onError)==null||O.call(S,"010",tt.error010());const j=D=>{const{defaultEdgeOptions:V,onConnect:H,hasDefaultEdges:g}=v.getState(),$={...V,...D};if(g){const{edges:N,setEdges:I}=v.getState();I($f($,N))}H==null||H($),a==null||a($)},_=D=>{if(!p)return;const V=ao(D);s&&(V&&D.button===0||!V)&&wo({event:D,handleId:y,nodeId:p,onConnect:j,isTarget:w,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||js}),V?u==null||u(D):d==null||d(D)},R=D=>{const{onClickConnectStart:V,onClickConnectEnd:H,connectionClickStartHandle:g,connectionMode:$,isValidConnection:N}=v.getState();if(!p||!g&&!s)return;if(!g){V==null||V(D,{nodeId:p,handleId:y,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:p,type:e,handleId:y}});return}const I=ro(D.target),L=n||N||js,{connection:k,isValid:T}=xo({nodeId:p,id:y,type:e},$,g.nodeId,g.handleId||null,g.type,L,I);T&&j(k),H==null||H(D),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":y,"data-nodeid":p,"data-handlepos":t,"data-id":`${p}-${y}-${e}`,className:je(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",M,l,{source:!w,target:w,connectable:r,connectablestart:s,connectableend:i,connecting:C,connectionindicator:r&&(s&&!b||i&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});bo.displayName="Handle";var ct=x.memo(bo);const vo=({data:e,isConnectable:t,targetPosition:n=q.Top,sourcePosition:r=q.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ct,{type:"source",position:r,isConnectable:t}));vo.displayName="DefaultNode";var Er=x.memo(vo);const _o=({data:e,isConnectable:t,sourcePosition:n=q.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ct,{type:"source",position:n,isConnectable:t}));_o.displayName="InputNode";var Eo=x.memo(_o);const No=({data:e,isConnectable:t,targetPosition:n=q.Top})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);No.displayName="OutputNode";var So=x.memo(No);const Vr=()=>null;Vr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),pn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(pn),t.selectedNodes.map(pn))&&ke(e.selectedEdges.map(pn),t.selectedEdges.map(pn))}const ko=x.memo(({onSelectionChange:e})=>{const t=Ee(),{selectedNodes:n,selectedEdges:r}=de(Df,Pf);return x.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});ko.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=de(zf);return e||t?A.createElement(ko,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Et(e,t){x.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ie(e,t,n){x.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:y,minZoom:w,maxZoom:v,nodeExtent:p,onNodesChange:E,onEdgesChange:M,elementsSelectable:b,connectionMode:C,snapGrid:j,snapToGrid:_,translateExtent:R,connectOnClick:S,defaultEdgeOptions:O,fitView:D,fitViewOptions:V,onNodesDelete:H,onEdgesDelete:g,onNodeDrag:$,onNodeDragStart:N,onNodeDragStop:I,onSelectionDrag:L,onSelectionDragStart:k,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:B,autoPanOnConnect:X,autoPanOnNodeDrag:K,onError:Q,connectionRadius:te,isValidConnection:oe,nodeDragThreshold:ne})=>{const{setNodes:re,setEdges:pe,setDefaultNodesAndEdges:ae,setMinZoom:ue,setMaxZoom:_e,setTranslateExtent:he,setNodeExtent:ye,reset:le}=de(Ff,ke),Z=Ee();return x.useEffect(()=>{const Ne=r==null?void 0:r.map(Ce=>({...Ce,...O}));return ae(n,Ne),()=>{le()}},[]),ie("defaultEdgeOptions",O,Z.setState),ie("connectionMode",C,Z.setState),ie("onConnect",s,Z.setState),ie("onConnectStart",i,Z.setState),ie("onConnectEnd",o,Z.setState),ie("onClickConnectStart",a,Z.setState),ie("onClickConnectEnd",c,Z.setState),ie("nodesDraggable",l,Z.setState),ie("nodesConnectable",u,Z.setState),ie("nodesFocusable",d,Z.setState),ie("edgesFocusable",m,Z.setState),ie("edgesUpdatable",f,Z.setState),ie("elementsSelectable",b,Z.setState),ie("elevateNodesOnSelect",y,Z.setState),ie("snapToGrid",_,Z.setState),ie("snapGrid",j,Z.setState),ie("onNodesChange",E,Z.setState),ie("onEdgesChange",M,Z.setState),ie("connectOnClick",S,Z.setState),ie("fitViewOnInit",D,Z.setState),ie("fitViewOnInitOptions",V,Z.setState),ie("onNodesDelete",H,Z.setState),ie("onEdgesDelete",g,Z.setState),ie("onNodeDrag",$,Z.setState),ie("onNodeDragStart",N,Z.setState),ie("onNodeDragStop",I,Z.setState),ie("onSelectionDrag",L,Z.setState),ie("onSelectionDragStart",k,Z.setState),ie("onSelectionDragStop",T,Z.setState),ie("noPanClassName",P,Z.setState),ie("nodeOrigin",z,Z.setState),ie("rfId",B,Z.setState),ie("autoPanOnConnect",X,Z.setState),ie("autoPanOnNodeDrag",K,Z.setState),ie("onError",Q,Z.setState),ie("connectionRadius",te,Z.setState),ie("isValidConnection",oe,Z.setState),ie("nodeDragThreshold",ne,Z.setState),Et(e,re),Et(t,pe),Et(w,ue),Et(v,_e),Et(R,he),Et(p,ye),null},Cs={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},jo="react-flow__node-desc",Co="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Xf({rfId:e}){const t=de(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Wf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${jo}-${e}`,style:Cs},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Co}-${e}`,style:Cs},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Xf,{rfId:e}))}var tn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=x.useState(!1),s=x.useRef(!1),i=x.useRef(new Set([])),[o,a]=x.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return x.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const w=Ms(f.code,a);i.current.add(f[w]),$s(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const w=Ms(f.code,a);$s(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[w]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Ms(e,t){return t.includes(e)?"code":"key"}function $o(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return $o(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[xe])==null?void 0:a.z)??0)>(n.z??0)?((c=i[xe])==null?void 0:c.z)??0:n.z??0},r)}function Mo(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=$o(r,e,{...r.position,z:((i=r[xe])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[xe].z=c,n!=null&&n[r.id]&&(r[xe].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Oe(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,xe,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[xe])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Mo(s,n,i),s}function Ao(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const y=n().filter(v=>{var E;const p=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?p&&t.nodes.some(M=>M.id===v.id):p}),w=y.every(v=>v.width&&v.height);if(y.length>0&&w){const v=on(y,d),{x:p,y:E,zoom:M}=go(v,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),b=Je.translate(p,E).scale(M);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Uf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[xe]:r[xe],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function gn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Uf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const Nt=()=>{},Kf={zoomIn:Nt,zoomOut:Nt,zoomTo:Nt,getZoom:()=>1,setViewport:Nt,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:Nt,fitBounds:Nt,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Ee(),{d3Zoom:t,d3Selection:n}=de(Zf,ke);return x.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=Je.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Ao(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=Je.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=go(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=Je.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),_r(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return _r(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=ho(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function an(){const e=Qf(),t=Ee(),n=x.useCallback(()=>t.getState().getNodes().map(w=>({...w})),[]),r=x.useCallback(w=>t.getState().nodeInternals.get(w),[]),s=x.useCallback(()=>{const{edges:w=[]}=t.getState();return w.map(v=>({...v}))},[]),i=x.useCallback(w=>{const{edges:v=[]}=t.getState();return v.find(p=>p.id===w)},[]),o=x.useCallback(w=>{const{getNodes:v,setNodes:p,hasDefaultNodes:E,onNodesChange:M}=t.getState(),b=v(),C=typeof w=="function"?w(b):w;if(E)p(C);else if(M){const j=C.length===0?b.map(_=>({type:"remove",id:_.id})):C.map(_=>({item:_,type:"reset"}));M(j)}},[]),a=x.useCallback(w=>{const{edges:v=[],setEdges:p,hasDefaultEdges:E,onEdgesChange:M}=t.getState(),b=typeof w=="function"?w(v):w;if(E)p(b);else if(M){const C=b.length===0?v.map(j=>({type:"remove",id:j.id})):b.map(j=>({item:j,type:"reset"}));M(C)}},[]),c=x.useCallback(w=>{const v=Array.isArray(w)?w:[w],{getNodes:p,setNodes:E,hasDefaultNodes:M,onNodesChange:b}=t.getState();if(M){const j=[...p(),...v];E(j)}else if(b){const C=v.map(j=>({item:j,type:"add"}));b(C)}},[]),l=x.useCallback(w=>{const v=Array.isArray(w)?w:[w],{edges:p=[],setEdges:E,hasDefaultEdges:M,onEdgesChange:b}=t.getState();if(M)E([...p,...v]);else if(b){const C=v.map(j=>({item:j,type:"add"}));b(C)}},[]),u=x.useCallback(()=>{const{getNodes:w,edges:v=[],transform:p}=t.getState(),[E,M,b]=p;return{nodes:w().map(C=>({...C})),edges:v.map(C=>({...C})),viewport:{x:E,y:M,zoom:b}}},[]),d=x.useCallback(({nodes:w,edges:v})=>{const{nodeInternals:p,getNodes:E,edges:M,hasDefaultNodes:b,hasDefaultEdges:C,onNodesDelete:j,onEdgesDelete:_,onNodesChange:R,onEdgesChange:S}=t.getState(),O=(w||[]).map($=>$.id),D=(v||[]).map($=>$.id),V=E().reduce(($,N)=>{const I=N.parentNode||N.parentId,L=!O.includes(N.id)&&I&&$.find(T=>T.id===I);return(typeof N.deletable=="boolean"?N.deletable:!0)&&(O.includes(N.id)||L)&&$.push(N),$},[]),H=M.filter($=>typeof $.deletable=="boolean"?$.deletable:!0),g=H.filter($=>D.includes($.id));if(V||g){const $=po(V,H),N=[...g,...$],I=N.reduce((L,k)=>(L.includes(k.id)||L.push(k.id),L),[]);if((C||b)&&(C&&t.setState({edges:M.filter(L=>!I.includes(L.id))}),b&&(V.forEach(L=>{p.delete(L.id)}),t.setState({nodeInternals:new Map(p)}))),I.length>0&&(_==null||_(N),S&&S(I.map(L=>({id:L,type:"remove"})))),V.length>0&&(j==null||j(V),R)){const L=V.map(k=>({id:k.id,type:"remove"}));R(L)}}},[]),m=x.useCallback(w=>{const v=yf(w),p=v?null:t.getState().nodeInternals.get(w.id);return!v&&!p?[null,null,v]:[v?w:vs(p),p,v]},[]),f=x.useCallback((w,v=!0,p)=>{const[E,M,b]=m(w);return E?(p||t.getState().getNodes()).filter(C=>{if(!b&&(C.id===M.id||!C.positionAbsolute))return!1;const j=vs(C),_=wr(j,E);return v&&_>0||_>=E.width*E.height}):[]},[]),y=x.useCallback((w,v,p=!0)=>{const[E]=m(w);if(!E)return!1;const M=wr(E,v);return p&&M>0||M>=E.width*E.height},[]);return x.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:y}),[e,n,r,s,i,o,a,c,l,u,d,f,y])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ee(),{deleteElements:r}=an(),s=tn(e,Jf),i=tn(t);x.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),x.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Ee();x.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Or(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",tt.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Br={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,yn=e=>({x:e.x,y:e.y,zoom:e.k}),St=(e,t)=>e.target.closest(`.${t}`),As=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rs=e=>{const t=e.ctrlKey&&Mn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:y,maxZoom:w,zoomActivationKeyCode:v,preventScrolling:p=!0,children:E,noWheelClassName:M,noPanClassName:b})=>{const C=x.useRef(),j=Ee(),_=x.useRef(!1),R=x.useRef(!1),S=x.useRef(null),O=x.useRef({x:0,y:0,zoom:0}),{d3Zoom:D,d3Selection:V,d3ZoomHandler:H,userSelectionActive:g}=de(rh,ke),$=tn(v),N=x.useRef(0),I=x.useRef(!1),L=x.useRef();return th(S),x.useEffect(()=>{if(S.current){const k=S.current.getBoundingClientRect(),T=eo().scaleExtent([y,w]).translateExtent(f),P=Te(S.current).call(T),z=Je.translate(m.x,m.y).scale(Tt(m.zoom,y,w)),B=[[0,0],[k.width,k.height]],X=T.constrain()(z,B,f);T.transform(P,X),T.wheelDelta(Rs),j.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[X.x,X.y,X.k],domNode:S.current.closest(".react-flow")})}},[]),x.useEffect(()=>{V&&D&&(o&&!$&&!g?V.on("wheel.zoom",k=>{if(St(k,M))return!1;k.preventDefault(),k.stopImmediatePropagation();const T=V.property("__zoom").k||1;if(k.ctrlKey&&i){const oe=ze(k),ne=Rs(k),re=T*Math.pow(2,ne);D.scaleTo(V,re,oe,k);return}const P=k.deltaMode===1?20:1;let z=c===gt.Vertical?0:k.deltaX*P,B=c===gt.Horizontal?0:k.deltaY*P;!Mn()&&k.shiftKey&&c!==gt.Vertical&&(z=k.deltaY*P,B=0),D.translateBy(V,-(z/T)*a,-(B/T)*a,{internal:!0});const X=yn(V.property("__zoom")),{onViewportChangeStart:K,onViewportChange:Q,onViewportChangeEnd:te}=j.getState();clearTimeout(L.current),I.current||(I.current=!0,t==null||t(k,X),K==null||K(X)),I.current&&(e==null||e(k,X),Q==null||Q(X),L.current=setTimeout(()=>{n==null||n(k,X),te==null||te(X),I.current=!1},150))},{passive:!1}):typeof H<"u"&&V.on("wheel.zoom",function(k,T){if(!p&&k.type==="wheel"&&!k.ctrlKey||St(k,M))return null;k.preventDefault(),H.call(this,k,T)},{passive:!1}))},[g,o,c,V,D,H,$,i,p,M,t,e,n]),x.useEffect(()=>{D&&D.on("start",k=>{var z,B;if(!k.sourceEvent||k.sourceEvent.internal)return null;N.current=(z=k.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=j.getState(),P=yn(k.transform);_.current=!0,O.current=P,((B=k.sourceEvent)==null?void 0:B.type)==="mousedown"&&j.setState({paneDragging:!0}),T==null||T(P),t==null||t(k.sourceEvent,P)})},[D,t]),x.useEffect(()=>{D&&(g&&!_.current?D.on("zoom",null):g||D.on("zoom",k=>{var P;const{onViewportChange:T}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),R.current=!!(r&&As(d,N.current??0)),(e||T)&&!((P=k.sourceEvent)!=null&&P.internal)){const z=yn(k.transform);T==null||T(z),e==null||e(k.sourceEvent,z)}}))},[g,D,e,d,r]),x.useEffect(()=>{D&&D.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=j.getState();if(_.current=!1,j.setState({paneDragging:!1}),r&&As(d,N.current??0)&&!R.current&&r(k.sourceEvent),R.current=!1,(n||T)&&nh(O.current,k.transform)){const P=yn(k.transform);O.current=P,clearTimeout(C.current),C.current=setTimeout(()=>{T==null||T(P),n==null||n(k.sourceEvent,P)},o?150:0)}})},[D,o,d,n,r]),x.useEffect(()=>{D&&D.filter(k=>{const T=$||s,P=i&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(St(k,"react-flow__node")||St(k,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||g||!l&&k.type==="dblclick"||St(k,M)&&k.type==="wheel"||St(k,b)&&(k.type!=="wheel"||o&&k.type==="wheel"&&!$)||!i&&k.ctrlKey&&k.type==="wheel"||!T&&!o&&!P&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&z})},[g,D,s,i,o,l,d,u,$]),A.createElement("div",{className:"react-flow__renderer",ref:S,style:Br},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=de(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Is(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&Is(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&Is(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ot=(e,t)=>({id:e,type:"select",selected:t});function jt(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ot(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ot(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ro=x.memo(({isSelecting:e,selectionMode:t=en.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=x.useRef(null),f=Ee(),y=x.useRef(0),w=x.useRef(0),v=x.useRef(),{userSelectionActive:p,elementsSelectable:E,dragging:M}=de(lh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),y.current=0,w.current=0},C=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,R=H=>{const{resetSelectedElements:g,domNode:$}=f.getState();if(v.current=$==null?void 0:$.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!v.current)return;const{x:N,y:I}=lt(H,v.current);g(),f.setState({userSelectionRect:{width:0,height:0,startX:N,startY:I,x:N,y:I}}),r==null||r(H)},S=H=>{const{userSelectionRect:g,nodeInternals:$,edges:N,transform:I,onNodesChange:L,onEdgesChange:k,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!g)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=lt(H,v.current),B=g.startX??0,X=g.startY??0,K={...g,x:z.xre.id),ne=te.map(re=>re.id);if(y.current!==ne.length){y.current=ne.length;const re=jt(Q,ne);re.length&&(L==null||L(re))}if(w.current!==oe.length){w.current=oe.length;const re=jt(N,oe);re.length&&(k==null||k(re))}f.setState({userSelectionRect:K})},O=H=>{if(H.button!==0)return;const{userSelectionRect:g}=f.getState();!p&&g&&H.target===m.current&&(C==null||C(H)),f.setState({nodesSelectionActive:y.current>0}),b(),s==null||s(H)},D=H=>{p&&(f.setState({nodesSelectionActive:y.current>0}),s==null||s(H)),b()},V=E&&(e||p);return A.createElement("div",{className:je(["react-flow__pane",{dragging:M,selection:e}]),onClick:V?void 0:er(C,m),onContextMenu:er(j,m),onWheel:er(_,m),onMouseEnter:V?void 0:c,onMouseDown:V?R:void 0,onMouseMove:V?S:l,onMouseUp:V?O:void 0,onMouseLeave:V?D:u,ref:m,style:Br},d,A.createElement(oh,null))});Ro.displayName="Pane";function Io(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Io(r,t):!1}function Ts(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Io(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function To(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Oe(m)&&Oe(f)&&Oe(d.width)&&Oe(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",tt.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Lr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Os=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Or(c)}})};function Vt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Nr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",tt.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Ee();return x.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Oo({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Ee(),[c,l]=x.useState(!1),u=x.useRef([]),d=x.useRef({x:null,y:null}),m=x.useRef(0),f=x.useRef(null),y=x.useRef({x:0,y:0}),w=x.useRef(null),v=x.useRef(!1),p=x.useRef(!1),E=x.useRef(!1),M=fh();return x.useEffect(()=>{if(e!=null&&e.current){const b=Te(e.current),C=({x:R,y:S})=>{const{nodeInternals:O,onNodeDrag:D,onSelectionDrag:V,updateNodePositions:H,nodeExtent:g,snapGrid:$,snapToGrid:N,nodeOrigin:I,onError:L}=a.getState();d.current={x:R,y:S};let k=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&g){const z=on(u.current,I);T=Jt(z)}if(u.current=u.current.map(z=>{const B={x:R-z.distance.x,y:S-z.distance.y};N&&(B.x=$[0]*Math.round(B.x/$[0]),B.y=$[1]*Math.round(B.y/$[1]));const X=[[g[0][0],g[0][1]],[g[1][0],g[1][1]]];u.current.length>1&&g&&!z.extent&&(X[0][0]=z.positionAbsolute.x-T.x+g[0][0],X[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+g[1][0],X[0][1]=z.positionAbsolute.y-T.y+g[0][1],X[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+g[1][1]);const K=To(z,B,O,X,I,L);return k=k||z.position.x!==K.position.x||z.position.y!==K.position.y,z.position=K.position,z.positionAbsolute=K.positionAbsolute,z}),!k)return;H(u.current,!0,!0),l(!0);const P=s?D:nr(V);if(P&&w.current){const[z,B]=tr({nodeId:s,dragItems:u.current,nodeInternals:O});P(w.current,z,B)}},j=()=>{if(!f.current)return;const[R,S]=no(y.current,f.current);if(R!==0||S!==0){const{transform:O,panBy:D}=a.getState();d.current.x=(d.current.x??0)-R/O[2],d.current.y=(d.current.y??0)-S/O[2],D({x:R,y:S})&&C(d.current)}m.current=requestAnimationFrame(j)},_=R=>{var I;const{nodeInternals:S,multiSelectionActive:O,nodesDraggable:D,unselectNodesAndEdges:V,onNodeDragStart:H,onSelectionDragStart:g}=a.getState();p.current=!0;const $=s?H:nr(g);(!o||!i)&&!O&&s&&((I=S.get(s))!=null&&I.selected||V()),s&&i&&o&&Nr({id:s,store:a,nodeRef:e});const N=M(R);if(d.current=N,u.current=uh(S,D,N,s),$&&u.current){const[L,k]=tr({nodeId:s,dragItems:u.current,nodeInternals:S});$(R.sourceEvent,L,k)}};if(t)b.on(".drag",null);else{const R=bu().on("start",S=>{const{domNode:O,nodeDragThreshold:D}=a.getState();D===0&&_(S),E.current=!1;const V=M(S);d.current=V,f.current=(O==null?void 0:O.getBoundingClientRect())||null,y.current=lt(S.sourceEvent,f.current)}).on("drag",S=>{var H,g;const O=M(S),{autoPanOnNodeDrag:D,nodeDragThreshold:V}=a.getState();if(S.sourceEvent.type==="touchmove"&&S.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&p.current&&D&&(v.current=!0,j()),!p.current){const $=O.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),N=O.ySnapped-(((g=d==null?void 0:d.current)==null?void 0:g.y)??0);Math.sqrt($*$+N*N)>V&&_(S)}(d.current.x!==O.xSnapped||d.current.y!==O.ySnapped)&&u.current&&p.current&&(w.current=S.sourceEvent,y.current=lt(S.sourceEvent,f.current),C(O))}}).on("end",S=>{if(!(!p.current||E.current)&&(l(!1),v.current=!1,p.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:O,nodeInternals:D,onNodeDragStop:V,onSelectionDragStop:H}=a.getState(),g=s?V:nr(H);if(O(u.current,!1,!1),g){const[$,N]=tr({nodeId:s,dragItems:u.current,nodeInternals:D});g(S.sourceEvent,$,N)}}}).filter(S=>{const O=S.target;return!S.button&&(!n||!Ts(O,`.${n}`,e))&&(!r||Ts(O,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,M]),c}function Lo(){const e=Ee();return x.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,y=n.isShiftPressed?4:1,w=n.x*m*y,v=n.y*f*y,p=d.map(E=>{if(E.positionAbsolute){const M={x:E.positionAbsolute.x+w,y:E.positionAbsolute.y+v};a&&(M.x=c[0]*Math.round(M.x/c[0]),M.y=c[1]*Math.round(M.y/c[1]));const{positionAbsolute:b,position:C}=To(E,M,r,s,void 0,l);E.position=C,E.positionAbsolute=b}return E});i(p,!0,!1)},[])}const Mt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Bt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:y,onDoubleClick:w,style:v,className:p,isDraggable:E,isSelectable:M,isConnectable:b,isFocusable:C,selectNodesOnDrag:j,sourcePosition:_,targetPosition:R,hidden:S,resizeObserver:O,dragHandle:D,zIndex:V,isParent:H,noDragClassName:g,noPanClassName:$,initialized:N,disableKeyboardA11y:I,ariaLabel:L,rfId:k,hasHandleBounds:T})=>{const P=Ee(),z=x.useRef(null),B=x.useRef(null),X=x.useRef(_),K=x.useRef(R),Q=x.useRef(r),te=M||E||u||d||m||f,oe=Lo(),ne=Vt(n,P.getState,d),re=Vt(n,P.getState,m),pe=Vt(n,P.getState,f),ae=Vt(n,P.getState,y),ue=Vt(n,P.getState,w),_e=le=>{const{nodeDragThreshold:Z}=P.getState();if(M&&(!j||!E||Z>0)&&Nr({id:n,store:P,nodeRef:z}),u){const Ne=P.getState().nodeInternals.get(n);Ne&&u(le,{...Ne})}},he=le=>{if(!br(le)&&!I)if(oo.includes(le.key)&&M){const Z=le.key==="Escape";Nr({id:n,store:P,unselect:Z,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Mt,le.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),oe({x:Mt[le.key].x,y:Mt[le.key].y,isShiftPressed:le.shiftKey}))};x.useEffect(()=>()=>{B.current&&(O==null||O.unobserve(B.current),B.current=null)},[]),x.useEffect(()=>{if(z.current&&!S){const le=z.current;(!N||!T||B.current!==le)&&(B.current&&(O==null||O.unobserve(B.current)),O==null||O.observe(le),B.current=le)}},[S,N,T]),x.useEffect(()=>{const le=Q.current!==r,Z=X.current!==_,Ne=K.current!==R;z.current&&(le||Z||Ne)&&(le&&(Q.current=r),Z&&(X.current=_),Ne&&(K.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const ye=Oo({nodeRef:z,disabled:S||!E,noDragClassName:g,handleSelector:D,nodeId:n,isSelectable:M,selectNodesOnDrag:j});return S?null:A.createElement("div",{className:je(["react-flow__node",`react-flow__node-${r}`,{[$]:E},p,{selected:l,selectable:M,parent:H,dragging:ye}]),ref:z,style:{zIndex:V,transform:`translate(${a}px,${c}px)`,pointerEvents:te?"all":"none",visibility:N?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:re,onMouseLeave:pe,onContextMenu:ae,onClick:_e,onDoubleClick:ue,onKeyDown:C?he:void 0,tabIndex:C?0:void 0,role:C?"button":void 0,"aria-describedby":I?void 0:`${jo}-${k}`,"aria-label":L},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:ye,dragHandle:D,zIndex:V})))};return t.displayName="NodeWrapper",x.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...on(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ee(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=de(hh,ke),u=Lo(),d=x.useRef(null);if(x.useEffect(()=>{var y;n||(y=d.current)==null||y.focus({preventScroll:!0})},[n]),Oo({nodeRef:d}),l||!s||!i)return null;const m=e?y=>{const w=r.getState().getNodes().filter(v=>v.selected);e(y,w)}:void 0,f=y=>{Object.prototype.hasOwnProperty.call(Mt,y.key)&&u({x:Mt[y.key].x,y:Mt[y.key].y,isShiftPressed:y.shiftKey})};return A.createElement("div",{className:je(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=x.memo(mh);const gh=e=>e.nodesSelectionActive,Do=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:y,onSelectionEnd:w,multiSelectionKeyCode:v,panActivationKeyCode:p,zoomActivationKeyCode:E,elementsSelectable:M,zoomOnScroll:b,zoomOnPinch:C,panOnScroll:j,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:S,panOnDrag:O,defaultViewport:D,translateExtent:V,minZoom:H,maxZoom:g,preventScrolling:$,onSelectionContextMenu:N,noWheelClassName:I,noPanClassName:L,disableKeyboardA11y:k})=>{const T=de(gh),P=tn(d),z=tn(p),B=z||O,X=z||j,K=P||m&&B!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:M,zoomOnScroll:b,zoomOnPinch:C,panOnScroll:X,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:S,panOnDrag:!P&&B,defaultViewport:D,translateExtent:V,minZoom:H,maxZoom:g,zoomActivationKeyCode:E,preventScrolling:$,noWheelClassName:I,noPanClassName:L},A.createElement(Ro,{onSelectionStart:y,onSelectionEnd:w,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:B,isSelecting:!!K,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:N,noPanClassName:L,disableKeyboardA11y:k})))};Do.displayName="FlowRenderer";var yh=x.memo(Do);function xh(e){return de(x.useCallback(n=>e?mo(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Bt(e.input||Eo),default:Bt(e.default||Er),output:Bt(e.output||So),group:Bt(e.group||Vr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Bt(e[i]||Er),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Po=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=de(vh,ke),a=xh(e.onlyRenderVisibleElements),c=x.useRef(),l=x.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return x.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Br},a.map(u=>{var C,j,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",tt.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),y=!!(u.selectable||s&&typeof u.selectable>"u"),w=!!(u.connectable||n&&typeof u.connectable>"u"),v=!!(u.focusable||r&&typeof u.focusable>"u"),p=e.nodeExtent?Lr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(p==null?void 0:p.x)??0,M=(p==null?void 0:p.y)??0,b=bh({x:E,y:M,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||q.Bottom,targetPosition:u.targetPosition||q.Top,hidden:u.hidden,xPos:E,yPos:M,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:y,isConnectable:w,isFocusable:v,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((C=u[xe])==null?void 0:C.z)??0,isParent:!!((j=u[xe])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[xe])!=null&&_.handleBounds)})}))};Po.displayName="NodeRenderer";var _h=x.memo(Po);const Eh=(e,t,n)=>n===q.Left?e-t:n===q.Right?e+t:e,Nh=(e,t,n)=>n===q.Top?e-t:n===q.Bottom?e+t:e,Ls="react-flow__edgeupdater",Ds=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:je([Ls,`${Ls}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var kt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:w,style:v,source:p,target:E,sourceX:M,sourceY:b,targetX:C,targetY:j,sourcePosition:_,targetPosition:R,elementsSelectable:S,hidden:O,sourceHandleId:D,targetHandleId:V,onContextMenu:H,onMouseEnter:g,onMouseMove:$,onMouseLeave:N,reconnectRadius:I,onReconnect:L,onReconnectStart:k,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:B,ariaLabel:X,isFocusable:K,isReconnectable:Q,pathOptions:te,interactionWidth:oe,disableKeyboardA11y:ne})=>{const re=x.useRef(null),[pe,ae]=x.useState(!1),[ue,_e]=x.useState(!1),he=Ee(),ye=x.useMemo(()=>`url('#${vr(z,B)}')`,[z,B]),le=x.useMemo(()=>`url('#${vr(P,B)}')`,[P,B]);if(O)return null;const Z=se=>{var Se;const{edges:me,addSelectedEdges:$e,unselectNodesAndEdges:W,multiSelectionActive:fe}=he.getState(),ge=me.find(dt=>dt.id===n);ge&&(S&&(he.setState({nodesSelectionActive:!1}),ge.selected&&fe?(W({nodes:[],edges:[ge]}),(Se=re.current)==null||Se.blur()):$e([n])),o&&o(se,ge))},Ne=Ft(n,he.getState,a),Ce=Ft(n,he.getState,H),ut=Ft(n,he.getState,g),Ae=Ft(n,he.getState,$),We=Ft(n,he.getState,N),Ie=(se,me)=>{if(se.button!==0)return;const{edges:$e,isValidConnection:W}=he.getState(),fe=me?E:p,ge=(me?V:D)||null,Se=me?"target":"source",dt=W||Sh,Ot=me,rt=$e.find(Pe=>Pe.id===n);_e(!0),k==null||k(se,rt,Se);const ft=Pe=>{_e(!1),T==null||T(Pe,rt,Se)};wo({event:se,handleId:ge,nodeId:fe,onConnect:Pe=>L==null?void 0:L(rt,Pe),isTarget:Ot,getState:he.getState,setState:he.setState,isValidConnection:dt,edgeUpdaterType:Se,onReconnectEnd:ft})},F=se=>Ie(se,!0),Y=se=>Ie(se,!1),G=()=>ae(!0),J=()=>ae(!1),U=!S&&!o,ee=se=>{var me;if(!ne&&oo.includes(se.key)&&S){const{unselectNodesAndEdges:$e,addSelectedEdges:W,edges:fe}=he.getState();se.key==="Escape"?((me=re.current)==null||me.blur(),$e({edges:[fe.find(Se=>Se.id===n)]})):W([n])}};return A.createElement("g",{className:je(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:pe}]),onClick:Z,onDoubleClick:Ne,onContextMenu:Ce,onMouseEnter:ut,onMouseMove:Ae,onMouseLeave:We,onKeyDown:K?ee:void 0,tabIndex:K?0:void 0,role:K?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":X===null?void 0:X||`Edge from ${p} to ${E}`,"aria-describedby":K?`${Co}-${B}`:void 0,ref:re},!ue&&A.createElement(e,{id:n,source:p,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:w,data:i,style:v,sourceX:M,sourceY:b,targetX:C,targetY:j,sourcePosition:_,targetPosition:R,sourceHandleId:D,targetHandleId:V,markerStart:ye,markerEnd:le,pathOptions:te,interactionWidth:oe}),Q&&A.createElement(A.Fragment,null,(Q==="source"||Q===!0)&&A.createElement(Ds,{position:_,centerX:M,centerY:b,radius:I,onMouseDown:F,onMouseEnter:G,onMouseOut:J,type:"source"}),(Q==="target"||Q===!0)&&A.createElement(Ds,{position:R,centerX:C,centerY:j,radius:I,onMouseDown:Y,onMouseEnter:G,onMouseOut:J,type:"target"})))};return t.displayName="EdgeWrapper",x.memo(t)};function kh(e){const t={default:kt(e.default||In),straight:kt(e.bezier||zr),step:kt(e.step||Pr),smoothstep:kt(e.step||Bn),simplebezier:kt(e.simplebezier||Dr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=kt(e[i]||In),s),n);return{...t,...r}}function Ps(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case q.Top:return{x:r+i/2,y:s};case q.Right:return{x:r+i,y:s+o/2};case q.Bottom:return{x:r+i/2,y:s+o};case q.Left:return{x:r,y:s+o/2}}}function zs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ps(n,e,t),a=Ps(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Jt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Hs(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[xe])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Oe(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),y=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),w=Math.max(((u=f==null?void 0:f[xe])==null?void 0:u.z)||0,((d=m==null?void 0:m[xe])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(y?w:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=de(x.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Fs={[An.Arrow]:Rh,[An.ArrowClosed]:Ih};function Th(e){const t=Ee();return x.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(Fs,e)?Fs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",tt.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=vr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},zo=({defaultColor:e,rfId:t})=>{const n=de(x.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};zo.displayName="MarkerDefinitions";var Dh=x.memo(zo);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ho=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:y,reconnectRadius:w,children:v,disableKeyboardA11y:p})=>{const{edgesFocusable:E,edgesUpdatable:M,elementsSelectable:b,width:C,height:j,connectionMode:_,nodeInternals:R,onError:S}=de(Ph,ke),O=Ah(t,R,n);return C?A.createElement(A.Fragment,null,O.map(({level:D,edges:V,isMaxLevel:H})=>A.createElement("svg",{key:D,style:{zIndex:D},width:C,height:j,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,V.map(g=>{const[$,N,I]=Hs(R.get(g.source)),[L,k,T]=Hs(R.get(g.target));if(!I||!T)return null;let P=g.type||"default";s[P]||(S==null||S("011",tt.error011(P)),P="default");const z=s[P]||s.default,B=_===vt.Strict?k.target:(k.target??[]).concat(k.source??[]),X=zs(N.source,g.sourceHandle),K=zs(B,g.targetHandle),Q=(X==null?void 0:X.position)||q.Bottom,te=(K==null?void 0:K.position)||q.Top,oe=!!(g.focusable||E&&typeof g.focusable>"u"),ne=g.reconnectable||g.updatable,re=typeof m<"u"&&(ne||M&&typeof ne>"u");if(!X||!K)return S==null||S("008",tt.error008(X,g)),null;const{sourceX:pe,sourceY:ae,targetX:ue,targetY:_e}=jh($,X,Q,L,K,te);return A.createElement(z,{key:g.id,id:g.id,className:je([g.className,i]),type:P,data:g.data,selected:!!g.selected,animated:!!g.animated,hidden:!!g.hidden,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,style:g.style,source:g.source,target:g.target,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerEnd:g.markerEnd,markerStart:g.markerStart,sourceX:pe,sourceY:ae,targetX:ue,targetY:_e,sourcePosition:Q,targetPosition:te,elementsSelectable:b,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:y,reconnectRadius:w,rfId:r,ariaLabel:g.ariaLabel,isFocusable:oe,isReconnectable:re,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth,disableKeyboardA11y:p})})))),v):null};Ho.displayName="EdgeRenderer";var zh=x.memo(Ho);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=de(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=an(),n=x.useRef(!1);x.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[q.Left]:q.Right,[q.Right]:q.Left,[q.Top]:q.Bottom,[q.Bottom]:q.Top},Fo=({nodeId:e,handleType:t,style:n,type:r=at.Bezier,CustomComponent:s,connectionStatus:i})=>{var j,_,R;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=de(x.useCallback(S=>({fromNode:S.nodeInternals.get(e),handleId:S.connectionHandleId,toX:(S.connectionPosition.x-S.transform[0])/S.transform[2],toY:(S.connectionPosition.y-S.transform[1])/S.transform[2],connectionMode:S.connectionMode}),[e]),ke),d=(j=o==null?void 0:o[xe])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(u===vt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(S=>S.id===a):m[0],y=f?f.x+f.width/2:(o.width??0)/2,w=f?f.y+f.height/2:o.height??0,v=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+y,p=(((R=o.positionAbsolute)==null?void 0:R.y)??0)+w,E=f==null?void 0:f.position,M=E?Bh[E]:null;if(!E||!M)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:v,fromY:p,toX:c,toY:l,fromPosition:E,toPosition:M,connectionStatus:i});let b="";const C={sourceX:v,sourceY:p,sourcePosition:E,targetX:c,targetY:l,targetPosition:M};return r===at.Bezier?[b]=fo(C):r===at.Step?[b]=Rn({...C,borderRadius:0}):r===at.SmoothStep?[b]=Rn(C):r===at.SimpleBezier?[b]=uo(C):b=`M${v},${p} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Fo.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=de(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:je(["react-flow__connection",l])},A.createElement(Fo,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Vs(e,t){return x.useRef(null),Ee(),x.useMemo(()=>t(e),[e])}const Vo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:y,onSelectionStart:w,onSelectionEnd:v,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:M,connectionLineContainerStyle:b,selectionKeyCode:C,selectionOnDrag:j,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:S,zoomActivationKeyCode:O,deleteKeyCode:D,onlyRenderVisibleElements:V,elementsSelectable:H,selectNodesOnDrag:g,defaultViewport:$,translateExtent:N,minZoom:I,maxZoom:L,preventScrolling:k,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:B,panOnScrollSpeed:X,panOnScrollMode:K,zoomOnDoubleClick:Q,panOnDrag:te,onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneScroll:ae,onPaneContextMenu:ue,onEdgeContextMenu:_e,onEdgeMouseEnter:he,onEdgeMouseMove:ye,onEdgeMouseLeave:le,onReconnect:Z,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,noDragClassName:Ae,noWheelClassName:We,noPanClassName:Ie,elevateEdgesOnSelect:F,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:J,rfId:U})=>{const ee=Vs(e,wh),se=Vs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneContextMenu:ue,onPaneScroll:ae,deleteKeyCode:D,selectionKeyCode:C,selectionOnDrag:j,selectionMode:_,onSelectionStart:w,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:S,zoomActivationKeyCode:O,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:Q,panOnScroll:B,panOnScrollSpeed:X,panOnScrollMode:K,panOnDrag:te,defaultViewport:$,translateExtent:N,minZoom:I,maxZoom:L,onSelectionContextMenu:y,preventScrolling:k,noDragClassName:Ae,noWheelClassName:We,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:V,onEdgeContextMenu:_e,onEdgeMouseEnter:he,onEdgeMouseMove:ye,onEdgeMouseLeave:le,onReconnect:Z,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!F,disableKeyboardA11y:Y,rfId:U},A.createElement(Yh,{style:E,type:p,component:M,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:ee,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:g,onlyRenderVisibleElements:V,noPanClassName:Ie,noDragClassName:Ae,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:J,rfId:U})))};Vo.displayName="GraphView";var Xh=x.memo(Vo);const Sr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],st={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Sr,nodeExtent:Sr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:vt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Wh=()=>Rc((e,t)=>({...st,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Jn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((w,v)=>{const p=s.get(v.id);if(p!=null&&p.hidden)s.set(p.id,{...p,[xe]:{...p[xe],handleBounds:void 0}});else if(p){const E=Or(v.nodeElement);!!(E.width&&E.height&&(p.width!==E.width||p.height!==E.height||v.forceUpdate))&&(s.set(p.id,{...p,[xe]:{...p[xe],handleBounds:{source:Os(".source",v.nodeElement,m,l),target:Os(".target",v.nodeElement,m,l)}},...E}),w.push({id:p.id,type:"dimensions",dimensions:E}))}return w},[]);Mo(s,l);const y=o||i&&!o&&Ao(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:y}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Jn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(i(),n),a=jt(s,[])),gn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(s,n),a=jt(i(),[])),gn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ot(u.id,!1))),l=a.map(u=>ot(u.id,!1));gn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ot(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ot(a.id,!1));gn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Lr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=Je.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:st.connectionNodeId,connectionHandleId:st.connectionHandleId,connectionHandleType:st.connectionHandleType,connectionStatus:st.connectionStatus,connectionStartHandle:st.connectionStartHandle,connectionEndHandle:st.connectionEndHandle}),reset:()=>e({...st})}),Object.is),Bo=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Wh()),A.createElement(df,{value:t.current},e)};Bo.displayName="ReactFlowProvider";const Go=({children:e})=>x.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Bo,null,e);Go.displayName="ReactFlowWrapper";const Uh={input:Eo,default:Er,output:So,group:Vr},qh={default:In,straight:zr,step:Pr,smoothstep:Bn,simplebezier:Dr},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Yo=x.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Uh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:y,onConnectEnd:w,onClickConnectStart:v,onClickConnectEnd:p,onNodeMouseEnter:E,onNodeMouseMove:M,onNodeMouseLeave:b,onNodeContextMenu:C,onNodeDoubleClick:j,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:S,onNodesDelete:O,onEdgesDelete:D,onSelectionChange:V,onSelectionDragStart:H,onSelectionDrag:g,onSelectionDragStop:$,onSelectionContextMenu:N,onSelectionStart:I,onSelectionEnd:L,connectionMode:k=vt.Strict,connectionLineType:T=at.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:B,deleteKeyCode:X="Backspace",selectionKeyCode:K="Shift",selectionOnDrag:Q=!1,selectionMode:te=en.Full,panActivationKeyCode:oe="Space",multiSelectionKeyCode:ne=Mn()?"Meta":"Control",zoomActivationKeyCode:re=Mn()?"Meta":"Control",snapToGrid:pe=!1,snapGrid:ae=Zh,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:_e=!0,nodesDraggable:he,nodesConnectable:ye,nodesFocusable:le,nodeOrigin:Z=Kh,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,defaultViewport:Ae=Qh,minZoom:We=.5,maxZoom:Ie=2,translateExtent:F=Sr,preventScrolling:Y=!0,nodeExtent:G,defaultMarkerColor:J="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:ee=!0,panOnScroll:se=!1,panOnScrollSpeed:me=.5,panOnScrollMode:$e=gt.Free,zoomOnDoubleClick:W=!0,panOnDrag:fe=!0,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,children:Lt,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ce,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:Zr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Xa,defaultEdgeOptions:Wa,elevateNodesOnSelect:Ua=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Qr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Jr,nodeDragThreshold:nc,...rc},sc)=>{const Xn=Jr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:je(["react-flow",s]),"data-testid":"rf__wrapper",id:Jr},A.createElement(Go,null,A.createElement(Xh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:M,onNodeMouseLeave:b,onNodeContextMenu:C,onNodeDoubleClick:j,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:B,selectionKeyCode:K,selectionOnDrag:Q,selectionMode:te,deleteKeyCode:X,multiSelectionKeyCode:ne,panActivationKeyCode:oe,zoomActivationKeyCode:re,onlyRenderVisibleElements:ue,selectNodesOnDrag:_e,defaultViewport:Ae,translateExtent:F,minZoom:We,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:U,zoomOnPinch:ee,zoomOnDoubleClick:W,panOnScroll:se,panOnScrollSpeed:me,panOnScrollMode:$e,panOnDrag:fe,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,onSelectionContextMenu:N,onSelectionStart:I,onSelectionEnd:L,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ce,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:J,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:Zr,elevateEdgesOnSelect:qa,rfId:Xn,disableKeyboardA11y:Qr,nodeOrigin:Z,nodeExtent:G}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:y,onConnectEnd:w,onClickConnectStart:v,onClickConnectEnd:p,nodesDraggable:he,nodesConnectable:ye,nodesFocusable:le,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,elevateNodesOnSelect:Ua,minZoom:We,maxZoom:Ie,nodeExtent:G,onNodesChange:Pa,onEdgesChange:za,snapToGrid:pe,snapGrid:ae,connectionMode:k,translateExtent:F,connectOnClick:Ga,defaultEdgeOptions:Wa,fitView:Va,fitViewOptions:Ba,onNodesDelete:O,onEdgesDelete:D,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:S,onSelectionDrag:g,onSelectionDragStart:H,onSelectionDragStop:$,noPanClassName:Zr,nodeOrigin:Z,rfId:Xn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:V}),Lt,A.createElement(hf,{proOptions:Xa,position:Ya}),A.createElement(Wf,{rfId:Xn,disableKeyboardA11y:Qr})))});Yo.displayName="ReactFlow";const Xo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:y,backgroundColor:w}=i||{},v=o||y||w;return A.createElement("rect",{className:je(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?p=>m(p,e):void 0})};Xo.displayName="MiniMapNode";var em=x.memo(Xo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=de(nm,ke),c=de(tm),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:y,y:w}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:y,y:w,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=x.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(on(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:y=!1,zoomable:w=!1,ariaLabel:v="React Flow mini map",inversePan:p=!1,zoomStep:E=10,offsetScale:M=5}){const b=Ee(),C=x.useRef(null),{boundingRect:j,viewBB:_,rfId:R}=de(am,ke),S=(e==null?void 0:e.width)??im,O=(e==null?void 0:e.height)??om,D=j.width/S,V=j.height/O,H=Math.max(D,V),g=H*S,$=H*O,N=M*H,I=j.x-(g-j.width)/2-N,L=j.y-($-j.height)/2-N,k=g+N*2,T=$+N*2,P=`${cm}-${R}`,z=x.useRef(0);z.current=H,x.useEffect(()=>{if(C.current){const K=Te(C.current),Q=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ae}=b.getState();if(ne.sourceEvent.type!=="wheel"||!pe||!ae)return;const ue=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,_e=re[2]*Math.pow(2,ue);ae.scaleTo(pe,_e)},te=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ae,translateExtent:ue,width:_e,height:he}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!pe||!ae)return;const ye=z.current*Math.max(1,re[2])*(p?-1:1),le={x:re[0]-ne.sourceEvent.movementX*ye,y:re[1]-ne.sourceEvent.movementY*ye},Z=[[0,0],[_e,he]],Ne=Je.translate(le.x,le.y).scale(re[2]),Ce=ae.constrain()(Ne,Z,ue);ae.transform(pe,Ce)},oe=eo().on("zoom",y?te:null).on("zoom.wheel",w?Q:null);return K.call(oe),()=>{K.on("zoom",null)}}},[y,w,p,E]);const B=m?K=>{const Q=ze(K);m(K,{x:Q[0],y:Q[1]})}:void 0,X=f?(K,Q)=>{const te=b.getState().nodeInternals.get(Q);f(K,te)}:void 0;return A.createElement(Tr,{position:d,style:e,className:je(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:S,height:O,viewBox:`${I} ${L} ${k} ${T}`,role:"img","aria-labelledby":P,ref:C,onClick:B},v&&A.createElement("title",{id:P},v),A.createElement(sm,{onClick:X,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${I-N},${L-N}h${k+N*2}v${T+N*2}h${-k-N*2}z + M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Wo.displayName="MiniMap";var lm=x.memo(Wo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Xt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:je(["react-flow__controls-button",t]),...n},e);Xt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ee(),[f,y]=x.useState(!1),{isInteractive:w,minZoomReached:v,maxZoomReached:p}=de(pm,ke),{zoomIn:E,zoomOut:M,fitView:b}=an();if(x.useEffect(()=>{y(!0)},[]),!f)return null;const C=()=>{E(),i==null||i()},j=()=>{M(),o==null||o()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!w,nodesConnectable:!w,elementsSelectable:!w}),c==null||c(!w)};return A.createElement(Tr,{className:je(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Xt,{onClick:C,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:p},A.createElement(um,null)),A.createElement(Xt,{onClick:j,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(dm,null))),n&&A.createElement(Xt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Xt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},w?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=x.memo(Uo),Le;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Le||(Le={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[Le.Dots]:"#91919a",[Le.Lines]:"#eee",[Le.Cross]:"#e2e2e2"},bm={[Le.Dots]:1,[Le.Lines]:1,[Le.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function qo({id:e,variant:t=Le.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=x.useRef(null),{transform:u,patternId:d}=de(vm,ke),m=o||wm[t],f=r||bm[t],y=t===Le.Dots,w=t===Le.Cross,v=Array.isArray(n)?n:[n,n],p=[v[0]*u[2]||1,v[1]*u[2]||1],E=f*u[2],M=w?[E,E]:p,b=y?[E/i,E/i]:[M[0]/i,M[1]/i];return A.createElement("svg",{className:je(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%p[0],y:u[1]%p[1],width:p[0],height:p[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},y?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:M,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}qo.displayName="Background";var _m=x.memo(qo);const Gr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Gr+e}async function we(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function nt(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new Ko(r.error??`${e}: ${n.status}`,n.status);return r}class Ko extends Error{constructor(n,r){super(n);be(this,"status");this.status=r}}const Cx=e=>we(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),$x=()=>we("/api/diagnostics"),Zo=(e,t)=>we(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Qo=()=>we("/api/ontology/ontologies"),Em=e=>we(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>we("/api/ontology/stack"),Sm=()=>we("/api/ontology/coverage"),km=(e,t,n)=>nt("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>we("/api/git/status"),Cm=()=>we("/api/git/diff"),$m=e=>nt("/api/git/commit",{message:e}),Mm=()=>nt("/api/git/discard",{}),Am=()=>we("/api/decisions"),Bs=(e,t)=>nt(`/api/decisions/${e}/verdict`,{verdict:t}),Mx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),we(`/api/glossary/terms?${t.toString()}`)},Ax=()=>we("/api/glossary/config"),Rx=e=>nt("/api/git/propose",e),Ix=(e="HEAD")=>we(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Tx=(e="HEAD")=>we(`/api/git/classify?base=${encodeURIComponent(e)}`),Ox=e=>nt("/api/git/classify",{changes:e}),Lx=e=>we(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Dx=(e="")=>we(`/api/git/context?user=${encodeURIComponent(e)}`),Px=(e="")=>we(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>we("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Gr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>nt("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>nt("/api/import/preview",{format:e,content:t}),zx=e=>we(`/api/import/stash/${encodeURIComponent(e)}`),Hx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Fx=(e,t,n)=>fetch(`${Gr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new Ko(await r.text(),r.status);return await r.json()}),Vx=()=>we("/api/glossary/subject-areas"),Bx=e=>we(`/api/glossary/subject-area/${e}`),Gx=(e,t)=>nt(`/api/glossary/subject-area/${e}/expand`,t);function Yx(){return{async load(e){try{const t=await we(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Yr="__entity_source",Xr="__entity_target",Pm=x.memo(function({data:t,selected:n}){var j;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:y}=t,w=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>w(_.a)-w(R.a)||_.i-R.i).map(_=>_.a),p=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const M=!!c&&!l;let b=0;if(M){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const C=(_,R)=>{const S="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:S,onMouseEnter:y?()=>y(_.id):void 0,onMouseLeave:y?()=>y(null):void 0,children:[h.jsx(ct,{id:_.id,type:"target",position:q.Left,className:"port attr-port"}),h.jsx(ct,{id:_.id,type:"source",position:q.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ct,{id:Xr,type:"target",position:q.Left,className:"port"}),h.jsx(ct,{id:Yr,type:"source",position:q.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((j=r.conceptual)==null?void 0:j.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var S;const _=(((S=r.conceptual)==null?void 0:S.ontology_refs)??[]).filter(O=>O.uri);if(_.length===0)return null;const R=_.map(O=>O.uri).join(` +`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),p.length>0&&h.jsx("div",{className:"attr-section keys",children:p.map(_=>C(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>C(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,y,w,v,p,E,M,b,C,j,_,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(S=>S.from.entity===e.id||S.to.entity===e.id),d=S=>{var O;return((O=t.entities.find(D=>D.id===S))==null?void 0:O.name)??S};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Ke,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:S=>r("rename_entity",{id:e.id,name:S})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Ke,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:S=>r("rename_entity",{id:e.id,physical_name:S})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Ke,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:S=>r("set_definition",{id:e.id,definition:S})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((y=l==null?void 0:l.ontology_refs)==null?void 0:y.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(w=e.term_map)!=null&&w.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((p=e.term_map)==null?void 0:p.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),(M=e.term_map)!=null&&M.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[((C=e.term_map)==null?void 0:C.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Ke,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:S=>{var O;return r("set_stewardship",{id:e.id,owner:S,steward:((O=l==null?void 0:l.stewardship)==null?void 0:O.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Ke,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:S=>{var O;return r("set_stewardship",{id:e.id,owner:((O=l==null?void 0:l.stewardship)==null?void 0:O.owner)??null,steward:S})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(S=>h.jsx(Xm,{a:S,entity:e,doc:t,readOnly:c,exec:r},S.id))})}),!c&&h.jsx(Wm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(S=>{const O=S.members.map(D=>{var V;return((V=e.attributes.find(H=>H.id===D))==null?void 0:V.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+S.type,children:S.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:S.name}),h.jsx("span",{className:"key-cols",children:O})]},S.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([S,O])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:S}),h.jsx("td",{className:"udp-val",children:String(O)})]},S))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(S=>{const O=S.from.entity===e.id?S.to.entity:S.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(O),children:[h.jsx("span",{className:"rel-card",children:Um(S,e.id)}),d(O)]}),(S.verb_phrase||S.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Ke,{value:S.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:D=>r("update_relationship",{id:S.id,verb_phrase:D})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Ke,{value:S.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:D=>r("update_relationship",{id:S.id,inverse_verb_phrase:D})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${S.name}`,onClick:()=>r("delete_relationship",{id:S.id}),children:"✕"})]},S.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var S;return(S=navigator.clipboard)==null?void 0:S.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Ke({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=x.useState(e);x.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Xm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Ke,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Ke,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Wm({entity:e,exec:t}){const[n,r]=x.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Um(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Gs="";let Km=class{constructor(t){be(this,"_isDirected",!0);be(this,"_isMultigraph",!1);be(this,"_isCompound",!1);be(this,"_label");be(this,"_defaultNodeLabelFn",()=>{});be(this,"_defaultEdgeLabelFn",()=>{});be(this,"_nodes",{});be(this,"_in",{});be(this,"_preds",{});be(this,"_out",{});be(this,"_sucs",{});be(this,"_edgeObjs",{});be(this,"_edgeLabels",{});be(this,"_nodeCount",0);be(this,"_edgeCount",0);be(this,"_parent");be(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Ys(this._preds[n],t),Ys(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Xs(this._preds[n],t),Xs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Ys(e,t){e[t]?e[t]++:e[t]=1}function Xs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Gs+i+Gs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function sr(e,t){return Wt(e,t.v,t.w,t.name)}var Wr=Km,Qm="2.2.4",Jm={Graph:Wr,version:Qm},ep=Wr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){be(this,"_arr",[]);be(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=ea,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ta=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ta,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),ia(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),ia(t(i),o=>s.push(o)))}}function ia(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=sa,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=sa,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Wr,Lp=Jo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:ea,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ta,topsort:ra},Us=Jm,Ve={Graph:Us.Graph,json:tp,alg:zp,version:Us.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return qs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&qs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function qs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ve.Graph,Gp=Vp;var Yp=Wp;let Xp=()=>1;function Wp(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Xp);return Up(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Up(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)ir(e,t,n,o);for(;o=s.dequeue();)ir(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(ir(e,t,n,o,!0));break}}}return r}function ir(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,jr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,jr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{jr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function jr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new oa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=da(la(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),aa(e,"border",s,t)}function og(e,t=ca){const n=[];for(let r=0;rca){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function la(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function ua(e){var t=++ug;return e+(""+t)}function da(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Ur(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=ve.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=ve;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=ve;var Yn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ve.Graph,On=Yn.slack,fa=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!On(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=On(t,s)),it.node(r).rank+=n)}var Rg=fa,Ks=Yn.slack,Ig=Yn.longestPath,Tg=Ve.alg.preorder,Og=Ve.alg.postorder,Lg=ve.simplify,Dg=_t;_t.initLowLimValues=Kr;_t.initCutValues=qr;_t.calcCutValue=ha;_t.leaveEdge=pa;_t.enterEdge=ga;_t.exchangeEdges=ya;function _t(e){e=Lg(e),Ig(e);var t=Rg(e);Kr(t),qr(t,e);for(var n,r;n=pa(t);)r=ga(t,e,n),ya(t,e,n,r)}function qr(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ha(e,t,n)}function ha(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Kr(e,t){arguments.length<2&&(t=e.nodes()[0]),ma(e,{},1,t)}function ma(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ma(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function pa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ga(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===Zs(e,e.node(u.v),a)&&c!==Zs(e,e.node(u.w),a));return l.reduce((u,d)=>Ks(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function Zs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Yn,xa=Fg.longestPath,Vg=fa,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Qs(e);break;case"tight-tree":Wg(e);break;case"longest-path":Xg(e);break;case"none":break;default:Qs(e)}}var Xg=xa;function Wg(e){xa(e),Vg(e)}function Qs(e){Bg(e)}var Ug=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Ln=ve;var Qg={run:Jg,cleanup:n0};function Jg(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=e0(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=t0(e)+1;e.children().forEach(a=>wa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function wa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{wa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,y=m.borderBottom?m.borderBottom:d,w=m.borderTop?r:2*r,v=f!==y?1:s-i[o]+1;e.setEdge(c,f,{weight:w,minlen:v,nestingEdge:!0}),e.setEdge(y,l,{weight:w,minlen:v,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function e0(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function t0(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function n0(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let r0=ve;var s0=i0;function i0(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iei(e.node(t))),e.edges().forEach(t=>ei(e.edge(t)))}function ei(e){let t=e.width;e.width=e.height,e.height=t}function l0(e){e.nodes().forEach(t=>or(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(or),Object.hasOwn(n,"y")&&or(n)})}function or(e){e.y=-e.y}function u0(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let ti=ve;var d0=f0;function f0(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=ti.applyWithChunking(Math.max,r),i=ti.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let h0=ve.zipObject;var m0=p0;function p0(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var y0=x0;function x0(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let w0=ve;var b0=v0;function v0(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _0(r)}function _0(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&E0(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>w0.pick(s,["vs","i","barycenter","weight"]))}function E0(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let N0=ve;var S0=k0;function k0(e,t){let n=N0.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(j0(!!t)),c=ni(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ni(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ni(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function j0(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let C0=y0,$0=b0,M0=S0;var A0=va;function va(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=C0(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=va(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&I0(m,f)}});let u=$0(l,n);R0(u,c);let d=M0(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function R0(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function I0(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let T0=Ve.Graph,O0=ve;var L0=D0;function D0(e,t,n,r){r||(r=e.nodes());let s=P0(e),i=new T0({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function P0(e){for(var t;e.hasNode(t=O0.uniqueId("_root")););return t}var z0=H0;function H0(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let F0=d0,V0=m0,B0=A0,G0=L0,Y0=z0,X0=Ve.Graph,xn=ve;var W0=_a;function _a(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,_a);return}let n=xn.maxRank(e),r=ri(e,xn.range(1,n+1),"inEdges"),s=ri(e,xn.range(n-1,-1,-1),"outEdges"),i=F0(e);if(si(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){U0(c%2?r:s,c%4>=2),i=xn.buildLayerMatrix(e);let u=V0(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return G0(e,i,n,r.get(i)||[])})}function U0(e,t){let n=new X0;e.forEach(function(r){let s=r.graph().root,i=B0(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Y0(r,n,i.vs)})}function si(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let q0=Ve.Graph,Ze=ve;var K0={positionX:ay};function Z0(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=J0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(y=>{e.predecessors(y).forEach(w=>{let v=e.node(w),p=v.order;(p{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&Ea(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function J0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ea(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function ey(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function ty(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let y=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((y,w)=>Math.min(y,i[w.w]-o.edge(w)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function ry(e,t,n,r){let s=new q0,i=e.graph(),o=cy(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function sy(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=ly(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-Ze.applyWithChunking(Math.min,l);o!=="l"&&(u=s-Ze.applyWithChunking(Math.max,l)),u&&(e[a]=Ze.mapValues(c,d=>d+u))})})}function oy(e,t){return Ze.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function ay(e){let t=Ze.buildLayerMatrix(e),n=Object.assign(Z0(e,t),Q0(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=ty(e,s,n,c),u=ny(e,s,l.root,l.align,a==="r");a==="r"&&(u=Ze.mapValues(u,d=>-d)),r[o+a]=u})});let i=sy(e,r);return iy(r,i),oy(r,e.graph().align)}function cy(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function ly(e,t){return e.node(t).width}let Na=ve,uy=K0.positionX;var dy=fy;function fy(e){e=Na.asNonCompoundGraph(e),hy(e),Object.entries(uy(e)).forEach(([t,n])=>e.node(t).x=n)}function hy(e){let t=Na.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ii=pg,oi=bg,my=Gg,py=ve.normalizeRanks,gy=Ug,yy=ve.removeEmptyRanks,ai=Qg,xy=s0,ci=o0,wy=W0,by=dy,De=ve,vy=Ve.Graph;var _y=Ey;function Ey(e,t){let n=t&&t.debugTiming?De.time:De.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>Iy(e));n(" runLayout",()=>Ny(r,n,t)),n(" updateInputGraph",()=>Sy(e,r))})}function Ny(e,t,n){t(" makeSpaceForEdgeLabels",()=>Ty(e)),t(" removeSelfEdges",()=>By(e)),t(" acyclic",()=>ii.run(e)),t(" nestingGraph.run",()=>ai.run(e)),t(" rank",()=>my(De.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Oy(e)),t(" removeEmptyRanks",()=>yy(e)),t(" nestingGraph.cleanup",()=>ai.cleanup(e)),t(" normalizeRanks",()=>py(e)),t(" assignRankMinMax",()=>Ly(e)),t(" removeEdgeLabelProxies",()=>Dy(e)),t(" normalize.run",()=>oi.run(e)),t(" parentDummyChains",()=>gy(e)),t(" addBorderSegments",()=>xy(e)),t(" order",()=>wy(e,n)),t(" insertSelfEdges",()=>Gy(e)),t(" adjustCoordinateSystem",()=>ci.adjust(e)),t(" position",()=>by(e)),t(" positionSelfEdges",()=>Yy(e)),t(" removeBorderNodes",()=>Vy(e)),t(" normalize.undo",()=>oi.undo(e)),t(" fixupEdgeLabelCoords",()=>Hy(e)),t(" undoCoordinateSystem",()=>ci.undo(e)),t(" translateGraph",()=>Py(e)),t(" assignNodeIntersects",()=>zy(e)),t(" reversePoints",()=>Fy(e)),t(" acyclic.undo",()=>ii.undo(e))}function Sy(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let ky=["nodesep","edgesep","ranksep","marginx","marginy"],jy={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Cy=["acyclicer","ranker","rankdir","align"],$y=["width","height","rank"],li={width:0,height:0},My=["minlen","weight","width","height","labeloffset"],Ay={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ry=["labelpos"];function Iy(e){let t=new vy({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},jy,cr(n,ky),De.pick(n,Cy))),e.nodes().forEach(r=>{let s=lr(e.node(r));const i=cr(s,$y);Object.keys(li).forEach(o=>{i[o]===void 0&&(i[o]=li[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},Ay,cr(s,My),De.pick(s,Ry)))}),t}function Ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Oy(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};De.addDummyNode(e,"edge-proxy",i,"_ep")}})}function Ly(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Dy(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Py(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function zy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(De.intersectRect(r,i)),n.points.push(De.intersectRect(s,o))})}function Hy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Fy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Vy(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function By(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Gy(e){var t=De.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{De.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Yy(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return De.mapValues(De.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Xy=ve,Wy=Ve.Graph;var Uy={debugOrdering:qy};function qy(e){let t=Xy.buildLayerMatrix(e),n=new Wy({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var Ky="1.1.8",Zy={graphlib:Ve,layout:_y,debug:Uy,util:{time:ve.time,notime:ve.notime},version:Ky};const ui=vi(Zy),Ye=264,Qy=44,Jy=26,ex=14;function wt(e){const t=Math.max(e.attributes.length,1);return Qy+t*Jy+ex}const tx=40;function ur(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?mi(e,n,o):r==="clustered"?hi(e,t,n,o,i):r==="hierarchical"||e.length<=tx?di(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?hi(e,t,n,o,i):mi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Sa(e,t,n,r=!1,s="LR"){const i=new ui.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Ye,height:d?wt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ui.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?wt(m):120,y=d.x-Ye/2,w=d.y-f/2;return a=Math.max(a,y+Ye),c=Math.max(c,w+f),{...u,position:{x:y,y:w}}}),width:a,height:c}}function di(e,t,n,r="LR"){return Sa(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?wt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Ye+ka);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Ye)}),i+=Math.max(...c.map(l=>n(l.id)))+ja}return{nodes:s,width:o,height:i}}const fi=120;function hi(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),y=new Set(f.map(E=>E.id));let w=0;for(const E of t)y.has(E.source)&&y.has(E.target)&&w++;const p=f.length<=8&&w>=f.length-1?Sa(f,t,n,!0,s):rx(f,n);return{name:m,...p}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const ka=40,ja=40;function mi(e,t,n){const r=l=>{const u=t.get(l);return u?wt(u):120},s=[...e].sort((l,u)=>{var w,v;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((w=t.get(l.id))==null?void 0:w.name)??l.id,y=((v=t.get(u.id))==null?void 0:v.name)??u.id;return f.localeCompare(y)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Ye+ka)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ja}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function cn({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ca=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var b,C;const[r,s]=x.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[i,o]=x.useState([]),[a,c]=x.useState(null),[l,u]=x.useState(null),[d,m]=x.useState("skos:exactMatch"),[f,y]=x.useState(((C=e.conceptual)==null?void 0:C.ontology_layer)??"core"),[w,v]=x.useState([]),[p,E]=x.useState("");x.useEffect(()=>{Qo().then(j=>v(j.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return o([]);Zo(r,p||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(j)},[r,p]);const M=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(cn,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[w.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(p===""?" active":""),onClick:()=>E(""),children:"all sources"}),w.map(j=>h.jsx("button",{className:"src-chip"+(p===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:p?`Search within ${p}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&w.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(j=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===j.iri?" picked":""),onClick:()=>u(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:sx.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>y(j.target.value),children:Ca.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:M,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var b,C,j;const[s,i]=x.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[o,a]=x.useState(((C=e.term_map)==null?void 0:C.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},y=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",w=t.project.kg_base_iri||`urn:${y}:`,v=(j=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:j.members.map(_=>{var R;return(R=e.attributes.find(S=>S.id===_))==null?void 0:R.name}).filter(Boolean),p=v&&v.length?`${w}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${w}${e.id}`,M=s.trim()||p;return h.jsxs(cn,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",M]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=x.useState(""),[o,a]=x.useState(""),[c,l]=x.useState(""),[u,d]=x.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const y=f==null?void 0:f.created_id;n(),y&&r(y)})};return h.jsxs(cn,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ca.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const $a=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=x.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=x.useState(r??""),[m,f]=x.useState(s??(l==null?void 0:l.id)??""),[y,w]=x.useState("many_to_one"),[v,p]=x.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",M=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:y,optionality:v}).then(o);return h.jsxs(cn,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:y,onChange:b=>w(b.target.value),children:$a.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>p(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:M,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=p=>{var E;return((E=t.entities.find(M=>M.id===p))==null?void 0:E.name)??"?"},[i,o]=x.useState(e.name),[a,c]=x.useState(e.cardinality),[l,u]=x.useState(e.optionality),[d,m]=x.useState(e.identifying),[f,y]=x.useState(!1),w=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(cn,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:p=>o(p.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:p=>c(p.target.value),children:$a.map(p=>h.jsx("option",{children:p},p))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:p=>u(p.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:p=>m(p.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>y(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:w,children:"Save"})]})]})}const pi=10,ux=6,Be=24;function dx(e,t){return t?e:Math.round(e/pi)*pi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-Be,o.right+Be);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&e1,g=c==null?void 0:c.onHoverEdge,$=p??(n+s)/2,N=(r+i)/2,I=p??M,L=p!=null?N:b,k=x.useCallback(B=>w&&C&&w(C.id,B),[w,C]),T=x.useCallback(B=>{var re,pe;if(!v||B.button!==0)return;B.stopPropagation(),(pe=(re=B.target).setPointerCapture)==null||pe.call(re,B.pointerId),f.current=!0,y.current=0;const K=u({x:B.clientX,y:B.clientY}).x;let Q=0,te=p??$;const oe=ae=>{const ue=u({x:ae.clientX,y:ae.clientY});y.current=Math.max(y.current,Math.abs(ue.x-K)),te=mx(ue.x,{shift:ae.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),Q||(Q=requestAnimationFrame(()=>{Q=0,m(te)}))},ne=()=>{window.removeEventListener("pointermove",oe),window.removeEventListener("pointerup",ne),Q&&cancelAnimationFrame(Q),f.current=!1,m(null),y.current>=gi&&k(te)};window.addEventListener("pointermove",oe),window.addEventListener("pointerup",ne)},[v,u,p,$,c,n,s,k]),P=x.useCallback(B=>{y.current>=gi&&(B.stopPropagation(),y.current=0)},[]),z=x.useCallback(B=>{v&&(B.stopPropagation(),k(null))},[v,k]);return h.jsxs("g",{className:V,children:[h.jsx("path",{id:t,className:"rel-path",d:E,fill:"none",strokeDasharray:S?void 0:"6 4"}),h.jsx("path",{d:E,fill:"none",strokeWidth:14,stroke:"transparent",onMouseEnter:g?()=>g(C.id):void 0,onMouseLeave:g?()=>g(null):void 0}),h.jsx(yi,{x:n,y:r,side:o,many:O,optional:R}),h.jsx(yi,{x:s,y:i,side:a,many:D,optional:!1}),v&&(l||d!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:T,onClickCapture:P,onDoubleClick:z,children:[h.jsx("rect",{x:$-6,y:N-10,width:12,height:20,fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:$-1.5,y:N-7,width:3,height:14,rx:1.5})]}),(l||H)&&C&&h.jsxs("text",{className:"rel-label",x:I,y:L-8,children:[l?C.verb_phrase||C.name:"",H?`${l?" ":""}(${c.memberCount})`:""]})]})});function yi({x:e,y:t,side:n,many:r,optional:s}){const i=n===q.Left?-1:1,o=7,a=12,c=[];return r?c.push(h.jsx("path",{className:"rel-glyph",d:`M ${e+i*a} ${t} L ${e} ${t-o} M ${e+i*a} ${t} L ${e} ${t} M ${e+i*a} ${t} L ${e} ${t+o}`,fill:"none"},"foot")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a-3),y1:t-o,x2:e+i*(a-3),y2:t+o},"one")),s?c.push(h.jsx("circle",{className:"rel-glyph ring",cx:e+i*(a+6),cy:t,r:4},"opt")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a+5),y1:t-o,x2:e+i*(a+5),y2:t+o},"mand")),h.jsx(h.Fragment,{children:c})}const gx={entity:Pm},yx={relationship:px},xi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],wi="#8a7d6a";function xx(e,t,n){const s=Ye;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function wx(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Yr,targetHandle:n(e.to.entity,s)?s:Xr}}function qx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:y,fitBounds:w,getNodes:v}=an(),[p,E]=x.useState([]),[M,b]=x.useState([]),C=x.useRef(!1),j=x.useMemo(()=>{const F=u&&u.size>0?[...u].sort():null;return F?"sa:"+F.join("+"):"__all__"},[u]),_=x.useRef(null),[R,S]=x.useState(0),O=x.useRef(new Map),D=x.useRef(null);x.useEffect(()=>{if(!f){_.current=null;return}const F=O.current.get(j);if(F){_.current=F,C.current=!1,S(G=>G+1);return}let Y=!1;return f.load(j).then(G=>{Y||(O.current.set(j,G),_.current=G,C.current=!1,S(J=>J+1))}),()=>{Y=!0}},[f,j]);const[V,H]=x.useState(null),[g,$]=x.useState(null),[N,I]=x.useState(!1),[L,k]=x.useState(null),[T,P]=x.useState(null),[z,B]=x.useState(null),[X,K]=x.useState(null),Q=x.useRef({}),te=!t.canEdit,oe=x.useRef(null),ne=x.useCallback(()=>{f&&(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{const F={};for(const J of v())J.hidden||(F[J.id]={x:Math.round(J.position.x),y:Math.round(J.position.y)});const Y={};for(const[J,U]of Object.entries(Q.current))Y[J]={routeX:Math.round(U)};const G={nodes:F,edges:Y};O.current.set(j,G),_.current=G,f.save(j,G)},800))},[f,v,j]),re=x.useCallback((F,Y)=>{Y==null?delete Q.current[F]:Q.current[F]=Y,b(G=>G.map(J=>J.id===F?{...J,data:{...J.data,routeX:Y??void 0}}:J)),ne()},[ne]),pe=x.useMemo(()=>{const F=new Map;return e.subject_areas.forEach((Y,G)=>F.set(Y.id,xi[G%xi.length])),F},[e]),ae=x.useMemo(()=>{const F=new Map;return e.entities.forEach(Y=>F.set(Y.id,Y)),F},[e]),ue=x.useMemo(()=>{const F=new Map,Y=new Map;return e.subject_areas.forEach(G=>{(G.members??[]).forEach(J=>Y.set(J,{id:G.id,name:G.name}))}),e.entities.forEach(G=>{var se,me;const J=(se=G.conceptual)!=null&&se.id?Y.get(G.conceptual.id):void 0,U=(me=G.conceptual)==null?void 0:me.subject_area,ee=J??(U?{id:U.id,name:U.name??U.id}:void 0);ee&&F.set(G.id,ee)}),F},[e]),_e=x.useCallback(F=>{var G;if(!u||u.size===0)return!1;const Y=(G=ue.get(F))==null?void 0:G.id;return!(Y&&u.has(Y))},[u,ue]),he=x.useMemo(()=>{const F=new Map,Y=(G,J)=>{if(!J.length)return;const U=F.get(G)??new Set;J.forEach(ee=>U.add(ee)),F.set(G,U)};for(const G of e.relationships)Y(G.from.entity,G.from.attributes),Y(G.to.entity,G.to.attributes);return F},[e]);x.useEffect(()=>{var $e;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const W of e.entities)(W.name.toLowerCase()+" "+((($e=W.conceptual)==null?void 0:$e.name.toLowerCase())??"")+" "+W.attributes.map(ge=>ge.name.toLowerCase()).join(" ")).includes(F)&&Y.add(W.id);const G=new Set;if(r){G.add(r);for(const W of e.relationships)W.from.entity===r&&G.add(W.to.entity),W.to.entity===r&&G.add(W.from.entity)}const J=e.entities.map(W=>{const fe=F!==""&&!Y.has(W.id),ge=r!==null&&!G.has(W.id);return{id:W.id,type:"entity",position:{x:0,y:0},hidden:_e(W.id),data:{entity:W,color:(()=>{const Se=ue.get(W.id);return Se?pe.get(Se.id)??wi:wi})(),dimmed:fe||ge,highlighted:F!==""&&Y.has(W.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(W.id))??!1,onToggleExpand:l,endpointAttrs:he.get(W.id),highlightAttrs:void 0,onHoverAttr:B}}}),U=e.relationships.filter(W=>ae.has(W.from.entity)&&ae.has(W.to.entity)).map(W=>{const{sourceHandle:fe,targetHandle:ge}=wx(W,ae),Se=r!==null&&W.from.entity!==r&&W.to.entity!==r;return{id:W.id,source:W.from.entity,target:W.to.entity,sourceHandle:fe,targetHandle:ge,type:"relationship",data:{relationship:W,dimmed:Se,memberCount:Math.max(W.from.attributes.length,W.to.attributes.length),onHoverEdge:K}}}),ee=_.current;if(Q.current={},ee)for(const[W,fe]of Object.entries(ee.edges))Q.current[W]=fe.routeX;let se=J;E(W=>{const fe=new Map(W.map(ce=>[ce.id,ce.position])),ge=J.every(ce=>fe.has(ce.id)),Se=((u==null?void 0:u.size)??0)>0;if(C.current&&ge&&W.length>=J.length&&!Se){const ce=J.map(Ue=>({...Ue,position:fe.get(Ue.id)??Ue.position}));return se=ce,ce}const dt=Se?J.filter(ce=>!ce.hidden):J,Ot=ur(dt,U,ae,"auto",ue),rt=new Map(Ot.map(ce=>[ce.id,ce.position])),ft=(ee==null?void 0:ee.nodes)??{},Lt=Object.keys(ft).length>0,Pe=[],Dt=J.map(ce=>{const Ue=ft[ce.id];if(Ue){const Pt={x:Ue.x,y:Ue.y};return Pe.push({x:Pt.x,y:Pt.y,w:Ye,h:wt(ce.data.entity)}),{...ce,position:Pt}}return rt.has(ce.id)?{...ce,position:rt.get(ce.id)}:fe.has(ce.id)&&C.current?{...ce,position:fe.get(ce.id)}:ce});if(Lt)for(const ce of Dt)ft[ce.id]||ce.hidden||(ce.position=xx(ce.position,wt(ce.data.entity),Pe),Pe.push({x:ce.position.x,y:ce.position.y,w:Ye,h:wt(ce.data.entity)}));return C.current=!0,Lt||requestAnimationFrame(()=>y({padding:.15,duration:300})),se=Dt,Dt});const me=new Map;for(const W of se)me.set(W.id,{left:W.position.x,right:W.position.x+Ye});b(U.map(W=>({...W,data:{...W.data,routeX:Q.current[W.id],onRouteChange:f?re:void 0,sourceCard:me.get(W.source),targetCard:me.get(W.target)}})))},[e,i,r,o,a,c,l,pe,ae,ue,_e,u,he,y,f,re,R]);const ye=x.useMemo(()=>{const F=new Set,Y=new Set,G=new Map,J=(U,ee)=>{if(!ee.length)return;const se=G.get(U)??new Set;ee.forEach(me=>se.add(me)),G.set(U,se)};if(z)for(const U of e.relationships)(U.from.attributes.includes(z)||U.to.attributes.includes(z))&&(F.add(U.id),Y.add(U.from.entity),Y.add(U.to.entity),J(U.from.entity,U.from.attributes),J(U.to.entity,U.to.attributes));if(X){const U=e.relationships.find(ee=>ee.id===X);U&&(J(U.from.entity,U.from.attributes),J(U.to.entity,U.to.attributes))}return{active:z!==null,relsForAttr:F,entsForAttr:Y,hitAttrsByEntity:G}},[e,z,X]);x.useEffect(()=>{var J;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const U of e.entities)(U.name.toLowerCase()+" "+(((J=U.conceptual)==null?void 0:J.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);const G=new Set;if(r){G.add(r);for(const U of e.relationships)U.from.entity===r&&G.add(U.to.entity),U.to.entity===r&&G.add(U.from.entity)}E(U=>U.map(ee=>{const se=F!==""&&!Y.has(ee.id),me=r!==null&&!G.has(ee.id),$e=ye.active&&!ye.entsForAttr.has(ee.id),W=se||me||$e,fe=F!==""&&Y.has(ee.id)||ye.active&&ye.entsForAttr.has(ee.id),ge=ye.hitAttrsByEntity.get(ee.id);return ee.data.dimmed===W&&ee.data.highlighted===fe&&ee.data.highlightAttrs===ge?ee:{...ee,data:{...ee.data,dimmed:W,highlighted:fe,highlightAttrs:ge}}})),b(U=>U.map(ee=>{var fe,ge;const se=(fe=ee.data)==null?void 0:fe.relationship,me=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,$e=ye.active&&!ye.relsForAttr.has(ee.id),W=me||$e;return((ge=ee.data)==null?void 0:ge.dimmed)===W?ee:{...ee,data:{...ee.data,dimmed:W}}}))},[ye,i,r,e]),x.useEffect(()=>{var J;const F=i.trim().toLowerCase();if(!F)return;const Y=new Set;for(const U of e.entities)(U.name.toLowerCase()+" "+(((J=U.conceptual)==null?void 0:J.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);if(!Y.size)return;const G=requestAnimationFrame(()=>{const U=v().filter(se=>Y.has(se.id));if(!U.length)return;const ee=Mf(U);w(ee,{padding:.35,duration:400})});return()=>cancelAnimationFrame(G)},[i,e,v,w]);const le=x.useCallback((F="auto",Y="LR")=>{D.current=Object.fromEntries(v().map(G=>[G.id,{x:G.position.x,y:G.position.y}])),E(G=>ur(G,M,ae,F,ue,Y)),requestAnimationFrame(()=>y({padding:.15,duration:300})),ne()},[M,ae,ue,y,v,ne]),Z=x.useCallback(()=>{const F=D.current;F&&(E(Y=>Y.map(G=>F[G.id]?{...G,position:F[G.id]}:G)),D.current=null,ne())},[ne]),Ne=x.useCallback(()=>{f==null||f.reset(j),O.current.delete(j),_.current=null,Q.current={},C.current=!1,b(F=>F.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(F=>{const Y=ur(F,M,ae,"auto",ue);return requestAnimationFrame(()=>y({padding:.15,duration:300})),Y})},[f,j,M,ae,ue,y]),Ce=x.useCallback(F=>{s(F),E(Y=>(Y.find(J=>J.id===F)&&requestAnimationFrame(()=>y({nodes:[{id:F}],padding:.4,duration:400})),Y))},[y,s]);x.useImperativeHandle(m,()=>({relayout:le,fitView:()=>y({padding:.15,duration:300}),focusEntity:Ce,newEntity:()=>I(!0),resetLayout:Ne,undoRelayout:Z}),[le,y,Ce,Ne,Z]);const ut=x.useCallback(F=>{if(te||!F.source||!F.target||F.source===F.target)return;const Y=F.sourceHandle&&F.sourceHandle!==Yr?F.sourceHandle:void 0,G=F.targetHandle&&F.targetHandle!==Xr?F.targetHandle:void 0;k({from:F.source,to:F.target,fromAttr:Y,toAttr:G})},[te]),Ae=x.useCallback(async(F,Y)=>{try{return await n(F,Y)}catch(G){throw d==null||d(G instanceof Error?G.message:String(G)),G}},[n,d]),We=r?ae.get(r)??null:null,Ie=e.relationships.find(F=>F.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Yo,{nodes:p,edges:M,nodeTypes:gx,edgeTypes:yx,onNodeClick:(F,Y)=>s(Y.id),onEdgeClick:(F,Y)=>!te&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(F,Y)=>{E(G=>G.map(J=>J.id===Y.id?{...J,position:Y.position}:J)),ne()},onConnect:ut,nodesConnectable:!te,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:Le.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:F=>{var Y;return((Y=F.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),We&&h.jsx(Hm,{entity:We,doc:e,caps:t,exec:Ae,onClose:()=>s(null),onFocusEntity:Ce,onAlign:H,onEditMapping:$}),V&&h.jsx(ix,{entity:V,exec:Ae,onClose:()=>H(null)}),g&&h.jsx(ox,{entity:g,doc:e,exec:Ae,onClose:()=>$(null)}),N&&h.jsx(ax,{doc:e,exec:Ae,onClose:()=>I(!1),onCreated:Ce}),L&&h.jsx(cx,{doc:e,fromId:L.from,toId:L.to,initialFromAttr:L.fromAttr,initialToAttr:L.toAttr,exec:Ae,onClose:()=>k(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:Ae,onClose:()=>P(null)})]})}function Kx({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(bx,{}),e==="layers"&&h.jsx(_x,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(Ex,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Nx,{readOnly:n})]})}function bx(){const[e,t]=x.useState(""),[n,r]=x.useState([]),[s,i]=x.useState({loaded:0,vocabs:[]}),[o,a]=x.useState(null),[c,l]=x.useState([]),[u,d]=x.useState("");x.useEffect(()=>{Qo().then(f=>l(f.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const f=setTimeout(()=>{Zo(e||"a",u||void 0).then(y=>{r(e?y.results:[]),i({loaded:y.loaded_terms,vocabs:y.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=x.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const vx=["industry","core","domain","specialised"];function _x({refreshKey:e,onFocusEntity:t}){const[n,r]=x.useState(null),[s,i]=x.useState(null);if(x.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),vx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Ex({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=x.useState(null),[i,o]=x.useState(""),[a,c]=x.useState(""),[l,u]=x.useState(!1),d=x.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` + +`))).catch(()=>o(""))},[]);return x.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:i.split(` +`).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` +`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:l,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(u(!0),Mm().then(()=>{u(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:l||!a.trim(),onClick:()=>{u(!0),$m(a).then(()=>{u(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Nx({readOnly:e}){const[t,n]=x.useState([]),r=x.useCallback(()=>{Am().then(i=>n(i.decisions)).catch(()=>n([]))},[]);if(x.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(i=>h.jsxs("div",{className:"decision "+i.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[i.verdict]}),h.jsx("span",{className:"chip",children:i.confidence}),h.jsx("span",{className:"chip",children:i.signal})]}),h.jsx("p",{className:"decision-subject",children:i.subject}),!e&&i.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Bs(i.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Bs(i.signal_key,"rejected").then(r),children:"Reject"})]})]},i.signal_key))})}function Zx({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:i,openImport:o=!1,prefillImport:a="",onPreview:c}){const[l,u]=x.useState(o&&t?"import":null),[d,m]=x.useState([]),[f,y]=x.useState("postgres"),w=x.useRef(null);x.useEffect(()=>{Rm().then(p=>m(p.formats)).catch(()=>m([]))},[]),x.useEffect(()=>{if(!l)return;const p=E=>{w.current&&!w.current.contains(E.target)&&u(null)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[l]);const v=d.find(p=>p.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:w,children:[h.jsxs("button",{className:s+(l==="export"?" on":""),onClick:()=>u(l==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(l==="import"?" on":""),onClick:()=>u(l==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),l==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(v==null?void 0:v.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:p=>y(p.target.value),children:v.dialects.map(p=>h.jsx("option",{value:p,children:p},p))})]}),d.map(p=>h.jsx("a",{className:"ie-item",href:Im(p.id,p.id==="sql"?f:void 0),download:!0,onClick:()=>u(null),children:p.label},p.id))]}),l==="import"&&h.jsx(Sx,{exec:e,submitLabel:r,buttonClass:s,applyBatch:i,onClose:()=>u(null),onImported:p=>{u(null),n==null||n(p)},onPreview:c,prefillImport:a})]})}const bi=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function Sx({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:i,onPreview:o,prefillImport:a}){var j;const[c,l]=x.useState(o?"erwin":"sql"),[u,d]=x.useState("postgres"),[m,f]=x.useState(a??""),[y,w]=x.useState(!1),[v,p]=x.useState(null),[E,M]=x.useState([]);x.useEffect(()=>{a&&f(a)},[a]);const b=_=>{_&&_.text().then(f).catch(()=>p("could not read that file"))},C=async()=>{w(!0),p(null),M([]);try{if(o&&c==="erwin"){const R=await Om(c,m);if(!R.changes.length){p(R.warnings[0]??"nothing to import from that document"),w(!1);return}s(),o(R),w(!1);return}const _=await Tm(c,m,c==="sql"?u:void 0);if(!_.changes.length){p(_.warnings[0]??"nothing to import from that document"),w(!1);return}if(r)await r(_.changes);else for(const R of _.changes)await e(R.op,R.payload);M(_.warnings),i(_.tables)}catch(_){p(_ instanceof Error?_.message:String(_))}finally{w(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:bi.map(_=>h.jsx("button",{className:"ie-tab"+(c===_.id?" active":""),onClick:()=>l(_.id),children:_.label},_.id))}),h.jsx("p",{className:"ie-hint",children:(j=bi.find(_=>_.id===c))==null?void 0:j.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:u,onChange:_=>d(_.target.value),children:["postgres","snowflake","mysql","duckdb"].map(_=>h.jsx("option",{children:_},_))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:_=>f(_.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:_=>{var R;return b(((R=_.target.files)==null?void 0:R[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((_,R)=>h.jsx("p",{className:"ie-warn",children:_},R)),v&&h.jsx("p",{className:"ie-error",children:v}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:y||!m.trim(),onClick:C,children:y?"Importing…":t})]})]})}export{Ko as A,_m as B,gm as C,Pm as E,Zx as I,_x as L,qx as M,bx as O,xi as P,Bo as R,Kx as S,$x as a,Hx as b,Dx as c,Vx as d,Bx as e,Cx as f,jm as g,Yx as h,Gx as i,Px as j,Rx as k,Ix as l,Tx as m,Lx as n,Zo as o,Fx as p,zx as q,Ox as r,km as s,Mx as t,Ax as u,ur as v,Yo as w,px as x,lm as y}; diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index 3ef1a9a..08775fa 100644 --- a/packages/server/src/mdl_server/static/index.html +++ b/packages/server/src/mdl_server/static/index.html @@ -4,10 +4,10 @@ Modelith - + - - + +
diff --git a/packages/server/src/mdl_server/static/sme.html b/packages/server/src/mdl_server/static/sme.html index ccd2daa..7b18363 100644 --- a/packages/server/src/mdl_server/static/sme.html +++ b/packages/server/src/mdl_server/static/sme.html @@ -4,10 +4,10 @@ Modelith Glossary - + - - + + diff --git a/packages/server/tests/test_layout_api.py b/packages/server/tests/test_layout_api.py new file mode 100644 index 0000000..4e6b42d --- /dev/null +++ b/packages/server/tests/test_layout_api.py @@ -0,0 +1,192 @@ +"""Visual layout sidecar API + its strict isolation from the model. + +Layout is visual only: it must never change the model fingerprint, the /api/model +document, validation/drift/export output, git dirtiness, or survive a revert as a +model change. These tests pin every one of those guarantees. +""" + +from __future__ import annotations + +import json +import subprocess +from pathlib import Path + +import pytest +from fastapi.testclient import TestClient +from mdl_server import create_app + +from mdl_core import commands + + +def _git(d: Path, *args: str) -> str: + return subprocess.run( + ["git", "-C", str(d), *args], capture_output=True, text=True + ).stdout.strip() + + +def _init(d: Path) -> None: + _git(d, "init") + _git(d, "config", "user.email", "t@example.com") + _git(d, "config", "user.name", "t") + _git(d, "add", "-A") + _git(d, "commit", "-m", "initial") + _git(d, "branch", "-M", "main") + + +@pytest.fixture +def client(model_dir): + return TestClient(create_app(model_dir)) + + +def test_get_empty_returns_empty_maps(client): + r = client.get("/api/layout?view=__all__") + assert r.status_code == 200 + d = r.json() + assert d == {"version": 1, "view": "__all__", "nodes": {}, "edges": {}} + + +def test_put_then_get_roundtrips(client, model_dir): + # use a real entity + relationship id so nothing is dropped + model = client.get("/api/model").json() + ent = model["entities"][0]["id"] + rel = model["relationships"][0]["id"] if model["relationships"] else None + nodes = {ent: {"x": 120.6, "y": 340.2}} + edges = {rel: {"routeX": 480.9}} if rel else {} + r = client.put("/api/layout", json={"view": "__all__", "nodes": nodes, "edges": edges}) + assert r.status_code == 200 and r.json()["ok"] + got = client.get("/api/layout?view=__all__").json() + assert got["nodes"][ent] == {"x": 121, "y": 340} # rounded to int + if rel: + assert got["edges"][rel] == {"routeX": 481} + + +def test_file_is_key_sorted_integers(client, model_dir): + model = client.get("/api/model").json() + e0, e1 = model["entities"][0]["id"], model["entities"][1]["id"] + client.put( + "/api/layout", + json={"view": "__all__", "nodes": {e1: {"x": 1.4, "y": 2.6}, e0: {"x": 3, "y": 4}}, "edges": {}}, + ) + text = (model_dir / ".mdl" / "layout.json").read_text() + doc = json.loads(text) + assert doc["version"] == 1 + # integer values, and keys serialized sorted + assert all(isinstance(v["x"], int) and isinstance(v["y"], int) for v in doc["views"]["__all__"]["nodes"].values()) + assert text.endswith("\n") + # sort_keys=True => the smaller ulid appears first in the raw text + assert text.index(f'"{min(e0, e1)}"') < text.index(f'"{max(e0, e1)}"') + + +def test_put_drops_ids_not_in_model(client): + r = client.put( + "/api/layout", + json={"view": "__all__", "nodes": {"01GHOSTNOTAREALENTITYID00": {"x": 1, "y": 2}}, "edges": {}}, + ) + assert r.status_code == 200 + assert client.get("/api/layout?view=__all__").json()["nodes"] == {} + + +def test_corrupt_file_treated_as_empty_and_overwritten(client, model_dir): + mdl = model_dir / ".mdl" + mdl.mkdir(parents=True, exist_ok=True) + (mdl / "layout.json").write_text("{ this is not json") + # GET does not crash + assert client.get("/api/layout?view=__all__").json()["nodes"] == {} + # next PUT overwrites cleanly + ent = client.get("/api/model").json()["entities"][0]["id"] + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 5, "y": 6}}, "edges": {}}) + assert client.get("/api/layout?view=__all__").json()["nodes"][ent] == {"x": 5, "y": 6} + + +def test_non_finite_and_long_keys_422(client): + ent = client.get("/api/model").json()["entities"][0]["id"] + # send Infinity as a raw body so it reaches the server (Python's json emits it, + # the server's _finite guard must reject it) + raw = f'{{"view": "__all__", "nodes": {{"{ent}": {{"x": Infinity, "y": 0}}}}, "edges": {{}}}}' + r = client.put("/api/layout", content=raw, headers={"content-type": "application/json"}) + assert r.status_code in (422, 400) + r2 = client.put("/api/layout", json={"view": "x" * 65, "nodes": {}, "edges": {}}) + assert r2.status_code == 422 + + +def test_put_and_delete_403_when_read_only(model_dir): + ro = TestClient(create_app(model_dir, read_only=True)) + assert ro.get("/api/layout?view=__all__").status_code == 200 # read still works + assert ro.put("/api/layout", json={"view": "__all__", "nodes": {}, "edges": {}}).status_code == 403 + assert ro.delete("/api/layout").status_code == 403 + + +def test_delete_one_view_and_all(client): + ent = client.get("/api/model").json()["entities"][0]["id"] + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 1, "y": 1}}, "edges": {}}) + client.put("/api/layout", json={"view": "sa:abc", "nodes": {ent: {"x": 2, "y": 2}}, "edges": {}}) + client.delete("/api/layout?view=sa:abc") + assert client.get("/api/layout?view=sa:abc").json()["nodes"] == {} + assert client.get("/api/layout?view=__all__").json()["nodes"] != {} + client.delete("/api/layout") # the whole file + assert client.get("/api/layout?view=__all__").json()["nodes"] == {} + + +# --- isolation: layout must be invisible to the model ------------------------- + + +def test_layout_does_not_change_fingerprint_or_model_doc(client, model_dir): + fp_before = commands.dir_fingerprint(model_dir) + doc_before = client.get("/api/model").json() + ent = doc_before["entities"][0]["id"] + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 9, "y": 9}}, "edges": {}}) + assert commands.dir_fingerprint(model_dir) == fp_before + assert client.get("/api/model").json() == doc_before + + +def test_validate_identical_with_and_without_layout(model_dir): + from mdl_core.repo import ModelRepo + from mdl_core.validate import validate + + before = [(d.code, d.message) for d in validate(ModelRepo.load(model_dir).model).items] + (model_dir / ".mdl").mkdir(parents=True, exist_ok=True) + (model_dir / ".mdl" / "layout.json").write_text( + json.dumps({"version": 1, "views": {"__all__": {"nodes": {"x": {"x": 1, "y": 2}}, "edges": {}}}}) + ) + after = [(d.code, d.message) for d in validate(ModelRepo.load(model_dir).model).items] + assert before == after + + +def test_export_identical_with_and_without_layout(client, model_dir): + before = client.get("/api/export/sql").text + ent = client.get("/api/model").json()["entities"][0]["id"] + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 1, "y": 2}}, "edges": {}}) + assert client.get("/api/export/sql").text == before + + +# --- isolation: git never sees layout as dirty, never deletes it -------------- + + +def test_git_status_not_dirty_from_layout(model_dir): + _init(model_dir) + client = TestClient(create_app(model_dir)) + ent = client.get("/api/model").json()["entities"][0]["id"] + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 1, "y": 2}}, "edges": {}}) + st = client.get("/api/git/status").json() + assert st["git"] is True + assert st["clean"] is True + assert not any(d["path"] == ".mdl/layout.json" for d in st["dirty"]) + + +def test_gitignore_created_after_first_write(model_dir): + _init(model_dir) + client = TestClient(create_app(model_dir)) + ent = client.get("/api/model").json()["entities"][0]["id"] + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 1, "y": 2}}, "edges": {}}) + gi = model_dir / ".mdl" / ".gitignore" + assert gi.exists() + assert "layout.json" in gi.read_text().splitlines() + + +def test_gitignore_not_created_outside_git(model_dir): + # model_dir is a bare tmp dir (no git init here) + client = TestClient(create_app(model_dir)) + ent = client.get("/api/model").json()["entities"][0]["id"] + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 1, "y": 2}}, "edges": {}}) + assert not (model_dir / ".mdl" / ".gitignore").exists() + assert (model_dir / ".mdl" / "layout.json").exists() # file still written diff --git a/specs/modelith-canvas-edge-drag-and-layout-spec.md b/specs/modelith-canvas-edge-drag-and-layout-spec.md new file mode 100644 index 0000000..bd4dcd5 --- /dev/null +++ b/specs/modelith-canvas-edge-drag-and-layout-spec.md @@ -0,0 +1,154 @@ +# Canvas: draggable relationship edges and saved layout + +Spec for Claude Code. Target repo: github.com/dbose/modelith, branch from `main` at or after `7dd170b`. Put this file at `specs/modelith-canvas-edge-drag-and-layout-spec.md`. + +## Context + +Author has imported a 7 MB erwin file, reversed it, and used the canvas with GitHub Copilot driving the MCP tools. Two gaps showed up against erwin's diagram editor (see the screen recording of erwin: selecting a relationship line shows a handle on its vertical segment, and dragging it slides the segment sideways while the ends stay glued to the entities). + +1. A relationship edge cannot be dragged. Every edge is drawn by `getSmoothStepPath` in `canvas/src/RelationshipEdge.tsx`, so its elbow position is decided by the library and cannot be adjusted. On a dense model many edges run through the same corridor and the diagram is unreadable. +2. Layout is not saved. `ModelCanvas.tsx` keeps node positions only in React state (`setNodes`), and recomputes them with `layoutGraph` on load. Every reload throws away manual placement. Nothing in the server stores layout. + +Layout is a visual concern only. It must never appear in the model, drift, validation, exports, diffs, proposals or dbt output. + +## Decisions (already made, do not reopen) + +- Layout lives in a sidecar file, `/.mdl/layout.json`, not in any model YAML and not in `mdl-project.yaml`. +- JSON, not YAML. Several code paths glob `*.yaml` or `*.y*ml` under the model dir (`commands.dir_fingerprint`, `status.py`, `app._dir_fingerprint`). A `.json` file stays out of all of them by construction. +- The file is git-ignored by default (see Part B). Sharing layout across a team is a later opt-in, not v1. +- Edge routing is orthogonal, same style as today. The only adjustable parameter per edge is the x position of its vertical segment (`routeX`). The canvas has ports on left and right sides only (`EntityNode.tsx`), so a vertical segment is the only free degree of freedom. No free-form waypoints in v1. +- The canvas component stays free of API calls. Persistence is injected through a prop, the same way `exec` is. + +## Part A: draggable relationship edges + +### Behaviour + +1. Hovering or selecting an edge shows a drag handle at the midpoint of its vertical segment (a small grip, cursor `ew-resize`). The existing invisible 14 px hit path stays for hover and click. +2. Dragging the handle moves the vertical segment horizontally. Both endpoints stay anchored to their attribute handles. The path redraws live while dragging, at 60 fps on a 7 MB erwin model (about 60 to 100 entities, a few hundred edges). +3. Smart adjustment, applied while dragging and on release: + - Snap to a 10 px grid. Holding Shift disables snapping. + - Magnetise: if the segment is within 6 px of another edge's segment x or of a card's left or right edge plus margin, snap to it so lines can be aligned. + - Never allow the segment inside a card's horizontal extent. If the drop lands inside a card, move it to the nearest outer edge plus a 24 px margin. For a forward edge (source left of target) with room, clamp to `[sourceX + 24, targetX - 24]`. For a backward edge (target left of source), allow any x outside both cards. +4. Double-clicking the handle (or the edge, when selected) resets that edge to automatic routing by removing its `routeX`. +5. A click still opens `RelEditModal` as today. A press on the handle that moves less than 3 px counts as a click. A real drag must not open the modal (call `stopPropagation` on the handle's pointer events and swallow the click that follows a drag). +6. When a node is dragged, its connected edges keep their stored `routeX`, re-clamped at render time. The stored value is not rewritten by a node move, so moving a card back restores the old routing. +7. The selected-edge label (`rel.verb_phrase || rel.name`) and the composite-key count label should sit at the vertical segment's x, not the geometric midpoint, once `routeX` is set. + +### Implementation notes + +- Add `routeX?: number` (flow coordinates) and `onRouteChange?: (relId: string, routeX: number | null) => void` to `RelationshipEdgeData`. +- Path: pass `centerX: routeX` to `getSmoothStepPath`. In `reactflow@11.11.4` (`@reactflow/core@11.11.4`, pinned in `canvas/package-lock.json`) `getSmoothStepPath` accepts `centerX` and `centerY`. Verify this in `node_modules/@reactflow/core` types before relying on it. If it behaves badly for backward edges, write a small `orthogonalPath(sourceX, sourceY, targetX, targetY, routeX, radius)` in `edgeRouting.ts` that draws horizontal stub, vertical run at `routeX`, horizontal stub, with the existing 10 px corner radius. +- Convert pointer position to flow coordinates with `useReactFlow().screenToFlowPosition` (available in 11.10+). Use pointer events with `setPointerCapture` and update on `requestAnimationFrame`. +- During a drag keep the in-progress `routeX` in local state inside the edge component. Do not call `setEdges` for every move; that rebuilds the whole array and will stutter on a large model (the hover overlay in `ModelCanvas.tsx` was already refactored for exactly this reason). Commit once on pointer release through `onRouteChange`. +- Put the geometry in a new pure module `canvas/src/edgeRouting.ts`: `snapRouteX`, `clampRouteX`, `magnetise`. Unit-test it without React. +- Card rectangles for clamping: node `position` from the store, width `NODE_WIDTH` (264) from `layout.ts`, height from `nodeHeight(entity)`. Expose them to the edge through edge data or `useStore`, whichever avoids re-rendering every edge on every node move. +- `onlyRenderVisibleElements` is on. An edge being dragged must stay mounted while off-screen endpoints scroll away. Check this. +- Readonly (`caps.canEdit === false`): dragging is still allowed. Routing is layout, not a model edit. It saves only if a layout store is provided (Part B). + +## Part B: saved layout, visual only + +### File and schema + +Path: `/.mdl/layout.json`. `model_dir` is the directory `mdl serve -m ` was started with (the same root `DecisionLedger` uses for `.mdl/decisions.yaml`). + +```json +{ + "version": 1, + "views": { + "__all__": { + "nodes": { "": { "x": 120, "y": 340 } }, + "edges": { "": { "routeX": 480 } } + }, + "sa:": { "nodes": {}, "edges": {} } + } +} +``` + +- A view is one canvas arrangement. `__all__` is the unfiltered canvas. When the subject-area filter (`activeAreas`) is active, the view key is `sa:` plus the selected ids, sorted and joined with `+`. This matters because `ModelCanvas.tsx` already re-lays-out the visible subset when filtering, so one flat position map would be overwritten every time the filter changes. +- Numbers are rounded to integers. Keys are sorted and the file is written with 1-space indent and a trailing newline, so any diff is small and stable. +- Unknown top-level keys and a higher `version` are preserved on read-modify-write and never crash the server. An unreadable or corrupt file is treated as empty (log once), never fatal. Never raise from `GET /api/model` because of it. + +### Server (`packages/server/src/mdl_server`) + +New module `layout_store.py`, plus two routes in `app.py`. + +- `GET /api/layout?view=` returns `{ "version": 1, "view": key, "nodes": {...}, "edges": {...} }`, empty maps when absent. Always 200 for a readable model. +- `PUT /api/layout` takes `{ "view": key, "nodes": {...}, "edges": {...} }` and replaces that view. It writes atomically (temp file in the same directory, then `os.replace`). Body limit 1 MB. Reject non-finite numbers and keys longer than 64 characters with 422. On write, drop entries whose id is not an entity or relationship in the current model (`_load().model`), so the file does not accumulate dead ids. +- `DELETE /api/layout?view=` removes one view. Omitting `view` removes the whole file (the "reset all layout" action). +- Under `read_only` (catalog browse, SME just looking) PUT and DELETE return 403. The canvas treats that as "session only" and does not show an error. +- Layout routes do not go through `commands.apply_command`, do not bump the model fingerprint, do not call `cache["repo"] = None`, and do not write an audit record. They are not model mutations. +- On first successful write, ensure the file is ignored by git: create `/.mdl/.gitignore` containing `layout.json` if that file is not already ignored. Do this only when `.mdl/` is inside a git work tree and never edit a user's existing ignore files beyond creating this one. + +### Canvas (`canvas/src`) + +- Add `LayoutStore` to `exec.ts` or a new `layoutStore.ts`: `{ load(view): Promise, save(view, layout): void, reset(view?): Promise }`. Implement `httpLayoutStore` in `api.ts` using the existing `get` helper and the `API_BASE` prefix. Add an optional prop `layoutStore?: LayoutStore` to `ModelCanvasProps`. The architect app (`App.tsx`) passes it. The SME and catalog shells do not, so staged or previewed models never persist layout. +- Load: after the model is derived and nodes are created, call `layoutStore.load(viewKey)` and apply saved positions in place of the `layoutGraph` result for entities that have one. Entities without a saved position (new ones, such as those Copilot just created) keep their auto-layout position, then get a simple overlap nudge so they do not land on top of an existing card. Run auto-layout once for the whole view as today, then override. Fit the view only when no saved layout exists, so a restored layout is not re-zoomed away. +- Save: on `onNodeDragStop`, on edge route commit, and on the toolbar Re-layout action. Debounce 800 ms and send the whole view. Show nothing on success, a quiet toast on failure. +- Re-layout is destructive of manual work. Keep the previous positions in memory and offer Undo in a toast for the session. Add "Reset layout" to the toolbar menu, calling `reset(viewKey)`. +- A node drag today only updates React state in `onNodeDragStop`. Keep that behaviour and add the save call there. +- Viewport (pan and zoom) is not saved in v1. + +### Isolation guarantees (must hold, with tests) + +`layout.json` must be invisible to: + +- `ModelRepo.load` and everything built on it: `mdl validate`, drift, `mdl diff`, emitters (dbt, ODCS, Pydantic, graph, RDF, OSI, MetricFlow). +- `/api/export` and `mdl export`. +- `commands.dir_fingerprint` and `app._dir_fingerprint` (they only glob `*.yaml`). +- The reverse writer prune (`writer.py` already excludes `.mdl/`; add a test so it stays that way). +- `git_api.py`: `status`, `diff`, propose, commit and the revert path that removes untracked files (around the `git status --porcelain` calls near lines 635, 793, 969, and the revert near line 901). If a user commits `layout.json` anyway, or ignores nothing, these paths must filter `.mdl/layout.json` out of "dirty" and must never delete it on revert. + +## Files expected to change + +- `canvas/src/RelationshipEdge.tsx`: handle, path, labels. +- `canvas/src/edgeRouting.ts`: new, pure geometry. +- `canvas/src/ModelCanvas.tsx`: layout load and save, route commit, overlap nudge, undo. +- `canvas/src/exec.ts` or `canvas/src/layoutStore.ts`, `canvas/src/api.ts`, `canvas/src/App.tsx`, `canvas/src/TopBar.tsx` (Reset layout). +- `canvas/src/types.ts`: layout payload types. +- `packages/server/src/mdl_server/layout_store.py` (new), `app.py` (routes), `git_api.py` (path filter). +- The built bundle under `packages/server/src/mdl_server/static/` is committed. Run `cd canvas && npm ci && npm run build` and commit the regenerated assets. Expect hashed filenames to change. +- `README.md` or docs: one short paragraph on saved layout and the git-ignore behaviour. Changelog line. + +`vscode/` needs no change: the canvas webview loads the served page. + +## Tests + +Python (`packages/server/tests/test_layout_api.py`, new): + +- GET with no file returns empty maps. PUT then GET round-trips. Output is key-sorted with integer values. +- PUT drops ids not present in the model. Corrupt existing file is treated as empty and overwritten on the next PUT. +- PUT and DELETE return 403 with `read_only=True`. +- Layout writes do not change `commands.dir_fingerprint`, and `GET /api/model` returns an identical document before and after a PUT. +- With `layout.json` present, `mdl validate`, drift and every emitter produce byte-identical output to the same model without it. Use the demo or the erwin test fixture. +- `/api/export` output is identical with and without the file. +- `git_api` status is not dirty because of `layout.json`, and revert does not delete it. +- The auto-created `.mdl/.gitignore` exists after the first PUT inside a git repo and is not created outside one. + +Canvas (`vitest`): + +- `edgeRouting.ts`: grid snap, Shift bypass, magnet within 6 px, clamp out of a card, forward and backward edge cases, reset returns auto. +- `RelationshipEdge`: renders handle on hover or select, calls `onRouteChange` once on release (not per move), a sub-3 px press does not call it, double-click calls it with `null`. +- Restore: saved positions override auto-layout, a new entity is placed without overlap, no `fitView` when a saved layout exists, a 403 from the store does not surface an error. + +## Acceptance criteria + +1. On the erwin-imported model, an edge can be dragged horizontally with both ends staying attached, snaps to the grid, and cannot be dropped inside a card. +2. Double-click returns the edge to automatic routing. +3. Reload the page or restart `mdl serve`: card positions and edge routes are restored exactly. Switching the subject-area filter and back restores each view's own arrangement. +4. New entities created through MCP (Copilot) appear without overlapping existing cards and do not disturb restored positions. +5. `git status` in the model repo stays clean after a layout change. `mdl validate`, drift, export and all emitters give identical results with and without `layout.json`. +6. Re-layout can be undone within the session. Reset layout removes the saved view. +7. `npm run build` (includes `tsc --noEmit`), `vitest run`, the server pytest suite, and `ruff` all pass. Dragging an edge on a 100-entity model stays smooth (no per-move rebuild of all nodes and edges). + +## Out of scope for v1 + +- Free-form multi-bend waypoints or horizontal segment dragging for top and bottom ports. +- Saving viewport, selection, collapse state or the chosen layout mode. +- Sharing layout through git as a first-class feature (a `layout: shared` setting) and merge handling for it. +- Layout for the SME and catalog views. +- Importing erwin's own diagram coordinates. This is a good follow-up: the erwin file carries positions, which would make the first import look like the original diagram. Note it, do not build it here. + +## Open questions + +- Should `__all__` and per-area views be separate, as specified, or should filtered views reuse `__all__` positions and only fall back to auto-layout for entities missing from it? Separate views are simpler and match current behaviour; reuse looks more consistent. Default to separate unless it feels wrong in use. +- Team sharing: ignore by default (as specified) or commit by default? Defaulting to ignored avoids noisy diffs and any chance of layout entering review flows. Revisit after v1 if teams ask. \ No newline at end of file From 48c3a86382cd72ca8d9a4fbb59f267dd18275e50 Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Sun, 11 Oct 2026 20:52:16 +1100 Subject: [PATCH 02/14] =?UTF-8?q?Release=200.6.15=20=E2=80=94=20canvas=20d?= =?UTF-8?q?raggable=20edges=20+=20saved=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- uv.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2f516d3..0abebaa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ # project, so the install name is `modelith-dbt` (install: uv tool install # modelith-dbt). The command stays `mdl`; the import modules stay mdl_*. name = "modelith-dbt" -version = "0.6.13" +version = "0.6.15" description = "Ontology-anchored, git-native data modeling tool for dbt-core teams" readme = "README.md" requires-python = ">=3.11" diff --git a/uv.lock b/uv.lock index 9e9d8b1..4ab7560 100644 --- a/uv.lock +++ b/uv.lock @@ -939,7 +939,7 @@ requires-dist = [ [[package]] name = "modelith-dbt" -version = "0.6.13" +version = "0.6.15" source = { editable = "." } dependencies = [ { name = "dbt-artifacts-parser" }, From b4ee02a94d3e744e5eb1ae8375efa0fddcf4dd1d Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Sun, 11 Oct 2026 20:57:46 +1100 Subject: [PATCH 03/14] canvas: make the edge drag handle zoom-invariant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The route grip was drawn at a fixed SVG size inside React Flow's scaled edge layer, so at the default 0.33x zoom a 3px grip rendered ~1px wide on screen — invisible and impossible to grab ("no drag icon, nothing works"). Divide the grip, its hit target and the edge's invisible click path by the live zoom (useStore transform[2]) so they keep a constant on-screen size (grip ~9x18px, hit target ~22x32px) at any zoom. The grip is now a rounded amber pill with two dots as a drag affordance. Test asserts the grip has a real, non-collapsed size. --- canvas/src/RelationshipEdge.test.tsx | 7 +++- canvas/src/RelationshipEdge.tsx | 40 ++++++++++++++----- canvas/src/styles.css | 8 ++-- ...m-CrqdkiTB.js => ModelDiagram-BiCY0Chy.js} | 2 +- .../{main-lOq9xM1X.js => main-DtrWQgbe.js} | 2 +- .../{sme-BJx0Kpa-.js => sme-r22DBFEH.js} | 4 +- ...tyles-DO3eXfyX.css => styles-BpoQ4C-h.css} | 2 +- .../static/assets/styles-SXBmvQqW.js | 23 ----------- .../static/assets/styles-_nxo2D6f.js | 23 +++++++++++ .../server/src/mdl_server/static/index.html | 6 +-- .../server/src/mdl_server/static/sme.html | 6 +-- 11 files changed, 74 insertions(+), 49 deletions(-) rename packages/server/src/mdl_server/static/assets/{ModelDiagram-CrqdkiTB.js => ModelDiagram-BiCY0Chy.js} (97%) rename packages/server/src/mdl_server/static/assets/{main-lOq9xM1X.js => main-DtrWQgbe.js} (99%) rename packages/server/src/mdl_server/static/assets/{sme-BJx0Kpa-.js => sme-r22DBFEH.js} (99%) rename packages/server/src/mdl_server/static/assets/{styles-DO3eXfyX.css => styles-BpoQ4C-h.css} (59%) delete mode 100644 packages/server/src/mdl_server/static/assets/styles-SXBmvQqW.js create mode 100644 packages/server/src/mdl_server/static/assets/styles-_nxo2D6f.js diff --git a/canvas/src/RelationshipEdge.test.tsx b/canvas/src/RelationshipEdge.test.tsx index 107a4ac..75c9a02 100644 --- a/canvas/src/RelationshipEdge.test.tsx +++ b/canvas/src/RelationshipEdge.test.tsx @@ -45,7 +45,12 @@ describe("RelationshipEdge drag handle", () => { it("shows the grip when selected and draggable", () => { const { container } = renderEdge({ onRouteChange: vi.fn() }, true); expect(container.querySelector(".rel-handle")).not.toBeNull(); - expect(container.querySelector(".rel-grip")).not.toBeNull(); + const grip = container.querySelector(".rel-grip"); + expect(grip).not.toBeNull(); + // grip must have a real, non-collapsed size (it rendered at ~1px when the + // sizing was zoom-naive — a constant on-screen size is the fix). At the test's + // default zoom (1) the SVG width is 9/zoom = 9. + expect(Number(grip!.getAttribute("width"))).toBeGreaterThanOrEqual(6); }); it("hides the grip when not selected", () => { diff --git a/canvas/src/RelationshipEdge.tsx b/canvas/src/RelationshipEdge.tsx index 36ef6e2..614d9f3 100644 --- a/canvas/src/RelationshipEdge.tsx +++ b/canvas/src/RelationshipEdge.tsx @@ -1,5 +1,5 @@ import { memo, useCallback, useRef, useState } from "react"; -import { getSmoothStepPath, Position, useReactFlow, type EdgeProps } from "reactflow"; +import { getSmoothStepPath, Position, useReactFlow, useStore, type EdgeProps } from "reactflow"; import type { Relationship } from "./types"; export interface RelationshipEdgeData { @@ -53,6 +53,11 @@ export const RelationshipEdge = memo(function RelationshipEdge({ selected, }: EdgeProps) { const { screenToFlowPosition } = useReactFlow(); + // The canvas zoom. The handle is drawn in flow coordinates inside a scaled , + // so a fixed SVG size shrinks to nothing when zoomed out (a 3px grip became ~1px + // on screen at the default 0.33x zoom). Divide sizes by the zoom so the grip keeps + // a constant on-screen size and stays grabbable at any zoom. + const zoom = useStore((s) => s.transform[2]); // while dragging, the live route is kept here so we do NOT rebuild all edges // per move; the committed value rides in data.routeX. const [dragX, setDragX] = useState(null); @@ -175,18 +180,20 @@ export const RelationshipEdge = memo(function RelationshipEdge({ fill="none" strokeDasharray={identifying ? undefined : "6 4"} /> - {/* wider invisible path for easier hover/click */} + {/* wider invisible path for easier hover/click — kept ~16px on screen at any zoom */} onHover(rel!.id) : undefined} onMouseLeave={onHover ? () => onHover(null) : undefined} /> - {/* drag handle on the vertical segment — only when draggable and hovered/selected */} + {/* drag handle on the vertical segment — only when draggable and hovered/selected. + Sizes are divided by the zoom so the grip keeps a constant ON-SCREEN size and + stays visible + grabbable however far the canvas is zoomed out. */} {draggable && (selected || dragX != null) && ( - {/* a fat transparent target around the grip for easy grabbing */} - + {/* a fat transparent target (~22px on screen) around the grip for easy grabbing */} + + {/* the visible grip: a rounded pill (~9x18px on screen) */} + {/* two dots to read as a drag affordance */} + + )} {(selected || composite) && rel && ( diff --git a/canvas/src/styles.css b/canvas/src/styles.css index d47b9e4..c310b28 100644 --- a/canvas/src/styles.css +++ b/canvas/src/styles.css @@ -255,9 +255,11 @@ body { font-family: var(--font); background: var(--bg); color: var(--text); } .rel-edge:hover .rel-glyph, .rel-edge.selected .rel-glyph { stroke: var(--accent); } .rel-edge.dimmed { opacity: 0.12; } .rel-label { fill: var(--text); font-size: 11px; text-anchor: middle; paint-order: stroke; stroke: var(--bg); stroke-width: 4px; } -/* draggable edge route handle (grip on the vertical segment) */ -.rel-handle .rel-grip { fill: var(--accent); stroke: var(--bg); stroke-width: 1; opacity: 0.9; } -.rel-handle:hover .rel-grip { opacity: 1; } +/* draggable edge route handle (grip on the vertical segment). Sizes are set + per-zoom in the component (zoom-invariant), so here we only style colour. */ +.rel-handle .rel-grip { fill: var(--accent); stroke: var(--bg); opacity: 0.95; } +.rel-handle .rel-grip-dot { fill: var(--bg); } +.rel-handle:hover .rel-grip { fill: var(--accent); filter: brightness(1.15); } .layout-menu-sep { height: 1px; margin: 4px 0; background: var(--border); } /* ---------- detail panel ---------- */ diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-CrqdkiTB.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-BiCY0Chy.js similarity index 97% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-CrqdkiTB.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-BiCY0Chy.js index 0c33152..9a12882 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-CrqdkiTB.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-BiCY0Chy.js @@ -1 +1 @@ -import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-SXBmvQqW.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; +import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-_nxo2D6f.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; diff --git a/packages/server/src/mdl_server/static/assets/main-lOq9xM1X.js b/packages/server/src/mdl_server/static/assets/main-DtrWQgbe.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-lOq9xM1X.js rename to packages/server/src/mdl_server/static/assets/main-DtrWQgbe.js index a016a29..6d4d0d2 100644 --- a/packages/server/src/mdl_server/static/assets/main-lOq9xM1X.js +++ b/packages/server/src/mdl_server/static/assets/main-DtrWQgbe.js @@ -1,2 +1,2 @@ -import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-SXBmvQqW.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` +import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-_nxo2D6f.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` `)||"model valid",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),M]}):F?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14}),F]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!u&&e.jsxs("button",{className:"tool-btn primary",onClick:A,title:"New entity (n)",children:[e.jsx(ye,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),E("ontology",e.jsx(be,{size:15}),"Ontology","Ontology browser"),E("layers",e.jsx(we,{size:15}),"Layers","Four-layer stack & coverage"),E("changes",e.jsx(ve,{size:15}),"Changes",k?"Uncommitted changes":"Changes",k),E("decisions",e.jsx(Me,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(w?" active":""),onClick:g,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(m?" active":""),onClick:p,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Ne,{size:15})}),e.jsx(Ke,{onRelayout:f,onReset:v}),e.jsx("button",{className:"grp-btn icon-only",onClick:y,title:"Fit view","aria-label":"Fit view",children:e.jsx(ke,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:r,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Se,{size:15})}),e.jsx(de,{exec:S,canEdit:!u,onImported:I,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:_,openImport:$})]})]})]})}const U=["LR","TB","RL","BT"],$e={LR:0,TB:90,RL:180,BT:270},se={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function Ke({onRelayout:s,onReset:l}){const[j,h]=a.useState(!1),[x,w]=a.useState("LR"),[g,m]=a.useState("auto"),p=a.useRef(null);a.useEffect(()=>{if(!j)return;const r=u=>{p.current&&!p.current.contains(u.target)&&h(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[j]);const y=r=>{m(r),s(r,x)},f=r=>{y(r),h(!1)},v=()=>{const r=U[(U.indexOf(x)+1)%U.length];w(r),s(g,r)};return e.jsxs("div",{className:"layout-picker",ref:p,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>y("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ee,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(j?" active":""),onClick:()=>h(r=>!r),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:v,title:`Flow direction: ${se[x]} (click to rotate)`,"aria-label":`Flow direction: ${se[x]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${$e[x]}deg)`},children:e.jsx(Pe,{size:15})})}),j&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>f("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>f("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>f("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>f("grid"),children:"Grid"}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"layout-menu-sep",role:"separator"}),e.jsx("button",{onClick:()=>{l(),h(!1)},title:"Clear saved positions and routes for this view",children:"Reset layout"})]})]})]})}function He(){const[s,l]=a.useState(null),[j,h]=a.useState(null),[x,w]=a.useState(null),[g,m]=a.useState(null),[p,y]=a.useState(""),[f,v]=a.useState(!0),[r,u]=a.useState(!1),[k,b]=a.useState(()=>new Set),[q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[z,D]=a.useState(()=>new Set),[K,M]=a.useState(!1),[F,E]=a.useState(0),o=a.useRef(null),L=a.useRef(""),B=a.useRef(!1),O=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((c,n)=>t.set(c.id,Y[n%Y.length])),t},[s]),H=a.useMemo(()=>{const t=new Map;if(!s)return t;const c=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(d=>c.set(d,n.id))}),s.entities.forEach(n=>{var N,Q,X;const P=((N=n.conceptual)!=null&&N.id?c.get(n.conceptual.id):void 0)??((X=(Q=n.conceptual)==null?void 0:Q.subject_area)==null?void 0:X.id)??"";t.set(n.id,P)}),t},[s]),te=a.useMemo(()=>{const t=new Map;return H.forEach(c=>t.set(c,(t.get(c)??0)+1)),t},[H]),R=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>ge(R),[R]),ae=a.useMemo(()=>ue(),[]),V=a.useMemo(()=>new URLSearchParams(window.location.search),[]),T=V.get("minimal")==="1";a.useEffect(()=>{T&&u(!0)},[T]);const re=a.useCallback(t=>{b(c=>{const n=new Set(c);return n.has(t)?n.delete(t):n.add(t),n})},[]),ce=V.get("import")==="1",W=a.useRef(!1),C=a.useCallback(()=>{J().then(l).catch(t=>w(String(t))),Z().then(h).catch(()=>h(null)),ee().then(t=>M(!!(t.git&&!t.clean))).catch(()=>M(!1)),E(t=>t+1)},[]);a.useEffect(C,[C]),a.useEffect(()=>{const t=setInterval(()=>{J().then(c=>{l(n=>n&&c.fingerprint===n.fingerprint?n:(B.current||(L.current=c.fingerprint),T||(Z().then(h).catch(()=>h(null)),ee().then(d=>M(!!(d.git&&!d.clean))).catch(()=>M(!1))),E(d=>d+1),c))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[T]),a.useEffect(()=>{s!=null&&s.fingerprint&&(L.current=s.fingerprint)},[s]);const G=a.useCallback(async(t,c)=>{if(s){B.current=!0;try{const n=await xe(t,c,L.current||s.fingerprint);return n!=null&&n.fingerprint&&(L.current=n.fingerprint),C(),n}catch(n){throw n instanceof pe&&n.status===409?(m("Model changed on disk — view refreshed, please retry."),C()):m(n instanceof Error?n.message:String(n)),n}finally{B.current=!1}}},[s,C]);a.useEffect(()=>{if(!g)return;const t=setTimeout(()=>m(null),5e3);return()=>clearTimeout(t)},[g]),a.useEffect(()=>{if(!s||W.current)return;const t=V.get("focus");if(!t)return;const c=s.entities.find(n=>{var d;return n.name===t||((d=n.conceptual)==null?void 0:d.name)===t});c&&(W.current=!0,requestAnimationFrame(()=>{var n;return(n=o.current)==null?void 0:n.focusEntity(c.id)}))},[s,V]);const oe=a.useCallback(()=>{var n;if(!s)return;const t=p.trim().toLowerCase();if(!t)return;const c=s.entities.find(d=>{var N;return(d.name.toLowerCase()+" "+(((N=d.conceptual)==null?void 0:N.name.toLowerCase())??"")+" "+d.attributes.map(Q=>Q.name.toLowerCase()).join(" ")).includes(t)});c&&((n=o.current)==null||n.focusEntity(c.id))},[s,p]);return a.useEffect(()=>{const t=c=>{var d,P,N;const n=(d=document.activeElement)==null?void 0:d.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(c.key==="/"&&(c.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),c.key==="n"&&!R&&((N=o.current)==null||N.newEntity()),c.key==="Escape"&&(A(null),y(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[R]),x?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:x}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!T&&e.jsx(_e,{doc:s,diagnostics:j,query:p,onQuery:y,onSubmitQuery:oe,showTypes:f,onToggleTypes:()=>v(t=>!t),collapseDetail:r,onToggleCollapse:()=>u(t=>!t),onFitView:()=>{var t;return(t=o.current)==null?void 0:t.fitView()},onRelayout:(t,c)=>{var n;return(n=o.current)==null?void 0:n.relayout(t,c)},onResetLayout:()=>{var t;return(t=o.current)==null?void 0:t.resetLayout()},onRefresh:C,readOnly:R,dirty:K,panelTab:S,onPanelTab:t=>I(c=>c===t?null:t),onNewEntity:()=>{var t;return(t=o.current)==null?void 0:t.newEntity()},exec:G,onImported:C,onImportBatch:je,openImport:ce,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:z.size}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(me,{doc:s,caps:ne,exec:G,selectedId:S?null:q,onSelect:A,query:p,showTypes:f,collapseDetail:r,expandedEntities:k,onToggleExpand:re,activeAreas:z,onError:m,handleRef:o,layoutStore:ae}),!T&&e.jsx(Ae,{doc:s,saColors:O,countByArea:te,activeAreas:z,onSetActive:D,open:_,onClose:()=>$(!1)}),S&&e.jsx(fe,{tab:S,onClose:()=>I(null),readOnly:R,refreshKey:F,onModelChanged:C,onFocusEntity:t=>{var c;I(null),(c=o.current)==null||c.focusEntity(t)}}),g&&e.jsx("div",{className:"toast",children:g})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ve(){return e.jsx(he,{children:e.jsx(He,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(le.StrictMode,{children:e.jsx(Ve,{})})); diff --git a/packages/server/src/mdl_server/static/assets/sme-BJx0Kpa-.js b/packages/server/src/mdl_server/static/assets/sme-r22DBFEH.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-BJx0Kpa-.js rename to packages/server/src/mdl_server/static/assets/sme-r22DBFEH.js index cca39ab..d7254e7 100644 --- a/packages/server/src/mdl_server/static/assets/sme-BJx0Kpa-.js +++ b/packages/server/src/mdl_server/static/assets/sme-r22DBFEH.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-CrqdkiTB.js","assets/client-DOmNpTln.js","assets/styles-SXBmvQqW.js","assets/styles-DO3eXfyX.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-SXBmvQqW.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-CrqdkiTB.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-BiCY0Chy.js","assets/client-DOmNpTln.js","assets/styles-_nxo2D6f.js","assets/styles-BpoQ4C-h.css"])))=>i.map(i=>d[i]); +import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-_nxo2D6f.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-BiCY0Chy.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); diff --git a/packages/server/src/mdl_server/static/assets/styles-DO3eXfyX.css b/packages/server/src/mdl_server/static/assets/styles-BpoQ4C-h.css similarity index 59% rename from packages/server/src/mdl_server/static/assets/styles-DO3eXfyX.css rename to packages/server/src/mdl_server/static/assets/styles-BpoQ4C-h.css index bf0c725..206133b 100644 --- a/packages/server/src/mdl_server/static/assets/styles-DO3eXfyX.css +++ b/packages/server/src/mdl_server/static/assets/styles-BpoQ4C-h.css @@ -1 +1 @@ -.react-flow{direction:ltr}.react-flow__container{position:absolute;width:100%;height:100%;top:0;left:0}.react-flow__pane{z-index:1;cursor:-webkit-grab;cursor:grab}.react-flow__pane.selection{cursor:pointer}.react-flow__pane.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__viewport{transform-origin:0 0;z-index:2;pointer-events:none}.react-flow__renderer{z-index:4}.react-flow__selection{z-index:6}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible{outline:none}.react-flow .react-flow__edges{pointer-events:none;overflow:visible}.react-flow__edge-path,.react-flow__connection-path{stroke:#b1b1b7;stroke-width:1;fill:none}.react-flow__edge{pointer-events:visibleStroke;cursor:pointer}.react-flow__edge.animated path{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__edge.animated path.react-flow__edge-interaction{stroke-dasharray:none;-webkit-animation:none;animation:none}.react-flow__edge.inactive{pointer-events:none}.react-flow__edge.selected,.react-flow__edge:focus,.react-flow__edge:focus-visible{outline:none}.react-flow__edge.selected .react-flow__edge-path,.react-flow__edge:focus .react-flow__edge-path,.react-flow__edge:focus-visible .react-flow__edge-path{stroke:#555}.react-flow__edge-textwrapper{pointer-events:all}.react-flow__edge-textbg{fill:#fff}.react-flow__edge .react-flow__edge-text{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__connection{pointer-events:none}.react-flow__connection .animated{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__connectionline{z-index:1001}.react-flow__nodes{pointer-events:none;transform-origin:0 0}.react-flow__node{position:absolute;-webkit-user-select:none;-moz-user-select:none;user-select:none;pointer-events:all;transform-origin:0 0;box-sizing:border-box;cursor:-webkit-grab;cursor:grab}.react-flow__node.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__nodesselection{z-index:3;transform-origin:left top;pointer-events:none}.react-flow__nodesselection-rect{position:absolute;pointer-events:all;cursor:-webkit-grab;cursor:grab}.react-flow__handle{position:absolute;pointer-events:none;min-width:5px;min-height:5px;width:6px;height:6px;background:#1a192b;border:1px solid white;border-radius:100%}.react-flow__handle.connectionindicator{pointer-events:all;cursor:crosshair}.react-flow__handle-bottom{top:auto;left:50%;bottom:-4px;transform:translate(-50%)}.react-flow__handle-top{left:50%;top:-4px;transform:translate(-50%)}.react-flow__handle-left{top:50%;left:-4px;transform:translateY(-50%)}.react-flow__handle-right{right:-4px;top:50%;transform:translateY(-50%)}.react-flow__edgeupdater{cursor:move;pointer-events:all}.react-flow__panel{position:absolute;z-index:5;margin:15px}.react-flow__panel.top{top:0}.react-flow__panel.bottom{bottom:0}.react-flow__panel.left{left:0}.react-flow__panel.right{right:0}.react-flow__panel.center{left:50%;transform:translate(-50%)}.react-flow__attribution{font-size:10px;background:#ffffff80;padding:2px 3px;margin:0}.react-flow__attribution a{text-decoration:none;color:#999}@-webkit-keyframes dashdraw{0%{stroke-dashoffset:10}}@keyframes dashdraw{0%{stroke-dashoffset:10}}.react-flow__edgelabel-renderer{position:absolute;width:100%;height:100%;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__edge.updating .react-flow__edge-path{stroke:#777}.react-flow__edge-text{font-size:10px}.react-flow__node.selectable:focus,.react-flow__node.selectable:focus-visible{outline:none}.react-flow__node-default,.react-flow__node-input,.react-flow__node-output,.react-flow__node-group{padding:10px;border-radius:3px;width:150px;font-size:12px;color:#222;text-align:center;border-width:1px;border-style:solid;border-color:#1a192b;background-color:#fff}.react-flow__node-default.selectable:hover,.react-flow__node-input.selectable:hover,.react-flow__node-output.selectable:hover,.react-flow__node-group.selectable:hover{box-shadow:0 1px 4px 1px #00000014}.react-flow__node-default.selectable.selected,.react-flow__node-default.selectable:focus,.react-flow__node-default.selectable:focus-visible,.react-flow__node-input.selectable.selected,.react-flow__node-input.selectable:focus,.react-flow__node-input.selectable:focus-visible,.react-flow__node-output.selectable.selected,.react-flow__node-output.selectable:focus,.react-flow__node-output.selectable:focus-visible,.react-flow__node-group.selectable.selected,.react-flow__node-group.selectable:focus,.react-flow__node-group.selectable:focus-visible{box-shadow:0 0 0 .5px #1a192b}.react-flow__node-group{background-color:#f0f0f040}.react-flow__nodesselection-rect,.react-flow__selection{background:#0059dc14;border:1px dotted rgba(0,89,220,.8)}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible,.react-flow__selection:focus,.react-flow__selection:focus-visible{outline:none}.react-flow__controls{box-shadow:0 0 2px 1px #00000014}.react-flow__controls-button{border:none;background:#fefefe;border-bottom:1px solid #eee;box-sizing:content-box;display:flex;justify-content:center;align-items:center;width:16px;height:16px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;padding:5px}.react-flow__controls-button:hover{background:#f4f4f4}.react-flow__controls-button svg{width:100%;max-width:12px;max-height:12px}.react-flow__controls-button:disabled{pointer-events:none}.react-flow__controls-button:disabled svg{fill-opacity:.4}.react-flow__minimap{background-color:#fff}.react-flow__minimap svg{display:block}.react-flow__resize-control{position:absolute}.react-flow__resize-control.left,.react-flow__resize-control.right{cursor:ew-resize}.react-flow__resize-control.top,.react-flow__resize-control.bottom{cursor:ns-resize}.react-flow__resize-control.top.left,.react-flow__resize-control.bottom.right{cursor:nwse-resize}.react-flow__resize-control.bottom.left,.react-flow__resize-control.top.right{cursor:nesw-resize}.react-flow__resize-control.handle{width:4px;height:4px;border:1px solid #fff;border-radius:1px;background-color:#3367d9;transform:translate(-50%,-50%)}.react-flow__resize-control.handle.left{left:0;top:50%}.react-flow__resize-control.handle.right{left:100%;top:50%}.react-flow__resize-control.handle.top{left:50%;top:0}.react-flow__resize-control.handle.bottom{left:50%;top:100%}.react-flow__resize-control.handle.top.left,.react-flow__resize-control.handle.bottom.left{left:0}.react-flow__resize-control.handle.top.right,.react-flow__resize-control.handle.bottom.right{left:100%}.react-flow__resize-control.line{border-color:#3367d9;border-width:0;border-style:solid}.react-flow__resize-control.line.left,.react-flow__resize-control.line.right{width:1px;transform:translate(-50%);top:0;height:100%}.react-flow__resize-control.line.left{left:0;border-left-width:1px}.react-flow__resize-control.line.right{left:100%;border-right-width:1px}.react-flow__resize-control.line.top,.react-flow__resize-control.line.bottom{height:1px;transform:translateY(-50%);left:0;width:100%}.react-flow__resize-control.line.top{top:0;border-top-width:1px}.react-flow__resize-control.line.bottom{border-bottom-width:1px;top:100%}.ie-wrap{position:relative;display:inline-flex;gap:6px}.erd-ico{font-size:13px;line-height:1;opacity:.85;margin-right:1px}.ie-wrap button:hover .erd-ico,.ie-wrap button.on .erd-ico,.ie-wrap button.active .erd-ico{opacity:1}.erd-caret{opacity:.55;margin-left:1px}.ie-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:30;min-width:220px;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:6px;box-shadow:0 12px 32px #00000073;display:flex;flex-direction:column;gap:2px}.ie-item{display:block;padding:8px 10px;border-radius:6px;color:var(--text);text-decoration:none;font-size:13px;cursor:pointer}.ie-item:hover{background:#5eead424;color:var(--accent)}.ie-dialect{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 10px 8px;margin-bottom:4px;border-bottom:1px solid var(--border);font-size:12px;color:var(--text-dim)}.ie-dialect select{background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;padding:3px 6px;font-size:12px}.ie-import{width:380px;padding:12px;gap:8px}.ie-tabs{display:flex;gap:4px}.ie-tab{flex:1;padding:6px 8px;border-radius:6px;font-size:12px;cursor:pointer;background:none;border:1px solid var(--border);color:var(--text-dim)}.ie-tab.active{border-color:var(--accent);color:var(--accent);background:#5eead41a}.ie-hint{font-size:11px;color:var(--text-dim);margin:0}.ie-textarea{width:100%;font-family:var(--mono);font-size:12px;resize:vertical;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:8px;padding:8px;box-sizing:border-box}.ie-textarea:focus{border-color:var(--accent);outline:none}.ie-file{font-size:11px;color:var(--text-dim)}.ie-warn{font-size:11px;color:var(--pk);margin:0}.ie-error{font-size:12px;color:var(--err);margin:0}.ie-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:4px}:root{--bg: #14110f;--bg-raised: #1c1815;--bg-card: #221d19;--border: #33291f;--border-strong: #4a3c2c;--text: #ece6dd;--text-dim: #a89a86;--accent: #e0a63a;--accent-soft: rgba(224, 166, 58, .15);--accent-ink: #241a08;--pk: #f2c14e;--err: #f0857a;--warn: #e6a94a;--ok: #6cbf73;--font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;--mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace}*{box-sizing:border-box}html,body,#root{height:100%;margin:0}body{font-family:var(--font);background:var(--bg);color:var(--text)}.app{display:flex;flex-direction:column;height:100%}.canvas-wrap{flex:1;position:relative;min-height:0}.react-flow{background:var(--bg)}.topbar{display:flex;flex-direction:column;padding:8px 16px 0;background:var(--bg-raised);border-bottom:1px solid var(--border);z-index:10}.topbar-row{display:flex;align-items:center;gap:14px}.topbar-row.context{padding-bottom:8px}.topbar-row.actions{gap:10px;padding-bottom:8px;flex-wrap:wrap}.brand{display:flex;align-items:baseline;gap:8px;white-space:nowrap}.logo{color:var(--accent);font-size:18px}.brand-name{font-weight:700;letter-spacing:.02em}.project-name{color:var(--text-dim);font-size:13px}.search{flex:0 1 300px;margin-left:auto;padding:7px 12px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-size:13px;outline:none}.search:focus{border-color:var(--accent)}.stats{display:flex;align-items:center;gap:12px;font-size:12px;color:var(--text-dim)}.stat-item{display:inline-flex;align-items:center;gap:5px}.stat-item svg{color:var(--text-dim)}.diag-chip{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:99px;font-weight:600}.diag-chip.ok{background:#34d39926;color:var(--ok)}.diag-chip.warn{background:#fbbf2426;color:var(--warn)}.diag-chip.err{background:#f8717126;color:var(--err)}.hamburger{position:relative;display:inline-flex;align-items:center;justify-content:center;padding:6px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer}.hamburger:hover{color:var(--text);border-color:var(--border-strong)}.hamburger.active{color:var(--accent);border-color:var(--accent)}.hamburger-badge{position:absolute;top:-6px;right:-6px;min-width:15px;height:15px;padding:0 3px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-size:10px;font-weight:700;line-height:15px;text-align:center}.btn-group{display:inline-flex;align-items:center;gap:2px;background:var(--bg-card);border:1px solid var(--border);border-radius:9px;padding:2px}.grp-tag{font-size:10px;color:var(--text-dim);opacity:.75;padding:0 6px 0 4px;letter-spacing:.03em;text-transform:none;white-space:nowrap}.grp-btn{display:inline-flex;align-items:center;gap:5px;padding:5px 9px;border-radius:6px;border:none;background:transparent;color:var(--text-dim);cursor:pointer;font-size:12px;white-space:nowrap}.grp-btn.icon-only{padding:5px 7px}.grp-btn:hover{color:var(--text);background:#ffffff0d}.grp-btn.active{color:var(--accent)}.grp-btn.active svg{color:var(--accent)}.grp-badge{width:6px;height:6px;border-radius:50%;background:var(--warn);display:inline-block;margin-left:1px}.dir-arrow{display:inline-flex;transition:transform .15s ease}.tool-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 11px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.tool-btn:hover{color:var(--text);border-color:var(--border-strong)}.tool-btn.active{color:var(--accent);border-color:var(--accent)}.tool-btn.primary{color:var(--accent);border-color:#e0a63a66;font-weight:600}.layout-picker{position:relative;display:inline-flex;gap:2px}.layout-picker .caret{font-size:10px}.layout-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:20;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:8px;padding:4px;min-width:150px;box-shadow:0 8px 24px #0006}.layout-menu button{display:block;width:100%;text-align:left;padding:7px 10px;border:0;border-radius:6px;background:transparent;color:var(--text-dim);cursor:pointer;font-size:13px}.layout-menu button:hover{background:var(--bg-card);color:var(--text)}.canvas-drawer{position:absolute;top:12px;left:12px;bottom:12px;width:300px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:16px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080;display:flex;flex-direction:column;gap:10px;transform:translate(calc(-100% - 16px));opacity:0;pointer-events:none;transition:transform .2s ease,opacity .2s ease}.canvas-drawer.open{transform:translate(0);opacity:1;pointer-events:auto}.drawer-header{display:flex;align-items:center;justify-content:space-between}.drawer-header h2{margin:0;font-size:15px;display:inline-flex;align-items:center;gap:7px}.drawer-header h2 svg{color:var(--accent)}.drawer-hint{font-size:11px;color:var(--text-dim);line-height:1.4}.sa-all{align-self:flex-start;padding:4px 10px;border-radius:7px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.sa-all:hover:not(:disabled){color:var(--text);border-color:var(--border-strong)}.sa-all.active{color:var(--accent);border-color:var(--accent)}.sa-all:disabled{opacity:.5;cursor:default}.sa-list{display:flex;flex-direction:column;gap:3px;margin-top:2px}.sa-row{display:flex;align-items:center;gap:9px;padding:7px 8px;border-radius:8px;cursor:pointer;border:1px solid transparent;-webkit-user-select:none;user-select:none}.sa-row:hover{background:var(--bg-card)}.sa-row.active{background:var(--accent-soft);border-color:#e0a63a66}.sa-row.muted{cursor:default;opacity:.7}.sa-row.muted:hover{background:transparent}.sa-row input[type=checkbox]{accent-color:var(--accent);cursor:pointer}.sa-chip{width:12px;height:12px;border-radius:3px;flex:0 0 auto}.sa-chip.none{background:repeating-linear-gradient(45deg,#4a3c2c,#4a3c2c 2px,transparent 2px,transparent 4px)}.sa-name{flex:1;font-size:13px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.sa-row.muted .sa-name{color:var(--text-dim)}.sa-count{font-size:11px;color:var(--text-dim);background:var(--bg-card);padding:1px 7px;border-radius:99px;flex:0 0 auto}.entity-node{width:264px;background:var(--bg-card);border:1px solid var(--border);border-top:3px solid var(--accent);border-radius:10px;overflow:hidden;box-shadow:0 4px 18px #00000059;font-size:12px;transition:opacity .15s,box-shadow .15s,border-color .15s}.entity-node.selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent),0 8px 24px #00000080}.entity-node.highlighted{box-shadow:0 0 0 2px var(--pk),0 8px 24px #00000080}.entity-node.dimmed{opacity:.18}.entity-header{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#ffffff08;border-bottom:1px solid var(--border)}.entity-name{font-weight:700;font-size:13px;letter-spacing:.01em}.entity-badges{display:flex;gap:4px}.badge{font-size:10px;padding:1px 6px;border-radius:99px;background:var(--accent-soft);color:var(--accent);text-transform:uppercase;letter-spacing:.05em}.badge.ontology{background:#93c5fd1f;color:#93c5fd}.attr-section{padding:4px 0}.attr-section.keys{border-bottom:1px solid var(--border);background:#fcd34d0a}.attr-row{display:flex;align-items:center;gap:6px;padding:3px 12px;height:26px;line-height:20px;position:relative}.attr-row.empty{color:var(--text-dim);font-style:italic}.attr-row.more{color:var(--text-dim);font-style:italic;cursor:pointer;justify-content:center;height:22px;font-size:11px}.attr-row.more:hover{color:var(--accent);background:var(--accent-soft)}.attr-row.rel-hit{background:var(--accent-soft);box-shadow:inset 2px 0 0 var(--accent)}.attr-row.rel-hit .attr-name{color:var(--accent);font-weight:600}.attr-row.rel-dim{opacity:.35}.attr-row.endpoint .attr-name{font-style:normal}.attr-port{width:8px!important;height:8px!important;opacity:0;top:50%!important}.attr-port.react-flow__handle-left{left:-5px!important}.attr-port.react-flow__handle-right{right:-5px!important}.entity-node:hover .attr-port{opacity:.5}.attr-row:hover .attr-port{opacity:1!important;background:var(--accent)!important}.attr-icon{width:14px;text-align:center;font-size:10px;flex:none}.attr-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attr-name.pk{color:var(--pk);font-weight:600}.attr-type{color:var(--text-dim);font-family:var(--mono);font-size:10px;flex:none}.attr-notnull{color:var(--text-dim);font-size:8px;flex:none}.port{width:11px!important;height:11px!important;background:var(--border-strong)!important;border:2px solid var(--bg)!important;opacity:.55;transition:transform .12s ease,background .12s ease,opacity .12s ease}.entity-node:hover .port{opacity:1;background:var(--accent)!important;transform:scale(1.25);box-shadow:0 0 0 4px var(--accent-soft);cursor:crosshair}.port:hover{transform:scale(1.6)!important;cursor:crosshair}.entity-node:hover{border-color:var(--accent);box-shadow:0 0 0 1px #e0a63a40}.react-flow__connectionline .react-flow__edge-path,.react-flow__connection-path{stroke:var(--accent)!important;stroke-width:2!important}.rel-path{stroke:var(--border-strong);stroke-width:1.6}.rel-edge{cursor:pointer}.rel-glyph{stroke:var(--border-strong);stroke-width:1.6;fill:none}.rel-glyph.ring{fill:var(--bg)}.rel-edge:hover .rel-path,.rel-edge.selected .rel-path,.rel-edge:hover .rel-glyph,.rel-edge.selected .rel-glyph{stroke:var(--accent)}.rel-edge.dimmed{opacity:.12}.rel-label{fill:var(--text);font-size:11px;text-anchor:middle;paint-order:stroke;stroke:var(--bg);stroke-width:4px}.rel-handle .rel-grip{fill:var(--accent);stroke:var(--bg);stroke-width:1;opacity:.9}.rel-handle:hover .rel-grip{opacity:1}.layout-menu-sep{height:1px;margin:4px 0;background:var(--border)}.detail-panel{position:absolute;top:12px;right:12px;bottom:12px;width:340px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.detail-header{display:flex;justify-content:space-between;align-items:flex-start}.detail-header h2{margin:0 0 6px;font-size:18px}.icon-btn{background:none;border:none;color:var(--text-dim);cursor:pointer;font-size:14px}.icon-btn:hover{color:var(--text)}.definition{color:var(--text-dim);font-size:13px;line-height:1.5}.detail-panel section{margin-top:18px}.detail-panel h3{margin:0 0 8px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.kv{display:flex;gap:8px;margin:4px 0;font-size:12px;align-items:baseline}.kv .k{color:var(--text-dim);min-width:72px}.kv .v{word-break:break-all}.chip{display:inline-block;font-size:11px;padding:2px 8px;margin:2px 4px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim)}.chip.pattern{background:var(--accent-soft);color:var(--accent)}.chip.layer-industry{background:#93c5fd26;color:#93c5fd}.chip.layer-core{background:var(--accent-soft);color:var(--accent)}.chip.layer-domain{background:#f0abfc26;color:#f0abfc}.chip.layer-specialised{background:#fcd34d26;color:var(--pk)}.cat-badge{font-size:10px;font-weight:700;margin-left:6px;padding:2px 8px;border-radius:5px;cursor:help}.cat-badge.supertype{background:#a78bfa2e;color:#a78bfa}.cat-badge.subtype{background:var(--accent-soft);color:var(--accent)}.udp-row td{padding:3px 6px;border-bottom:1px solid var(--border);font-size:12px}.udp-key{color:var(--text-dim);font-family:var(--mono);font-size:11px}.udp-val{color:var(--text)}.enum-badge{font-size:8px;font-weight:700;margin-left:6px;padding:1px 5px;border-radius:4px;background:#a78bfa2e;color:#a78bfa;vertical-align:middle;cursor:help}.key-row{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:12px}.key-badge{font-size:9px;font-weight:700;padding:2px 6px;border-radius:5px;background:#94a3b826;color:var(--text-dim);flex:none}.key-badge.pk{background:#fcd34d2e;color:var(--pk)}.key-badge.unique,.key-badge.alternate{background:var(--accent-soft);color:var(--accent)}.key-name{font-weight:600}.key-cols{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}.attr-table td{padding:4px 6px;border-bottom:1px solid var(--border)}.attr-table td:first-child{width:100%}.attr-table td:first-child .edit-input{min-width:120px}.attr-table td.pk{color:var(--pk);font-weight:600}.attr-table td.type{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table td.null{color:var(--text-dim);font-size:10px;text-align:right}.rel-link{display:flex;gap:8px;align-items:center;width:100%;background:var(--bg-card);border:1px solid var(--border);border-radius:8px;color:var(--text);padding:7px 10px;margin:4px 0;cursor:pointer;font-size:12px;text-align:left}.rel-link:hover{border-color:var(--accent)}.rel-card{color:var(--text-dim);font-family:var(--mono);font-size:11px}.ulid{font-family:var(--mono);font-size:11px;color:var(--text-dim);cursor:copy;word-break:break-all}.ulid:hover{color:var(--accent)}.splash{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--text-dim)}.splash.error pre{background:var(--bg-card);padding:12px 16px;border-radius:8px;max-width:640px;overflow:auto;color:var(--err);font-size:12px}.react-flow__minimap{background:var(--bg-raised)!important;border-radius:10px}.react-flow__controls{border-radius:10px;overflow:hidden;box-shadow:none!important}.react-flow__controls-button{background:var(--bg-raised)!important;border-bottom:1px solid var(--border)!important;fill:var(--text-dim)!important}.react-flow__controls-button:hover{fill:var(--text)!important}.edit-input{width:100%;padding:6px 9px;border-radius:7px;font-size:12px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-family:var(--font);outline:none}.edit-input:focus{border-color:var(--accent)}.entity-title-input{font-size:17px;font-weight:700;background:transparent;border-color:transparent;padding-left:0}.entity-title-input:hover,.entity-title-input:focus{border-color:var(--border);background:var(--bg-card);padding-left:9px}.definition-input{color:var(--text-dim);line-height:1.5;resize:vertical}.chip-select,.cell-select{font-size:11px;padding:2px 6px;margin:2px 6px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim);border:1px solid transparent;outline:none}.chip-select:hover,.cell-select:hover{border-color:var(--border-strong);color:var(--text)}.cell-select{border-radius:6px;background:transparent;max-width:110px}.mini-btn{font-size:11px;padding:3px 9px;border-radius:7px;cursor:pointer;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim)}.mini-btn:hover{color:var(--accent);border-color:var(--accent)}.mini-btn.danger:hover{color:var(--err);border-color:var(--err)}.h3-actions{float:right;display:inline-flex;gap:6px}.empty-hint{color:var(--text-dim);font-size:12px;font-style:italic}.add-attr{display:flex;gap:6px;margin-top:8px}.rel-row{display:flex;gap:6px;align-items:flex-start}.rel-row .rel-main{flex:1}.verb-phrases{display:flex;align-items:center;gap:4px;margin-top:2px;padding-left:4px}.verb-phrases .verb-input{font-size:11px;font-style:italic;color:var(--text-dim);min-width:40px}.verb-phrases .verb-sep{color:var(--text-dim);font-size:11px}.physical-name-row{display:flex;align-items:center;gap:6px;margin-top:2px}.physical-name-row .physical-label{font-size:9px;text-transform:uppercase;color:var(--text-dim);letter-spacing:.04em}.physical-name-input{font-size:12px;color:var(--text-dim)}.physical-col{display:block;font-size:10px;color:var(--text-dim);font-family:var(--mono, monospace)}.physical-col-input{display:block;font-size:10px;color:var(--text-dim)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#05080db3;z-index:50;display:flex;align-items:center;justify-content:center}.modal{width:440px;max-height:80vh;overflow-y:auto;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:14px;padding:20px;box-shadow:0 24px 80px #0009}.modal.wide{width:600px}.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}.modal-header h2{margin:0;font-size:16px}.modal-search{margin-bottom:10px}.modal-footer{display:flex;gap:10px;justify-content:flex-end;align-items:center;margin-top:14px}.modal-footer label{font-size:11px;color:var(--text-dim);display:flex;flex-direction:column;gap:3px}.modal-footer select,.form-row select{background:var(--bg-card);color:var(--text);border:1px solid var(--border);border-radius:7px;padding:5px 8px;font-size:12px}.primary-btn{padding:8px 16px;border-radius:8px;border:none;cursor:pointer;background:var(--accent);color:var(--accent-ink);font-weight:700;font-size:13px}.primary-btn:disabled{opacity:.4;cursor:default}.danger-btn{padding:8px 16px;border-radius:8px;border:1px solid var(--err);cursor:pointer;background:#f8717124;color:var(--err);font-weight:700;font-size:13px}.form-row{display:flex;flex-direction:column;gap:4px;margin-bottom:14px;font-size:12px;color:var(--text-dim)}.form-row>label{font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:10px}.form-error{color:var(--err);font-size:11px}.form-preview{color:var(--text-dim);font-size:11px;word-break:break-all;opacity:.85}.form-preview:before{content:""}.form-hint{color:var(--text-dim);font-size:11px;font-style:italic;opacity:.75;word-break:break-word}.term-results{display:flex;flex-direction:column;gap:8px;max-height:44vh;overflow-y:auto}.term-card{text-align:left;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:10px 12px;cursor:pointer;color:var(--text)}.term-card:hover{border-color:var(--border-strong)}.term-card.picked{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}.term-head{display:flex;justify-content:space-between;align-items:baseline}.term-label{font-weight:600;font-size:13px}.term-source{font-size:10px;color:var(--text-dim);text-transform:uppercase;letter-spacing:.06em}.term-iri{font-size:10px;color:var(--accent);display:block;margin:2px 0;word-break:break-all}.term-def{font-size:11px;color:var(--text-dim);margin:4px 0 0;line-height:1.45}.kind-badge{font-size:8px;padding:1px 5px;margin-right:6px;border-radius:999px;background:#f0abfc26;color:#f0abfc;letter-spacing:.04em}.src-picker{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}.src-chip{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:3px 9px;border-radius:999px;background:var(--bg);border:1px solid var(--border);color:var(--text-dim);cursor:pointer}.src-chip:hover{border-color:var(--border-strong);color:var(--text)}.src-chip.active{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}.src-layer{font-size:8px;padding:0 5px;border-radius:999px;text-transform:uppercase;letter-spacing:.04em}.side-panel{position:absolute;top:12px;right:12px;bottom:12px;width:380px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.side-panel h2{margin:0;font-size:16px}.side-panel h4{margin:10px 0 6px;font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.panel-body{margin-top:12px}.panel-body.ok{color:var(--ok)}.meta-line{font-size:10px;color:var(--text-dim);margin:6px 0 10px}.coverage-banner{font-size:12px;padding:8px 12px;border-radius:9px;margin-bottom:12px;background:#34d3991a;color:var(--ok)}.coverage-banner.warn{background:#fbbf241a;color:var(--warn)}.layer-band{border:1px dashed var(--border);border-radius:10px;padding:8px 12px 10px;margin-bottom:10px}.layer-band.external{border-style:solid;background:#93c5fd0a}.stack-term{display:flex;justify-content:space-between;align-items:baseline;gap:8px;width:100%;background:var(--bg-card);border:1px solid var(--border);color:var(--text);border-radius:7px;padding:5px 10px;margin:4px 0;font-size:12px;cursor:pointer;text-align:left}div.stack-term{cursor:default}.stack-term:hover{border-color:var(--border-strong)}.stack-term.uncovered{border-color:var(--err)}.align-arrow{font-size:10px;color:var(--accent);white-space:nowrap}.align-arrow.unresolved{color:var(--warn)}.align-arrow.missing{color:var(--err);font-style:italic}.align-arrow.proposed{color:var(--warn);font-style:italic}.ref-list{display:flex;flex-direction:column;gap:6px;margin-top:4px}.ref-card{border:1px solid var(--border);border-radius:8px;padding:6px 8px;background:var(--bg)}.ref-card.proposed{border-color:var(--warn)}.ref-head{display:flex;align-items:baseline;gap:8px;justify-content:space-between}.ref-uri{font-family:var(--mono);font-size:12px;word-break:break-all}.ref-status{font-size:9px;text-transform:uppercase;letter-spacing:.04em}.ref-status.accepted{color:var(--accent)}.ref-status.proposed{color:var(--warn)}.ref-meta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:5px}.ref-pill{font-size:10px;padding:1px 6px;border-radius:999px;background:var(--accent-soft);color:var(--accent)}.ref-via{font-size:10px;color:var(--text-dim)}.ref-actions{display:flex;gap:6px;margin-top:6px}.dirty-list{list-style:none;padding:0;margin:0 0 10px;font-size:12px}.dirty-list li{padding:2px 0}.dirty-state{color:var(--warn);margin-right:6px;font-family:var(--mono)}.diff-view{background:var(--bg);border:1px solid var(--border);border-radius:9px;padding:10px;font-size:10.5px;line-height:1.5;overflow:auto;max-height:42vh;font-family:var(--mono);white-space:pre;margin-bottom:10px}.diff-add{color:var(--ok)}.diff-del{color:var(--err)}.diff-hunk{color:#93c5fd}.decision{border:1px solid var(--border);border-radius:9px;padding:8px 12px;margin-bottom:8px}.decision.accepted{opacity:.65}.decision.rejected{opacity:.45}.decision-head{display:flex;gap:6px;align-items:center}.decision-mark{font-weight:700}.decision-subject{font-size:12px;margin:6px 0}.decision-actions{display:flex;gap:6px}.toast{position:absolute;bottom:20px;left:50%;transform:translate(-50%);background:var(--bg-raised);border:1px solid var(--warn);color:var(--text);border-radius:10px;padding:10px 18px;font-size:12px;z-index:60;box-shadow:0 10px 30px #00000080} +.react-flow{direction:ltr}.react-flow__container{position:absolute;width:100%;height:100%;top:0;left:0}.react-flow__pane{z-index:1;cursor:-webkit-grab;cursor:grab}.react-flow__pane.selection{cursor:pointer}.react-flow__pane.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__viewport{transform-origin:0 0;z-index:2;pointer-events:none}.react-flow__renderer{z-index:4}.react-flow__selection{z-index:6}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible{outline:none}.react-flow .react-flow__edges{pointer-events:none;overflow:visible}.react-flow__edge-path,.react-flow__connection-path{stroke:#b1b1b7;stroke-width:1;fill:none}.react-flow__edge{pointer-events:visibleStroke;cursor:pointer}.react-flow__edge.animated path{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__edge.animated path.react-flow__edge-interaction{stroke-dasharray:none;-webkit-animation:none;animation:none}.react-flow__edge.inactive{pointer-events:none}.react-flow__edge.selected,.react-flow__edge:focus,.react-flow__edge:focus-visible{outline:none}.react-flow__edge.selected .react-flow__edge-path,.react-flow__edge:focus .react-flow__edge-path,.react-flow__edge:focus-visible .react-flow__edge-path{stroke:#555}.react-flow__edge-textwrapper{pointer-events:all}.react-flow__edge-textbg{fill:#fff}.react-flow__edge .react-flow__edge-text{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__connection{pointer-events:none}.react-flow__connection .animated{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__connectionline{z-index:1001}.react-flow__nodes{pointer-events:none;transform-origin:0 0}.react-flow__node{position:absolute;-webkit-user-select:none;-moz-user-select:none;user-select:none;pointer-events:all;transform-origin:0 0;box-sizing:border-box;cursor:-webkit-grab;cursor:grab}.react-flow__node.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__nodesselection{z-index:3;transform-origin:left top;pointer-events:none}.react-flow__nodesselection-rect{position:absolute;pointer-events:all;cursor:-webkit-grab;cursor:grab}.react-flow__handle{position:absolute;pointer-events:none;min-width:5px;min-height:5px;width:6px;height:6px;background:#1a192b;border:1px solid white;border-radius:100%}.react-flow__handle.connectionindicator{pointer-events:all;cursor:crosshair}.react-flow__handle-bottom{top:auto;left:50%;bottom:-4px;transform:translate(-50%)}.react-flow__handle-top{left:50%;top:-4px;transform:translate(-50%)}.react-flow__handle-left{top:50%;left:-4px;transform:translateY(-50%)}.react-flow__handle-right{right:-4px;top:50%;transform:translateY(-50%)}.react-flow__edgeupdater{cursor:move;pointer-events:all}.react-flow__panel{position:absolute;z-index:5;margin:15px}.react-flow__panel.top{top:0}.react-flow__panel.bottom{bottom:0}.react-flow__panel.left{left:0}.react-flow__panel.right{right:0}.react-flow__panel.center{left:50%;transform:translate(-50%)}.react-flow__attribution{font-size:10px;background:#ffffff80;padding:2px 3px;margin:0}.react-flow__attribution a{text-decoration:none;color:#999}@-webkit-keyframes dashdraw{0%{stroke-dashoffset:10}}@keyframes dashdraw{0%{stroke-dashoffset:10}}.react-flow__edgelabel-renderer{position:absolute;width:100%;height:100%;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__edge.updating .react-flow__edge-path{stroke:#777}.react-flow__edge-text{font-size:10px}.react-flow__node.selectable:focus,.react-flow__node.selectable:focus-visible{outline:none}.react-flow__node-default,.react-flow__node-input,.react-flow__node-output,.react-flow__node-group{padding:10px;border-radius:3px;width:150px;font-size:12px;color:#222;text-align:center;border-width:1px;border-style:solid;border-color:#1a192b;background-color:#fff}.react-flow__node-default.selectable:hover,.react-flow__node-input.selectable:hover,.react-flow__node-output.selectable:hover,.react-flow__node-group.selectable:hover{box-shadow:0 1px 4px 1px #00000014}.react-flow__node-default.selectable.selected,.react-flow__node-default.selectable:focus,.react-flow__node-default.selectable:focus-visible,.react-flow__node-input.selectable.selected,.react-flow__node-input.selectable:focus,.react-flow__node-input.selectable:focus-visible,.react-flow__node-output.selectable.selected,.react-flow__node-output.selectable:focus,.react-flow__node-output.selectable:focus-visible,.react-flow__node-group.selectable.selected,.react-flow__node-group.selectable:focus,.react-flow__node-group.selectable:focus-visible{box-shadow:0 0 0 .5px #1a192b}.react-flow__node-group{background-color:#f0f0f040}.react-flow__nodesselection-rect,.react-flow__selection{background:#0059dc14;border:1px dotted rgba(0,89,220,.8)}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible,.react-flow__selection:focus,.react-flow__selection:focus-visible{outline:none}.react-flow__controls{box-shadow:0 0 2px 1px #00000014}.react-flow__controls-button{border:none;background:#fefefe;border-bottom:1px solid #eee;box-sizing:content-box;display:flex;justify-content:center;align-items:center;width:16px;height:16px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;padding:5px}.react-flow__controls-button:hover{background:#f4f4f4}.react-flow__controls-button svg{width:100%;max-width:12px;max-height:12px}.react-flow__controls-button:disabled{pointer-events:none}.react-flow__controls-button:disabled svg{fill-opacity:.4}.react-flow__minimap{background-color:#fff}.react-flow__minimap svg{display:block}.react-flow__resize-control{position:absolute}.react-flow__resize-control.left,.react-flow__resize-control.right{cursor:ew-resize}.react-flow__resize-control.top,.react-flow__resize-control.bottom{cursor:ns-resize}.react-flow__resize-control.top.left,.react-flow__resize-control.bottom.right{cursor:nwse-resize}.react-flow__resize-control.bottom.left,.react-flow__resize-control.top.right{cursor:nesw-resize}.react-flow__resize-control.handle{width:4px;height:4px;border:1px solid #fff;border-radius:1px;background-color:#3367d9;transform:translate(-50%,-50%)}.react-flow__resize-control.handle.left{left:0;top:50%}.react-flow__resize-control.handle.right{left:100%;top:50%}.react-flow__resize-control.handle.top{left:50%;top:0}.react-flow__resize-control.handle.bottom{left:50%;top:100%}.react-flow__resize-control.handle.top.left,.react-flow__resize-control.handle.bottom.left{left:0}.react-flow__resize-control.handle.top.right,.react-flow__resize-control.handle.bottom.right{left:100%}.react-flow__resize-control.line{border-color:#3367d9;border-width:0;border-style:solid}.react-flow__resize-control.line.left,.react-flow__resize-control.line.right{width:1px;transform:translate(-50%);top:0;height:100%}.react-flow__resize-control.line.left{left:0;border-left-width:1px}.react-flow__resize-control.line.right{left:100%;border-right-width:1px}.react-flow__resize-control.line.top,.react-flow__resize-control.line.bottom{height:1px;transform:translateY(-50%);left:0;width:100%}.react-flow__resize-control.line.top{top:0;border-top-width:1px}.react-flow__resize-control.line.bottom{border-bottom-width:1px;top:100%}.ie-wrap{position:relative;display:inline-flex;gap:6px}.erd-ico{font-size:13px;line-height:1;opacity:.85;margin-right:1px}.ie-wrap button:hover .erd-ico,.ie-wrap button.on .erd-ico,.ie-wrap button.active .erd-ico{opacity:1}.erd-caret{opacity:.55;margin-left:1px}.ie-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:30;min-width:220px;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:6px;box-shadow:0 12px 32px #00000073;display:flex;flex-direction:column;gap:2px}.ie-item{display:block;padding:8px 10px;border-radius:6px;color:var(--text);text-decoration:none;font-size:13px;cursor:pointer}.ie-item:hover{background:#5eead424;color:var(--accent)}.ie-dialect{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 10px 8px;margin-bottom:4px;border-bottom:1px solid var(--border);font-size:12px;color:var(--text-dim)}.ie-dialect select{background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;padding:3px 6px;font-size:12px}.ie-import{width:380px;padding:12px;gap:8px}.ie-tabs{display:flex;gap:4px}.ie-tab{flex:1;padding:6px 8px;border-radius:6px;font-size:12px;cursor:pointer;background:none;border:1px solid var(--border);color:var(--text-dim)}.ie-tab.active{border-color:var(--accent);color:var(--accent);background:#5eead41a}.ie-hint{font-size:11px;color:var(--text-dim);margin:0}.ie-textarea{width:100%;font-family:var(--mono);font-size:12px;resize:vertical;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:8px;padding:8px;box-sizing:border-box}.ie-textarea:focus{border-color:var(--accent);outline:none}.ie-file{font-size:11px;color:var(--text-dim)}.ie-warn{font-size:11px;color:var(--pk);margin:0}.ie-error{font-size:12px;color:var(--err);margin:0}.ie-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:4px}:root{--bg: #14110f;--bg-raised: #1c1815;--bg-card: #221d19;--border: #33291f;--border-strong: #4a3c2c;--text: #ece6dd;--text-dim: #a89a86;--accent: #e0a63a;--accent-soft: rgba(224, 166, 58, .15);--accent-ink: #241a08;--pk: #f2c14e;--err: #f0857a;--warn: #e6a94a;--ok: #6cbf73;--font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;--mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace}*{box-sizing:border-box}html,body,#root{height:100%;margin:0}body{font-family:var(--font);background:var(--bg);color:var(--text)}.app{display:flex;flex-direction:column;height:100%}.canvas-wrap{flex:1;position:relative;min-height:0}.react-flow{background:var(--bg)}.topbar{display:flex;flex-direction:column;padding:8px 16px 0;background:var(--bg-raised);border-bottom:1px solid var(--border);z-index:10}.topbar-row{display:flex;align-items:center;gap:14px}.topbar-row.context{padding-bottom:8px}.topbar-row.actions{gap:10px;padding-bottom:8px;flex-wrap:wrap}.brand{display:flex;align-items:baseline;gap:8px;white-space:nowrap}.logo{color:var(--accent);font-size:18px}.brand-name{font-weight:700;letter-spacing:.02em}.project-name{color:var(--text-dim);font-size:13px}.search{flex:0 1 300px;margin-left:auto;padding:7px 12px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-size:13px;outline:none}.search:focus{border-color:var(--accent)}.stats{display:flex;align-items:center;gap:12px;font-size:12px;color:var(--text-dim)}.stat-item{display:inline-flex;align-items:center;gap:5px}.stat-item svg{color:var(--text-dim)}.diag-chip{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:99px;font-weight:600}.diag-chip.ok{background:#34d39926;color:var(--ok)}.diag-chip.warn{background:#fbbf2426;color:var(--warn)}.diag-chip.err{background:#f8717126;color:var(--err)}.hamburger{position:relative;display:inline-flex;align-items:center;justify-content:center;padding:6px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer}.hamburger:hover{color:var(--text);border-color:var(--border-strong)}.hamburger.active{color:var(--accent);border-color:var(--accent)}.hamburger-badge{position:absolute;top:-6px;right:-6px;min-width:15px;height:15px;padding:0 3px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-size:10px;font-weight:700;line-height:15px;text-align:center}.btn-group{display:inline-flex;align-items:center;gap:2px;background:var(--bg-card);border:1px solid var(--border);border-radius:9px;padding:2px}.grp-tag{font-size:10px;color:var(--text-dim);opacity:.75;padding:0 6px 0 4px;letter-spacing:.03em;text-transform:none;white-space:nowrap}.grp-btn{display:inline-flex;align-items:center;gap:5px;padding:5px 9px;border-radius:6px;border:none;background:transparent;color:var(--text-dim);cursor:pointer;font-size:12px;white-space:nowrap}.grp-btn.icon-only{padding:5px 7px}.grp-btn:hover{color:var(--text);background:#ffffff0d}.grp-btn.active{color:var(--accent)}.grp-btn.active svg{color:var(--accent)}.grp-badge{width:6px;height:6px;border-radius:50%;background:var(--warn);display:inline-block;margin-left:1px}.dir-arrow{display:inline-flex;transition:transform .15s ease}.tool-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 11px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.tool-btn:hover{color:var(--text);border-color:var(--border-strong)}.tool-btn.active{color:var(--accent);border-color:var(--accent)}.tool-btn.primary{color:var(--accent);border-color:#e0a63a66;font-weight:600}.layout-picker{position:relative;display:inline-flex;gap:2px}.layout-picker .caret{font-size:10px}.layout-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:20;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:8px;padding:4px;min-width:150px;box-shadow:0 8px 24px #0006}.layout-menu button{display:block;width:100%;text-align:left;padding:7px 10px;border:0;border-radius:6px;background:transparent;color:var(--text-dim);cursor:pointer;font-size:13px}.layout-menu button:hover{background:var(--bg-card);color:var(--text)}.canvas-drawer{position:absolute;top:12px;left:12px;bottom:12px;width:300px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:16px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080;display:flex;flex-direction:column;gap:10px;transform:translate(calc(-100% - 16px));opacity:0;pointer-events:none;transition:transform .2s ease,opacity .2s ease}.canvas-drawer.open{transform:translate(0);opacity:1;pointer-events:auto}.drawer-header{display:flex;align-items:center;justify-content:space-between}.drawer-header h2{margin:0;font-size:15px;display:inline-flex;align-items:center;gap:7px}.drawer-header h2 svg{color:var(--accent)}.drawer-hint{font-size:11px;color:var(--text-dim);line-height:1.4}.sa-all{align-self:flex-start;padding:4px 10px;border-radius:7px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.sa-all:hover:not(:disabled){color:var(--text);border-color:var(--border-strong)}.sa-all.active{color:var(--accent);border-color:var(--accent)}.sa-all:disabled{opacity:.5;cursor:default}.sa-list{display:flex;flex-direction:column;gap:3px;margin-top:2px}.sa-row{display:flex;align-items:center;gap:9px;padding:7px 8px;border-radius:8px;cursor:pointer;border:1px solid transparent;-webkit-user-select:none;user-select:none}.sa-row:hover{background:var(--bg-card)}.sa-row.active{background:var(--accent-soft);border-color:#e0a63a66}.sa-row.muted{cursor:default;opacity:.7}.sa-row.muted:hover{background:transparent}.sa-row input[type=checkbox]{accent-color:var(--accent);cursor:pointer}.sa-chip{width:12px;height:12px;border-radius:3px;flex:0 0 auto}.sa-chip.none{background:repeating-linear-gradient(45deg,#4a3c2c,#4a3c2c 2px,transparent 2px,transparent 4px)}.sa-name{flex:1;font-size:13px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.sa-row.muted .sa-name{color:var(--text-dim)}.sa-count{font-size:11px;color:var(--text-dim);background:var(--bg-card);padding:1px 7px;border-radius:99px;flex:0 0 auto}.entity-node{width:264px;background:var(--bg-card);border:1px solid var(--border);border-top:3px solid var(--accent);border-radius:10px;overflow:hidden;box-shadow:0 4px 18px #00000059;font-size:12px;transition:opacity .15s,box-shadow .15s,border-color .15s}.entity-node.selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent),0 8px 24px #00000080}.entity-node.highlighted{box-shadow:0 0 0 2px var(--pk),0 8px 24px #00000080}.entity-node.dimmed{opacity:.18}.entity-header{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#ffffff08;border-bottom:1px solid var(--border)}.entity-name{font-weight:700;font-size:13px;letter-spacing:.01em}.entity-badges{display:flex;gap:4px}.badge{font-size:10px;padding:1px 6px;border-radius:99px;background:var(--accent-soft);color:var(--accent);text-transform:uppercase;letter-spacing:.05em}.badge.ontology{background:#93c5fd1f;color:#93c5fd}.attr-section{padding:4px 0}.attr-section.keys{border-bottom:1px solid var(--border);background:#fcd34d0a}.attr-row{display:flex;align-items:center;gap:6px;padding:3px 12px;height:26px;line-height:20px;position:relative}.attr-row.empty{color:var(--text-dim);font-style:italic}.attr-row.more{color:var(--text-dim);font-style:italic;cursor:pointer;justify-content:center;height:22px;font-size:11px}.attr-row.more:hover{color:var(--accent);background:var(--accent-soft)}.attr-row.rel-hit{background:var(--accent-soft);box-shadow:inset 2px 0 0 var(--accent)}.attr-row.rel-hit .attr-name{color:var(--accent);font-weight:600}.attr-row.rel-dim{opacity:.35}.attr-row.endpoint .attr-name{font-style:normal}.attr-port{width:8px!important;height:8px!important;opacity:0;top:50%!important}.attr-port.react-flow__handle-left{left:-5px!important}.attr-port.react-flow__handle-right{right:-5px!important}.entity-node:hover .attr-port{opacity:.5}.attr-row:hover .attr-port{opacity:1!important;background:var(--accent)!important}.attr-icon{width:14px;text-align:center;font-size:10px;flex:none}.attr-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attr-name.pk{color:var(--pk);font-weight:600}.attr-type{color:var(--text-dim);font-family:var(--mono);font-size:10px;flex:none}.attr-notnull{color:var(--text-dim);font-size:8px;flex:none}.port{width:11px!important;height:11px!important;background:var(--border-strong)!important;border:2px solid var(--bg)!important;opacity:.55;transition:transform .12s ease,background .12s ease,opacity .12s ease}.entity-node:hover .port{opacity:1;background:var(--accent)!important;transform:scale(1.25);box-shadow:0 0 0 4px var(--accent-soft);cursor:crosshair}.port:hover{transform:scale(1.6)!important;cursor:crosshair}.entity-node:hover{border-color:var(--accent);box-shadow:0 0 0 1px #e0a63a40}.react-flow__connectionline .react-flow__edge-path,.react-flow__connection-path{stroke:var(--accent)!important;stroke-width:2!important}.rel-path{stroke:var(--border-strong);stroke-width:1.6}.rel-edge{cursor:pointer}.rel-glyph{stroke:var(--border-strong);stroke-width:1.6;fill:none}.rel-glyph.ring{fill:var(--bg)}.rel-edge:hover .rel-path,.rel-edge.selected .rel-path,.rel-edge:hover .rel-glyph,.rel-edge.selected .rel-glyph{stroke:var(--accent)}.rel-edge.dimmed{opacity:.12}.rel-label{fill:var(--text);font-size:11px;text-anchor:middle;paint-order:stroke;stroke:var(--bg);stroke-width:4px}.rel-handle .rel-grip{fill:var(--accent);stroke:var(--bg);opacity:.95}.rel-handle .rel-grip-dot{fill:var(--bg)}.rel-handle:hover .rel-grip{fill:var(--accent);filter:brightness(1.15)}.layout-menu-sep{height:1px;margin:4px 0;background:var(--border)}.detail-panel{position:absolute;top:12px;right:12px;bottom:12px;width:340px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.detail-header{display:flex;justify-content:space-between;align-items:flex-start}.detail-header h2{margin:0 0 6px;font-size:18px}.icon-btn{background:none;border:none;color:var(--text-dim);cursor:pointer;font-size:14px}.icon-btn:hover{color:var(--text)}.definition{color:var(--text-dim);font-size:13px;line-height:1.5}.detail-panel section{margin-top:18px}.detail-panel h3{margin:0 0 8px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.kv{display:flex;gap:8px;margin:4px 0;font-size:12px;align-items:baseline}.kv .k{color:var(--text-dim);min-width:72px}.kv .v{word-break:break-all}.chip{display:inline-block;font-size:11px;padding:2px 8px;margin:2px 4px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim)}.chip.pattern{background:var(--accent-soft);color:var(--accent)}.chip.layer-industry{background:#93c5fd26;color:#93c5fd}.chip.layer-core{background:var(--accent-soft);color:var(--accent)}.chip.layer-domain{background:#f0abfc26;color:#f0abfc}.chip.layer-specialised{background:#fcd34d26;color:var(--pk)}.cat-badge{font-size:10px;font-weight:700;margin-left:6px;padding:2px 8px;border-radius:5px;cursor:help}.cat-badge.supertype{background:#a78bfa2e;color:#a78bfa}.cat-badge.subtype{background:var(--accent-soft);color:var(--accent)}.udp-row td{padding:3px 6px;border-bottom:1px solid var(--border);font-size:12px}.udp-key{color:var(--text-dim);font-family:var(--mono);font-size:11px}.udp-val{color:var(--text)}.enum-badge{font-size:8px;font-weight:700;margin-left:6px;padding:1px 5px;border-radius:4px;background:#a78bfa2e;color:#a78bfa;vertical-align:middle;cursor:help}.key-row{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:12px}.key-badge{font-size:9px;font-weight:700;padding:2px 6px;border-radius:5px;background:#94a3b826;color:var(--text-dim);flex:none}.key-badge.pk{background:#fcd34d2e;color:var(--pk)}.key-badge.unique,.key-badge.alternate{background:var(--accent-soft);color:var(--accent)}.key-name{font-weight:600}.key-cols{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}.attr-table td{padding:4px 6px;border-bottom:1px solid var(--border)}.attr-table td:first-child{width:100%}.attr-table td:first-child .edit-input{min-width:120px}.attr-table td.pk{color:var(--pk);font-weight:600}.attr-table td.type{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table td.null{color:var(--text-dim);font-size:10px;text-align:right}.rel-link{display:flex;gap:8px;align-items:center;width:100%;background:var(--bg-card);border:1px solid var(--border);border-radius:8px;color:var(--text);padding:7px 10px;margin:4px 0;cursor:pointer;font-size:12px;text-align:left}.rel-link:hover{border-color:var(--accent)}.rel-card{color:var(--text-dim);font-family:var(--mono);font-size:11px}.ulid{font-family:var(--mono);font-size:11px;color:var(--text-dim);cursor:copy;word-break:break-all}.ulid:hover{color:var(--accent)}.splash{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--text-dim)}.splash.error pre{background:var(--bg-card);padding:12px 16px;border-radius:8px;max-width:640px;overflow:auto;color:var(--err);font-size:12px}.react-flow__minimap{background:var(--bg-raised)!important;border-radius:10px}.react-flow__controls{border-radius:10px;overflow:hidden;box-shadow:none!important}.react-flow__controls-button{background:var(--bg-raised)!important;border-bottom:1px solid var(--border)!important;fill:var(--text-dim)!important}.react-flow__controls-button:hover{fill:var(--text)!important}.edit-input{width:100%;padding:6px 9px;border-radius:7px;font-size:12px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-family:var(--font);outline:none}.edit-input:focus{border-color:var(--accent)}.entity-title-input{font-size:17px;font-weight:700;background:transparent;border-color:transparent;padding-left:0}.entity-title-input:hover,.entity-title-input:focus{border-color:var(--border);background:var(--bg-card);padding-left:9px}.definition-input{color:var(--text-dim);line-height:1.5;resize:vertical}.chip-select,.cell-select{font-size:11px;padding:2px 6px;margin:2px 6px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim);border:1px solid transparent;outline:none}.chip-select:hover,.cell-select:hover{border-color:var(--border-strong);color:var(--text)}.cell-select{border-radius:6px;background:transparent;max-width:110px}.mini-btn{font-size:11px;padding:3px 9px;border-radius:7px;cursor:pointer;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim)}.mini-btn:hover{color:var(--accent);border-color:var(--accent)}.mini-btn.danger:hover{color:var(--err);border-color:var(--err)}.h3-actions{float:right;display:inline-flex;gap:6px}.empty-hint{color:var(--text-dim);font-size:12px;font-style:italic}.add-attr{display:flex;gap:6px;margin-top:8px}.rel-row{display:flex;gap:6px;align-items:flex-start}.rel-row .rel-main{flex:1}.verb-phrases{display:flex;align-items:center;gap:4px;margin-top:2px;padding-left:4px}.verb-phrases .verb-input{font-size:11px;font-style:italic;color:var(--text-dim);min-width:40px}.verb-phrases .verb-sep{color:var(--text-dim);font-size:11px}.physical-name-row{display:flex;align-items:center;gap:6px;margin-top:2px}.physical-name-row .physical-label{font-size:9px;text-transform:uppercase;color:var(--text-dim);letter-spacing:.04em}.physical-name-input{font-size:12px;color:var(--text-dim)}.physical-col{display:block;font-size:10px;color:var(--text-dim);font-family:var(--mono, monospace)}.physical-col-input{display:block;font-size:10px;color:var(--text-dim)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#05080db3;z-index:50;display:flex;align-items:center;justify-content:center}.modal{width:440px;max-height:80vh;overflow-y:auto;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:14px;padding:20px;box-shadow:0 24px 80px #0009}.modal.wide{width:600px}.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}.modal-header h2{margin:0;font-size:16px}.modal-search{margin-bottom:10px}.modal-footer{display:flex;gap:10px;justify-content:flex-end;align-items:center;margin-top:14px}.modal-footer label{font-size:11px;color:var(--text-dim);display:flex;flex-direction:column;gap:3px}.modal-footer select,.form-row select{background:var(--bg-card);color:var(--text);border:1px solid var(--border);border-radius:7px;padding:5px 8px;font-size:12px}.primary-btn{padding:8px 16px;border-radius:8px;border:none;cursor:pointer;background:var(--accent);color:var(--accent-ink);font-weight:700;font-size:13px}.primary-btn:disabled{opacity:.4;cursor:default}.danger-btn{padding:8px 16px;border-radius:8px;border:1px solid var(--err);cursor:pointer;background:#f8717124;color:var(--err);font-weight:700;font-size:13px}.form-row{display:flex;flex-direction:column;gap:4px;margin-bottom:14px;font-size:12px;color:var(--text-dim)}.form-row>label{font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:10px}.form-error{color:var(--err);font-size:11px}.form-preview{color:var(--text-dim);font-size:11px;word-break:break-all;opacity:.85}.form-preview:before{content:""}.form-hint{color:var(--text-dim);font-size:11px;font-style:italic;opacity:.75;word-break:break-word}.term-results{display:flex;flex-direction:column;gap:8px;max-height:44vh;overflow-y:auto}.term-card{text-align:left;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:10px 12px;cursor:pointer;color:var(--text)}.term-card:hover{border-color:var(--border-strong)}.term-card.picked{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}.term-head{display:flex;justify-content:space-between;align-items:baseline}.term-label{font-weight:600;font-size:13px}.term-source{font-size:10px;color:var(--text-dim);text-transform:uppercase;letter-spacing:.06em}.term-iri{font-size:10px;color:var(--accent);display:block;margin:2px 0;word-break:break-all}.term-def{font-size:11px;color:var(--text-dim);margin:4px 0 0;line-height:1.45}.kind-badge{font-size:8px;padding:1px 5px;margin-right:6px;border-radius:999px;background:#f0abfc26;color:#f0abfc;letter-spacing:.04em}.src-picker{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}.src-chip{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:3px 9px;border-radius:999px;background:var(--bg);border:1px solid var(--border);color:var(--text-dim);cursor:pointer}.src-chip:hover{border-color:var(--border-strong);color:var(--text)}.src-chip.active{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}.src-layer{font-size:8px;padding:0 5px;border-radius:999px;text-transform:uppercase;letter-spacing:.04em}.side-panel{position:absolute;top:12px;right:12px;bottom:12px;width:380px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.side-panel h2{margin:0;font-size:16px}.side-panel h4{margin:10px 0 6px;font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.panel-body{margin-top:12px}.panel-body.ok{color:var(--ok)}.meta-line{font-size:10px;color:var(--text-dim);margin:6px 0 10px}.coverage-banner{font-size:12px;padding:8px 12px;border-radius:9px;margin-bottom:12px;background:#34d3991a;color:var(--ok)}.coverage-banner.warn{background:#fbbf241a;color:var(--warn)}.layer-band{border:1px dashed var(--border);border-radius:10px;padding:8px 12px 10px;margin-bottom:10px}.layer-band.external{border-style:solid;background:#93c5fd0a}.stack-term{display:flex;justify-content:space-between;align-items:baseline;gap:8px;width:100%;background:var(--bg-card);border:1px solid var(--border);color:var(--text);border-radius:7px;padding:5px 10px;margin:4px 0;font-size:12px;cursor:pointer;text-align:left}div.stack-term{cursor:default}.stack-term:hover{border-color:var(--border-strong)}.stack-term.uncovered{border-color:var(--err)}.align-arrow{font-size:10px;color:var(--accent);white-space:nowrap}.align-arrow.unresolved{color:var(--warn)}.align-arrow.missing{color:var(--err);font-style:italic}.align-arrow.proposed{color:var(--warn);font-style:italic}.ref-list{display:flex;flex-direction:column;gap:6px;margin-top:4px}.ref-card{border:1px solid var(--border);border-radius:8px;padding:6px 8px;background:var(--bg)}.ref-card.proposed{border-color:var(--warn)}.ref-head{display:flex;align-items:baseline;gap:8px;justify-content:space-between}.ref-uri{font-family:var(--mono);font-size:12px;word-break:break-all}.ref-status{font-size:9px;text-transform:uppercase;letter-spacing:.04em}.ref-status.accepted{color:var(--accent)}.ref-status.proposed{color:var(--warn)}.ref-meta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:5px}.ref-pill{font-size:10px;padding:1px 6px;border-radius:999px;background:var(--accent-soft);color:var(--accent)}.ref-via{font-size:10px;color:var(--text-dim)}.ref-actions{display:flex;gap:6px;margin-top:6px}.dirty-list{list-style:none;padding:0;margin:0 0 10px;font-size:12px}.dirty-list li{padding:2px 0}.dirty-state{color:var(--warn);margin-right:6px;font-family:var(--mono)}.diff-view{background:var(--bg);border:1px solid var(--border);border-radius:9px;padding:10px;font-size:10.5px;line-height:1.5;overflow:auto;max-height:42vh;font-family:var(--mono);white-space:pre;margin-bottom:10px}.diff-add{color:var(--ok)}.diff-del{color:var(--err)}.diff-hunk{color:#93c5fd}.decision{border:1px solid var(--border);border-radius:9px;padding:8px 12px;margin-bottom:8px}.decision.accepted{opacity:.65}.decision.rejected{opacity:.45}.decision-head{display:flex;gap:6px;align-items:center}.decision-mark{font-weight:700}.decision-subject{font-size:12px;margin:6px 0}.decision-actions{display:flex;gap:6px}.toast{position:absolute;bottom:20px;left:50%;transform:translate(-50%);background:var(--bg-raised);border:1px solid var(--warn);color:var(--text);border-radius:10px;padding:10px 18px;font-size:12px;z-index:60;box-shadow:0 10px 30px #00000080} diff --git a/packages/server/src/mdl_server/static/assets/styles-SXBmvQqW.js b/packages/server/src/mdl_server/static/assets/styles-SXBmvQqW.js deleted file mode 100644 index d07c7ab..0000000 --- a/packages/server/src/mdl_server/static/assets/styles-SXBmvQqW.js +++ /dev/null @@ -1,23 +0,0 @@ -var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var be=(e,t,n)=>oc(e,typeof t!="symbol"?t+"":t,n);import{r as x,g as vi,R as A,j as h}from"./client-DOmNpTln.js";function je(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?mc:hc;Si.useSyncExternalStore=At.useSyncExternalStore!==void 0?At.useSyncExternalStore:pc;Ni.exports=Si;var gc=Ni.exports;/** - * @license React - * use-sync-external-store-shim/with-selector.production.js - * - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var Dn=x,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=Dn.useRef,_c=Dn.useEffect,Ec=Dn.useMemo,Nc=Dn.useDebugValue;Ei.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var y=o.value;if(s(y,f))return d=y}return d=f}if(y=d,wc(u,f))return y;var w=r(f);return s!==void 0&&s(y,w)?(u=f,y):(u=f,d=w)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};_i.exports=Ei;var Sc=_i.exports;const kc=vi(Sc),jc={},es=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(y=>y(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?es(e):es,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function ki(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const ts=(e,t)=>{const n=Cc(e),r=(s,i=t)=>ki(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?ts(e,t):ts;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rs.hasOwnProperty(t)?{space:rs[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===dr&&t.documentElement.namespaceURI===dr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ji(e){var t=zn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function Cr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=Cr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=M&&(M=E+1);!(C=v[M])&&++M=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Rt(this.node(),e)}function Rt(e,t){return e.style.getPropertyValue(t)||Ri(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ii(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Ti(e)}function Ti(e){this._node=e,this._names=Ii(e.getAttribute("class")||"")}Ti.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Oi(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function fr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}fr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Pn("start","drag","end"),o=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",p,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,C){if(!(u||!e.call(this,b,C))){var j=M(this,t.call(this,b,C),b,C,"mouse");j&&(Te(b.view).on("mousemove.drag",y,Ut).on("mouseup.drag",w,Ut),zi(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,j("start",b))}}function y(b){if(Ct(b),!l){var C=b.clientX-a,j=b.clientY-c;l=C*C+j*j>d}s.mouse("drag",b)}function w(b){Te(b.view).on("mousemove.drag mouseup.drag",null),Hi(b.view,l),Ct(b),s.mouse("end",b)}function v(b,C){if(e.call(this,b,C)){var j=b.changedTouches,_=t.call(this,b,C),R=j.length,S,O;for(S=0;S>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?un(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?un(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Me(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Me(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?un(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?un(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?us(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?us(t[1],t[2]/100,t[3]/100,t[4]):ss.hasOwnProperty(e)?as(ss[e]):e==="transparent"?new Me(NaN,NaN,NaN,0):null}function as(e){return new Me(e>>16&255,e>>8&255,e&255,1)}function un(e,t,n,r){return r<=0&&(e=t=n=NaN),new Me(e,t,n,r)}function Mu(e){return e instanceof rn||(e=Zt(e)),e?(e=e.rgb(),new Me(e.r,e.g,e.b,e.opacity)):new Me}function hr(e,t,n,r){return arguments.length===1?Mu(e):new Me(e,t,n,r??1)}function Me(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Mr(Me,hr,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Me(yt(this.r),yt(this.g),yt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:cs,formatHex:cs,formatHex8:Au,formatRgb:ls,toString:ls}));function cs(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function ls(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function us(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new He(e,t,n,r)}function Vi(e){if(e instanceof He)return new He(e.h,e.s,e.l,e.opacity);if(e instanceof rn||(e=Zt(e)),!e)return new He;if(e instanceof He)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new He(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Vi(e):new He(e,t,n,r??1)}function He(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Mr(He,Ru,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new He(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new He(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Me(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new He(ds(this.h),dn(this.s),dn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${ds(this.h)}, ${dn(this.s)*100}%, ${dn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ds(e){return e=(e||0)%360,e<0?e+360:e}function dn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Bi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Gi:function(t,n){return n-t?Tu(t,n,e):Bi(isNaN(t)?n:t)}}function Gi(e,t){var n=t-e;return n?Iu(e,n):Bi(isNaN(e)?t:e)}const fs=function e(t){var n=Ou(t);function r(s,i){var o=n((s=hr(s)).r,(i=hr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Gi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function it(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var mr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(mr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=mr.lastIndex=Kn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=mr.exec(e))&&(s=Kn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:it(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:it(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:it(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,y){if(l!==d||u!==m){var w=f.push(s(f)+"scale(",null,",",null,")");y.push({i:w-4,x:it(l,d)},{i:w-2,x:it(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var y=-1,w=m.length,v;++y=0&&e._call.call(void 0,t),e=e._next;--It}function ps(){bt=(Cn=Qt.now())+Hn,It=Gt=0;try{Uu()}finally{It=0,Ku(),bt=0}}function qu(){var e=Qt.now(),t=e-Cn;t>Wi&&(Hn-=t,Cn=e)}function Ku(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Yt=e,gr(r)}function gr(e){if(!It){Gt&&(Gt=clearTimeout(Gt));var t=e-bt;t>24?(e<1/0&&(Gt=setTimeout(ps,e-Qt.now()-Hn)),zt&&(zt=clearInterval(zt))):(zt||(Cn=Qt.now(),zt=setInterval(qu,Wi)),It=1,Ui(ps))}}function gs(e,t,n){var r=new $n;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Pn("start","end","cancel","interrupt"),Qu=[],Ki=0,ys=1,yr=2,vn=3,xs=4,xr=5,_n=6;function Fn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Ki})}function Rr(e,t){var n=Fe(e,t);if(n.state>Ki)throw new Error("too late; already scheduled");return n}function Xe(e,t){var n=Fe(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Fe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=qi(i,0,n.time);function i(l){n.state=ys,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ys)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return gs(o);f.state===xs?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uyr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Rr:Xe;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Fe(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Cr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Qe(e,t,n){this.k=e,this.x=t,this.y=n}Qe.prototype={constructor:Qe,scale:function(e){return e===1?this:new Qe(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Qe(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Je=new Qe(1,0,0);Qe.prototype;function Zn(e){e.stopImmediatePropagation()}function Ht(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ws(){return this.__zoom||Je}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function eo(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Xu,l=Pn("start","zoom","end"),u,d,m,f=500,y=150,w=0,v=10;function p(g){g.property("__zoom",ws).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",S).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",D).on("touchmove.zoom",V).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}p.transform=function(g,$,N,I){var L=g.selection?g.selection():g;L.property("__zoom",ws),g!==L?C(g,$,N,I):L.interrupt().each(function(){j(this,arguments).event(I).start().zoom(null,typeof $=="function"?$.apply(this,arguments):$).end()})},p.scaleBy=function(g,$,N,I){p.scaleTo(g,function(){var L=this.__zoom.k,k=typeof $=="function"?$.apply(this,arguments):$;return L*k},N,I)},p.scaleTo=function(g,$,N,I){p.transform(g,function(){var L=t.apply(this,arguments),k=this.__zoom,T=N==null?b(L):typeof N=="function"?N.apply(this,arguments):N,P=k.invert(T),z=typeof $=="function"?$.apply(this,arguments):$;return n(M(E(k,z),T,P),L,o)},N,I)},p.translateBy=function(g,$,N,I){p.transform(g,function(){return n(this.__zoom.translate(typeof $=="function"?$.apply(this,arguments):$,typeof N=="function"?N.apply(this,arguments):N),t.apply(this,arguments),o)},null,I)},p.translateTo=function(g,$,N,I,L){p.transform(g,function(){var k=t.apply(this,arguments),T=this.__zoom,P=I==null?b(k):typeof I=="function"?I.apply(this,arguments):I;return n(Je.translate(P[0],P[1]).scale(T.k).translate(typeof $=="function"?-$.apply(this,arguments):-$,typeof N=="function"?-N.apply(this,arguments):-N),k,o)},I,L)};function E(g,$){return $=Math.max(i[0],Math.min(i[1],$)),$===g.k?g:new Qe($,g.x,g.y)}function M(g,$,N){var I=$[0]-N[0]*g.k,L=$[1]-N[1]*g.k;return I===g.x&&L===g.y?g:new Qe(g.k,I,L)}function b(g){return[(+g[0][0]+ +g[1][0])/2,(+g[0][1]+ +g[1][1])/2]}function C(g,$,N,I){g.on("start.zoom",function(){j(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(I).end()}).tween("zoom",function(){var L=this,k=arguments,T=j(L,k).event(I),P=t.apply(L,k),z=N==null?b(P):typeof N=="function"?N.apply(L,k):N,B=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),X=L.__zoom,K=typeof $=="function"?$.apply(L,k):$,Q=c(X.invert(z).concat(B/X.k),K.invert(z).concat(B/K.k));return function(te){if(te===1)te=K;else{var oe=Q(te),ne=B/oe[2];te=new Qe(ne,z[0]-oe[0]*ne,z[1]-oe[1]*ne)}T.zoom(null,te)}})}function j(g,$,N){return!N&&g.__zooming||new _(g,$)}function _(g,$){this.that=g,this.args=$,this.active=0,this.sourceEvent=null,this.extent=t.apply(g,$),this.taps=0}_.prototype={event:function(g){return g&&(this.sourceEvent=g),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(g,$){return this.mouse&&g!=="mouse"&&(this.mouse[1]=$.invert(this.mouse[0])),this.touch0&&g!=="touch"&&(this.touch0[1]=$.invert(this.touch0[0])),this.touch1&&g!=="touch"&&(this.touch1[1]=$.invert(this.touch1[0])),this.that.__zoom=$,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(g){var $=Te(this.that).datum();l.call(g,this.that,new sf(g,{sourceEvent:this.sourceEvent,target:p,transform:this.that.__zoom,dispatch:l}),$)}};function R(g,...$){if(!e.apply(this,arguments))return;var N=j(this,$).event(g),I=this.__zoom,L=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,r.apply(this,arguments)))),k=ze(g);if(N.wheel)(N.mouse[0][0]!==k[0]||N.mouse[0][1]!==k[1])&&(N.mouse[1]=I.invert(N.mouse[0]=k)),clearTimeout(N.wheel);else{if(I.k===L)return;N.mouse=[k,I.invert(k)],En(this),N.start()}Ht(g),N.wheel=setTimeout(T,y),N.zoom("mouse",n(M(E(I,L),N.mouse[0],N.mouse[1]),N.extent,o));function T(){N.wheel=null,N.end()}}function S(g,...$){if(m||!e.apply(this,arguments))return;var N=g.currentTarget,I=j(this,$,!0).event(g),L=Te(g.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",B,!0),k=ze(g,N),T=g.clientX,P=g.clientY;zi(g.view),Zn(g),I.mouse=[k,this.__zoom.invert(k)],En(this),I.start();function z(X){if(Ht(X),!I.moved){var K=X.clientX-T,Q=X.clientY-P;I.moved=K*K+Q*Q>w}I.event(X).zoom("mouse",n(M(I.that.__zoom,I.mouse[0]=ze(X,N),I.mouse[1]),I.extent,o))}function B(X){L.on("mousemove.zoom mouseup.zoom",null),Hi(X.view,I.moved),Ht(X),I.event(X).end()}}function O(g,...$){if(e.apply(this,arguments)){var N=this.__zoom,I=ze(g.changedTouches?g.changedTouches[0]:g,this),L=N.invert(I),k=N.k*(g.shiftKey?.5:2),T=n(M(E(N,k),I,L),t.apply(this,$),o);Ht(g),a>0?Te(this).transition().duration(a).call(C,T,I,g):Te(this).call(p.transform,T,I,g)}}function D(g,...$){if(e.apply(this,arguments)){var N=g.touches,I=N.length,L=j(this,$,g.changedTouches.length===I).event(g),k,T,P,z;for(Zn(g),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},to=tt.error001();function de(e,t){const n=x.useContext(Vn);if(n===null)throw new Error(to);return ki(n,e,t)}const Ee=()=>{const e=x.useContext(Vn);if(e===null)throw new Error(to);return x.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Tr({position:e,children:t,className:n,style:r,...s}){const i=de(ff),o=`${e}`.split("-");return A.createElement("div",{className:je(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Tr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=x.useRef(null),[m,f]=x.useState({x:0,y:0,width:0,height:0}),y=je(["react-flow__edge-textwrapper",l]);return x.useEffect(()=>{if(d.current){const w=d.current.getBBox();f({x:w.x,y:w.y,width:w.width,height:w.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:y,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=x.memo(mf);const Or=e=>({width:e.offsetWidth,height:e.offsetHeight}),Tt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Lr=(e={x:0,y:0},t)=>({x:Tt(e.x,t[0][0],t[1][0]),y:Tt(e.y,t[0][1],t[1][1])}),bs=(e,t,n)=>en?-Tt(Math.abs(e-n),1,50)/50:0,no=(e,t)=>{const n=bs(e.x,35,t.width-35)*20,r=bs(e.y,35,t.height-35)*20;return[n,r]},ro=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},so=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Jt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),io=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),vs=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>io(so(Jt(e),Jt(t))),wr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Oe(e.width)&&Oe(e.height)&&Oe(e.x)&&Oe(e.y),Oe=e=>!isNaN(e)&&isFinite(e),xe=Symbol.for("internals"),oo=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function br(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const ao=e=>"clientX"in e,lt=(e,t)=>{var i,o;const n=ao(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Mn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},sn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Oe(n)&&Oe(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);sn.displayName="BaseEdge";function Ft(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function co({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[v,p,E]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(sn,{path:v,labelX:p,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:y,interactionWidth:w})});Dr.displayName="SimpleBezierEdge";const Es={[q.Left]:{x:-1,y:0},[q.Right]:{x:1,y:0},[q.Top]:{x:0,y:-1},[q.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=q.Bottom,target:n})=>t===q.Left||t===q.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=q.Bottom,target:n,targetPosition:r=q.Top,center:s,offset:i}){const o=Es[t],a=Es[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],y,w;const v={x:0,y:0},p={x:0,y:0},[E,M,b,C]=co({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){y=s.x??E,w=s.y??M;const _=[{x:y,y:c.y},{x:y,y:l.y}],R=[{x:c.x,y:w},{x:l.x,y:w}];o[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?R:_:f=o.y===m?_:R,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const g=Math.min(i-1,i-H);o[d]===m?v[d]=(c[d]>e[d]?-1:1)*g:p[d]=(l[d]>n[d]?-1:1)*g}}if(t!==r){const H=d==="x"?"y":"x",g=o[d]===a[H],$=c[H]>l[H],N=c[H]=V?(y=(S.x+O.x)/2,w=f[0].y):(y=f[0].x,w=(S.y+O.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:l.x+p.x,y:l.y+p.y},n],y,w,b,C]}function _f(e,t,n,r){const s=Math.min(Ns(e,t)/2,Ns(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let M="";return E>0&&E{const[p,E,M]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:w==null?void 0:w.borderRadius,offset:w==null?void 0:w.offset});return A.createElement(sn,{path:p,labelX:E,labelY:M,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:y,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const Pr=x.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:x.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Pr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=co({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const zr=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[y,w,v]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(sn,{path:y,labelX:w,labelY:v,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});zr.displayName="StraightEdge";function mn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Ss({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case q.Left:return[t-mn(t-r,i),n];case q.Right:return[t+mn(r-t,i),n];case q.Top:return[t,n-mn(n-s,i)];case q.Bottom:return[t,n+mn(s-n,i)]}}function fo({sourceX:e,sourceY:t,sourcePosition:n=q.Bottom,targetX:r,targetY:s,targetPosition:i=q.Top,curvature:o=.25}){const[a,c]=Ss({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Ss({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,y]=lo({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,y]}const In=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=q.Bottom,targetPosition:i=q.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:y,pathOptions:w,interactionWidth:v})=>{const[p,E,M]=fo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:w==null?void 0:w.curvature});return A.createElement(sn,{path:p,labelX:E,labelY:M,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:y,interactionWidth:v})});In.displayName="BezierEdge";const Hr=x.createContext(null),Nf=Hr.Provider;Hr.Consumer;const Sf=()=>x.useContext(Hr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,vr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},_r=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},ho=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},on=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return so(r,Jt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return io(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),on(e,t)),mo=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:y=!1}=u;if(o&&!f||y)return!1;const{positionAbsolute:w}=xt(u,a),v={x:w.x,y:w.y,width:d||0,height:m||0},p=wr(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,M=i&&p>0,b=(d||0)*(m||0);(E||M||p>=b||u.dragging)&&l.push(u)}),l},po=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},go=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Tt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function ks(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=lt(e),l=t.elementsFromPoint(o,a).find(y=>y.classList.contains("react-flow__handle"));if(l){const y=l.getAttribute("data-nodeid");if(y){const w=Fr(void 0,l),v=l.getAttribute("data-handleid"),p=i({nodeId:y,id:v,type:w});if(p){const E=s.find(M=>M.nodeId===y&&M.type===w&&M.id===v);return{handle:{id:v,type:w,nodeId:y,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:p}}}}let u=[],d=1/0;if(s.forEach(y=>{const w=Math.sqrt((y.x-n.x)**2+(y.y-n.y)**2);if(w<=r){const v=i(y);w<=d&&(wy.isValid),f=u.some(({handle:y})=>y.type==="target");return u.find(({handle:y,validHandleResult:w})=>f?y.type==="target":m?w.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},yo=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function xo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...yo(),handleDomNode:c};if(c){const u=Fr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),y=c.classList.contains("connectableend"),w={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=w,f&&y&&(t===vt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(w))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[xe]){const{handleBounds:o}=i[xe];let a=[],c=[];o&&(a=ks(i,o,"source",`${t}-${n}-${r}`),c=ks(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Fr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function wo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ro(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:y,onConnectStart:w,panBy:v,getNodes:p,cancelConnection:E}=i();let M=0,b;const{x:C,y:j}=lt(e),_=u==null?void 0:u.elementFromPoint(C,j),R=Fr(c,_),S=m==null?void 0:m.getBoundingClientRect();if(!S||!R)return;let O,D=lt(e,S),V=!1,H=null,g=!1,$=null;const N=If({nodes:p(),nodeId:n,handleId:t,handleType:R}),I=()=>{if(!f)return;const[T,P]=no(D,S);v({x:T,y:P}),M=requestAnimationFrame(I)};o({connectionPosition:D,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),w==null||w(e,{nodeId:n,handleId:t,handleType:R});function L(T){const{transform:P}=i();D=lt(T,S);const{handle:z,validHandleResult:B}=Af(T,u,_r(D,P,!1,[1,1]),y,N,X=>xo(X,d,n,t,s?"target":"source",a,u));if(b=z,V||(I(),V=!0),$=B.handleDomNode,H=B.connection,g=B.isValid,o({connectionPosition:b&&g?ho({x:b.x,y:b.y},P):D,connectionStatus:Tf(!!b,g),connectionEndHandle:B.endHandle}),!b&&!g&&!$)return Qn(O);H.source!==H.target&&$&&(Qn(O),O=$,$.classList.add("connecting","react-flow__handle-connecting"),$.classList.toggle("valid",g),$.classList.toggle("react-flow__handle-valid",g))}function k(T){var P,z;(b||$)&&H&&g&&(r==null||r(H)),(z=(P=i()).onConnectEnd)==null||z.call(P,T),c&&(l==null||l(T)),Qn(O),E(),cancelAnimationFrame(M),V=!1,g=!1,H=null,$=null,u.removeEventListener("mousemove",L),u.removeEventListener("mouseup",k),u.removeEventListener("touchmove",L),u.removeEventListener("touchend",k)}u.addEventListener("mousemove",L),u.addEventListener("mouseup",k),u.addEventListener("touchmove",L),u.addEventListener("touchend",k)}const js=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},bo=x.forwardRef(({type:e="source",position:t=q.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var S,O;const y=o||null,w=e==="target",v=Ee(),p=Sf(),{connectOnClick:E,noPanClassName:M}=de(Of,ke),{connecting:b,clickConnecting:C}=de(Lf(p,y,e),ke);p||(O=(S=v.getState()).onError)==null||O.call(S,"010",tt.error010());const j=D=>{const{defaultEdgeOptions:V,onConnect:H,hasDefaultEdges:g}=v.getState(),$={...V,...D};if(g){const{edges:N,setEdges:I}=v.getState();I($f($,N))}H==null||H($),a==null||a($)},_=D=>{if(!p)return;const V=ao(D);s&&(V&&D.button===0||!V)&&wo({event:D,handleId:y,nodeId:p,onConnect:j,isTarget:w,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||js}),V?u==null||u(D):d==null||d(D)},R=D=>{const{onClickConnectStart:V,onClickConnectEnd:H,connectionClickStartHandle:g,connectionMode:$,isValidConnection:N}=v.getState();if(!p||!g&&!s)return;if(!g){V==null||V(D,{nodeId:p,handleId:y,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:p,type:e,handleId:y}});return}const I=ro(D.target),L=n||N||js,{connection:k,isValid:T}=xo({nodeId:p,id:y,type:e},$,g.nodeId,g.handleId||null,g.type,L,I);T&&j(k),H==null||H(D),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":y,"data-nodeid":p,"data-handlepos":t,"data-id":`${p}-${y}-${e}`,className:je(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",M,l,{source:!w,target:w,connectable:r,connectablestart:s,connectableend:i,connecting:C,connectionindicator:r&&(s&&!b||i&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});bo.displayName="Handle";var ct=x.memo(bo);const vo=({data:e,isConnectable:t,targetPosition:n=q.Top,sourcePosition:r=q.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ct,{type:"source",position:r,isConnectable:t}));vo.displayName="DefaultNode";var Er=x.memo(vo);const _o=({data:e,isConnectable:t,sourcePosition:n=q.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ct,{type:"source",position:n,isConnectable:t}));_o.displayName="InputNode";var Eo=x.memo(_o);const No=({data:e,isConnectable:t,targetPosition:n=q.Top})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);No.displayName="OutputNode";var So=x.memo(No);const Vr=()=>null;Vr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),pn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(pn),t.selectedNodes.map(pn))&&ke(e.selectedEdges.map(pn),t.selectedEdges.map(pn))}const ko=x.memo(({onSelectionChange:e})=>{const t=Ee(),{selectedNodes:n,selectedEdges:r}=de(Df,Pf);return x.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});ko.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=de(zf);return e||t?A.createElement(ko,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Et(e,t){x.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ie(e,t,n){x.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:y,minZoom:w,maxZoom:v,nodeExtent:p,onNodesChange:E,onEdgesChange:M,elementsSelectable:b,connectionMode:C,snapGrid:j,snapToGrid:_,translateExtent:R,connectOnClick:S,defaultEdgeOptions:O,fitView:D,fitViewOptions:V,onNodesDelete:H,onEdgesDelete:g,onNodeDrag:$,onNodeDragStart:N,onNodeDragStop:I,onSelectionDrag:L,onSelectionDragStart:k,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:B,autoPanOnConnect:X,autoPanOnNodeDrag:K,onError:Q,connectionRadius:te,isValidConnection:oe,nodeDragThreshold:ne})=>{const{setNodes:re,setEdges:pe,setDefaultNodesAndEdges:ae,setMinZoom:ue,setMaxZoom:_e,setTranslateExtent:he,setNodeExtent:ye,reset:le}=de(Ff,ke),Z=Ee();return x.useEffect(()=>{const Ne=r==null?void 0:r.map(Ce=>({...Ce,...O}));return ae(n,Ne),()=>{le()}},[]),ie("defaultEdgeOptions",O,Z.setState),ie("connectionMode",C,Z.setState),ie("onConnect",s,Z.setState),ie("onConnectStart",i,Z.setState),ie("onConnectEnd",o,Z.setState),ie("onClickConnectStart",a,Z.setState),ie("onClickConnectEnd",c,Z.setState),ie("nodesDraggable",l,Z.setState),ie("nodesConnectable",u,Z.setState),ie("nodesFocusable",d,Z.setState),ie("edgesFocusable",m,Z.setState),ie("edgesUpdatable",f,Z.setState),ie("elementsSelectable",b,Z.setState),ie("elevateNodesOnSelect",y,Z.setState),ie("snapToGrid",_,Z.setState),ie("snapGrid",j,Z.setState),ie("onNodesChange",E,Z.setState),ie("onEdgesChange",M,Z.setState),ie("connectOnClick",S,Z.setState),ie("fitViewOnInit",D,Z.setState),ie("fitViewOnInitOptions",V,Z.setState),ie("onNodesDelete",H,Z.setState),ie("onEdgesDelete",g,Z.setState),ie("onNodeDrag",$,Z.setState),ie("onNodeDragStart",N,Z.setState),ie("onNodeDragStop",I,Z.setState),ie("onSelectionDrag",L,Z.setState),ie("onSelectionDragStart",k,Z.setState),ie("onSelectionDragStop",T,Z.setState),ie("noPanClassName",P,Z.setState),ie("nodeOrigin",z,Z.setState),ie("rfId",B,Z.setState),ie("autoPanOnConnect",X,Z.setState),ie("autoPanOnNodeDrag",K,Z.setState),ie("onError",Q,Z.setState),ie("connectionRadius",te,Z.setState),ie("isValidConnection",oe,Z.setState),ie("nodeDragThreshold",ne,Z.setState),Et(e,re),Et(t,pe),Et(w,ue),Et(v,_e),Et(R,he),Et(p,ye),null},Cs={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},jo="react-flow__node-desc",Co="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Xf({rfId:e}){const t=de(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Wf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${jo}-${e}`,style:Cs},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Co}-${e}`,style:Cs},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Xf,{rfId:e}))}var tn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=x.useState(!1),s=x.useRef(!1),i=x.useRef(new Set([])),[o,a]=x.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return x.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const w=Ms(f.code,a);i.current.add(f[w]),$s(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const w=Ms(f.code,a);$s(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[w]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Ms(e,t){return t.includes(e)?"code":"key"}function $o(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return $o(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[xe])==null?void 0:a.z)??0)>(n.z??0)?((c=i[xe])==null?void 0:c.z)??0:n.z??0},r)}function Mo(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=$o(r,e,{...r.position,z:((i=r[xe])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[xe].z=c,n!=null&&n[r.id]&&(r[xe].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Oe(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,xe,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[xe])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Mo(s,n,i),s}function Ao(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const y=n().filter(v=>{var E;const p=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?p&&t.nodes.some(M=>M.id===v.id):p}),w=y.every(v=>v.width&&v.height);if(y.length>0&&w){const v=on(y,d),{x:p,y:E,zoom:M}=go(v,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),b=Je.translate(p,E).scale(M);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Uf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[xe]:r[xe],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function gn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Uf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const Nt=()=>{},Kf={zoomIn:Nt,zoomOut:Nt,zoomTo:Nt,getZoom:()=>1,setViewport:Nt,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:Nt,fitBounds:Nt,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Ee(),{d3Zoom:t,d3Selection:n}=de(Zf,ke);return x.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=Je.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Ao(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=Je.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=go(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=Je.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),_r(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return _r(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=ho(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function an(){const e=Qf(),t=Ee(),n=x.useCallback(()=>t.getState().getNodes().map(w=>({...w})),[]),r=x.useCallback(w=>t.getState().nodeInternals.get(w),[]),s=x.useCallback(()=>{const{edges:w=[]}=t.getState();return w.map(v=>({...v}))},[]),i=x.useCallback(w=>{const{edges:v=[]}=t.getState();return v.find(p=>p.id===w)},[]),o=x.useCallback(w=>{const{getNodes:v,setNodes:p,hasDefaultNodes:E,onNodesChange:M}=t.getState(),b=v(),C=typeof w=="function"?w(b):w;if(E)p(C);else if(M){const j=C.length===0?b.map(_=>({type:"remove",id:_.id})):C.map(_=>({item:_,type:"reset"}));M(j)}},[]),a=x.useCallback(w=>{const{edges:v=[],setEdges:p,hasDefaultEdges:E,onEdgesChange:M}=t.getState(),b=typeof w=="function"?w(v):w;if(E)p(b);else if(M){const C=b.length===0?v.map(j=>({type:"remove",id:j.id})):b.map(j=>({item:j,type:"reset"}));M(C)}},[]),c=x.useCallback(w=>{const v=Array.isArray(w)?w:[w],{getNodes:p,setNodes:E,hasDefaultNodes:M,onNodesChange:b}=t.getState();if(M){const j=[...p(),...v];E(j)}else if(b){const C=v.map(j=>({item:j,type:"add"}));b(C)}},[]),l=x.useCallback(w=>{const v=Array.isArray(w)?w:[w],{edges:p=[],setEdges:E,hasDefaultEdges:M,onEdgesChange:b}=t.getState();if(M)E([...p,...v]);else if(b){const C=v.map(j=>({item:j,type:"add"}));b(C)}},[]),u=x.useCallback(()=>{const{getNodes:w,edges:v=[],transform:p}=t.getState(),[E,M,b]=p;return{nodes:w().map(C=>({...C})),edges:v.map(C=>({...C})),viewport:{x:E,y:M,zoom:b}}},[]),d=x.useCallback(({nodes:w,edges:v})=>{const{nodeInternals:p,getNodes:E,edges:M,hasDefaultNodes:b,hasDefaultEdges:C,onNodesDelete:j,onEdgesDelete:_,onNodesChange:R,onEdgesChange:S}=t.getState(),O=(w||[]).map($=>$.id),D=(v||[]).map($=>$.id),V=E().reduce(($,N)=>{const I=N.parentNode||N.parentId,L=!O.includes(N.id)&&I&&$.find(T=>T.id===I);return(typeof N.deletable=="boolean"?N.deletable:!0)&&(O.includes(N.id)||L)&&$.push(N),$},[]),H=M.filter($=>typeof $.deletable=="boolean"?$.deletable:!0),g=H.filter($=>D.includes($.id));if(V||g){const $=po(V,H),N=[...g,...$],I=N.reduce((L,k)=>(L.includes(k.id)||L.push(k.id),L),[]);if((C||b)&&(C&&t.setState({edges:M.filter(L=>!I.includes(L.id))}),b&&(V.forEach(L=>{p.delete(L.id)}),t.setState({nodeInternals:new Map(p)}))),I.length>0&&(_==null||_(N),S&&S(I.map(L=>({id:L,type:"remove"})))),V.length>0&&(j==null||j(V),R)){const L=V.map(k=>({id:k.id,type:"remove"}));R(L)}}},[]),m=x.useCallback(w=>{const v=yf(w),p=v?null:t.getState().nodeInternals.get(w.id);return!v&&!p?[null,null,v]:[v?w:vs(p),p,v]},[]),f=x.useCallback((w,v=!0,p)=>{const[E,M,b]=m(w);return E?(p||t.getState().getNodes()).filter(C=>{if(!b&&(C.id===M.id||!C.positionAbsolute))return!1;const j=vs(C),_=wr(j,E);return v&&_>0||_>=E.width*E.height}):[]},[]),y=x.useCallback((w,v,p=!0)=>{const[E]=m(w);if(!E)return!1;const M=wr(E,v);return p&&M>0||M>=E.width*E.height},[]);return x.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:y}),[e,n,r,s,i,o,a,c,l,u,d,f,y])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ee(),{deleteElements:r}=an(),s=tn(e,Jf),i=tn(t);x.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),x.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Ee();x.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Or(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",tt.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Br={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,yn=e=>({x:e.x,y:e.y,zoom:e.k}),St=(e,t)=>e.target.closest(`.${t}`),As=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rs=e=>{const t=e.ctrlKey&&Mn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:y,maxZoom:w,zoomActivationKeyCode:v,preventScrolling:p=!0,children:E,noWheelClassName:M,noPanClassName:b})=>{const C=x.useRef(),j=Ee(),_=x.useRef(!1),R=x.useRef(!1),S=x.useRef(null),O=x.useRef({x:0,y:0,zoom:0}),{d3Zoom:D,d3Selection:V,d3ZoomHandler:H,userSelectionActive:g}=de(rh,ke),$=tn(v),N=x.useRef(0),I=x.useRef(!1),L=x.useRef();return th(S),x.useEffect(()=>{if(S.current){const k=S.current.getBoundingClientRect(),T=eo().scaleExtent([y,w]).translateExtent(f),P=Te(S.current).call(T),z=Je.translate(m.x,m.y).scale(Tt(m.zoom,y,w)),B=[[0,0],[k.width,k.height]],X=T.constrain()(z,B,f);T.transform(P,X),T.wheelDelta(Rs),j.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[X.x,X.y,X.k],domNode:S.current.closest(".react-flow")})}},[]),x.useEffect(()=>{V&&D&&(o&&!$&&!g?V.on("wheel.zoom",k=>{if(St(k,M))return!1;k.preventDefault(),k.stopImmediatePropagation();const T=V.property("__zoom").k||1;if(k.ctrlKey&&i){const oe=ze(k),ne=Rs(k),re=T*Math.pow(2,ne);D.scaleTo(V,re,oe,k);return}const P=k.deltaMode===1?20:1;let z=c===gt.Vertical?0:k.deltaX*P,B=c===gt.Horizontal?0:k.deltaY*P;!Mn()&&k.shiftKey&&c!==gt.Vertical&&(z=k.deltaY*P,B=0),D.translateBy(V,-(z/T)*a,-(B/T)*a,{internal:!0});const X=yn(V.property("__zoom")),{onViewportChangeStart:K,onViewportChange:Q,onViewportChangeEnd:te}=j.getState();clearTimeout(L.current),I.current||(I.current=!0,t==null||t(k,X),K==null||K(X)),I.current&&(e==null||e(k,X),Q==null||Q(X),L.current=setTimeout(()=>{n==null||n(k,X),te==null||te(X),I.current=!1},150))},{passive:!1}):typeof H<"u"&&V.on("wheel.zoom",function(k,T){if(!p&&k.type==="wheel"&&!k.ctrlKey||St(k,M))return null;k.preventDefault(),H.call(this,k,T)},{passive:!1}))},[g,o,c,V,D,H,$,i,p,M,t,e,n]),x.useEffect(()=>{D&&D.on("start",k=>{var z,B;if(!k.sourceEvent||k.sourceEvent.internal)return null;N.current=(z=k.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=j.getState(),P=yn(k.transform);_.current=!0,O.current=P,((B=k.sourceEvent)==null?void 0:B.type)==="mousedown"&&j.setState({paneDragging:!0}),T==null||T(P),t==null||t(k.sourceEvent,P)})},[D,t]),x.useEffect(()=>{D&&(g&&!_.current?D.on("zoom",null):g||D.on("zoom",k=>{var P;const{onViewportChange:T}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),R.current=!!(r&&As(d,N.current??0)),(e||T)&&!((P=k.sourceEvent)!=null&&P.internal)){const z=yn(k.transform);T==null||T(z),e==null||e(k.sourceEvent,z)}}))},[g,D,e,d,r]),x.useEffect(()=>{D&&D.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=j.getState();if(_.current=!1,j.setState({paneDragging:!1}),r&&As(d,N.current??0)&&!R.current&&r(k.sourceEvent),R.current=!1,(n||T)&&nh(O.current,k.transform)){const P=yn(k.transform);O.current=P,clearTimeout(C.current),C.current=setTimeout(()=>{T==null||T(P),n==null||n(k.sourceEvent,P)},o?150:0)}})},[D,o,d,n,r]),x.useEffect(()=>{D&&D.filter(k=>{const T=$||s,P=i&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(St(k,"react-flow__node")||St(k,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||g||!l&&k.type==="dblclick"||St(k,M)&&k.type==="wheel"||St(k,b)&&(k.type!=="wheel"||o&&k.type==="wheel"&&!$)||!i&&k.ctrlKey&&k.type==="wheel"||!T&&!o&&!P&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&z})},[g,D,s,i,o,l,d,u,$]),A.createElement("div",{className:"react-flow__renderer",ref:S,style:Br},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=de(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Is(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&Is(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&Is(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ot=(e,t)=>({id:e,type:"select",selected:t});function jt(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ot(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ot(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ro=x.memo(({isSelecting:e,selectionMode:t=en.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=x.useRef(null),f=Ee(),y=x.useRef(0),w=x.useRef(0),v=x.useRef(),{userSelectionActive:p,elementsSelectable:E,dragging:M}=de(lh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),y.current=0,w.current=0},C=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,R=H=>{const{resetSelectedElements:g,domNode:$}=f.getState();if(v.current=$==null?void 0:$.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!v.current)return;const{x:N,y:I}=lt(H,v.current);g(),f.setState({userSelectionRect:{width:0,height:0,startX:N,startY:I,x:N,y:I}}),r==null||r(H)},S=H=>{const{userSelectionRect:g,nodeInternals:$,edges:N,transform:I,onNodesChange:L,onEdgesChange:k,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!g)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=lt(H,v.current),B=g.startX??0,X=g.startY??0,K={...g,x:z.xre.id),ne=te.map(re=>re.id);if(y.current!==ne.length){y.current=ne.length;const re=jt(Q,ne);re.length&&(L==null||L(re))}if(w.current!==oe.length){w.current=oe.length;const re=jt(N,oe);re.length&&(k==null||k(re))}f.setState({userSelectionRect:K})},O=H=>{if(H.button!==0)return;const{userSelectionRect:g}=f.getState();!p&&g&&H.target===m.current&&(C==null||C(H)),f.setState({nodesSelectionActive:y.current>0}),b(),s==null||s(H)},D=H=>{p&&(f.setState({nodesSelectionActive:y.current>0}),s==null||s(H)),b()},V=E&&(e||p);return A.createElement("div",{className:je(["react-flow__pane",{dragging:M,selection:e}]),onClick:V?void 0:er(C,m),onContextMenu:er(j,m),onWheel:er(_,m),onMouseEnter:V?void 0:c,onMouseDown:V?R:void 0,onMouseMove:V?S:l,onMouseUp:V?O:void 0,onMouseLeave:V?D:u,ref:m,style:Br},d,A.createElement(oh,null))});Ro.displayName="Pane";function Io(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Io(r,t):!1}function Ts(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Io(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function To(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Oe(m)&&Oe(f)&&Oe(d.width)&&Oe(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",tt.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Lr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Os=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Or(c)}})};function Vt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Nr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",tt.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Ee();return x.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Oo({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Ee(),[c,l]=x.useState(!1),u=x.useRef([]),d=x.useRef({x:null,y:null}),m=x.useRef(0),f=x.useRef(null),y=x.useRef({x:0,y:0}),w=x.useRef(null),v=x.useRef(!1),p=x.useRef(!1),E=x.useRef(!1),M=fh();return x.useEffect(()=>{if(e!=null&&e.current){const b=Te(e.current),C=({x:R,y:S})=>{const{nodeInternals:O,onNodeDrag:D,onSelectionDrag:V,updateNodePositions:H,nodeExtent:g,snapGrid:$,snapToGrid:N,nodeOrigin:I,onError:L}=a.getState();d.current={x:R,y:S};let k=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&g){const z=on(u.current,I);T=Jt(z)}if(u.current=u.current.map(z=>{const B={x:R-z.distance.x,y:S-z.distance.y};N&&(B.x=$[0]*Math.round(B.x/$[0]),B.y=$[1]*Math.round(B.y/$[1]));const X=[[g[0][0],g[0][1]],[g[1][0],g[1][1]]];u.current.length>1&&g&&!z.extent&&(X[0][0]=z.positionAbsolute.x-T.x+g[0][0],X[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+g[1][0],X[0][1]=z.positionAbsolute.y-T.y+g[0][1],X[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+g[1][1]);const K=To(z,B,O,X,I,L);return k=k||z.position.x!==K.position.x||z.position.y!==K.position.y,z.position=K.position,z.positionAbsolute=K.positionAbsolute,z}),!k)return;H(u.current,!0,!0),l(!0);const P=s?D:nr(V);if(P&&w.current){const[z,B]=tr({nodeId:s,dragItems:u.current,nodeInternals:O});P(w.current,z,B)}},j=()=>{if(!f.current)return;const[R,S]=no(y.current,f.current);if(R!==0||S!==0){const{transform:O,panBy:D}=a.getState();d.current.x=(d.current.x??0)-R/O[2],d.current.y=(d.current.y??0)-S/O[2],D({x:R,y:S})&&C(d.current)}m.current=requestAnimationFrame(j)},_=R=>{var I;const{nodeInternals:S,multiSelectionActive:O,nodesDraggable:D,unselectNodesAndEdges:V,onNodeDragStart:H,onSelectionDragStart:g}=a.getState();p.current=!0;const $=s?H:nr(g);(!o||!i)&&!O&&s&&((I=S.get(s))!=null&&I.selected||V()),s&&i&&o&&Nr({id:s,store:a,nodeRef:e});const N=M(R);if(d.current=N,u.current=uh(S,D,N,s),$&&u.current){const[L,k]=tr({nodeId:s,dragItems:u.current,nodeInternals:S});$(R.sourceEvent,L,k)}};if(t)b.on(".drag",null);else{const R=bu().on("start",S=>{const{domNode:O,nodeDragThreshold:D}=a.getState();D===0&&_(S),E.current=!1;const V=M(S);d.current=V,f.current=(O==null?void 0:O.getBoundingClientRect())||null,y.current=lt(S.sourceEvent,f.current)}).on("drag",S=>{var H,g;const O=M(S),{autoPanOnNodeDrag:D,nodeDragThreshold:V}=a.getState();if(S.sourceEvent.type==="touchmove"&&S.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&p.current&&D&&(v.current=!0,j()),!p.current){const $=O.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),N=O.ySnapped-(((g=d==null?void 0:d.current)==null?void 0:g.y)??0);Math.sqrt($*$+N*N)>V&&_(S)}(d.current.x!==O.xSnapped||d.current.y!==O.ySnapped)&&u.current&&p.current&&(w.current=S.sourceEvent,y.current=lt(S.sourceEvent,f.current),C(O))}}).on("end",S=>{if(!(!p.current||E.current)&&(l(!1),v.current=!1,p.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:O,nodeInternals:D,onNodeDragStop:V,onSelectionDragStop:H}=a.getState(),g=s?V:nr(H);if(O(u.current,!1,!1),g){const[$,N]=tr({nodeId:s,dragItems:u.current,nodeInternals:D});g(S.sourceEvent,$,N)}}}).filter(S=>{const O=S.target;return!S.button&&(!n||!Ts(O,`.${n}`,e))&&(!r||Ts(O,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,M]),c}function Lo(){const e=Ee();return x.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,y=n.isShiftPressed?4:1,w=n.x*m*y,v=n.y*f*y,p=d.map(E=>{if(E.positionAbsolute){const M={x:E.positionAbsolute.x+w,y:E.positionAbsolute.y+v};a&&(M.x=c[0]*Math.round(M.x/c[0]),M.y=c[1]*Math.round(M.y/c[1]));const{positionAbsolute:b,position:C}=To(E,M,r,s,void 0,l);E.position=C,E.positionAbsolute=b}return E});i(p,!0,!1)},[])}const Mt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Bt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:y,onDoubleClick:w,style:v,className:p,isDraggable:E,isSelectable:M,isConnectable:b,isFocusable:C,selectNodesOnDrag:j,sourcePosition:_,targetPosition:R,hidden:S,resizeObserver:O,dragHandle:D,zIndex:V,isParent:H,noDragClassName:g,noPanClassName:$,initialized:N,disableKeyboardA11y:I,ariaLabel:L,rfId:k,hasHandleBounds:T})=>{const P=Ee(),z=x.useRef(null),B=x.useRef(null),X=x.useRef(_),K=x.useRef(R),Q=x.useRef(r),te=M||E||u||d||m||f,oe=Lo(),ne=Vt(n,P.getState,d),re=Vt(n,P.getState,m),pe=Vt(n,P.getState,f),ae=Vt(n,P.getState,y),ue=Vt(n,P.getState,w),_e=le=>{const{nodeDragThreshold:Z}=P.getState();if(M&&(!j||!E||Z>0)&&Nr({id:n,store:P,nodeRef:z}),u){const Ne=P.getState().nodeInternals.get(n);Ne&&u(le,{...Ne})}},he=le=>{if(!br(le)&&!I)if(oo.includes(le.key)&&M){const Z=le.key==="Escape";Nr({id:n,store:P,unselect:Z,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Mt,le.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),oe({x:Mt[le.key].x,y:Mt[le.key].y,isShiftPressed:le.shiftKey}))};x.useEffect(()=>()=>{B.current&&(O==null||O.unobserve(B.current),B.current=null)},[]),x.useEffect(()=>{if(z.current&&!S){const le=z.current;(!N||!T||B.current!==le)&&(B.current&&(O==null||O.unobserve(B.current)),O==null||O.observe(le),B.current=le)}},[S,N,T]),x.useEffect(()=>{const le=Q.current!==r,Z=X.current!==_,Ne=K.current!==R;z.current&&(le||Z||Ne)&&(le&&(Q.current=r),Z&&(X.current=_),Ne&&(K.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const ye=Oo({nodeRef:z,disabled:S||!E,noDragClassName:g,handleSelector:D,nodeId:n,isSelectable:M,selectNodesOnDrag:j});return S?null:A.createElement("div",{className:je(["react-flow__node",`react-flow__node-${r}`,{[$]:E},p,{selected:l,selectable:M,parent:H,dragging:ye}]),ref:z,style:{zIndex:V,transform:`translate(${a}px,${c}px)`,pointerEvents:te?"all":"none",visibility:N?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:re,onMouseLeave:pe,onContextMenu:ae,onClick:_e,onDoubleClick:ue,onKeyDown:C?he:void 0,tabIndex:C?0:void 0,role:C?"button":void 0,"aria-describedby":I?void 0:`${jo}-${k}`,"aria-label":L},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:ye,dragHandle:D,zIndex:V})))};return t.displayName="NodeWrapper",x.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...on(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ee(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=de(hh,ke),u=Lo(),d=x.useRef(null);if(x.useEffect(()=>{var y;n||(y=d.current)==null||y.focus({preventScroll:!0})},[n]),Oo({nodeRef:d}),l||!s||!i)return null;const m=e?y=>{const w=r.getState().getNodes().filter(v=>v.selected);e(y,w)}:void 0,f=y=>{Object.prototype.hasOwnProperty.call(Mt,y.key)&&u({x:Mt[y.key].x,y:Mt[y.key].y,isShiftPressed:y.shiftKey})};return A.createElement("div",{className:je(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=x.memo(mh);const gh=e=>e.nodesSelectionActive,Do=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:y,onSelectionEnd:w,multiSelectionKeyCode:v,panActivationKeyCode:p,zoomActivationKeyCode:E,elementsSelectable:M,zoomOnScroll:b,zoomOnPinch:C,panOnScroll:j,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:S,panOnDrag:O,defaultViewport:D,translateExtent:V,minZoom:H,maxZoom:g,preventScrolling:$,onSelectionContextMenu:N,noWheelClassName:I,noPanClassName:L,disableKeyboardA11y:k})=>{const T=de(gh),P=tn(d),z=tn(p),B=z||O,X=z||j,K=P||m&&B!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:M,zoomOnScroll:b,zoomOnPinch:C,panOnScroll:X,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:S,panOnDrag:!P&&B,defaultViewport:D,translateExtent:V,minZoom:H,maxZoom:g,zoomActivationKeyCode:E,preventScrolling:$,noWheelClassName:I,noPanClassName:L},A.createElement(Ro,{onSelectionStart:y,onSelectionEnd:w,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:B,isSelecting:!!K,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:N,noPanClassName:L,disableKeyboardA11y:k})))};Do.displayName="FlowRenderer";var yh=x.memo(Do);function xh(e){return de(x.useCallback(n=>e?mo(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Bt(e.input||Eo),default:Bt(e.default||Er),output:Bt(e.output||So),group:Bt(e.group||Vr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Bt(e[i]||Er),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Po=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=de(vh,ke),a=xh(e.onlyRenderVisibleElements),c=x.useRef(),l=x.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return x.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Br},a.map(u=>{var C,j,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",tt.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),y=!!(u.selectable||s&&typeof u.selectable>"u"),w=!!(u.connectable||n&&typeof u.connectable>"u"),v=!!(u.focusable||r&&typeof u.focusable>"u"),p=e.nodeExtent?Lr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(p==null?void 0:p.x)??0,M=(p==null?void 0:p.y)??0,b=bh({x:E,y:M,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||q.Bottom,targetPosition:u.targetPosition||q.Top,hidden:u.hidden,xPos:E,yPos:M,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:y,isConnectable:w,isFocusable:v,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((C=u[xe])==null?void 0:C.z)??0,isParent:!!((j=u[xe])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[xe])!=null&&_.handleBounds)})}))};Po.displayName="NodeRenderer";var _h=x.memo(Po);const Eh=(e,t,n)=>n===q.Left?e-t:n===q.Right?e+t:e,Nh=(e,t,n)=>n===q.Top?e-t:n===q.Bottom?e+t:e,Ls="react-flow__edgeupdater",Ds=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:je([Ls,`${Ls}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var kt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:w,style:v,source:p,target:E,sourceX:M,sourceY:b,targetX:C,targetY:j,sourcePosition:_,targetPosition:R,elementsSelectable:S,hidden:O,sourceHandleId:D,targetHandleId:V,onContextMenu:H,onMouseEnter:g,onMouseMove:$,onMouseLeave:N,reconnectRadius:I,onReconnect:L,onReconnectStart:k,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:B,ariaLabel:X,isFocusable:K,isReconnectable:Q,pathOptions:te,interactionWidth:oe,disableKeyboardA11y:ne})=>{const re=x.useRef(null),[pe,ae]=x.useState(!1),[ue,_e]=x.useState(!1),he=Ee(),ye=x.useMemo(()=>`url('#${vr(z,B)}')`,[z,B]),le=x.useMemo(()=>`url('#${vr(P,B)}')`,[P,B]);if(O)return null;const Z=se=>{var Se;const{edges:me,addSelectedEdges:$e,unselectNodesAndEdges:W,multiSelectionActive:fe}=he.getState(),ge=me.find(dt=>dt.id===n);ge&&(S&&(he.setState({nodesSelectionActive:!1}),ge.selected&&fe?(W({nodes:[],edges:[ge]}),(Se=re.current)==null||Se.blur()):$e([n])),o&&o(se,ge))},Ne=Ft(n,he.getState,a),Ce=Ft(n,he.getState,H),ut=Ft(n,he.getState,g),Ae=Ft(n,he.getState,$),We=Ft(n,he.getState,N),Ie=(se,me)=>{if(se.button!==0)return;const{edges:$e,isValidConnection:W}=he.getState(),fe=me?E:p,ge=(me?V:D)||null,Se=me?"target":"source",dt=W||Sh,Ot=me,rt=$e.find(Pe=>Pe.id===n);_e(!0),k==null||k(se,rt,Se);const ft=Pe=>{_e(!1),T==null||T(Pe,rt,Se)};wo({event:se,handleId:ge,nodeId:fe,onConnect:Pe=>L==null?void 0:L(rt,Pe),isTarget:Ot,getState:he.getState,setState:he.setState,isValidConnection:dt,edgeUpdaterType:Se,onReconnectEnd:ft})},F=se=>Ie(se,!0),Y=se=>Ie(se,!1),G=()=>ae(!0),J=()=>ae(!1),U=!S&&!o,ee=se=>{var me;if(!ne&&oo.includes(se.key)&&S){const{unselectNodesAndEdges:$e,addSelectedEdges:W,edges:fe}=he.getState();se.key==="Escape"?((me=re.current)==null||me.blur(),$e({edges:[fe.find(Se=>Se.id===n)]})):W([n])}};return A.createElement("g",{className:je(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:pe}]),onClick:Z,onDoubleClick:Ne,onContextMenu:Ce,onMouseEnter:ut,onMouseMove:Ae,onMouseLeave:We,onKeyDown:K?ee:void 0,tabIndex:K?0:void 0,role:K?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":X===null?void 0:X||`Edge from ${p} to ${E}`,"aria-describedby":K?`${Co}-${B}`:void 0,ref:re},!ue&&A.createElement(e,{id:n,source:p,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:w,data:i,style:v,sourceX:M,sourceY:b,targetX:C,targetY:j,sourcePosition:_,targetPosition:R,sourceHandleId:D,targetHandleId:V,markerStart:ye,markerEnd:le,pathOptions:te,interactionWidth:oe}),Q&&A.createElement(A.Fragment,null,(Q==="source"||Q===!0)&&A.createElement(Ds,{position:_,centerX:M,centerY:b,radius:I,onMouseDown:F,onMouseEnter:G,onMouseOut:J,type:"source"}),(Q==="target"||Q===!0)&&A.createElement(Ds,{position:R,centerX:C,centerY:j,radius:I,onMouseDown:Y,onMouseEnter:G,onMouseOut:J,type:"target"})))};return t.displayName="EdgeWrapper",x.memo(t)};function kh(e){const t={default:kt(e.default||In),straight:kt(e.bezier||zr),step:kt(e.step||Pr),smoothstep:kt(e.step||Bn),simplebezier:kt(e.simplebezier||Dr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=kt(e[i]||In),s),n);return{...t,...r}}function Ps(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case q.Top:return{x:r+i/2,y:s};case q.Right:return{x:r+i,y:s+o/2};case q.Bottom:return{x:r+i/2,y:s+o};case q.Left:return{x:r,y:s+o/2}}}function zs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ps(n,e,t),a=Ps(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Jt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Hs(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[xe])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Oe(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),y=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),w=Math.max(((u=f==null?void 0:f[xe])==null?void 0:u.z)||0,((d=m==null?void 0:m[xe])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(y?w:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=de(x.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Fs={[An.Arrow]:Rh,[An.ArrowClosed]:Ih};function Th(e){const t=Ee();return x.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(Fs,e)?Fs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",tt.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=vr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},zo=({defaultColor:e,rfId:t})=>{const n=de(x.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};zo.displayName="MarkerDefinitions";var Dh=x.memo(zo);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ho=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:y,reconnectRadius:w,children:v,disableKeyboardA11y:p})=>{const{edgesFocusable:E,edgesUpdatable:M,elementsSelectable:b,width:C,height:j,connectionMode:_,nodeInternals:R,onError:S}=de(Ph,ke),O=Ah(t,R,n);return C?A.createElement(A.Fragment,null,O.map(({level:D,edges:V,isMaxLevel:H})=>A.createElement("svg",{key:D,style:{zIndex:D},width:C,height:j,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,V.map(g=>{const[$,N,I]=Hs(R.get(g.source)),[L,k,T]=Hs(R.get(g.target));if(!I||!T)return null;let P=g.type||"default";s[P]||(S==null||S("011",tt.error011(P)),P="default");const z=s[P]||s.default,B=_===vt.Strict?k.target:(k.target??[]).concat(k.source??[]),X=zs(N.source,g.sourceHandle),K=zs(B,g.targetHandle),Q=(X==null?void 0:X.position)||q.Bottom,te=(K==null?void 0:K.position)||q.Top,oe=!!(g.focusable||E&&typeof g.focusable>"u"),ne=g.reconnectable||g.updatable,re=typeof m<"u"&&(ne||M&&typeof ne>"u");if(!X||!K)return S==null||S("008",tt.error008(X,g)),null;const{sourceX:pe,sourceY:ae,targetX:ue,targetY:_e}=jh($,X,Q,L,K,te);return A.createElement(z,{key:g.id,id:g.id,className:je([g.className,i]),type:P,data:g.data,selected:!!g.selected,animated:!!g.animated,hidden:!!g.hidden,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,style:g.style,source:g.source,target:g.target,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerEnd:g.markerEnd,markerStart:g.markerStart,sourceX:pe,sourceY:ae,targetX:ue,targetY:_e,sourcePosition:Q,targetPosition:te,elementsSelectable:b,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:y,reconnectRadius:w,rfId:r,ariaLabel:g.ariaLabel,isFocusable:oe,isReconnectable:re,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth,disableKeyboardA11y:p})})))),v):null};Ho.displayName="EdgeRenderer";var zh=x.memo(Ho);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=de(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=an(),n=x.useRef(!1);x.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[q.Left]:q.Right,[q.Right]:q.Left,[q.Top]:q.Bottom,[q.Bottom]:q.Top},Fo=({nodeId:e,handleType:t,style:n,type:r=at.Bezier,CustomComponent:s,connectionStatus:i})=>{var j,_,R;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=de(x.useCallback(S=>({fromNode:S.nodeInternals.get(e),handleId:S.connectionHandleId,toX:(S.connectionPosition.x-S.transform[0])/S.transform[2],toY:(S.connectionPosition.y-S.transform[1])/S.transform[2],connectionMode:S.connectionMode}),[e]),ke),d=(j=o==null?void 0:o[xe])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(u===vt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(S=>S.id===a):m[0],y=f?f.x+f.width/2:(o.width??0)/2,w=f?f.y+f.height/2:o.height??0,v=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+y,p=(((R=o.positionAbsolute)==null?void 0:R.y)??0)+w,E=f==null?void 0:f.position,M=E?Bh[E]:null;if(!E||!M)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:v,fromY:p,toX:c,toY:l,fromPosition:E,toPosition:M,connectionStatus:i});let b="";const C={sourceX:v,sourceY:p,sourcePosition:E,targetX:c,targetY:l,targetPosition:M};return r===at.Bezier?[b]=fo(C):r===at.Step?[b]=Rn({...C,borderRadius:0}):r===at.SmoothStep?[b]=Rn(C):r===at.SimpleBezier?[b]=uo(C):b=`M${v},${p} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Fo.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=de(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:je(["react-flow__connection",l])},A.createElement(Fo,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Vs(e,t){return x.useRef(null),Ee(),x.useMemo(()=>t(e),[e])}const Vo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:y,onSelectionStart:w,onSelectionEnd:v,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:M,connectionLineContainerStyle:b,selectionKeyCode:C,selectionOnDrag:j,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:S,zoomActivationKeyCode:O,deleteKeyCode:D,onlyRenderVisibleElements:V,elementsSelectable:H,selectNodesOnDrag:g,defaultViewport:$,translateExtent:N,minZoom:I,maxZoom:L,preventScrolling:k,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:B,panOnScrollSpeed:X,panOnScrollMode:K,zoomOnDoubleClick:Q,panOnDrag:te,onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneScroll:ae,onPaneContextMenu:ue,onEdgeContextMenu:_e,onEdgeMouseEnter:he,onEdgeMouseMove:ye,onEdgeMouseLeave:le,onReconnect:Z,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,noDragClassName:Ae,noWheelClassName:We,noPanClassName:Ie,elevateEdgesOnSelect:F,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:J,rfId:U})=>{const ee=Vs(e,wh),se=Vs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneContextMenu:ue,onPaneScroll:ae,deleteKeyCode:D,selectionKeyCode:C,selectionOnDrag:j,selectionMode:_,onSelectionStart:w,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:S,zoomActivationKeyCode:O,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:Q,panOnScroll:B,panOnScrollSpeed:X,panOnScrollMode:K,panOnDrag:te,defaultViewport:$,translateExtent:N,minZoom:I,maxZoom:L,onSelectionContextMenu:y,preventScrolling:k,noDragClassName:Ae,noWheelClassName:We,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:V,onEdgeContextMenu:_e,onEdgeMouseEnter:he,onEdgeMouseMove:ye,onEdgeMouseLeave:le,onReconnect:Z,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!F,disableKeyboardA11y:Y,rfId:U},A.createElement(Yh,{style:E,type:p,component:M,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:ee,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:g,onlyRenderVisibleElements:V,noPanClassName:Ie,noDragClassName:Ae,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:J,rfId:U})))};Vo.displayName="GraphView";var Xh=x.memo(Vo);const Sr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],st={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Sr,nodeExtent:Sr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:vt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Wh=()=>Rc((e,t)=>({...st,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Jn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((w,v)=>{const p=s.get(v.id);if(p!=null&&p.hidden)s.set(p.id,{...p,[xe]:{...p[xe],handleBounds:void 0}});else if(p){const E=Or(v.nodeElement);!!(E.width&&E.height&&(p.width!==E.width||p.height!==E.height||v.forceUpdate))&&(s.set(p.id,{...p,[xe]:{...p[xe],handleBounds:{source:Os(".source",v.nodeElement,m,l),target:Os(".target",v.nodeElement,m,l)}},...E}),w.push({id:p.id,type:"dimensions",dimensions:E}))}return w},[]);Mo(s,l);const y=o||i&&!o&&Ao(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:y}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Jn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(i(),n),a=jt(s,[])),gn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(s,n),a=jt(i(),[])),gn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ot(u.id,!1))),l=a.map(u=>ot(u.id,!1));gn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ot(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ot(a.id,!1));gn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Lr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=Je.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:st.connectionNodeId,connectionHandleId:st.connectionHandleId,connectionHandleType:st.connectionHandleType,connectionStatus:st.connectionStatus,connectionStartHandle:st.connectionStartHandle,connectionEndHandle:st.connectionEndHandle}),reset:()=>e({...st})}),Object.is),Bo=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Wh()),A.createElement(df,{value:t.current},e)};Bo.displayName="ReactFlowProvider";const Go=({children:e})=>x.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Bo,null,e);Go.displayName="ReactFlowWrapper";const Uh={input:Eo,default:Er,output:So,group:Vr},qh={default:In,straight:zr,step:Pr,smoothstep:Bn,simplebezier:Dr},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Yo=x.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Uh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:y,onConnectEnd:w,onClickConnectStart:v,onClickConnectEnd:p,onNodeMouseEnter:E,onNodeMouseMove:M,onNodeMouseLeave:b,onNodeContextMenu:C,onNodeDoubleClick:j,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:S,onNodesDelete:O,onEdgesDelete:D,onSelectionChange:V,onSelectionDragStart:H,onSelectionDrag:g,onSelectionDragStop:$,onSelectionContextMenu:N,onSelectionStart:I,onSelectionEnd:L,connectionMode:k=vt.Strict,connectionLineType:T=at.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:B,deleteKeyCode:X="Backspace",selectionKeyCode:K="Shift",selectionOnDrag:Q=!1,selectionMode:te=en.Full,panActivationKeyCode:oe="Space",multiSelectionKeyCode:ne=Mn()?"Meta":"Control",zoomActivationKeyCode:re=Mn()?"Meta":"Control",snapToGrid:pe=!1,snapGrid:ae=Zh,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:_e=!0,nodesDraggable:he,nodesConnectable:ye,nodesFocusable:le,nodeOrigin:Z=Kh,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,defaultViewport:Ae=Qh,minZoom:We=.5,maxZoom:Ie=2,translateExtent:F=Sr,preventScrolling:Y=!0,nodeExtent:G,defaultMarkerColor:J="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:ee=!0,panOnScroll:se=!1,panOnScrollSpeed:me=.5,panOnScrollMode:$e=gt.Free,zoomOnDoubleClick:W=!0,panOnDrag:fe=!0,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,children:Lt,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ce,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:Zr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Xa,defaultEdgeOptions:Wa,elevateNodesOnSelect:Ua=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Qr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Jr,nodeDragThreshold:nc,...rc},sc)=>{const Xn=Jr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:je(["react-flow",s]),"data-testid":"rf__wrapper",id:Jr},A.createElement(Go,null,A.createElement(Xh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:M,onNodeMouseLeave:b,onNodeContextMenu:C,onNodeDoubleClick:j,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:B,selectionKeyCode:K,selectionOnDrag:Q,selectionMode:te,deleteKeyCode:X,multiSelectionKeyCode:ne,panActivationKeyCode:oe,zoomActivationKeyCode:re,onlyRenderVisibleElements:ue,selectNodesOnDrag:_e,defaultViewport:Ae,translateExtent:F,minZoom:We,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:U,zoomOnPinch:ee,zoomOnDoubleClick:W,panOnScroll:se,panOnScrollSpeed:me,panOnScrollMode:$e,panOnDrag:fe,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,onSelectionContextMenu:N,onSelectionStart:I,onSelectionEnd:L,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ce,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:J,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:Zr,elevateEdgesOnSelect:qa,rfId:Xn,disableKeyboardA11y:Qr,nodeOrigin:Z,nodeExtent:G}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:y,onConnectEnd:w,onClickConnectStart:v,onClickConnectEnd:p,nodesDraggable:he,nodesConnectable:ye,nodesFocusable:le,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,elevateNodesOnSelect:Ua,minZoom:We,maxZoom:Ie,nodeExtent:G,onNodesChange:Pa,onEdgesChange:za,snapToGrid:pe,snapGrid:ae,connectionMode:k,translateExtent:F,connectOnClick:Ga,defaultEdgeOptions:Wa,fitView:Va,fitViewOptions:Ba,onNodesDelete:O,onEdgesDelete:D,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:S,onSelectionDrag:g,onSelectionDragStart:H,onSelectionDragStop:$,noPanClassName:Zr,nodeOrigin:Z,rfId:Xn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:V}),Lt,A.createElement(hf,{proOptions:Xa,position:Ya}),A.createElement(Wf,{rfId:Xn,disableKeyboardA11y:Qr})))});Yo.displayName="ReactFlow";const Xo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:y,backgroundColor:w}=i||{},v=o||y||w;return A.createElement("rect",{className:je(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?p=>m(p,e):void 0})};Xo.displayName="MiniMapNode";var em=x.memo(Xo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=de(nm,ke),c=de(tm),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:y,y:w}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:y,y:w,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=x.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(on(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:y=!1,zoomable:w=!1,ariaLabel:v="React Flow mini map",inversePan:p=!1,zoomStep:E=10,offsetScale:M=5}){const b=Ee(),C=x.useRef(null),{boundingRect:j,viewBB:_,rfId:R}=de(am,ke),S=(e==null?void 0:e.width)??im,O=(e==null?void 0:e.height)??om,D=j.width/S,V=j.height/O,H=Math.max(D,V),g=H*S,$=H*O,N=M*H,I=j.x-(g-j.width)/2-N,L=j.y-($-j.height)/2-N,k=g+N*2,T=$+N*2,P=`${cm}-${R}`,z=x.useRef(0);z.current=H,x.useEffect(()=>{if(C.current){const K=Te(C.current),Q=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ae}=b.getState();if(ne.sourceEvent.type!=="wheel"||!pe||!ae)return;const ue=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,_e=re[2]*Math.pow(2,ue);ae.scaleTo(pe,_e)},te=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ae,translateExtent:ue,width:_e,height:he}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!pe||!ae)return;const ye=z.current*Math.max(1,re[2])*(p?-1:1),le={x:re[0]-ne.sourceEvent.movementX*ye,y:re[1]-ne.sourceEvent.movementY*ye},Z=[[0,0],[_e,he]],Ne=Je.translate(le.x,le.y).scale(re[2]),Ce=ae.constrain()(Ne,Z,ue);ae.transform(pe,Ce)},oe=eo().on("zoom",y?te:null).on("zoom.wheel",w?Q:null);return K.call(oe),()=>{K.on("zoom",null)}}},[y,w,p,E]);const B=m?K=>{const Q=ze(K);m(K,{x:Q[0],y:Q[1]})}:void 0,X=f?(K,Q)=>{const te=b.getState().nodeInternals.get(Q);f(K,te)}:void 0;return A.createElement(Tr,{position:d,style:e,className:je(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:S,height:O,viewBox:`${I} ${L} ${k} ${T}`,role:"img","aria-labelledby":P,ref:C,onClick:B},v&&A.createElement("title",{id:P},v),A.createElement(sm,{onClick:X,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${I-N},${L-N}h${k+N*2}v${T+N*2}h${-k-N*2}z - M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Wo.displayName="MiniMap";var lm=x.memo(Wo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Xt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:je(["react-flow__controls-button",t]),...n},e);Xt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ee(),[f,y]=x.useState(!1),{isInteractive:w,minZoomReached:v,maxZoomReached:p}=de(pm,ke),{zoomIn:E,zoomOut:M,fitView:b}=an();if(x.useEffect(()=>{y(!0)},[]),!f)return null;const C=()=>{E(),i==null||i()},j=()=>{M(),o==null||o()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!w,nodesConnectable:!w,elementsSelectable:!w}),c==null||c(!w)};return A.createElement(Tr,{className:je(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Xt,{onClick:C,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:p},A.createElement(um,null)),A.createElement(Xt,{onClick:j,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(dm,null))),n&&A.createElement(Xt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Xt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},w?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=x.memo(Uo),Le;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Le||(Le={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[Le.Dots]:"#91919a",[Le.Lines]:"#eee",[Le.Cross]:"#e2e2e2"},bm={[Le.Dots]:1,[Le.Lines]:1,[Le.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function qo({id:e,variant:t=Le.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=x.useRef(null),{transform:u,patternId:d}=de(vm,ke),m=o||wm[t],f=r||bm[t],y=t===Le.Dots,w=t===Le.Cross,v=Array.isArray(n)?n:[n,n],p=[v[0]*u[2]||1,v[1]*u[2]||1],E=f*u[2],M=w?[E,E]:p,b=y?[E/i,E/i]:[M[0]/i,M[1]/i];return A.createElement("svg",{className:je(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%p[0],y:u[1]%p[1],width:p[0],height:p[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},y?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:M,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}qo.displayName="Background";var _m=x.memo(qo);const Gr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Gr+e}async function we(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function nt(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new Ko(r.error??`${e}: ${n.status}`,n.status);return r}class Ko extends Error{constructor(n,r){super(n);be(this,"status");this.status=r}}const Cx=e=>we(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),$x=()=>we("/api/diagnostics"),Zo=(e,t)=>we(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Qo=()=>we("/api/ontology/ontologies"),Em=e=>we(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>we("/api/ontology/stack"),Sm=()=>we("/api/ontology/coverage"),km=(e,t,n)=>nt("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>we("/api/git/status"),Cm=()=>we("/api/git/diff"),$m=e=>nt("/api/git/commit",{message:e}),Mm=()=>nt("/api/git/discard",{}),Am=()=>we("/api/decisions"),Bs=(e,t)=>nt(`/api/decisions/${e}/verdict`,{verdict:t}),Mx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),we(`/api/glossary/terms?${t.toString()}`)},Ax=()=>we("/api/glossary/config"),Rx=e=>nt("/api/git/propose",e),Ix=(e="HEAD")=>we(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Tx=(e="HEAD")=>we(`/api/git/classify?base=${encodeURIComponent(e)}`),Ox=e=>nt("/api/git/classify",{changes:e}),Lx=e=>we(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Dx=(e="")=>we(`/api/git/context?user=${encodeURIComponent(e)}`),Px=(e="")=>we(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>we("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Gr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>nt("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>nt("/api/import/preview",{format:e,content:t}),zx=e=>we(`/api/import/stash/${encodeURIComponent(e)}`),Hx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Fx=(e,t,n)=>fetch(`${Gr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new Ko(await r.text(),r.status);return await r.json()}),Vx=()=>we("/api/glossary/subject-areas"),Bx=e=>we(`/api/glossary/subject-area/${e}`),Gx=(e,t)=>nt(`/api/glossary/subject-area/${e}/expand`,t);function Yx(){return{async load(e){try{const t=await we(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Yr="__entity_source",Xr="__entity_target",Pm=x.memo(function({data:t,selected:n}){var j;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:y}=t,w=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>w(_.a)-w(R.a)||_.i-R.i).map(_=>_.a),p=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const M=!!c&&!l;let b=0;if(M){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const C=(_,R)=>{const S="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:S,onMouseEnter:y?()=>y(_.id):void 0,onMouseLeave:y?()=>y(null):void 0,children:[h.jsx(ct,{id:_.id,type:"target",position:q.Left,className:"port attr-port"}),h.jsx(ct,{id:_.id,type:"source",position:q.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ct,{id:Xr,type:"target",position:q.Left,className:"port"}),h.jsx(ct,{id:Yr,type:"source",position:q.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((j=r.conceptual)==null?void 0:j.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var S;const _=(((S=r.conceptual)==null?void 0:S.ontology_refs)??[]).filter(O=>O.uri);if(_.length===0)return null;const R=_.map(O=>O.uri).join(` -`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),p.length>0&&h.jsx("div",{className:"attr-section keys",children:p.map(_=>C(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>C(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,y,w,v,p,E,M,b,C,j,_,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(S=>S.from.entity===e.id||S.to.entity===e.id),d=S=>{var O;return((O=t.entities.find(D=>D.id===S))==null?void 0:O.name)??S};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Ke,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:S=>r("rename_entity",{id:e.id,name:S})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Ke,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:S=>r("rename_entity",{id:e.id,physical_name:S})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Ke,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:S=>r("set_definition",{id:e.id,definition:S})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((y=l==null?void 0:l.ontology_refs)==null?void 0:y.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(w=e.term_map)!=null&&w.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((p=e.term_map)==null?void 0:p.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),(M=e.term_map)!=null&&M.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[((C=e.term_map)==null?void 0:C.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Ke,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:S=>{var O;return r("set_stewardship",{id:e.id,owner:S,steward:((O=l==null?void 0:l.stewardship)==null?void 0:O.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Ke,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:S=>{var O;return r("set_stewardship",{id:e.id,owner:((O=l==null?void 0:l.stewardship)==null?void 0:O.owner)??null,steward:S})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(S=>h.jsx(Xm,{a:S,entity:e,doc:t,readOnly:c,exec:r},S.id))})}),!c&&h.jsx(Wm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(S=>{const O=S.members.map(D=>{var V;return((V=e.attributes.find(H=>H.id===D))==null?void 0:V.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+S.type,children:S.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:S.name}),h.jsx("span",{className:"key-cols",children:O})]},S.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([S,O])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:S}),h.jsx("td",{className:"udp-val",children:String(O)})]},S))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(S=>{const O=S.from.entity===e.id?S.to.entity:S.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(O),children:[h.jsx("span",{className:"rel-card",children:Um(S,e.id)}),d(O)]}),(S.verb_phrase||S.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Ke,{value:S.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:D=>r("update_relationship",{id:S.id,verb_phrase:D})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Ke,{value:S.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:D=>r("update_relationship",{id:S.id,inverse_verb_phrase:D})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${S.name}`,onClick:()=>r("delete_relationship",{id:S.id}),children:"✕"})]},S.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var S;return(S=navigator.clipboard)==null?void 0:S.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Ke({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=x.useState(e);x.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Xm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Ke,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Ke,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Wm({entity:e,exec:t}){const[n,r]=x.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Um(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Gs="";let Km=class{constructor(t){be(this,"_isDirected",!0);be(this,"_isMultigraph",!1);be(this,"_isCompound",!1);be(this,"_label");be(this,"_defaultNodeLabelFn",()=>{});be(this,"_defaultEdgeLabelFn",()=>{});be(this,"_nodes",{});be(this,"_in",{});be(this,"_preds",{});be(this,"_out",{});be(this,"_sucs",{});be(this,"_edgeObjs",{});be(this,"_edgeLabels",{});be(this,"_nodeCount",0);be(this,"_edgeCount",0);be(this,"_parent");be(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Ys(this._preds[n],t),Ys(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Xs(this._preds[n],t),Xs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Ys(e,t){e[t]?e[t]++:e[t]=1}function Xs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Gs+i+Gs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function sr(e,t){return Wt(e,t.v,t.w,t.name)}var Wr=Km,Qm="2.2.4",Jm={Graph:Wr,version:Qm},ep=Wr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){be(this,"_arr",[]);be(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=ea,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ta=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ta,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),ia(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),ia(t(i),o=>s.push(o)))}}function ia(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=sa,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=sa,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Wr,Lp=Jo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:ea,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ta,topsort:ra},Us=Jm,Ve={Graph:Us.Graph,json:tp,alg:zp,version:Us.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return qs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&qs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function qs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ve.Graph,Gp=Vp;var Yp=Wp;let Xp=()=>1;function Wp(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Xp);return Up(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Up(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)ir(e,t,n,o);for(;o=s.dequeue();)ir(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(ir(e,t,n,o,!0));break}}}return r}function ir(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,jr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,jr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{jr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function jr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new oa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=da(la(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),aa(e,"border",s,t)}function og(e,t=ca){const n=[];for(let r=0;rca){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function la(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function ua(e){var t=++ug;return e+(""+t)}function da(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Ur(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=ve.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=ve;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=ve;var Yn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ve.Graph,On=Yn.slack,fa=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!On(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=On(t,s)),it.node(r).rank+=n)}var Rg=fa,Ks=Yn.slack,Ig=Yn.longestPath,Tg=Ve.alg.preorder,Og=Ve.alg.postorder,Lg=ve.simplify,Dg=_t;_t.initLowLimValues=Kr;_t.initCutValues=qr;_t.calcCutValue=ha;_t.leaveEdge=pa;_t.enterEdge=ga;_t.exchangeEdges=ya;function _t(e){e=Lg(e),Ig(e);var t=Rg(e);Kr(t),qr(t,e);for(var n,r;n=pa(t);)r=ga(t,e,n),ya(t,e,n,r)}function qr(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ha(e,t,n)}function ha(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Kr(e,t){arguments.length<2&&(t=e.nodes()[0]),ma(e,{},1,t)}function ma(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ma(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function pa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ga(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===Zs(e,e.node(u.v),a)&&c!==Zs(e,e.node(u.w),a));return l.reduce((u,d)=>Ks(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function Zs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Yn,xa=Fg.longestPath,Vg=fa,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Qs(e);break;case"tight-tree":Wg(e);break;case"longest-path":Xg(e);break;case"none":break;default:Qs(e)}}var Xg=xa;function Wg(e){xa(e),Vg(e)}function Qs(e){Bg(e)}var Ug=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Ln=ve;var Qg={run:Jg,cleanup:n0};function Jg(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=e0(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=t0(e)+1;e.children().forEach(a=>wa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function wa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{wa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,y=m.borderBottom?m.borderBottom:d,w=m.borderTop?r:2*r,v=f!==y?1:s-i[o]+1;e.setEdge(c,f,{weight:w,minlen:v,nestingEdge:!0}),e.setEdge(y,l,{weight:w,minlen:v,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function e0(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function t0(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function n0(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let r0=ve;var s0=i0;function i0(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iei(e.node(t))),e.edges().forEach(t=>ei(e.edge(t)))}function ei(e){let t=e.width;e.width=e.height,e.height=t}function l0(e){e.nodes().forEach(t=>or(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(or),Object.hasOwn(n,"y")&&or(n)})}function or(e){e.y=-e.y}function u0(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let ti=ve;var d0=f0;function f0(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=ti.applyWithChunking(Math.max,r),i=ti.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let h0=ve.zipObject;var m0=p0;function p0(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var y0=x0;function x0(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let w0=ve;var b0=v0;function v0(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _0(r)}function _0(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&E0(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>w0.pick(s,["vs","i","barycenter","weight"]))}function E0(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let N0=ve;var S0=k0;function k0(e,t){let n=N0.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(j0(!!t)),c=ni(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ni(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ni(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function j0(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let C0=y0,$0=b0,M0=S0;var A0=va;function va(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=C0(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=va(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&I0(m,f)}});let u=$0(l,n);R0(u,c);let d=M0(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function R0(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function I0(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let T0=Ve.Graph,O0=ve;var L0=D0;function D0(e,t,n,r){r||(r=e.nodes());let s=P0(e),i=new T0({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function P0(e){for(var t;e.hasNode(t=O0.uniqueId("_root")););return t}var z0=H0;function H0(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let F0=d0,V0=m0,B0=A0,G0=L0,Y0=z0,X0=Ve.Graph,xn=ve;var W0=_a;function _a(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,_a);return}let n=xn.maxRank(e),r=ri(e,xn.range(1,n+1),"inEdges"),s=ri(e,xn.range(n-1,-1,-1),"outEdges"),i=F0(e);if(si(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){U0(c%2?r:s,c%4>=2),i=xn.buildLayerMatrix(e);let u=V0(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return G0(e,i,n,r.get(i)||[])})}function U0(e,t){let n=new X0;e.forEach(function(r){let s=r.graph().root,i=B0(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Y0(r,n,i.vs)})}function si(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let q0=Ve.Graph,Ze=ve;var K0={positionX:ay};function Z0(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=J0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(y=>{e.predecessors(y).forEach(w=>{let v=e.node(w),p=v.order;(p{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&Ea(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function J0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ea(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function ey(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function ty(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let y=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((y,w)=>Math.min(y,i[w.w]-o.edge(w)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function ry(e,t,n,r){let s=new q0,i=e.graph(),o=cy(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function sy(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=ly(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-Ze.applyWithChunking(Math.min,l);o!=="l"&&(u=s-Ze.applyWithChunking(Math.max,l)),u&&(e[a]=Ze.mapValues(c,d=>d+u))})})}function oy(e,t){return Ze.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function ay(e){let t=Ze.buildLayerMatrix(e),n=Object.assign(Z0(e,t),Q0(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=ty(e,s,n,c),u=ny(e,s,l.root,l.align,a==="r");a==="r"&&(u=Ze.mapValues(u,d=>-d)),r[o+a]=u})});let i=sy(e,r);return iy(r,i),oy(r,e.graph().align)}function cy(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function ly(e,t){return e.node(t).width}let Na=ve,uy=K0.positionX;var dy=fy;function fy(e){e=Na.asNonCompoundGraph(e),hy(e),Object.entries(uy(e)).forEach(([t,n])=>e.node(t).x=n)}function hy(e){let t=Na.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ii=pg,oi=bg,my=Gg,py=ve.normalizeRanks,gy=Ug,yy=ve.removeEmptyRanks,ai=Qg,xy=s0,ci=o0,wy=W0,by=dy,De=ve,vy=Ve.Graph;var _y=Ey;function Ey(e,t){let n=t&&t.debugTiming?De.time:De.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>Iy(e));n(" runLayout",()=>Ny(r,n,t)),n(" updateInputGraph",()=>Sy(e,r))})}function Ny(e,t,n){t(" makeSpaceForEdgeLabels",()=>Ty(e)),t(" removeSelfEdges",()=>By(e)),t(" acyclic",()=>ii.run(e)),t(" nestingGraph.run",()=>ai.run(e)),t(" rank",()=>my(De.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Oy(e)),t(" removeEmptyRanks",()=>yy(e)),t(" nestingGraph.cleanup",()=>ai.cleanup(e)),t(" normalizeRanks",()=>py(e)),t(" assignRankMinMax",()=>Ly(e)),t(" removeEdgeLabelProxies",()=>Dy(e)),t(" normalize.run",()=>oi.run(e)),t(" parentDummyChains",()=>gy(e)),t(" addBorderSegments",()=>xy(e)),t(" order",()=>wy(e,n)),t(" insertSelfEdges",()=>Gy(e)),t(" adjustCoordinateSystem",()=>ci.adjust(e)),t(" position",()=>by(e)),t(" positionSelfEdges",()=>Yy(e)),t(" removeBorderNodes",()=>Vy(e)),t(" normalize.undo",()=>oi.undo(e)),t(" fixupEdgeLabelCoords",()=>Hy(e)),t(" undoCoordinateSystem",()=>ci.undo(e)),t(" translateGraph",()=>Py(e)),t(" assignNodeIntersects",()=>zy(e)),t(" reversePoints",()=>Fy(e)),t(" acyclic.undo",()=>ii.undo(e))}function Sy(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let ky=["nodesep","edgesep","ranksep","marginx","marginy"],jy={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Cy=["acyclicer","ranker","rankdir","align"],$y=["width","height","rank"],li={width:0,height:0},My=["minlen","weight","width","height","labeloffset"],Ay={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ry=["labelpos"];function Iy(e){let t=new vy({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},jy,cr(n,ky),De.pick(n,Cy))),e.nodes().forEach(r=>{let s=lr(e.node(r));const i=cr(s,$y);Object.keys(li).forEach(o=>{i[o]===void 0&&(i[o]=li[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},Ay,cr(s,My),De.pick(s,Ry)))}),t}function Ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Oy(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};De.addDummyNode(e,"edge-proxy",i,"_ep")}})}function Ly(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Dy(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Py(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function zy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(De.intersectRect(r,i)),n.points.push(De.intersectRect(s,o))})}function Hy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Fy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Vy(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function By(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Gy(e){var t=De.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{De.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Yy(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return De.mapValues(De.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Xy=ve,Wy=Ve.Graph;var Uy={debugOrdering:qy};function qy(e){let t=Xy.buildLayerMatrix(e),n=new Wy({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var Ky="1.1.8",Zy={graphlib:Ve,layout:_y,debug:Uy,util:{time:ve.time,notime:ve.notime},version:Ky};const ui=vi(Zy),Ye=264,Qy=44,Jy=26,ex=14;function wt(e){const t=Math.max(e.attributes.length,1);return Qy+t*Jy+ex}const tx=40;function ur(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?mi(e,n,o):r==="clustered"?hi(e,t,n,o,i):r==="hierarchical"||e.length<=tx?di(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?hi(e,t,n,o,i):mi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Sa(e,t,n,r=!1,s="LR"){const i=new ui.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Ye,height:d?wt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ui.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?wt(m):120,y=d.x-Ye/2,w=d.y-f/2;return a=Math.max(a,y+Ye),c=Math.max(c,w+f),{...u,position:{x:y,y:w}}}),width:a,height:c}}function di(e,t,n,r="LR"){return Sa(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?wt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Ye+ka);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Ye)}),i+=Math.max(...c.map(l=>n(l.id)))+ja}return{nodes:s,width:o,height:i}}const fi=120;function hi(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),y=new Set(f.map(E=>E.id));let w=0;for(const E of t)y.has(E.source)&&y.has(E.target)&&w++;const p=f.length<=8&&w>=f.length-1?Sa(f,t,n,!0,s):rx(f,n);return{name:m,...p}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const ka=40,ja=40;function mi(e,t,n){const r=l=>{const u=t.get(l);return u?wt(u):120},s=[...e].sort((l,u)=>{var w,v;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((w=t.get(l.id))==null?void 0:w.name)??l.id,y=((v=t.get(u.id))==null?void 0:v.name)??u.id;return f.localeCompare(y)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Ye+ka)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ja}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function cn({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ca=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var b,C;const[r,s]=x.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[i,o]=x.useState([]),[a,c]=x.useState(null),[l,u]=x.useState(null),[d,m]=x.useState("skos:exactMatch"),[f,y]=x.useState(((C=e.conceptual)==null?void 0:C.ontology_layer)??"core"),[w,v]=x.useState([]),[p,E]=x.useState("");x.useEffect(()=>{Qo().then(j=>v(j.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return o([]);Zo(r,p||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(j)},[r,p]);const M=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(cn,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[w.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(p===""?" active":""),onClick:()=>E(""),children:"all sources"}),w.map(j=>h.jsx("button",{className:"src-chip"+(p===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:p?`Search within ${p}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&w.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(j=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===j.iri?" picked":""),onClick:()=>u(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:sx.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>y(j.target.value),children:Ca.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:M,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var b,C,j;const[s,i]=x.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[o,a]=x.useState(((C=e.term_map)==null?void 0:C.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},y=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",w=t.project.kg_base_iri||`urn:${y}:`,v=(j=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:j.members.map(_=>{var R;return(R=e.attributes.find(S=>S.id===_))==null?void 0:R.name}).filter(Boolean),p=v&&v.length?`${w}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${w}${e.id}`,M=s.trim()||p;return h.jsxs(cn,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",M]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=x.useState(""),[o,a]=x.useState(""),[c,l]=x.useState(""),[u,d]=x.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const y=f==null?void 0:f.created_id;n(),y&&r(y)})};return h.jsxs(cn,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ca.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const $a=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=x.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=x.useState(r??""),[m,f]=x.useState(s??(l==null?void 0:l.id)??""),[y,w]=x.useState("many_to_one"),[v,p]=x.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",M=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:y,optionality:v}).then(o);return h.jsxs(cn,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:y,onChange:b=>w(b.target.value),children:$a.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>p(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:M,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=p=>{var E;return((E=t.entities.find(M=>M.id===p))==null?void 0:E.name)??"?"},[i,o]=x.useState(e.name),[a,c]=x.useState(e.cardinality),[l,u]=x.useState(e.optionality),[d,m]=x.useState(e.identifying),[f,y]=x.useState(!1),w=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(cn,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:p=>o(p.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:p=>c(p.target.value),children:$a.map(p=>h.jsx("option",{children:p},p))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:p=>u(p.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:p=>m(p.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>y(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:w,children:"Save"})]})]})}const pi=10,ux=6,Be=24;function dx(e,t){return t?e:Math.round(e/pi)*pi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-Be,o.right+Be);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&e1,g=c==null?void 0:c.onHoverEdge,$=p??(n+s)/2,N=(r+i)/2,I=p??M,L=p!=null?N:b,k=x.useCallback(B=>w&&C&&w(C.id,B),[w,C]),T=x.useCallback(B=>{var re,pe;if(!v||B.button!==0)return;B.stopPropagation(),(pe=(re=B.target).setPointerCapture)==null||pe.call(re,B.pointerId),f.current=!0,y.current=0;const K=u({x:B.clientX,y:B.clientY}).x;let Q=0,te=p??$;const oe=ae=>{const ue=u({x:ae.clientX,y:ae.clientY});y.current=Math.max(y.current,Math.abs(ue.x-K)),te=mx(ue.x,{shift:ae.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),Q||(Q=requestAnimationFrame(()=>{Q=0,m(te)}))},ne=()=>{window.removeEventListener("pointermove",oe),window.removeEventListener("pointerup",ne),Q&&cancelAnimationFrame(Q),f.current=!1,m(null),y.current>=gi&&k(te)};window.addEventListener("pointermove",oe),window.addEventListener("pointerup",ne)},[v,u,p,$,c,n,s,k]),P=x.useCallback(B=>{y.current>=gi&&(B.stopPropagation(),y.current=0)},[]),z=x.useCallback(B=>{v&&(B.stopPropagation(),k(null))},[v,k]);return h.jsxs("g",{className:V,children:[h.jsx("path",{id:t,className:"rel-path",d:E,fill:"none",strokeDasharray:S?void 0:"6 4"}),h.jsx("path",{d:E,fill:"none",strokeWidth:14,stroke:"transparent",onMouseEnter:g?()=>g(C.id):void 0,onMouseLeave:g?()=>g(null):void 0}),h.jsx(yi,{x:n,y:r,side:o,many:O,optional:R}),h.jsx(yi,{x:s,y:i,side:a,many:D,optional:!1}),v&&(l||d!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:T,onClickCapture:P,onDoubleClick:z,children:[h.jsx("rect",{x:$-6,y:N-10,width:12,height:20,fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:$-1.5,y:N-7,width:3,height:14,rx:1.5})]}),(l||H)&&C&&h.jsxs("text",{className:"rel-label",x:I,y:L-8,children:[l?C.verb_phrase||C.name:"",H?`${l?" ":""}(${c.memberCount})`:""]})]})});function yi({x:e,y:t,side:n,many:r,optional:s}){const i=n===q.Left?-1:1,o=7,a=12,c=[];return r?c.push(h.jsx("path",{className:"rel-glyph",d:`M ${e+i*a} ${t} L ${e} ${t-o} M ${e+i*a} ${t} L ${e} ${t} M ${e+i*a} ${t} L ${e} ${t+o}`,fill:"none"},"foot")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a-3),y1:t-o,x2:e+i*(a-3),y2:t+o},"one")),s?c.push(h.jsx("circle",{className:"rel-glyph ring",cx:e+i*(a+6),cy:t,r:4},"opt")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a+5),y1:t-o,x2:e+i*(a+5),y2:t+o},"mand")),h.jsx(h.Fragment,{children:c})}const gx={entity:Pm},yx={relationship:px},xi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],wi="#8a7d6a";function xx(e,t,n){const s=Ye;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function wx(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Yr,targetHandle:n(e.to.entity,s)?s:Xr}}function qx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:y,fitBounds:w,getNodes:v}=an(),[p,E]=x.useState([]),[M,b]=x.useState([]),C=x.useRef(!1),j=x.useMemo(()=>{const F=u&&u.size>0?[...u].sort():null;return F?"sa:"+F.join("+"):"__all__"},[u]),_=x.useRef(null),[R,S]=x.useState(0),O=x.useRef(new Map),D=x.useRef(null);x.useEffect(()=>{if(!f){_.current=null;return}const F=O.current.get(j);if(F){_.current=F,C.current=!1,S(G=>G+1);return}let Y=!1;return f.load(j).then(G=>{Y||(O.current.set(j,G),_.current=G,C.current=!1,S(J=>J+1))}),()=>{Y=!0}},[f,j]);const[V,H]=x.useState(null),[g,$]=x.useState(null),[N,I]=x.useState(!1),[L,k]=x.useState(null),[T,P]=x.useState(null),[z,B]=x.useState(null),[X,K]=x.useState(null),Q=x.useRef({}),te=!t.canEdit,oe=x.useRef(null),ne=x.useCallback(()=>{f&&(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{const F={};for(const J of v())J.hidden||(F[J.id]={x:Math.round(J.position.x),y:Math.round(J.position.y)});const Y={};for(const[J,U]of Object.entries(Q.current))Y[J]={routeX:Math.round(U)};const G={nodes:F,edges:Y};O.current.set(j,G),_.current=G,f.save(j,G)},800))},[f,v,j]),re=x.useCallback((F,Y)=>{Y==null?delete Q.current[F]:Q.current[F]=Y,b(G=>G.map(J=>J.id===F?{...J,data:{...J.data,routeX:Y??void 0}}:J)),ne()},[ne]),pe=x.useMemo(()=>{const F=new Map;return e.subject_areas.forEach((Y,G)=>F.set(Y.id,xi[G%xi.length])),F},[e]),ae=x.useMemo(()=>{const F=new Map;return e.entities.forEach(Y=>F.set(Y.id,Y)),F},[e]),ue=x.useMemo(()=>{const F=new Map,Y=new Map;return e.subject_areas.forEach(G=>{(G.members??[]).forEach(J=>Y.set(J,{id:G.id,name:G.name}))}),e.entities.forEach(G=>{var se,me;const J=(se=G.conceptual)!=null&&se.id?Y.get(G.conceptual.id):void 0,U=(me=G.conceptual)==null?void 0:me.subject_area,ee=J??(U?{id:U.id,name:U.name??U.id}:void 0);ee&&F.set(G.id,ee)}),F},[e]),_e=x.useCallback(F=>{var G;if(!u||u.size===0)return!1;const Y=(G=ue.get(F))==null?void 0:G.id;return!(Y&&u.has(Y))},[u,ue]),he=x.useMemo(()=>{const F=new Map,Y=(G,J)=>{if(!J.length)return;const U=F.get(G)??new Set;J.forEach(ee=>U.add(ee)),F.set(G,U)};for(const G of e.relationships)Y(G.from.entity,G.from.attributes),Y(G.to.entity,G.to.attributes);return F},[e]);x.useEffect(()=>{var $e;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const W of e.entities)(W.name.toLowerCase()+" "+((($e=W.conceptual)==null?void 0:$e.name.toLowerCase())??"")+" "+W.attributes.map(ge=>ge.name.toLowerCase()).join(" ")).includes(F)&&Y.add(W.id);const G=new Set;if(r){G.add(r);for(const W of e.relationships)W.from.entity===r&&G.add(W.to.entity),W.to.entity===r&&G.add(W.from.entity)}const J=e.entities.map(W=>{const fe=F!==""&&!Y.has(W.id),ge=r!==null&&!G.has(W.id);return{id:W.id,type:"entity",position:{x:0,y:0},hidden:_e(W.id),data:{entity:W,color:(()=>{const Se=ue.get(W.id);return Se?pe.get(Se.id)??wi:wi})(),dimmed:fe||ge,highlighted:F!==""&&Y.has(W.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(W.id))??!1,onToggleExpand:l,endpointAttrs:he.get(W.id),highlightAttrs:void 0,onHoverAttr:B}}}),U=e.relationships.filter(W=>ae.has(W.from.entity)&&ae.has(W.to.entity)).map(W=>{const{sourceHandle:fe,targetHandle:ge}=wx(W,ae),Se=r!==null&&W.from.entity!==r&&W.to.entity!==r;return{id:W.id,source:W.from.entity,target:W.to.entity,sourceHandle:fe,targetHandle:ge,type:"relationship",data:{relationship:W,dimmed:Se,memberCount:Math.max(W.from.attributes.length,W.to.attributes.length),onHoverEdge:K}}}),ee=_.current;if(Q.current={},ee)for(const[W,fe]of Object.entries(ee.edges))Q.current[W]=fe.routeX;let se=J;E(W=>{const fe=new Map(W.map(ce=>[ce.id,ce.position])),ge=J.every(ce=>fe.has(ce.id)),Se=((u==null?void 0:u.size)??0)>0;if(C.current&&ge&&W.length>=J.length&&!Se){const ce=J.map(Ue=>({...Ue,position:fe.get(Ue.id)??Ue.position}));return se=ce,ce}const dt=Se?J.filter(ce=>!ce.hidden):J,Ot=ur(dt,U,ae,"auto",ue),rt=new Map(Ot.map(ce=>[ce.id,ce.position])),ft=(ee==null?void 0:ee.nodes)??{},Lt=Object.keys(ft).length>0,Pe=[],Dt=J.map(ce=>{const Ue=ft[ce.id];if(Ue){const Pt={x:Ue.x,y:Ue.y};return Pe.push({x:Pt.x,y:Pt.y,w:Ye,h:wt(ce.data.entity)}),{...ce,position:Pt}}return rt.has(ce.id)?{...ce,position:rt.get(ce.id)}:fe.has(ce.id)&&C.current?{...ce,position:fe.get(ce.id)}:ce});if(Lt)for(const ce of Dt)ft[ce.id]||ce.hidden||(ce.position=xx(ce.position,wt(ce.data.entity),Pe),Pe.push({x:ce.position.x,y:ce.position.y,w:Ye,h:wt(ce.data.entity)}));return C.current=!0,Lt||requestAnimationFrame(()=>y({padding:.15,duration:300})),se=Dt,Dt});const me=new Map;for(const W of se)me.set(W.id,{left:W.position.x,right:W.position.x+Ye});b(U.map(W=>({...W,data:{...W.data,routeX:Q.current[W.id],onRouteChange:f?re:void 0,sourceCard:me.get(W.source),targetCard:me.get(W.target)}})))},[e,i,r,o,a,c,l,pe,ae,ue,_e,u,he,y,f,re,R]);const ye=x.useMemo(()=>{const F=new Set,Y=new Set,G=new Map,J=(U,ee)=>{if(!ee.length)return;const se=G.get(U)??new Set;ee.forEach(me=>se.add(me)),G.set(U,se)};if(z)for(const U of e.relationships)(U.from.attributes.includes(z)||U.to.attributes.includes(z))&&(F.add(U.id),Y.add(U.from.entity),Y.add(U.to.entity),J(U.from.entity,U.from.attributes),J(U.to.entity,U.to.attributes));if(X){const U=e.relationships.find(ee=>ee.id===X);U&&(J(U.from.entity,U.from.attributes),J(U.to.entity,U.to.attributes))}return{active:z!==null,relsForAttr:F,entsForAttr:Y,hitAttrsByEntity:G}},[e,z,X]);x.useEffect(()=>{var J;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const U of e.entities)(U.name.toLowerCase()+" "+(((J=U.conceptual)==null?void 0:J.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);const G=new Set;if(r){G.add(r);for(const U of e.relationships)U.from.entity===r&&G.add(U.to.entity),U.to.entity===r&&G.add(U.from.entity)}E(U=>U.map(ee=>{const se=F!==""&&!Y.has(ee.id),me=r!==null&&!G.has(ee.id),$e=ye.active&&!ye.entsForAttr.has(ee.id),W=se||me||$e,fe=F!==""&&Y.has(ee.id)||ye.active&&ye.entsForAttr.has(ee.id),ge=ye.hitAttrsByEntity.get(ee.id);return ee.data.dimmed===W&&ee.data.highlighted===fe&&ee.data.highlightAttrs===ge?ee:{...ee,data:{...ee.data,dimmed:W,highlighted:fe,highlightAttrs:ge}}})),b(U=>U.map(ee=>{var fe,ge;const se=(fe=ee.data)==null?void 0:fe.relationship,me=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,$e=ye.active&&!ye.relsForAttr.has(ee.id),W=me||$e;return((ge=ee.data)==null?void 0:ge.dimmed)===W?ee:{...ee,data:{...ee.data,dimmed:W}}}))},[ye,i,r,e]),x.useEffect(()=>{var J;const F=i.trim().toLowerCase();if(!F)return;const Y=new Set;for(const U of e.entities)(U.name.toLowerCase()+" "+(((J=U.conceptual)==null?void 0:J.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);if(!Y.size)return;const G=requestAnimationFrame(()=>{const U=v().filter(se=>Y.has(se.id));if(!U.length)return;const ee=Mf(U);w(ee,{padding:.35,duration:400})});return()=>cancelAnimationFrame(G)},[i,e,v,w]);const le=x.useCallback((F="auto",Y="LR")=>{D.current=Object.fromEntries(v().map(G=>[G.id,{x:G.position.x,y:G.position.y}])),E(G=>ur(G,M,ae,F,ue,Y)),requestAnimationFrame(()=>y({padding:.15,duration:300})),ne()},[M,ae,ue,y,v,ne]),Z=x.useCallback(()=>{const F=D.current;F&&(E(Y=>Y.map(G=>F[G.id]?{...G,position:F[G.id]}:G)),D.current=null,ne())},[ne]),Ne=x.useCallback(()=>{f==null||f.reset(j),O.current.delete(j),_.current=null,Q.current={},C.current=!1,b(F=>F.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(F=>{const Y=ur(F,M,ae,"auto",ue);return requestAnimationFrame(()=>y({padding:.15,duration:300})),Y})},[f,j,M,ae,ue,y]),Ce=x.useCallback(F=>{s(F),E(Y=>(Y.find(J=>J.id===F)&&requestAnimationFrame(()=>y({nodes:[{id:F}],padding:.4,duration:400})),Y))},[y,s]);x.useImperativeHandle(m,()=>({relayout:le,fitView:()=>y({padding:.15,duration:300}),focusEntity:Ce,newEntity:()=>I(!0),resetLayout:Ne,undoRelayout:Z}),[le,y,Ce,Ne,Z]);const ut=x.useCallback(F=>{if(te||!F.source||!F.target||F.source===F.target)return;const Y=F.sourceHandle&&F.sourceHandle!==Yr?F.sourceHandle:void 0,G=F.targetHandle&&F.targetHandle!==Xr?F.targetHandle:void 0;k({from:F.source,to:F.target,fromAttr:Y,toAttr:G})},[te]),Ae=x.useCallback(async(F,Y)=>{try{return await n(F,Y)}catch(G){throw d==null||d(G instanceof Error?G.message:String(G)),G}},[n,d]),We=r?ae.get(r)??null:null,Ie=e.relationships.find(F=>F.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Yo,{nodes:p,edges:M,nodeTypes:gx,edgeTypes:yx,onNodeClick:(F,Y)=>s(Y.id),onEdgeClick:(F,Y)=>!te&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(F,Y)=>{E(G=>G.map(J=>J.id===Y.id?{...J,position:Y.position}:J)),ne()},onConnect:ut,nodesConnectable:!te,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:Le.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:F=>{var Y;return((Y=F.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),We&&h.jsx(Hm,{entity:We,doc:e,caps:t,exec:Ae,onClose:()=>s(null),onFocusEntity:Ce,onAlign:H,onEditMapping:$}),V&&h.jsx(ix,{entity:V,exec:Ae,onClose:()=>H(null)}),g&&h.jsx(ox,{entity:g,doc:e,exec:Ae,onClose:()=>$(null)}),N&&h.jsx(ax,{doc:e,exec:Ae,onClose:()=>I(!1),onCreated:Ce}),L&&h.jsx(cx,{doc:e,fromId:L.from,toId:L.to,initialFromAttr:L.fromAttr,initialToAttr:L.toAttr,exec:Ae,onClose:()=>k(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:Ae,onClose:()=>P(null)})]})}function Kx({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(bx,{}),e==="layers"&&h.jsx(_x,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(Ex,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Nx,{readOnly:n})]})}function bx(){const[e,t]=x.useState(""),[n,r]=x.useState([]),[s,i]=x.useState({loaded:0,vocabs:[]}),[o,a]=x.useState(null),[c,l]=x.useState([]),[u,d]=x.useState("");x.useEffect(()=>{Qo().then(f=>l(f.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const f=setTimeout(()=>{Zo(e||"a",u||void 0).then(y=>{r(e?y.results:[]),i({loaded:y.loaded_terms,vocabs:y.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=x.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const vx=["industry","core","domain","specialised"];function _x({refreshKey:e,onFocusEntity:t}){const[n,r]=x.useState(null),[s,i]=x.useState(null);if(x.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),vx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Ex({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=x.useState(null),[i,o]=x.useState(""),[a,c]=x.useState(""),[l,u]=x.useState(!1),d=x.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` - -`))).catch(()=>o(""))},[]);return x.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:i.split(` -`).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` -`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:l,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(u(!0),Mm().then(()=>{u(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:l||!a.trim(),onClick:()=>{u(!0),$m(a).then(()=>{u(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Nx({readOnly:e}){const[t,n]=x.useState([]),r=x.useCallback(()=>{Am().then(i=>n(i.decisions)).catch(()=>n([]))},[]);if(x.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(i=>h.jsxs("div",{className:"decision "+i.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[i.verdict]}),h.jsx("span",{className:"chip",children:i.confidence}),h.jsx("span",{className:"chip",children:i.signal})]}),h.jsx("p",{className:"decision-subject",children:i.subject}),!e&&i.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Bs(i.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Bs(i.signal_key,"rejected").then(r),children:"Reject"})]})]},i.signal_key))})}function Zx({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:i,openImport:o=!1,prefillImport:a="",onPreview:c}){const[l,u]=x.useState(o&&t?"import":null),[d,m]=x.useState([]),[f,y]=x.useState("postgres"),w=x.useRef(null);x.useEffect(()=>{Rm().then(p=>m(p.formats)).catch(()=>m([]))},[]),x.useEffect(()=>{if(!l)return;const p=E=>{w.current&&!w.current.contains(E.target)&&u(null)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[l]);const v=d.find(p=>p.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:w,children:[h.jsxs("button",{className:s+(l==="export"?" on":""),onClick:()=>u(l==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(l==="import"?" on":""),onClick:()=>u(l==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),l==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(v==null?void 0:v.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:p=>y(p.target.value),children:v.dialects.map(p=>h.jsx("option",{value:p,children:p},p))})]}),d.map(p=>h.jsx("a",{className:"ie-item",href:Im(p.id,p.id==="sql"?f:void 0),download:!0,onClick:()=>u(null),children:p.label},p.id))]}),l==="import"&&h.jsx(Sx,{exec:e,submitLabel:r,buttonClass:s,applyBatch:i,onClose:()=>u(null),onImported:p=>{u(null),n==null||n(p)},onPreview:c,prefillImport:a})]})}const bi=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function Sx({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:i,onPreview:o,prefillImport:a}){var j;const[c,l]=x.useState(o?"erwin":"sql"),[u,d]=x.useState("postgres"),[m,f]=x.useState(a??""),[y,w]=x.useState(!1),[v,p]=x.useState(null),[E,M]=x.useState([]);x.useEffect(()=>{a&&f(a)},[a]);const b=_=>{_&&_.text().then(f).catch(()=>p("could not read that file"))},C=async()=>{w(!0),p(null),M([]);try{if(o&&c==="erwin"){const R=await Om(c,m);if(!R.changes.length){p(R.warnings[0]??"nothing to import from that document"),w(!1);return}s(),o(R),w(!1);return}const _=await Tm(c,m,c==="sql"?u:void 0);if(!_.changes.length){p(_.warnings[0]??"nothing to import from that document"),w(!1);return}if(r)await r(_.changes);else for(const R of _.changes)await e(R.op,R.payload);M(_.warnings),i(_.tables)}catch(_){p(_ instanceof Error?_.message:String(_))}finally{w(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:bi.map(_=>h.jsx("button",{className:"ie-tab"+(c===_.id?" active":""),onClick:()=>l(_.id),children:_.label},_.id))}),h.jsx("p",{className:"ie-hint",children:(j=bi.find(_=>_.id===c))==null?void 0:j.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:u,onChange:_=>d(_.target.value),children:["postgres","snowflake","mysql","duckdb"].map(_=>h.jsx("option",{children:_},_))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:_=>f(_.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:_=>{var R;return b(((R=_.target.files)==null?void 0:R[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((_,R)=>h.jsx("p",{className:"ie-warn",children:_},R)),v&&h.jsx("p",{className:"ie-error",children:v}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:y||!m.trim(),onClick:C,children:y?"Importing…":t})]})]})}export{Ko as A,_m as B,gm as C,Pm as E,Zx as I,_x as L,qx as M,bx as O,xi as P,Bo as R,Kx as S,$x as a,Hx as b,Dx as c,Vx as d,Bx as e,Cx as f,jm as g,Yx as h,Gx as i,Px as j,Rx as k,Ix as l,Tx as m,Lx as n,Zo as o,Fx as p,zx as q,Ox as r,km as s,Mx as t,Ax as u,ur as v,Yo as w,px as x,lm as y}; diff --git a/packages/server/src/mdl_server/static/assets/styles-_nxo2D6f.js b/packages/server/src/mdl_server/static/assets/styles-_nxo2D6f.js new file mode 100644 index 0000000..1b698c2 --- /dev/null +++ b/packages/server/src/mdl_server/static/assets/styles-_nxo2D6f.js @@ -0,0 +1,23 @@ +var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ve=(e,t,n)=>oc(e,typeof t!="symbol"?t+"":t,n);import{r as x,g as vi,R as A,j as h}from"./client-DOmNpTln.js";function je(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?mc:hc;Si.useSyncExternalStore=At.useSyncExternalStore!==void 0?At.useSyncExternalStore:pc;Ni.exports=Si;var gc=Ni.exports;/** + * @license React + * use-sync-external-store-shim/with-selector.production.js + * + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var Dn=x,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=Dn.useRef,_c=Dn.useEffect,Ec=Dn.useMemo,Nc=Dn.useDebugValue;Ei.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var w=o.value;if(s(w,f))return d=w}return d=f}if(w=d,wc(u,f))return w;var y=r(f);return s!==void 0&&s(w,y)?(u=f,w):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};_i.exports=Ei;var Sc=_i.exports;const kc=vi(Sc),jc={},es=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(w=>w(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?es(e):es,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function ki(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const ts=(e,t)=>{const n=Cc(e),r=(s,i=t)=>ki(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?ts(e,t):ts;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rs.hasOwnProperty(t)?{space:rs[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===dr&&t.documentElement.namespaceURI===dr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ji(e){var t=zn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function Cr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=Cr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=$&&($=E+1);!(M=v[$])&&++$=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Rt(this.node(),e)}function Rt(e,t){return e.style.getPropertyValue(t)||Ri(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ii(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Ti(e)}function Ti(e){this._node=e,this._names=Ii(e.getAttribute("class")||"")}Ti.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Oi(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function fr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}fr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Pn("start","drag","end"),o=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",p,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,M){if(!(u||!e.call(this,b,M))){var N=$(this,t.call(this,b,M),b,M,"mouse");N&&(Te(b.view).on("mousemove.drag",w,Ut).on("mouseup.drag",y,Ut),zi(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,N("start",b))}}function w(b){if(Ct(b),!l){var M=b.clientX-a,N=b.clientY-c;l=M*M+N*N>d}s.mouse("drag",b)}function y(b){Te(b.view).on("mousemove.drag mouseup.drag",null),Hi(b.view,l),Ct(b),s.mouse("end",b)}function v(b,M){if(e.call(this,b,M)){var N=b.changedTouches,_=t.call(this,b,M),R=N.length,k,O;for(k=0;k>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?un(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?un(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Me(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Me(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?un(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?un(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?us(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?us(t[1],t[2]/100,t[3]/100,t[4]):ss.hasOwnProperty(e)?as(ss[e]):e==="transparent"?new Me(NaN,NaN,NaN,0):null}function as(e){return new Me(e>>16&255,e>>8&255,e&255,1)}function un(e,t,n,r){return r<=0&&(e=t=n=NaN),new Me(e,t,n,r)}function Mu(e){return e instanceof rn||(e=Zt(e)),e?(e=e.rgb(),new Me(e.r,e.g,e.b,e.opacity)):new Me}function hr(e,t,n,r){return arguments.length===1?Mu(e):new Me(e,t,n,r??1)}function Me(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Mr(Me,hr,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Me(yt(this.r),yt(this.g),yt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:cs,formatHex:cs,formatHex8:Au,formatRgb:ls,toString:ls}));function cs(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function ls(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function us(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new He(e,t,n,r)}function Vi(e){if(e instanceof He)return new He(e.h,e.s,e.l,e.opacity);if(e instanceof rn||(e=Zt(e)),!e)return new He;if(e instanceof He)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new He(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Vi(e):new He(e,t,n,r??1)}function He(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Mr(He,Ru,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new He(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new He(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Me(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new He(ds(this.h),dn(this.s),dn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${ds(this.h)}, ${dn(this.s)*100}%, ${dn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ds(e){return e=(e||0)%360,e<0?e+360:e}function dn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Bi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Gi:function(t,n){return n-t?Tu(t,n,e):Bi(isNaN(t)?n:t)}}function Gi(e,t){var n=t-e;return n?Iu(e,n):Bi(isNaN(e)?t:e)}const fs=function e(t){var n=Ou(t);function r(s,i){var o=n((s=hr(s)).r,(i=hr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Gi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function it(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var mr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(mr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=mr.lastIndex=Kn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=mr.exec(e))&&(s=Kn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:it(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:it(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:it(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,w){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");w.push({i:y-4,x:it(l,d)},{i:y-2,x:it(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var w=-1,y=m.length,v;++w=0&&e._call.call(void 0,t),e=e._next;--It}function ps(){bt=(Cn=Qt.now())+Hn,It=Gt=0;try{Uu()}finally{It=0,Ku(),bt=0}}function qu(){var e=Qt.now(),t=e-Cn;t>Xi&&(Hn-=t,Cn=e)}function Ku(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Yt=e,gr(r)}function gr(e){if(!It){Gt&&(Gt=clearTimeout(Gt));var t=e-bt;t>24?(e<1/0&&(Gt=setTimeout(ps,e-Qt.now()-Hn)),zt&&(zt=clearInterval(zt))):(zt||(Cn=Qt.now(),zt=setInterval(qu,Xi)),It=1,Ui(ps))}}function gs(e,t,n){var r=new $n;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Pn("start","end","cancel","interrupt"),Qu=[],Ki=0,ys=1,yr=2,vn=3,xs=4,xr=5,_n=6;function Fn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Ki})}function Rr(e,t){var n=Fe(e,t);if(n.state>Ki)throw new Error("too late; already scheduled");return n}function We(e,t){var n=Fe(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Fe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=qi(i,0,n.time);function i(l){n.state=ys,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ys)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return gs(o);f.state===xs?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uyr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Rr:We;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Fe(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Cr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Qe(e,t,n){this.k=e,this.x=t,this.y=n}Qe.prototype={constructor:Qe,scale:function(e){return e===1?this:new Qe(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Qe(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Je=new Qe(1,0,0);Qe.prototype;function Zn(e){e.stopImmediatePropagation()}function Ht(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ws(){return this.__zoom||Je}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function eo(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Wu,l=Pn("start","zoom","end"),u,d,m,f=500,w=150,y=0,v=10;function p(g){g.property("__zoom",ws).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",D).on("touchmove.zoom",B).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}p.transform=function(g,C,S,I){var L=g.selection?g.selection():g;L.property("__zoom",ws),g!==L?M(g,C,S,I):L.interrupt().each(function(){N(this,arguments).event(I).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},p.scaleBy=function(g,C,S,I){p.scaleTo(g,function(){var L=this.__zoom.k,j=typeof C=="function"?C.apply(this,arguments):C;return L*j},S,I)},p.scaleTo=function(g,C,S,I){p.transform(g,function(){var L=t.apply(this,arguments),j=this.__zoom,T=S==null?b(L):typeof S=="function"?S.apply(this,arguments):S,P=j.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n($(E(j,z),T,P),L,o)},S,I)},p.translateBy=function(g,C,S,I){p.transform(g,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,I)},p.translateTo=function(g,C,S,I,L){p.transform(g,function(){var j=t.apply(this,arguments),T=this.__zoom,P=I==null?b(j):typeof I=="function"?I.apply(this,arguments):I;return n(Je.translate(P[0],P[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof S=="function"?-S.apply(this,arguments):-S),j,o)},I,L)};function E(g,C){return C=Math.max(i[0],Math.min(i[1],C)),C===g.k?g:new Qe(C,g.x,g.y)}function $(g,C,S){var I=C[0]-S[0]*g.k,L=C[1]-S[1]*g.k;return I===g.x&&L===g.y?g:new Qe(g.k,I,L)}function b(g){return[(+g[0][0]+ +g[1][0])/2,(+g[0][1]+ +g[1][1])/2]}function M(g,C,S,I){g.on("start.zoom",function(){N(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(I).end()}).tween("zoom",function(){var L=this,j=arguments,T=N(L,j).event(I),P=t.apply(L,j),z=S==null?b(P):typeof S=="function"?S.apply(L,j):S,W=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),V=L.__zoom,Z=typeof C=="function"?C.apply(L,j):C,J=c(V.invert(z).concat(W/V.k),Z.invert(z).concat(W/Z.k));return function(ee){if(ee===1)ee=Z;else{var oe=J(ee),ne=W/oe[2];ee=new Qe(ne,z[0]-oe[0]*ne,z[1]-oe[1]*ne)}T.zoom(null,ee)}})}function N(g,C,S){return!S&&g.__zooming||new _(g,C)}function _(g,C){this.that=g,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(g,C),this.taps=0}_.prototype={event:function(g){return g&&(this.sourceEvent=g),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(g,C){return this.mouse&&g!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&g!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&g!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(g){var C=Te(this.that).datum();l.call(g,this.that,new sf(g,{sourceEvent:this.sourceEvent,target:p,transform:this.that.__zoom,dispatch:l}),C)}};function R(g,...C){if(!e.apply(this,arguments))return;var S=N(this,C).event(g),I=this.__zoom,L=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,r.apply(this,arguments)))),j=ze(g);if(S.wheel)(S.mouse[0][0]!==j[0]||S.mouse[0][1]!==j[1])&&(S.mouse[1]=I.invert(S.mouse[0]=j)),clearTimeout(S.wheel);else{if(I.k===L)return;S.mouse=[j,I.invert(j)],En(this),S.start()}Ht(g),S.wheel=setTimeout(T,w),S.zoom("mouse",n($(E(I,L),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function k(g,...C){if(m||!e.apply(this,arguments))return;var S=g.currentTarget,I=N(this,C,!0).event(g),L=Te(g.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",W,!0),j=ze(g,S),T=g.clientX,P=g.clientY;zi(g.view),Zn(g),I.mouse=[j,this.__zoom.invert(j)],En(this),I.start();function z(V){if(Ht(V),!I.moved){var Z=V.clientX-T,J=V.clientY-P;I.moved=Z*Z+J*J>y}I.event(V).zoom("mouse",n($(I.that.__zoom,I.mouse[0]=ze(V,S),I.mouse[1]),I.extent,o))}function W(V){L.on("mousemove.zoom mouseup.zoom",null),Hi(V.view,I.moved),Ht(V),I.event(V).end()}}function O(g,...C){if(e.apply(this,arguments)){var S=this.__zoom,I=ze(g.changedTouches?g.changedTouches[0]:g,this),L=S.invert(I),j=S.k*(g.shiftKey?.5:2),T=n($(E(S,j),I,L),t.apply(this,C),o);Ht(g),a>0?Te(this).transition().duration(a).call(M,T,I,g):Te(this).call(p.transform,T,I,g)}}function D(g,...C){if(e.apply(this,arguments)){var S=g.touches,I=S.length,L=N(this,C,g.changedTouches.length===I).event(g),j,T,P,z;for(Zn(g),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},to=tt.error001();function de(e,t){const n=x.useContext(Vn);if(n===null)throw new Error(to);return ki(n,e,t)}const Ee=()=>{const e=x.useContext(Vn);if(e===null)throw new Error(to);return x.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Tr({position:e,children:t,className:n,style:r,...s}){const i=de(ff),o=`${e}`.split("-");return A.createElement("div",{className:je(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Tr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=x.useRef(null),[m,f]=x.useState({x:0,y:0,width:0,height:0}),w=je(["react-flow__edge-textwrapper",l]);return x.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:w,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=x.memo(mf);const Or=e=>({width:e.offsetWidth,height:e.offsetHeight}),Tt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Lr=(e={x:0,y:0},t)=>({x:Tt(e.x,t[0][0],t[1][0]),y:Tt(e.y,t[0][1],t[1][1])}),bs=(e,t,n)=>en?-Tt(Math.abs(e-n),1,50)/50:0,no=(e,t)=>{const n=bs(e.x,35,t.width-35)*20,r=bs(e.y,35,t.height-35)*20;return[n,r]},ro=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},so=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Jt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),io=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),vs=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>io(so(Jt(e),Jt(t))),wr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Oe(e.width)&&Oe(e.height)&&Oe(e.x)&&Oe(e.y),Oe=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),oo=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function br(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const ao=e=>"clientX"in e,lt=(e,t)=>{var i,o;const n=ao(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Mn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},sn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Oe(n)&&Oe(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);sn.displayName="BaseEdge";function Ft(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function co({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[v,p,E]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(sn,{path:v,labelX:p,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:y})});Dr.displayName="SimpleBezierEdge";const Es={[q.Left]:{x:-1,y:0},[q.Right]:{x:1,y:0},[q.Top]:{x:0,y:-1},[q.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=q.Bottom,target:n})=>t===q.Left||t===q.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=q.Bottom,target:n,targetPosition:r=q.Top,center:s,offset:i}){const o=Es[t],a=Es[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],w,y;const v={x:0,y:0},p={x:0,y:0},[E,$,b,M]=co({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){w=s.x??E,y=s.y??$;const _=[{x:w,y:c.y},{x:w,y:l.y}],R=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?R:_:f=o.y===m?_:R,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const g=Math.min(i-1,i-H);o[d]===m?v[d]=(c[d]>e[d]?-1:1)*g:p[d]=(l[d]>n[d]?-1:1)*g}}if(t!==r){const H=d==="x"?"y":"x",g=o[d]===a[H],C=c[H]>l[H],S=c[H]=B?(w=(k.x+O.x)/2,y=f[0].y):(w=f[0].x,y=(k.y+O.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:l.x+p.x,y:l.y+p.y},n],w,y,b,M]}function _f(e,t,n,r){const s=Math.min(Ns(e,t)/2,Ns(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let $="";return E>0&&E{const[p,E,$]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:w,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const Pr=x.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:x.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Pr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=co({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const zr=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[w,y,v]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(sn,{path:w,labelX:y,labelY:v,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});zr.displayName="StraightEdge";function mn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Ss({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case q.Left:return[t-mn(t-r,i),n];case q.Right:return[t+mn(r-t,i),n];case q.Top:return[t,n-mn(n-s,i)];case q.Bottom:return[t,n+mn(s-n,i)]}}function fo({sourceX:e,sourceY:t,sourcePosition:n=q.Bottom,targetX:r,targetY:s,targetPosition:i=q.Top,curvature:o=.25}){const[a,c]=Ss({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Ss({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,w]=lo({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,w]}const In=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=q.Bottom,targetPosition:i=q.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,pathOptions:y,interactionWidth:v})=>{const[p,E,$]=fo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:v})});In.displayName="BezierEdge";const Hr=x.createContext(null),Nf=Hr.Provider;Hr.Consumer;const Sf=()=>x.useContext(Hr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,vr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},_r=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},ho=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},on=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return so(r,Jt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return io(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),on(e,t)),mo=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:w=!1}=u;if(o&&!f||w)return!1;const{positionAbsolute:y}=xt(u,a),v={x:y.x,y:y.y,width:d||0,height:m||0},p=wr(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,$=i&&p>0,b=(d||0)*(m||0);(E||$||p>=b||u.dragging)&&l.push(u)}),l},po=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},go=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Tt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function ks(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=lt(e),l=t.elementsFromPoint(o,a).find(w=>w.classList.contains("react-flow__handle"));if(l){const w=l.getAttribute("data-nodeid");if(w){const y=Fr(void 0,l),v=l.getAttribute("data-handleid"),p=i({nodeId:w,id:v,type:y});if(p){const E=s.find($=>$.nodeId===w&&$.type===y&&$.id===v);return{handle:{id:v,type:y,nodeId:w,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:p}}}}let u=[],d=1/0;if(s.forEach(w=>{const y=Math.sqrt((w.x-n.x)**2+(w.y-n.y)**2);if(y<=r){const v=i(w);y<=d&&(yw.isValid),f=u.some(({handle:w})=>w.type==="target");return u.find(({handle:w,validHandleResult:y})=>f?w.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},yo=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function xo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...yo(),handleDomNode:c};if(c){const u=Fr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),w=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&w&&(t===vt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=ks(i,o,"source",`${t}-${n}-${r}`),c=ks(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Fr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function wo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ro(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:w,onConnectStart:y,panBy:v,getNodes:p,cancelConnection:E}=i();let $=0,b;const{x:M,y:N}=lt(e),_=u==null?void 0:u.elementFromPoint(M,N),R=Fr(c,_),k=m==null?void 0:m.getBoundingClientRect();if(!k||!R)return;let O,D=lt(e,k),B=!1,H=null,g=!1,C=null;const S=If({nodes:p(),nodeId:n,handleId:t,handleType:R}),I=()=>{if(!f)return;const[T,P]=no(D,k);v({x:T,y:P}),$=requestAnimationFrame(I)};o({connectionPosition:D,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:R});function L(T){const{transform:P}=i();D=lt(T,k);const{handle:z,validHandleResult:W}=Af(T,u,_r(D,P,!1,[1,1]),w,S,V=>xo(V,d,n,t,s?"target":"source",a,u));if(b=z,B||(I(),B=!0),C=W.handleDomNode,H=W.connection,g=W.isValid,o({connectionPosition:b&&g?ho({x:b.x,y:b.y},P):D,connectionStatus:Tf(!!b,g),connectionEndHandle:W.endHandle}),!b&&!g&&!C)return Qn(O);H.source!==H.target&&C&&(Qn(O),O=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",g),C.classList.toggle("react-flow__handle-valid",g))}function j(T){var P,z;(b||C)&&H&&g&&(r==null||r(H)),(z=(P=i()).onConnectEnd)==null||z.call(P,T),c&&(l==null||l(T)),Qn(O),E(),cancelAnimationFrame($),B=!1,g=!1,H=null,C=null,u.removeEventListener("mousemove",L),u.removeEventListener("mouseup",j),u.removeEventListener("touchmove",L),u.removeEventListener("touchend",j)}u.addEventListener("mousemove",L),u.addEventListener("mouseup",j),u.addEventListener("touchmove",L),u.addEventListener("touchend",j)}const js=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},bo=x.forwardRef(({type:e="source",position:t=q.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var k,O;const w=o||null,y=e==="target",v=Ee(),p=Sf(),{connectOnClick:E,noPanClassName:$}=de(Of,ke),{connecting:b,clickConnecting:M}=de(Lf(p,w,e),ke);p||(O=(k=v.getState()).onError)==null||O.call(k,"010",tt.error010());const N=D=>{const{defaultEdgeOptions:B,onConnect:H,hasDefaultEdges:g}=v.getState(),C={...B,...D};if(g){const{edges:S,setEdges:I}=v.getState();I($f(C,S))}H==null||H(C),a==null||a(C)},_=D=>{if(!p)return;const B=ao(D);s&&(B&&D.button===0||!B)&&wo({event:D,handleId:w,nodeId:p,onConnect:N,isTarget:y,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||js}),B?u==null||u(D):d==null||d(D)},R=D=>{const{onClickConnectStart:B,onClickConnectEnd:H,connectionClickStartHandle:g,connectionMode:C,isValidConnection:S}=v.getState();if(!p||!g&&!s)return;if(!g){B==null||B(D,{nodeId:p,handleId:w,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:p,type:e,handleId:w}});return}const I=ro(D.target),L=n||S||js,{connection:j,isValid:T}=xo({nodeId:p,id:w,type:e},C,g.nodeId,g.handleId||null,g.type,L,I);T&&N(j),H==null||H(D),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":w,"data-nodeid":p,"data-handlepos":t,"data-id":`${p}-${w}-${e}`,className:je(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",$,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!b||i&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});bo.displayName="Handle";var ct=x.memo(bo);const vo=({data:e,isConnectable:t,targetPosition:n=q.Top,sourcePosition:r=q.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ct,{type:"source",position:r,isConnectable:t}));vo.displayName="DefaultNode";var Er=x.memo(vo);const _o=({data:e,isConnectable:t,sourcePosition:n=q.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ct,{type:"source",position:n,isConnectable:t}));_o.displayName="InputNode";var Eo=x.memo(_o);const No=({data:e,isConnectable:t,targetPosition:n=q.Top})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);No.displayName="OutputNode";var So=x.memo(No);const Vr=()=>null;Vr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),pn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(pn),t.selectedNodes.map(pn))&&ke(e.selectedEdges.map(pn),t.selectedEdges.map(pn))}const ko=x.memo(({onSelectionChange:e})=>{const t=Ee(),{selectedNodes:n,selectedEdges:r}=de(Df,Pf);return x.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});ko.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=de(zf);return e||t?A.createElement(ko,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Et(e,t){x.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ie(e,t,n){x.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:w,minZoom:y,maxZoom:v,nodeExtent:p,onNodesChange:E,onEdgesChange:$,elementsSelectable:b,connectionMode:M,snapGrid:N,snapToGrid:_,translateExtent:R,connectOnClick:k,defaultEdgeOptions:O,fitView:D,fitViewOptions:B,onNodesDelete:H,onEdgesDelete:g,onNodeDrag:C,onNodeDragStart:S,onNodeDragStop:I,onSelectionDrag:L,onSelectionDragStart:j,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:W,autoPanOnConnect:V,autoPanOnNodeDrag:Z,onError:J,connectionRadius:ee,isValidConnection:oe,nodeDragThreshold:ne})=>{const{setNodes:re,setEdges:pe,setDefaultNodesAndEdges:ce,setMinZoom:ue,setMaxZoom:ye,setTranslateExtent:he,setNodeExtent:xe,reset:le}=de(Ff,ke),K=Ee();return x.useEffect(()=>{const Ne=r==null?void 0:r.map(Ce=>({...Ce,...O}));return ce(n,Ne),()=>{le()}},[]),ie("defaultEdgeOptions",O,K.setState),ie("connectionMode",M,K.setState),ie("onConnect",s,K.setState),ie("onConnectStart",i,K.setState),ie("onConnectEnd",o,K.setState),ie("onClickConnectStart",a,K.setState),ie("onClickConnectEnd",c,K.setState),ie("nodesDraggable",l,K.setState),ie("nodesConnectable",u,K.setState),ie("nodesFocusable",d,K.setState),ie("edgesFocusable",m,K.setState),ie("edgesUpdatable",f,K.setState),ie("elementsSelectable",b,K.setState),ie("elevateNodesOnSelect",w,K.setState),ie("snapToGrid",_,K.setState),ie("snapGrid",N,K.setState),ie("onNodesChange",E,K.setState),ie("onEdgesChange",$,K.setState),ie("connectOnClick",k,K.setState),ie("fitViewOnInit",D,K.setState),ie("fitViewOnInitOptions",B,K.setState),ie("onNodesDelete",H,K.setState),ie("onEdgesDelete",g,K.setState),ie("onNodeDrag",C,K.setState),ie("onNodeDragStart",S,K.setState),ie("onNodeDragStop",I,K.setState),ie("onSelectionDrag",L,K.setState),ie("onSelectionDragStart",j,K.setState),ie("onSelectionDragStop",T,K.setState),ie("noPanClassName",P,K.setState),ie("nodeOrigin",z,K.setState),ie("rfId",W,K.setState),ie("autoPanOnConnect",V,K.setState),ie("autoPanOnNodeDrag",Z,K.setState),ie("onError",J,K.setState),ie("connectionRadius",ee,K.setState),ie("isValidConnection",oe,K.setState),ie("nodeDragThreshold",ne,K.setState),Et(e,re),Et(t,pe),Et(y,ue),Et(v,ye),Et(R,he),Et(p,xe),null},Cs={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},jo="react-flow__node-desc",Co="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Wf({rfId:e}){const t=de(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Xf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${jo}-${e}`,style:Cs},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Co}-${e}`,style:Cs},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Wf,{rfId:e}))}var tn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=x.useState(!1),s=x.useRef(!1),i=x.useRef(new Set([])),[o,a]=x.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return x.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);i.current.add(f[y]),$s(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);$s(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Ms(e,t){return t.includes(e)?"code":"key"}function $o(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return $o(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function Mo(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=$o(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Oe(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Mo(s,n,i),s}function Ao(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const w=n().filter(v=>{var E;const p=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?p&&t.nodes.some($=>$.id===v.id):p}),y=w.every(v=>v.width&&v.height);if(w.length>0&&y){const v=on(w,d),{x:p,y:E,zoom:$}=go(v,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),b=Je.translate(p,E).scale($);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Uf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function gn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Uf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const Nt=()=>{},Kf={zoomIn:Nt,zoomOut:Nt,zoomTo:Nt,getZoom:()=>1,setViewport:Nt,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:Nt,fitBounds:Nt,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Ee(),{d3Zoom:t,d3Selection:n}=de(Zf,ke);return x.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=Je.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Ao(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=Je.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=go(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=Je.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),_r(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return _r(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=ho(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function an(){const e=Qf(),t=Ee(),n=x.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=x.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=x.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(v=>({...v}))},[]),i=x.useCallback(y=>{const{edges:v=[]}=t.getState();return v.find(p=>p.id===y)},[]),o=x.useCallback(y=>{const{getNodes:v,setNodes:p,hasDefaultNodes:E,onNodesChange:$}=t.getState(),b=v(),M=typeof y=="function"?y(b):y;if(E)p(M);else if($){const N=M.length===0?b.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));$(N)}},[]),a=x.useCallback(y=>{const{edges:v=[],setEdges:p,hasDefaultEdges:E,onEdgesChange:$}=t.getState(),b=typeof y=="function"?y(v):y;if(E)p(b);else if($){const M=b.length===0?v.map(N=>({type:"remove",id:N.id})):b.map(N=>({item:N,type:"reset"}));$(M)}},[]),c=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{getNodes:p,setNodes:E,hasDefaultNodes:$,onNodesChange:b}=t.getState();if($){const N=[...p(),...v];E(N)}else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),l=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{edges:p=[],setEdges:E,hasDefaultEdges:$,onEdgesChange:b}=t.getState();if($)E([...p,...v]);else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),u=x.useCallback(()=>{const{getNodes:y,edges:v=[],transform:p}=t.getState(),[E,$,b]=p;return{nodes:y().map(M=>({...M})),edges:v.map(M=>({...M})),viewport:{x:E,y:$,zoom:b}}},[]),d=x.useCallback(({nodes:y,edges:v})=>{const{nodeInternals:p,getNodes:E,edges:$,hasDefaultNodes:b,hasDefaultEdges:M,onNodesDelete:N,onEdgesDelete:_,onNodesChange:R,onEdgesChange:k}=t.getState(),O=(y||[]).map(C=>C.id),D=(v||[]).map(C=>C.id),B=E().reduce((C,S)=>{const I=S.parentNode||S.parentId,L=!O.includes(S.id)&&I&&C.find(T=>T.id===I);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(O.includes(S.id)||L)&&C.push(S),C},[]),H=$.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),g=H.filter(C=>D.includes(C.id));if(B||g){const C=po(B,H),S=[...g,...C],I=S.reduce((L,j)=>(L.includes(j.id)||L.push(j.id),L),[]);if((M||b)&&(M&&t.setState({edges:$.filter(L=>!I.includes(L.id))}),b&&(B.forEach(L=>{p.delete(L.id)}),t.setState({nodeInternals:new Map(p)}))),I.length>0&&(_==null||_(S),k&&k(I.map(L=>({id:L,type:"remove"})))),B.length>0&&(N==null||N(B),R)){const L=B.map(j=>({id:j.id,type:"remove"}));R(L)}}},[]),m=x.useCallback(y=>{const v=yf(y),p=v?null:t.getState().nodeInternals.get(y.id);return!v&&!p?[null,null,v]:[v?y:vs(p),p,v]},[]),f=x.useCallback((y,v=!0,p)=>{const[E,$,b]=m(y);return E?(p||t.getState().getNodes()).filter(M=>{if(!b&&(M.id===$.id||!M.positionAbsolute))return!1;const N=vs(M),_=wr(N,E);return v&&_>0||_>=E.width*E.height}):[]},[]),w=x.useCallback((y,v,p=!0)=>{const[E]=m(y);if(!E)return!1;const $=wr(E,v);return p&&$>0||$>=E.width*E.height},[]);return x.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:w}),[e,n,r,s,i,o,a,c,l,u,d,f,w])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ee(),{deleteElements:r}=an(),s=tn(e,Jf),i=tn(t);x.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),x.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Ee();x.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Or(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",tt.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Br={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,yn=e=>({x:e.x,y:e.y,zoom:e.k}),St=(e,t)=>e.target.closest(`.${t}`),As=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rs=e=>{const t=e.ctrlKey&&Mn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:w,maxZoom:y,zoomActivationKeyCode:v,preventScrolling:p=!0,children:E,noWheelClassName:$,noPanClassName:b})=>{const M=x.useRef(),N=Ee(),_=x.useRef(!1),R=x.useRef(!1),k=x.useRef(null),O=x.useRef({x:0,y:0,zoom:0}),{d3Zoom:D,d3Selection:B,d3ZoomHandler:H,userSelectionActive:g}=de(rh,ke),C=tn(v),S=x.useRef(0),I=x.useRef(!1),L=x.useRef();return th(k),x.useEffect(()=>{if(k.current){const j=k.current.getBoundingClientRect(),T=eo().scaleExtent([w,y]).translateExtent(f),P=Te(k.current).call(T),z=Je.translate(m.x,m.y).scale(Tt(m.zoom,w,y)),W=[[0,0],[j.width,j.height]],V=T.constrain()(z,W,f);T.transform(P,V),T.wheelDelta(Rs),N.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[V.x,V.y,V.k],domNode:k.current.closest(".react-flow")})}},[]),x.useEffect(()=>{B&&D&&(o&&!C&&!g?B.on("wheel.zoom",j=>{if(St(j,$))return!1;j.preventDefault(),j.stopImmediatePropagation();const T=B.property("__zoom").k||1;if(j.ctrlKey&&i){const oe=ze(j),ne=Rs(j),re=T*Math.pow(2,ne);D.scaleTo(B,re,oe,j);return}const P=j.deltaMode===1?20:1;let z=c===gt.Vertical?0:j.deltaX*P,W=c===gt.Horizontal?0:j.deltaY*P;!Mn()&&j.shiftKey&&c!==gt.Vertical&&(z=j.deltaY*P,W=0),D.translateBy(B,-(z/T)*a,-(W/T)*a,{internal:!0});const V=yn(B.property("__zoom")),{onViewportChangeStart:Z,onViewportChange:J,onViewportChangeEnd:ee}=N.getState();clearTimeout(L.current),I.current||(I.current=!0,t==null||t(j,V),Z==null||Z(V)),I.current&&(e==null||e(j,V),J==null||J(V),L.current=setTimeout(()=>{n==null||n(j,V),ee==null||ee(V),I.current=!1},150))},{passive:!1}):typeof H<"u"&&B.on("wheel.zoom",function(j,T){if(!p&&j.type==="wheel"&&!j.ctrlKey||St(j,$))return null;j.preventDefault(),H.call(this,j,T)},{passive:!1}))},[g,o,c,B,D,H,C,i,p,$,t,e,n]),x.useEffect(()=>{D&&D.on("start",j=>{var z,W;if(!j.sourceEvent||j.sourceEvent.internal)return null;S.current=(z=j.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=N.getState(),P=yn(j.transform);_.current=!0,O.current=P,((W=j.sourceEvent)==null?void 0:W.type)==="mousedown"&&N.setState({paneDragging:!0}),T==null||T(P),t==null||t(j.sourceEvent,P)})},[D,t]),x.useEffect(()=>{D&&(g&&!_.current?D.on("zoom",null):g||D.on("zoom",j=>{var P;const{onViewportChange:T}=N.getState();if(N.setState({transform:[j.transform.x,j.transform.y,j.transform.k]}),R.current=!!(r&&As(d,S.current??0)),(e||T)&&!((P=j.sourceEvent)!=null&&P.internal)){const z=yn(j.transform);T==null||T(z),e==null||e(j.sourceEvent,z)}}))},[g,D,e,d,r]),x.useEffect(()=>{D&&D.on("end",j=>{if(!j.sourceEvent||j.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=N.getState();if(_.current=!1,N.setState({paneDragging:!1}),r&&As(d,S.current??0)&&!R.current&&r(j.sourceEvent),R.current=!1,(n||T)&&nh(O.current,j.transform)){const P=yn(j.transform);O.current=P,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(P),n==null||n(j.sourceEvent,P)},o?150:0)}})},[D,o,d,n,r]),x.useEffect(()=>{D&&D.filter(j=>{const T=C||s,P=i&&j.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&j.button===1&&j.type==="mousedown"&&(St(j,"react-flow__node")||St(j,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||g||!l&&j.type==="dblclick"||St(j,$)&&j.type==="wheel"||St(j,b)&&(j.type!=="wheel"||o&&j.type==="wheel"&&!C)||!i&&j.ctrlKey&&j.type==="wheel"||!T&&!o&&!P&&j.type==="wheel"||!d&&(j.type==="mousedown"||j.type==="touchstart")||Array.isArray(d)&&!d.includes(j.button)&&j.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(j.button)||!j.button||j.button<=1;return(!j.ctrlKey||j.type==="wheel")&&z})},[g,D,s,i,o,l,d,u,C]),A.createElement("div",{className:"react-flow__renderer",ref:k,style:Br},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=de(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Is(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&Is(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&Is(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ot=(e,t)=>({id:e,type:"select",selected:t});function jt(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ot(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ot(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ro=x.memo(({isSelecting:e,selectionMode:t=en.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=x.useRef(null),f=Ee(),w=x.useRef(0),y=x.useRef(0),v=x.useRef(),{userSelectionActive:p,elementsSelectable:E,dragging:$}=de(lh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),w.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},N=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,R=H=>{const{resetSelectedElements:g,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!v.current)return;const{x:S,y:I}=lt(H,v.current);g(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:I,x:S,y:I}}),r==null||r(H)},k=H=>{const{userSelectionRect:g,nodeInternals:C,edges:S,transform:I,onNodesChange:L,onEdgesChange:j,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!g)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=lt(H,v.current),W=g.startX??0,V=g.startY??0,Z={...g,x:z.xre.id),ne=ee.map(re=>re.id);if(w.current!==ne.length){w.current=ne.length;const re=jt(J,ne);re.length&&(L==null||L(re))}if(y.current!==oe.length){y.current=oe.length;const re=jt(S,oe);re.length&&(j==null||j(re))}f.setState({userSelectionRect:Z})},O=H=>{if(H.button!==0)return;const{userSelectionRect:g}=f.getState();!p&&g&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:w.current>0}),b(),s==null||s(H)},D=H=>{p&&(f.setState({nodesSelectionActive:w.current>0}),s==null||s(H)),b()},B=E&&(e||p);return A.createElement("div",{className:je(["react-flow__pane",{dragging:$,selection:e}]),onClick:B?void 0:er(M,m),onContextMenu:er(N,m),onWheel:er(_,m),onMouseEnter:B?void 0:c,onMouseDown:B?R:void 0,onMouseMove:B?k:l,onMouseUp:B?O:void 0,onMouseLeave:B?D:u,ref:m,style:Br},d,A.createElement(oh,null))});Ro.displayName="Pane";function Io(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Io(r,t):!1}function Ts(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Io(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function To(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Oe(m)&&Oe(f)&&Oe(d.width)&&Oe(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",tt.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Lr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Os=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Or(c)}})};function Vt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Nr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",tt.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Ee();return x.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Oo({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Ee(),[c,l]=x.useState(!1),u=x.useRef([]),d=x.useRef({x:null,y:null}),m=x.useRef(0),f=x.useRef(null),w=x.useRef({x:0,y:0}),y=x.useRef(null),v=x.useRef(!1),p=x.useRef(!1),E=x.useRef(!1),$=fh();return x.useEffect(()=>{if(e!=null&&e.current){const b=Te(e.current),M=({x:R,y:k})=>{const{nodeInternals:O,onNodeDrag:D,onSelectionDrag:B,updateNodePositions:H,nodeExtent:g,snapGrid:C,snapToGrid:S,nodeOrigin:I,onError:L}=a.getState();d.current={x:R,y:k};let j=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&g){const z=on(u.current,I);T=Jt(z)}if(u.current=u.current.map(z=>{const W={x:R-z.distance.x,y:k-z.distance.y};S&&(W.x=C[0]*Math.round(W.x/C[0]),W.y=C[1]*Math.round(W.y/C[1]));const V=[[g[0][0],g[0][1]],[g[1][0],g[1][1]]];u.current.length>1&&g&&!z.extent&&(V[0][0]=z.positionAbsolute.x-T.x+g[0][0],V[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+g[1][0],V[0][1]=z.positionAbsolute.y-T.y+g[0][1],V[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+g[1][1]);const Z=To(z,W,O,V,I,L);return j=j||z.position.x!==Z.position.x||z.position.y!==Z.position.y,z.position=Z.position,z.positionAbsolute=Z.positionAbsolute,z}),!j)return;H(u.current,!0,!0),l(!0);const P=s?D:nr(B);if(P&&y.current){const[z,W]=tr({nodeId:s,dragItems:u.current,nodeInternals:O});P(y.current,z,W)}},N=()=>{if(!f.current)return;const[R,k]=no(w.current,f.current);if(R!==0||k!==0){const{transform:O,panBy:D}=a.getState();d.current.x=(d.current.x??0)-R/O[2],d.current.y=(d.current.y??0)-k/O[2],D({x:R,y:k})&&M(d.current)}m.current=requestAnimationFrame(N)},_=R=>{var I;const{nodeInternals:k,multiSelectionActive:O,nodesDraggable:D,unselectNodesAndEdges:B,onNodeDragStart:H,onSelectionDragStart:g}=a.getState();p.current=!0;const C=s?H:nr(g);(!o||!i)&&!O&&s&&((I=k.get(s))!=null&&I.selected||B()),s&&i&&o&&Nr({id:s,store:a,nodeRef:e});const S=$(R);if(d.current=S,u.current=uh(k,D,S,s),C&&u.current){const[L,j]=tr({nodeId:s,dragItems:u.current,nodeInternals:k});C(R.sourceEvent,L,j)}};if(t)b.on(".drag",null);else{const R=bu().on("start",k=>{const{domNode:O,nodeDragThreshold:D}=a.getState();D===0&&_(k),E.current=!1;const B=$(k);d.current=B,f.current=(O==null?void 0:O.getBoundingClientRect())||null,w.current=lt(k.sourceEvent,f.current)}).on("drag",k=>{var H,g;const O=$(k),{autoPanOnNodeDrag:D,nodeDragThreshold:B}=a.getState();if(k.sourceEvent.type==="touchmove"&&k.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&p.current&&D&&(v.current=!0,N()),!p.current){const C=O.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=O.ySnapped-(((g=d==null?void 0:d.current)==null?void 0:g.y)??0);Math.sqrt(C*C+S*S)>B&&_(k)}(d.current.x!==O.xSnapped||d.current.y!==O.ySnapped)&&u.current&&p.current&&(y.current=k.sourceEvent,w.current=lt(k.sourceEvent,f.current),M(O))}}).on("end",k=>{if(!(!p.current||E.current)&&(l(!1),v.current=!1,p.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:O,nodeInternals:D,onNodeDragStop:B,onSelectionDragStop:H}=a.getState(),g=s?B:nr(H);if(O(u.current,!1,!1),g){const[C,S]=tr({nodeId:s,dragItems:u.current,nodeInternals:D});g(k.sourceEvent,C,S)}}}).filter(k=>{const O=k.target;return!k.button&&(!n||!Ts(O,`.${n}`,e))&&(!r||Ts(O,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,$]),c}function Lo(){const e=Ee();return x.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,w=n.isShiftPressed?4:1,y=n.x*m*w,v=n.y*f*w,p=d.map(E=>{if(E.positionAbsolute){const $={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+v};a&&($.x=c[0]*Math.round($.x/c[0]),$.y=c[1]*Math.round($.y/c[1]));const{positionAbsolute:b,position:M}=To(E,$,r,s,void 0,l);E.position=M,E.positionAbsolute=b}return E});i(p,!0,!1)},[])}const Mt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Bt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:w,onDoubleClick:y,style:v,className:p,isDraggable:E,isSelectable:$,isConnectable:b,isFocusable:M,selectNodesOnDrag:N,sourcePosition:_,targetPosition:R,hidden:k,resizeObserver:O,dragHandle:D,zIndex:B,isParent:H,noDragClassName:g,noPanClassName:C,initialized:S,disableKeyboardA11y:I,ariaLabel:L,rfId:j,hasHandleBounds:T})=>{const P=Ee(),z=x.useRef(null),W=x.useRef(null),V=x.useRef(_),Z=x.useRef(R),J=x.useRef(r),ee=$||E||u||d||m||f,oe=Lo(),ne=Vt(n,P.getState,d),re=Vt(n,P.getState,m),pe=Vt(n,P.getState,f),ce=Vt(n,P.getState,w),ue=Vt(n,P.getState,y),ye=le=>{const{nodeDragThreshold:K}=P.getState();if($&&(!N||!E||K>0)&&Nr({id:n,store:P,nodeRef:z}),u){const Ne=P.getState().nodeInternals.get(n);Ne&&u(le,{...Ne})}},he=le=>{if(!br(le)&&!I)if(oo.includes(le.key)&&$){const K=le.key==="Escape";Nr({id:n,store:P,unselect:K,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Mt,le.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),oe({x:Mt[le.key].x,y:Mt[le.key].y,isShiftPressed:le.shiftKey}))};x.useEffect(()=>()=>{W.current&&(O==null||O.unobserve(W.current),W.current=null)},[]),x.useEffect(()=>{if(z.current&&!k){const le=z.current;(!S||!T||W.current!==le)&&(W.current&&(O==null||O.unobserve(W.current)),O==null||O.observe(le),W.current=le)}},[k,S,T]),x.useEffect(()=>{const le=J.current!==r,K=V.current!==_,Ne=Z.current!==R;z.current&&(le||K||Ne)&&(le&&(J.current=r),K&&(V.current=_),Ne&&(Z.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const xe=Oo({nodeRef:z,disabled:k||!E,noDragClassName:g,handleSelector:D,nodeId:n,isSelectable:$,selectNodesOnDrag:N});return k?null:A.createElement("div",{className:je(["react-flow__node",`react-flow__node-${r}`,{[C]:E},p,{selected:l,selectable:$,parent:H,dragging:xe}]),ref:z,style:{zIndex:B,transform:`translate(${a}px,${c}px)`,pointerEvents:ee?"all":"none",visibility:S?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:re,onMouseLeave:pe,onContextMenu:ce,onClick:ye,onDoubleClick:ue,onKeyDown:M?he:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":I?void 0:`${jo}-${j}`,"aria-label":L},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:xe,dragHandle:D,zIndex:B})))};return t.displayName="NodeWrapper",x.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...on(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ee(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=de(hh,ke),u=Lo(),d=x.useRef(null);if(x.useEffect(()=>{var w;n||(w=d.current)==null||w.focus({preventScroll:!0})},[n]),Oo({nodeRef:d}),l||!s||!i)return null;const m=e?w=>{const y=r.getState().getNodes().filter(v=>v.selected);e(w,y)}:void 0,f=w=>{Object.prototype.hasOwnProperty.call(Mt,w.key)&&u({x:Mt[w.key].x,y:Mt[w.key].y,isShiftPressed:w.shiftKey})};return A.createElement("div",{className:je(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=x.memo(mh);const gh=e=>e.nodesSelectionActive,Do=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:w,onSelectionEnd:y,multiSelectionKeyCode:v,panActivationKeyCode:p,zoomActivationKeyCode:E,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:N,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:O,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,preventScrolling:C,onSelectionContextMenu:S,noWheelClassName:I,noPanClassName:L,disableKeyboardA11y:j})=>{const T=de(gh),P=tn(d),z=tn(p),W=z||O,V=z||N,Z=P||m&&W!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:V,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:!P&&W,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:I,noPanClassName:L},A.createElement(Ro,{onSelectionStart:w,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:W,isSelecting:!!Z,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:L,disableKeyboardA11y:j})))};Do.displayName="FlowRenderer";var yh=x.memo(Do);function xh(e){return de(x.useCallback(n=>e?mo(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Bt(e.input||Eo),default:Bt(e.default||Er),output:Bt(e.output||So),group:Bt(e.group||Vr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Bt(e[i]||Er),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Po=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=de(vh,ke),a=xh(e.onlyRenderVisibleElements),c=x.useRef(),l=x.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return x.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Br},a.map(u=>{var M,N,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",tt.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),w=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),v=!!(u.focusable||r&&typeof u.focusable>"u"),p=e.nodeExtent?Lr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(p==null?void 0:p.x)??0,$=(p==null?void 0:p.y)??0,b=bh({x:E,y:$,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||q.Bottom,targetPosition:u.targetPosition||q.Top,hidden:u.hidden,xPos:E,yPos:$,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:w,isConnectable:y,isFocusable:v,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((N=u[we])!=null&&N.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Po.displayName="NodeRenderer";var _h=x.memo(Po);const Eh=(e,t,n)=>n===q.Left?e-t:n===q.Right?e+t:e,Nh=(e,t,n)=>n===q.Top?e-t:n===q.Bottom?e+t:e,Ls="react-flow__edgeupdater",Ds=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:je([Ls,`${Ls}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var kt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,style:v,source:p,target:E,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,elementsSelectable:k,hidden:O,sourceHandleId:D,targetHandleId:B,onContextMenu:H,onMouseEnter:g,onMouseMove:C,onMouseLeave:S,reconnectRadius:I,onReconnect:L,onReconnectStart:j,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:W,ariaLabel:V,isFocusable:Z,isReconnectable:J,pathOptions:ee,interactionWidth:oe,disableKeyboardA11y:ne})=>{const re=x.useRef(null),[pe,ce]=x.useState(!1),[ue,ye]=x.useState(!1),he=Ee(),xe=x.useMemo(()=>`url('#${vr(z,W)}')`,[z,W]),le=x.useMemo(()=>`url('#${vr(P,W)}')`,[P,W]);if(O)return null;const K=se=>{var Se;const{edges:me,addSelectedEdges:$e,unselectNodesAndEdges:X,multiSelectionActive:fe}=he.getState(),ge=me.find(dt=>dt.id===n);ge&&(k&&(he.setState({nodesSelectionActive:!1}),ge.selected&&fe?(X({nodes:[],edges:[ge]}),(Se=re.current)==null||Se.blur()):$e([n])),o&&o(se,ge))},Ne=Ft(n,he.getState,a),Ce=Ft(n,he.getState,H),ut=Ft(n,he.getState,g),Ae=Ft(n,he.getState,C),Xe=Ft(n,he.getState,S),Ie=(se,me)=>{if(se.button!==0)return;const{edges:$e,isValidConnection:X}=he.getState(),fe=me?E:p,ge=(me?B:D)||null,Se=me?"target":"source",dt=X||Sh,Ot=me,rt=$e.find(Pe=>Pe.id===n);ye(!0),j==null||j(se,rt,Se);const ft=Pe=>{ye(!1),T==null||T(Pe,rt,Se)};wo({event:se,handleId:ge,nodeId:fe,onConnect:Pe=>L==null?void 0:L(rt,Pe),isTarget:Ot,getState:he.getState,setState:he.setState,isValidConnection:dt,edgeUpdaterType:Se,onReconnectEnd:ft})},F=se=>Ie(se,!0),Y=se=>Ie(se,!1),G=()=>ce(!0),Q=()=>ce(!1),U=!k&&!o,te=se=>{var me;if(!ne&&oo.includes(se.key)&&k){const{unselectNodesAndEdges:$e,addSelectedEdges:X,edges:fe}=he.getState();se.key==="Escape"?((me=re.current)==null||me.blur(),$e({edges:[fe.find(Se=>Se.id===n)]})):X([n])}};return A.createElement("g",{className:je(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:pe}]),onClick:K,onDoubleClick:Ne,onContextMenu:Ce,onMouseEnter:ut,onMouseMove:Ae,onMouseLeave:Xe,onKeyDown:Z?te:void 0,tabIndex:Z?0:void 0,role:Z?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":V===null?void 0:V||`Edge from ${p} to ${E}`,"aria-describedby":Z?`${Co}-${W}`:void 0,ref:re},!ue&&A.createElement(e,{id:n,source:p,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,data:i,style:v,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,sourceHandleId:D,targetHandleId:B,markerStart:xe,markerEnd:le,pathOptions:ee,interactionWidth:oe}),J&&A.createElement(A.Fragment,null,(J==="source"||J===!0)&&A.createElement(Ds,{position:_,centerX:$,centerY:b,radius:I,onMouseDown:F,onMouseEnter:G,onMouseOut:Q,type:"source"}),(J==="target"||J===!0)&&A.createElement(Ds,{position:R,centerX:M,centerY:N,radius:I,onMouseDown:Y,onMouseEnter:G,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",x.memo(t)};function kh(e){const t={default:kt(e.default||In),straight:kt(e.bezier||zr),step:kt(e.step||Pr),smoothstep:kt(e.step||Bn),simplebezier:kt(e.simplebezier||Dr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=kt(e[i]||In),s),n);return{...t,...r}}function Ps(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case q.Top:return{x:r+i/2,y:s};case q.Right:return{x:r+i,y:s+o/2};case q.Bottom:return{x:r+i/2,y:s+o};case q.Left:return{x:r,y:s+o/2}}}function zs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ps(n,e,t),a=Ps(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Jt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Hs(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Oe(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),w=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(w?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=de(x.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Fs={[An.Arrow]:Rh,[An.ArrowClosed]:Ih};function Th(e){const t=Ee();return x.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(Fs,e)?Fs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",tt.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=vr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},zo=({defaultColor:e,rfId:t})=>{const n=de(x.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};zo.displayName="MarkerDefinitions";var Dh=x.memo(zo);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ho=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,children:v,disableKeyboardA11y:p})=>{const{edgesFocusable:E,edgesUpdatable:$,elementsSelectable:b,width:M,height:N,connectionMode:_,nodeInternals:R,onError:k}=de(Ph,ke),O=Ah(t,R,n);return M?A.createElement(A.Fragment,null,O.map(({level:D,edges:B,isMaxLevel:H})=>A.createElement("svg",{key:D,style:{zIndex:D},width:M,height:N,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,B.map(g=>{const[C,S,I]=Hs(R.get(g.source)),[L,j,T]=Hs(R.get(g.target));if(!I||!T)return null;let P=g.type||"default";s[P]||(k==null||k("011",tt.error011(P)),P="default");const z=s[P]||s.default,W=_===vt.Strict?j.target:(j.target??[]).concat(j.source??[]),V=zs(S.source,g.sourceHandle),Z=zs(W,g.targetHandle),J=(V==null?void 0:V.position)||q.Bottom,ee=(Z==null?void 0:Z.position)||q.Top,oe=!!(g.focusable||E&&typeof g.focusable>"u"),ne=g.reconnectable||g.updatable,re=typeof m<"u"&&(ne||$&&typeof ne>"u");if(!V||!Z)return k==null||k("008",tt.error008(V,g)),null;const{sourceX:pe,sourceY:ce,targetX:ue,targetY:ye}=jh(C,V,J,L,Z,ee);return A.createElement(z,{key:g.id,id:g.id,className:je([g.className,i]),type:P,data:g.data,selected:!!g.selected,animated:!!g.animated,hidden:!!g.hidden,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,style:g.style,source:g.source,target:g.target,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerEnd:g.markerEnd,markerStart:g.markerStart,sourceX:pe,sourceY:ce,targetX:ue,targetY:ye,sourcePosition:J,targetPosition:ee,elementsSelectable:b,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,rfId:r,ariaLabel:g.ariaLabel,isFocusable:oe,isReconnectable:re,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth,disableKeyboardA11y:p})})))),v):null};Ho.displayName="EdgeRenderer";var zh=x.memo(Ho);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=de(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=an(),n=x.useRef(!1);x.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[q.Left]:q.Right,[q.Right]:q.Left,[q.Top]:q.Bottom,[q.Bottom]:q.Top},Fo=({nodeId:e,handleType:t,style:n,type:r=at.Bezier,CustomComponent:s,connectionStatus:i})=>{var N,_,R;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=de(x.useCallback(k=>({fromNode:k.nodeInternals.get(e),handleId:k.connectionHandleId,toX:(k.connectionPosition.x-k.transform[0])/k.transform[2],toY:(k.connectionPosition.y-k.transform[1])/k.transform[2],connectionMode:k.connectionMode}),[e]),ke),d=(N=o==null?void 0:o[we])==null?void 0:N.handleBounds;let m=d==null?void 0:d[t];if(u===vt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(k=>k.id===a):m[0],w=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,v=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+w,p=(((R=o.positionAbsolute)==null?void 0:R.y)??0)+y,E=f==null?void 0:f.position,$=E?Bh[E]:null;if(!E||!$)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:v,fromY:p,toX:c,toY:l,fromPosition:E,toPosition:$,connectionStatus:i});let b="";const M={sourceX:v,sourceY:p,sourcePosition:E,targetX:c,targetY:l,targetPosition:$};return r===at.Bezier?[b]=fo(M):r===at.Step?[b]=Rn({...M,borderRadius:0}):r===at.SmoothStep?[b]=Rn(M):r===at.SimpleBezier?[b]=uo(M):b=`M${v},${p} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Fo.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=de(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:je(["react-flow__connection",l])},A.createElement(Fo,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Vs(e,t){return x.useRef(null),Ee(),x.useMemo(()=>t(e),[e])}const Vo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:w,onSelectionStart:y,onSelectionEnd:v,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:$,connectionLineContainerStyle:b,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,deleteKeyCode:D,onlyRenderVisibleElements:B,elementsSelectable:H,selectNodesOnDrag:g,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,preventScrolling:j,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:W,panOnScrollSpeed:V,panOnScrollMode:Z,zoomOnDoubleClick:J,panOnDrag:ee,onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneScroll:ce,onPaneContextMenu:ue,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,noDragClassName:Ae,noWheelClassName:Xe,noPanClassName:Ie,elevateEdgesOnSelect:F,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})=>{const te=Vs(e,wh),se=Vs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneContextMenu:ue,onPaneScroll:ce,deleteKeyCode:D,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,onSelectionStart:y,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:J,panOnScroll:W,panOnScrollSpeed:V,panOnScrollMode:Z,panOnDrag:ee,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,onSelectionContextMenu:w,preventScrolling:j,noDragClassName:Ae,noWheelClassName:Xe,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:B,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!F,disableKeyboardA11y:Y,rfId:U},A.createElement(Yh,{style:E,type:p,component:$,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:te,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:g,onlyRenderVisibleElements:B,noPanClassName:Ie,noDragClassName:Ae,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})))};Vo.displayName="GraphView";var Wh=x.memo(Vo);const Sr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],st={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Sr,nodeExtent:Sr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:vt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Xh=()=>Rc((e,t)=>({...st,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Jn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,v)=>{const p=s.get(v.id);if(p!=null&&p.hidden)s.set(p.id,{...p,[we]:{...p[we],handleBounds:void 0}});else if(p){const E=Or(v.nodeElement);!!(E.width&&E.height&&(p.width!==E.width||p.height!==E.height||v.forceUpdate))&&(s.set(p.id,{...p,[we]:{...p[we],handleBounds:{source:Os(".source",v.nodeElement,m,l),target:Os(".target",v.nodeElement,m,l)}},...E}),y.push({id:p.id,type:"dimensions",dimensions:E}))}return y},[]);Mo(s,l);const w=o||i&&!o&&Ao(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:w}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Jn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(i(),n),a=jt(s,[])),gn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(s,n),a=jt(i(),[])),gn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ot(u.id,!1))),l=a.map(u=>ot(u.id,!1));gn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ot(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ot(a.id,!1));gn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Lr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=Je.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:st.connectionNodeId,connectionHandleId:st.connectionHandleId,connectionHandleType:st.connectionHandleType,connectionStatus:st.connectionStatus,connectionStartHandle:st.connectionStartHandle,connectionEndHandle:st.connectionEndHandle}),reset:()=>e({...st})}),Object.is),Bo=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Xh()),A.createElement(df,{value:t.current},e)};Bo.displayName="ReactFlowProvider";const Go=({children:e})=>x.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Bo,null,e);Go.displayName="ReactFlowWrapper";const Uh={input:Eo,default:Er,output:So,group:Vr},qh={default:In,straight:zr,step:Pr,smoothstep:Bn,simplebezier:Dr},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Yo=x.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Uh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onNodesDelete:O,onEdgesDelete:D,onSelectionChange:B,onSelectionDragStart:H,onSelectionDrag:g,onSelectionDragStop:C,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,connectionMode:j=vt.Strict,connectionLineType:T=at.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:W,deleteKeyCode:V="Backspace",selectionKeyCode:Z="Shift",selectionOnDrag:J=!1,selectionMode:ee=en.Full,panActivationKeyCode:oe="Space",multiSelectionKeyCode:ne=Mn()?"Meta":"Control",zoomActivationKeyCode:re=Mn()?"Meta":"Control",snapToGrid:pe=!1,snapGrid:ce=Zh,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:ye=!0,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,nodeOrigin:K=Kh,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,defaultViewport:Ae=Qh,minZoom:Xe=.5,maxZoom:Ie=2,translateExtent:F=Sr,preventScrolling:Y=!0,nodeExtent:G,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:te=!0,panOnScroll:se=!1,panOnScrollSpeed:me=.5,panOnScrollMode:$e=gt.Free,zoomOnDoubleClick:X=!0,panOnDrag:fe=!0,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,children:Lt,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:Zr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Wa,defaultEdgeOptions:Xa,elevateNodesOnSelect:Ua=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Qr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Jr,nodeDragThreshold:nc,...rc},sc)=>{const Wn=Jr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:je(["react-flow",s]),"data-testid":"rf__wrapper",id:Jr},A.createElement(Go,null,A.createElement(Wh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:W,selectionKeyCode:Z,selectionOnDrag:J,selectionMode:ee,deleteKeyCode:V,multiSelectionKeyCode:ne,panActivationKeyCode:oe,zoomActivationKeyCode:re,onlyRenderVisibleElements:ue,selectNodesOnDrag:ye,defaultViewport:Ae,translateExtent:F,minZoom:Xe,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:U,zoomOnPinch:te,zoomOnDoubleClick:X,panOnScroll:se,panOnScrollSpeed:me,panOnScrollMode:$e,panOnDrag:fe,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:Zr,elevateEdgesOnSelect:qa,rfId:Wn,disableKeyboardA11y:Qr,nodeOrigin:K,nodeExtent:G}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,elevateNodesOnSelect:Ua,minZoom:Xe,maxZoom:Ie,nodeExtent:G,onNodesChange:Pa,onEdgesChange:za,snapToGrid:pe,snapGrid:ce,connectionMode:j,translateExtent:F,connectOnClick:Ga,defaultEdgeOptions:Xa,fitView:Va,fitViewOptions:Ba,onNodesDelete:O,onEdgesDelete:D,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onSelectionDrag:g,onSelectionDragStart:H,onSelectionDragStop:C,noPanClassName:Zr,nodeOrigin:K,rfId:Wn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:B}),Lt,A.createElement(hf,{proOptions:Wa,position:Ya}),A.createElement(Xf,{rfId:Wn,disableKeyboardA11y:Qr})))});Yo.displayName="ReactFlow";const Wo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:w,backgroundColor:y}=i||{},v=o||w||y;return A.createElement("rect",{className:je(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?p=>m(p,e):void 0})};Wo.displayName="MiniMapNode";var em=x.memo(Wo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=de(nm,ke),c=de(tm),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:w,y}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:w,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=x.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(on(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Xo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:w=!1,zoomable:y=!1,ariaLabel:v="React Flow mini map",inversePan:p=!1,zoomStep:E=10,offsetScale:$=5}){const b=Ee(),M=x.useRef(null),{boundingRect:N,viewBB:_,rfId:R}=de(am,ke),k=(e==null?void 0:e.width)??im,O=(e==null?void 0:e.height)??om,D=N.width/k,B=N.height/O,H=Math.max(D,B),g=H*k,C=H*O,S=$*H,I=N.x-(g-N.width)/2-S,L=N.y-(C-N.height)/2-S,j=g+S*2,T=C+S*2,P=`${cm}-${R}`,z=x.useRef(0);z.current=H,x.useEffect(()=>{if(M.current){const Z=Te(M.current),J=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce}=b.getState();if(ne.sourceEvent.type!=="wheel"||!pe||!ce)return;const ue=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,ye=re[2]*Math.pow(2,ue);ce.scaleTo(pe,ye)},ee=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce,translateExtent:ue,width:ye,height:he}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!pe||!ce)return;const xe=z.current*Math.max(1,re[2])*(p?-1:1),le={x:re[0]-ne.sourceEvent.movementX*xe,y:re[1]-ne.sourceEvent.movementY*xe},K=[[0,0],[ye,he]],Ne=Je.translate(le.x,le.y).scale(re[2]),Ce=ce.constrain()(Ne,K,ue);ce.transform(pe,Ce)},oe=eo().on("zoom",w?ee:null).on("zoom.wheel",y?J:null);return Z.call(oe),()=>{Z.on("zoom",null)}}},[w,y,p,E]);const W=m?Z=>{const J=ze(Z);m(Z,{x:J[0],y:J[1]})}:void 0,V=f?(Z,J)=>{const ee=b.getState().nodeInternals.get(J);f(Z,ee)}:void 0;return A.createElement(Tr,{position:d,style:e,className:je(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:k,height:O,viewBox:`${I} ${L} ${j} ${T}`,role:"img","aria-labelledby":P,ref:M,onClick:W},v&&A.createElement("title",{id:P},v),A.createElement(sm,{onClick:V,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${I-S},${L-S}h${j+S*2}v${T+S*2}h${-j-S*2}z + M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Xo.displayName="MiniMap";var lm=x.memo(Xo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Wt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:je(["react-flow__controls-button",t]),...n},e);Wt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ee(),[f,w]=x.useState(!1),{isInteractive:y,minZoomReached:v,maxZoomReached:p}=de(pm,ke),{zoomIn:E,zoomOut:$,fitView:b}=an();if(x.useEffect(()=>{w(!0)},[]),!f)return null;const M=()=>{E(),i==null||i()},N=()=>{$(),o==null||o()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c==null||c(!y)};return A.createElement(Tr,{className:je(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Wt,{onClick:M,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:p},A.createElement(um,null)),A.createElement(Wt,{onClick:N,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(dm,null))),n&&A.createElement(Wt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Wt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},y?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=x.memo(Uo),Le;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Le||(Le={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[Le.Dots]:"#91919a",[Le.Lines]:"#eee",[Le.Cross]:"#e2e2e2"},bm={[Le.Dots]:1,[Le.Lines]:1,[Le.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function qo({id:e,variant:t=Le.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=x.useRef(null),{transform:u,patternId:d}=de(vm,ke),m=o||wm[t],f=r||bm[t],w=t===Le.Dots,y=t===Le.Cross,v=Array.isArray(n)?n:[n,n],p=[v[0]*u[2]||1,v[1]*u[2]||1],E=f*u[2],$=y?[E,E]:p,b=w?[E/i,E/i]:[$[0]/i,$[1]/i];return A.createElement("svg",{className:je(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%p[0],y:u[1]%p[1],width:p[0],height:p[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},w?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:$,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}qo.displayName="Background";var _m=x.memo(qo);const Gr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Gr+e}async function be(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function nt(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new Ko(r.error??`${e}: ${n.status}`,n.status);return r}class Ko extends Error{constructor(n,r){super(n);ve(this,"status");this.status=r}}const Cx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),$x=()=>be("/api/diagnostics"),Zo=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Qo=()=>be("/api/ontology/ontologies"),Em=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>be("/api/ontology/stack"),Sm=()=>be("/api/ontology/coverage"),km=(e,t,n)=>nt("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>be("/api/git/status"),Cm=()=>be("/api/git/diff"),$m=e=>nt("/api/git/commit",{message:e}),Mm=()=>nt("/api/git/discard",{}),Am=()=>be("/api/decisions"),Bs=(e,t)=>nt(`/api/decisions/${e}/verdict`,{verdict:t}),Mx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Ax=()=>be("/api/glossary/config"),Rx=e=>nt("/api/git/propose",e),Ix=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Tx=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),Ox=e=>nt("/api/git/classify",{changes:e}),Lx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Dx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Px=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>be("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Gr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>nt("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>nt("/api/import/preview",{format:e,content:t}),zx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Hx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Fx=(e,t,n)=>fetch(`${Gr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new Ko(await r.text(),r.status);return await r.json()}),Vx=()=>be("/api/glossary/subject-areas"),Bx=e=>be(`/api/glossary/subject-area/${e}`),Gx=(e,t)=>nt(`/api/glossary/subject-area/${e}/expand`,t);function Yx(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Yr="__entity_source",Wr="__entity_target",Pm=x.memo(function({data:t,selected:n}){var N;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:w}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>y(_.a)-y(R.a)||_.i-R.i).map(_=>_.a),p=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const $=!!c&&!l;let b=0;if($){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const M=(_,R)=>{const k="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:k,onMouseEnter:w?()=>w(_.id):void 0,onMouseLeave:w?()=>w(null):void 0,children:[h.jsx(ct,{id:_.id,type:"target",position:q.Left,className:"port attr-port"}),h.jsx(ct,{id:_.id,type:"source",position:q.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ct,{id:Wr,type:"target",position:q.Left,className:"port"}),h.jsx(ct,{id:Yr,type:"source",position:q.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((N=r.conceptual)==null?void 0:N.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var k;const _=(((k=r.conceptual)==null?void 0:k.ontology_refs)??[]).filter(O=>O.uri);if(_.length===0)return null;const R=_.map(O=>O.uri).join(` +`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),p.length>0&&h.jsx("div",{className:"attr-section keys",children:p.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,w,y,v,p,E,$,b,M,N,_,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(k=>k.from.entity===e.id||k.to.entity===e.id),d=k=>{var O;return((O=t.entities.find(D=>D.id===k))==null?void 0:O.name)??k};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Ke,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,name:k})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Ke,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,physical_name:k})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Ke,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:k=>r("set_definition",{id:e.id,definition:k})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((w=l==null?void 0:l.ontology_refs)==null?void 0:w.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((p=e.term_map)==null?void 0:p.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),($=e.term_map)!=null&&$.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((N=e.term_map)==null?void 0:N.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Ke,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:k,steward:((O=l==null?void 0:l.stewardship)==null?void 0:O.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Ke,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:((O=l==null?void 0:l.stewardship)==null?void 0:O.owner)??null,steward:k})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(k=>h.jsx(Wm,{a:k,entity:e,doc:t,readOnly:c,exec:r},k.id))})}),!c&&h.jsx(Xm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(k=>{const O=k.members.map(D=>{var B;return((B=e.attributes.find(H=>H.id===D))==null?void 0:B.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+k.type,children:k.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:k.name}),h.jsx("span",{className:"key-cols",children:O})]},k.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([k,O])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:k}),h.jsx("td",{className:"udp-val",children:String(O)})]},k))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(k=>{const O=k.from.entity===e.id?k.to.entity:k.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(O),children:[h.jsx("span",{className:"rel-card",children:Um(k,e.id)}),d(O)]}),(k.verb_phrase||k.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Ke,{value:k.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,verb_phrase:D})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Ke,{value:k.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,inverse_verb_phrase:D})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${k.name}`,onClick:()=>r("delete_relationship",{id:k.id}),children:"✕"})]},k.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var k;return(k=navigator.clipboard)==null?void 0:k.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Ke({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=x.useState(e);x.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Wm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Ke,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Ke,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Xm({entity:e,exec:t}){const[n,r]=x.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Um(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Gs="";let Km=class{constructor(t){ve(this,"_isDirected",!0);ve(this,"_isMultigraph",!1);ve(this,"_isCompound",!1);ve(this,"_label");ve(this,"_defaultNodeLabelFn",()=>{});ve(this,"_defaultEdgeLabelFn",()=>{});ve(this,"_nodes",{});ve(this,"_in",{});ve(this,"_preds",{});ve(this,"_out",{});ve(this,"_sucs",{});ve(this,"_edgeObjs",{});ve(this,"_edgeLabels",{});ve(this,"_nodeCount",0);ve(this,"_edgeCount",0);ve(this,"_parent");ve(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Xt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Ys(this._preds[n],t),Ys(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Xt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Xt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Xt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Ws(this._preds[n],t),Ws(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Ys(e,t){e[t]?e[t]++:e[t]=1}function Ws(e,t){--e[t]||delete e[t]}function Xt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Gs+i+Gs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function sr(e,t){return Xt(e,t.v,t.w,t.name)}var Xr=Km,Qm="2.2.4",Jm={Graph:Xr,version:Qm},ep=Xr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){ve(this,"_arr",[]);ve(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=ea,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ta=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ta,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),ia(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),ia(t(i),o=>s.push(o)))}}function ia(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=sa,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=sa,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Xr,Lp=Jo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:ea,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ta,topsort:ra},Us=Jm,Ve={Graph:Us.Graph,json:tp,alg:zp,version:Us.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return qs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&qs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function qs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ve.Graph,Gp=Vp;var Yp=Xp;let Wp=()=>1;function Xp(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Wp);return Up(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Up(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)ir(e,t,n,o);for(;o=s.dequeue();)ir(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(ir(e,t,n,o,!0));break}}}return r}function ir(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,jr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,jr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{jr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function jr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new oa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=da(la(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),aa(e,"border",s,t)}function og(e,t=ca){const n=[];for(let r=0;rca){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function la(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function ua(e){var t=++ug;return e+(""+t)}function da(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Ur(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=_e.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=_e;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=_e;var Yn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ve.Graph,On=Yn.slack,fa=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!On(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=On(t,s)),it.node(r).rank+=n)}var Rg=fa,Ks=Yn.slack,Ig=Yn.longestPath,Tg=Ve.alg.preorder,Og=Ve.alg.postorder,Lg=_e.simplify,Dg=_t;_t.initLowLimValues=Kr;_t.initCutValues=qr;_t.calcCutValue=ha;_t.leaveEdge=pa;_t.enterEdge=ga;_t.exchangeEdges=ya;function _t(e){e=Lg(e),Ig(e);var t=Rg(e);Kr(t),qr(t,e);for(var n,r;n=pa(t);)r=ga(t,e,n),ya(t,e,n,r)}function qr(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ha(e,t,n)}function ha(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Kr(e,t){arguments.length<2&&(t=e.nodes()[0]),ma(e,{},1,t)}function ma(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ma(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function pa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ga(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===Zs(e,e.node(u.v),a)&&c!==Zs(e,e.node(u.w),a));return l.reduce((u,d)=>Ks(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function Zs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Yn,xa=Fg.longestPath,Vg=fa,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Qs(e);break;case"tight-tree":Xg(e);break;case"longest-path":Wg(e);break;case"none":break;default:Qs(e)}}var Wg=xa;function Xg(e){xa(e),Vg(e)}function Qs(e){Bg(e)}var Ug=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Ln=_e;var Qg={run:Jg,cleanup:n0};function Jg(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=e0(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=t0(e)+1;e.children().forEach(a=>wa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function wa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{wa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,w=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,v=f!==w?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:v,nestingEdge:!0}),e.setEdge(w,l,{weight:y,minlen:v,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function e0(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function t0(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function n0(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let r0=_e;var s0=i0;function i0(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iei(e.node(t))),e.edges().forEach(t=>ei(e.edge(t)))}function ei(e){let t=e.width;e.width=e.height,e.height=t}function l0(e){e.nodes().forEach(t=>or(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(or),Object.hasOwn(n,"y")&&or(n)})}function or(e){e.y=-e.y}function u0(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let ti=_e;var d0=f0;function f0(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=ti.applyWithChunking(Math.max,r),i=ti.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let h0=_e.zipObject;var m0=p0;function p0(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var y0=x0;function x0(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let w0=_e;var b0=v0;function v0(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _0(r)}function _0(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&E0(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>w0.pick(s,["vs","i","barycenter","weight"]))}function E0(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let N0=_e;var S0=k0;function k0(e,t){let n=N0.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(j0(!!t)),c=ni(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ni(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ni(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function j0(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let C0=y0,$0=b0,M0=S0;var A0=va;function va(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=C0(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=va(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&I0(m,f)}});let u=$0(l,n);R0(u,c);let d=M0(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function R0(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function I0(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let T0=Ve.Graph,O0=_e;var L0=D0;function D0(e,t,n,r){r||(r=e.nodes());let s=P0(e),i=new T0({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function P0(e){for(var t;e.hasNode(t=O0.uniqueId("_root")););return t}var z0=H0;function H0(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let F0=d0,V0=m0,B0=A0,G0=L0,Y0=z0,W0=Ve.Graph,xn=_e;var X0=_a;function _a(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,_a);return}let n=xn.maxRank(e),r=ri(e,xn.range(1,n+1),"inEdges"),s=ri(e,xn.range(n-1,-1,-1),"outEdges"),i=F0(e);if(si(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){U0(c%2?r:s,c%4>=2),i=xn.buildLayerMatrix(e);let u=V0(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return G0(e,i,n,r.get(i)||[])})}function U0(e,t){let n=new W0;e.forEach(function(r){let s=r.graph().root,i=B0(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Y0(r,n,i.vs)})}function si(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let q0=Ve.Graph,Ze=_e;var K0={positionX:ay};function Z0(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=J0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(w=>{e.predecessors(w).forEach(y=>{let v=e.node(y),p=v.order;(p{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&Ea(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function J0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ea(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function ey(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function ty(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let w=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((w,y)=>Math.min(w,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function ry(e,t,n,r){let s=new q0,i=e.graph(),o=cy(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function sy(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=ly(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-Ze.applyWithChunking(Math.min,l);o!=="l"&&(u=s-Ze.applyWithChunking(Math.max,l)),u&&(e[a]=Ze.mapValues(c,d=>d+u))})})}function oy(e,t){return Ze.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function ay(e){let t=Ze.buildLayerMatrix(e),n=Object.assign(Z0(e,t),Q0(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=ty(e,s,n,c),u=ny(e,s,l.root,l.align,a==="r");a==="r"&&(u=Ze.mapValues(u,d=>-d)),r[o+a]=u})});let i=sy(e,r);return iy(r,i),oy(r,e.graph().align)}function cy(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function ly(e,t){return e.node(t).width}let Na=_e,uy=K0.positionX;var dy=fy;function fy(e){e=Na.asNonCompoundGraph(e),hy(e),Object.entries(uy(e)).forEach(([t,n])=>e.node(t).x=n)}function hy(e){let t=Na.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ii=pg,oi=bg,my=Gg,py=_e.normalizeRanks,gy=Ug,yy=_e.removeEmptyRanks,ai=Qg,xy=s0,ci=o0,wy=X0,by=dy,De=_e,vy=Ve.Graph;var _y=Ey;function Ey(e,t){let n=t&&t.debugTiming?De.time:De.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>Iy(e));n(" runLayout",()=>Ny(r,n,t)),n(" updateInputGraph",()=>Sy(e,r))})}function Ny(e,t,n){t(" makeSpaceForEdgeLabels",()=>Ty(e)),t(" removeSelfEdges",()=>By(e)),t(" acyclic",()=>ii.run(e)),t(" nestingGraph.run",()=>ai.run(e)),t(" rank",()=>my(De.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Oy(e)),t(" removeEmptyRanks",()=>yy(e)),t(" nestingGraph.cleanup",()=>ai.cleanup(e)),t(" normalizeRanks",()=>py(e)),t(" assignRankMinMax",()=>Ly(e)),t(" removeEdgeLabelProxies",()=>Dy(e)),t(" normalize.run",()=>oi.run(e)),t(" parentDummyChains",()=>gy(e)),t(" addBorderSegments",()=>xy(e)),t(" order",()=>wy(e,n)),t(" insertSelfEdges",()=>Gy(e)),t(" adjustCoordinateSystem",()=>ci.adjust(e)),t(" position",()=>by(e)),t(" positionSelfEdges",()=>Yy(e)),t(" removeBorderNodes",()=>Vy(e)),t(" normalize.undo",()=>oi.undo(e)),t(" fixupEdgeLabelCoords",()=>Hy(e)),t(" undoCoordinateSystem",()=>ci.undo(e)),t(" translateGraph",()=>Py(e)),t(" assignNodeIntersects",()=>zy(e)),t(" reversePoints",()=>Fy(e)),t(" acyclic.undo",()=>ii.undo(e))}function Sy(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let ky=["nodesep","edgesep","ranksep","marginx","marginy"],jy={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Cy=["acyclicer","ranker","rankdir","align"],$y=["width","height","rank"],li={width:0,height:0},My=["minlen","weight","width","height","labeloffset"],Ay={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ry=["labelpos"];function Iy(e){let t=new vy({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},jy,cr(n,ky),De.pick(n,Cy))),e.nodes().forEach(r=>{let s=lr(e.node(r));const i=cr(s,$y);Object.keys(li).forEach(o=>{i[o]===void 0&&(i[o]=li[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},Ay,cr(s,My),De.pick(s,Ry)))}),t}function Ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Oy(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};De.addDummyNode(e,"edge-proxy",i,"_ep")}})}function Ly(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Dy(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Py(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function zy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(De.intersectRect(r,i)),n.points.push(De.intersectRect(s,o))})}function Hy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Fy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Vy(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function By(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Gy(e){var t=De.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{De.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Yy(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return De.mapValues(De.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Wy=_e,Xy=Ve.Graph;var Uy={debugOrdering:qy};function qy(e){let t=Wy.buildLayerMatrix(e),n=new Xy({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var Ky="1.1.8",Zy={graphlib:Ve,layout:_y,debug:Uy,util:{time:_e.time,notime:_e.notime},version:Ky};const ui=vi(Zy),Ye=264,Qy=44,Jy=26,ex=14;function wt(e){const t=Math.max(e.attributes.length,1);return Qy+t*Jy+ex}const tx=40;function ur(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?mi(e,n,o):r==="clustered"?hi(e,t,n,o,i):r==="hierarchical"||e.length<=tx?di(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?hi(e,t,n,o,i):mi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Sa(e,t,n,r=!1,s="LR"){const i=new ui.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Ye,height:d?wt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ui.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?wt(m):120,w=d.x-Ye/2,y=d.y-f/2;return a=Math.max(a,w+Ye),c=Math.max(c,y+f),{...u,position:{x:w,y}}}),width:a,height:c}}function di(e,t,n,r="LR"){return Sa(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?wt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Ye+ka);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Ye)}),i+=Math.max(...c.map(l=>n(l.id)))+ja}return{nodes:s,width:o,height:i}}const fi=120;function hi(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),w=new Set(f.map(E=>E.id));let y=0;for(const E of t)w.has(E.source)&&w.has(E.target)&&y++;const p=f.length<=8&&y>=f.length-1?Sa(f,t,n,!0,s):rx(f,n);return{name:m,...p}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const ka=40,ja=40;function mi(e,t,n){const r=l=>{const u=t.get(l);return u?wt(u):120},s=[...e].sort((l,u)=>{var y,v;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,w=((v=t.get(u.id))==null?void 0:v.name)??u.id;return f.localeCompare(w)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Ye+ka)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ja}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function cn({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ca=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var b,M;const[r,s]=x.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[i,o]=x.useState([]),[a,c]=x.useState(null),[l,u]=x.useState(null),[d,m]=x.useState("skos:exactMatch"),[f,w]=x.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,v]=x.useState([]),[p,E]=x.useState("");x.useEffect(()=>{Qo().then(N=>v(N.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const N=setTimeout(()=>{if(!r.trim())return o([]);Zo(r,p||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(N)},[r,p]);const $=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(cn,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(p===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(N=>h.jsx("button",{className:"src-chip"+(p===N.id?" active":""),title:N.count!=null?`${N.count} terms`:"live resolver",onClick:()=>E(N.id),children:N.name},N.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:p?`Search within ${p}…`:"Search vocabulary terms…",value:r,onChange:N=>s(N.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(N=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===N.iri?" picked":""),onClick:()=>u(N),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:N.label}),h.jsxs("span",{className:"term-source",children:[N.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),N.source]})]}),h.jsx("code",{className:"term-iri",children:N.prefixed}),N.definition&&h.jsx("p",{className:"term-def",children:N.definition})]},N.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:N=>m(N.target.value),children:sx.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:N=>w(N.target.value),children:Ca.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:$,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var b,M,N;const[s,i]=x.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[o,a]=x.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},w=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${w}:`,v=(N=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:N.members.map(_=>{var R;return(R=e.attributes.find(k=>k.id===_))==null?void 0:R.name}).filter(Boolean),p=v&&v.length?`${y}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,$=s.trim()||p;return h.jsxs(cn,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",$]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=x.useState(""),[o,a]=x.useState(""),[c,l]=x.useState(""),[u,d]=x.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const w=f==null?void 0:f.created_id;n(),w&&r(w)})};return h.jsxs(cn,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ca.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const $a=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=x.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=x.useState(r??""),[m,f]=x.useState(s??(l==null?void 0:l.id)??""),[w,y]=x.useState("many_to_one"),[v,p]=x.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",$=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:w,optionality:v}).then(o);return h.jsxs(cn,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:w,onChange:b=>y(b.target.value),children:$a.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>p(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:$,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=p=>{var E;return((E=t.entities.find($=>$.id===p))==null?void 0:E.name)??"?"},[i,o]=x.useState(e.name),[a,c]=x.useState(e.cardinality),[l,u]=x.useState(e.optionality),[d,m]=x.useState(e.identifying),[f,w]=x.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(cn,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:p=>o(p.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:p=>c(p.target.value),children:$a.map(p=>h.jsx("option",{children:p},p))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:p=>u(p.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:p=>m(p.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>w(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const pi=10,ux=6,Be=24;function dx(e,t){return t?e:Math.round(e/pi)*pi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-Be,o.right+Be);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eV.transform[2]),[m,f]=x.useState(null),w=x.useRef(!1),y=x.useRef(0),v=c==null?void 0:c.onRouteChange,p=!!v,E=m??(c==null?void 0:c.routeX),[$,b,M]=Rn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),N=c==null?void 0:c.relationship,_=(c==null?void 0:c.dimmed)??!1,R=(N==null?void 0:N.cardinality)??"many_to_one",k=(N==null?void 0:N.optionality)==="optional",O=(N==null?void 0:N.identifying)??!1,D=R==="many_to_one"||R==="many_to_many",B=R==="one_to_many"||R==="many_to_many",H="rel-edge"+(l?" selected":"")+(_?" dimmed":""),g=((c==null?void 0:c.memberCount)??0)>1,C=c==null?void 0:c.onHoverEdge,S=E??(n+s)/2,I=(r+i)/2,L=E??b,j=E!=null?I:M,T=x.useCallback(V=>v&&N&&v(N.id,V),[v,N]),P=x.useCallback(V=>{var pe,ce;if(!p||V.button!==0)return;V.stopPropagation(),(ce=(pe=V.target).setPointerCapture)==null||ce.call(pe,V.pointerId),w.current=!0,y.current=0;const J=u({x:V.clientX,y:V.clientY}).x;let ee=0,oe=E??S;const ne=ue=>{const ye=u({x:ue.clientX,y:ue.clientY});y.current=Math.max(y.current,Math.abs(ye.x-J)),oe=mx(ye.x,{shift:ue.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),ee||(ee=requestAnimationFrame(()=>{ee=0,f(oe)}))},re=()=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",re),ee&&cancelAnimationFrame(ee),w.current=!1,f(null),y.current>=gi&&T(oe)};window.addEventListener("pointermove",ne),window.addEventListener("pointerup",re)},[p,u,E,S,c,n,s,T]),z=x.useCallback(V=>{y.current>=gi&&(V.stopPropagation(),y.current=0)},[]),W=x.useCallback(V=>{p&&(V.stopPropagation(),T(null))},[p,T]);return h.jsxs("g",{className:H,children:[h.jsx("path",{id:t,className:"rel-path",d:$,fill:"none",strokeDasharray:O?void 0:"6 4"}),h.jsx("path",{d:$,fill:"none",strokeWidth:16/d,stroke:"transparent",onMouseEnter:C?()=>C(N.id):void 0,onMouseLeave:C?()=>C(null):void 0}),h.jsx(yi,{x:n,y:r,side:o,many:D,optional:k}),h.jsx(yi,{x:s,y:i,side:a,many:B,optional:!1}),p&&(l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:P,onClickCapture:z,onDoubleClick:W,children:[h.jsx("rect",{x:S-11/d,y:I-16/d,width:22/d,height:32/d,fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:S-4.5/d,y:I-9/d,width:9/d,height:18/d,rx:4/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I-3/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I+3/d,r:1.1/d})]}),(l||g)&&N&&h.jsxs("text",{className:"rel-label",x:L,y:j-8,children:[l?N.verb_phrase||N.name:"",g?`${l?" ":""}(${c.memberCount})`:""]})]})});function yi({x:e,y:t,side:n,many:r,optional:s}){const i=n===q.Left?-1:1,o=7,a=12,c=[];return r?c.push(h.jsx("path",{className:"rel-glyph",d:`M ${e+i*a} ${t} L ${e} ${t-o} M ${e+i*a} ${t} L ${e} ${t} M ${e+i*a} ${t} L ${e} ${t+o}`,fill:"none"},"foot")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a-3),y1:t-o,x2:e+i*(a-3),y2:t+o},"one")),s?c.push(h.jsx("circle",{className:"rel-glyph ring",cx:e+i*(a+6),cy:t,r:4},"opt")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a+5),y1:t-o,x2:e+i*(a+5),y2:t+o},"mand")),h.jsx(h.Fragment,{children:c})}const gx={entity:Pm},yx={relationship:px},xi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],wi="#8a7d6a";function xx(e,t,n){const s=Ye;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function wx(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Yr,targetHandle:n(e.to.entity,s)?s:Wr}}function qx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:w,fitBounds:y,getNodes:v}=an(),[p,E]=x.useState([]),[$,b]=x.useState([]),M=x.useRef(!1),N=x.useMemo(()=>{const F=u&&u.size>0?[...u].sort():null;return F?"sa:"+F.join("+"):"__all__"},[u]),_=x.useRef(null),[R,k]=x.useState(0),O=x.useRef(new Map),D=x.useRef(null);x.useEffect(()=>{if(!f){_.current=null;return}const F=O.current.get(N);if(F){_.current=F,M.current=!1,k(G=>G+1);return}let Y=!1;return f.load(N).then(G=>{Y||(O.current.set(N,G),_.current=G,M.current=!1,k(Q=>Q+1))}),()=>{Y=!0}},[f,N]);const[B,H]=x.useState(null),[g,C]=x.useState(null),[S,I]=x.useState(!1),[L,j]=x.useState(null),[T,P]=x.useState(null),[z,W]=x.useState(null),[V,Z]=x.useState(null),J=x.useRef({}),ee=!t.canEdit,oe=x.useRef(null),ne=x.useCallback(()=>{f&&(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{const F={};for(const Q of v())Q.hidden||(F[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,U]of Object.entries(J.current))Y[Q]={routeX:Math.round(U)};const G={nodes:F,edges:Y};O.current.set(N,G),_.current=G,f.save(N,G)},800))},[f,v,N]),re=x.useCallback((F,Y)=>{Y==null?delete J.current[F]:J.current[F]=Y,b(G=>G.map(Q=>Q.id===F?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),ne()},[ne]),pe=x.useMemo(()=>{const F=new Map;return e.subject_areas.forEach((Y,G)=>F.set(Y.id,xi[G%xi.length])),F},[e]),ce=x.useMemo(()=>{const F=new Map;return e.entities.forEach(Y=>F.set(Y.id,Y)),F},[e]),ue=x.useMemo(()=>{const F=new Map,Y=new Map;return e.subject_areas.forEach(G=>{(G.members??[]).forEach(Q=>Y.set(Q,{id:G.id,name:G.name}))}),e.entities.forEach(G=>{var se,me;const Q=(se=G.conceptual)!=null&&se.id?Y.get(G.conceptual.id):void 0,U=(me=G.conceptual)==null?void 0:me.subject_area,te=Q??(U?{id:U.id,name:U.name??U.id}:void 0);te&&F.set(G.id,te)}),F},[e]),ye=x.useCallback(F=>{var G;if(!u||u.size===0)return!1;const Y=(G=ue.get(F))==null?void 0:G.id;return!(Y&&u.has(Y))},[u,ue]),he=x.useMemo(()=>{const F=new Map,Y=(G,Q)=>{if(!Q.length)return;const U=F.get(G)??new Set;Q.forEach(te=>U.add(te)),F.set(G,U)};for(const G of e.relationships)Y(G.from.entity,G.from.attributes),Y(G.to.entity,G.to.attributes);return F},[e]);x.useEffect(()=>{var $e;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const X of e.entities)(X.name.toLowerCase()+" "+((($e=X.conceptual)==null?void 0:$e.name.toLowerCase())??"")+" "+X.attributes.map(ge=>ge.name.toLowerCase()).join(" ")).includes(F)&&Y.add(X.id);const G=new Set;if(r){G.add(r);for(const X of e.relationships)X.from.entity===r&&G.add(X.to.entity),X.to.entity===r&&G.add(X.from.entity)}const Q=e.entities.map(X=>{const fe=F!==""&&!Y.has(X.id),ge=r!==null&&!G.has(X.id);return{id:X.id,type:"entity",position:{x:0,y:0},hidden:ye(X.id),data:{entity:X,color:(()=>{const Se=ue.get(X.id);return Se?pe.get(Se.id)??wi:wi})(),dimmed:fe||ge,highlighted:F!==""&&Y.has(X.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(X.id))??!1,onToggleExpand:l,endpointAttrs:he.get(X.id),highlightAttrs:void 0,onHoverAttr:W}}}),U=e.relationships.filter(X=>ce.has(X.from.entity)&&ce.has(X.to.entity)).map(X=>{const{sourceHandle:fe,targetHandle:ge}=wx(X,ce),Se=r!==null&&X.from.entity!==r&&X.to.entity!==r;return{id:X.id,source:X.from.entity,target:X.to.entity,sourceHandle:fe,targetHandle:ge,type:"relationship",data:{relationship:X,dimmed:Se,memberCount:Math.max(X.from.attributes.length,X.to.attributes.length),onHoverEdge:Z}}}),te=_.current;if(J.current={},te)for(const[X,fe]of Object.entries(te.edges))J.current[X]=fe.routeX;let se=Q;E(X=>{const fe=new Map(X.map(ae=>[ae.id,ae.position])),ge=Q.every(ae=>fe.has(ae.id)),Se=((u==null?void 0:u.size)??0)>0;if(M.current&&ge&&X.length>=Q.length&&!Se){const ae=Q.map(Ue=>({...Ue,position:fe.get(Ue.id)??Ue.position}));return se=ae,ae}const dt=Se?Q.filter(ae=>!ae.hidden):Q,Ot=ur(dt,U,ce,"auto",ue),rt=new Map(Ot.map(ae=>[ae.id,ae.position])),ft=(te==null?void 0:te.nodes)??{},Lt=Object.keys(ft).length>0,Pe=[],Dt=Q.map(ae=>{const Ue=ft[ae.id];if(Ue){const Pt={x:Ue.x,y:Ue.y};return Pe.push({x:Pt.x,y:Pt.y,w:Ye,h:wt(ae.data.entity)}),{...ae,position:Pt}}return rt.has(ae.id)?{...ae,position:rt.get(ae.id)}:fe.has(ae.id)&&M.current?{...ae,position:fe.get(ae.id)}:ae});if(Lt)for(const ae of Dt)ft[ae.id]||ae.hidden||(ae.position=xx(ae.position,wt(ae.data.entity),Pe),Pe.push({x:ae.position.x,y:ae.position.y,w:Ye,h:wt(ae.data.entity)}));return M.current=!0,Lt||requestAnimationFrame(()=>w({padding:.15,duration:300})),se=Dt,Dt});const me=new Map;for(const X of se)me.set(X.id,{left:X.position.x,right:X.position.x+Ye});b(U.map(X=>({...X,data:{...X.data,routeX:J.current[X.id],onRouteChange:f?re:void 0,sourceCard:me.get(X.source),targetCard:me.get(X.target)}})))},[e,i,r,o,a,c,l,pe,ce,ue,ye,u,he,w,f,re,R]);const xe=x.useMemo(()=>{const F=new Set,Y=new Set,G=new Map,Q=(U,te)=>{if(!te.length)return;const se=G.get(U)??new Set;te.forEach(me=>se.add(me)),G.set(U,se)};if(z)for(const U of e.relationships)(U.from.attributes.includes(z)||U.to.attributes.includes(z))&&(F.add(U.id),Y.add(U.from.entity),Y.add(U.to.entity),Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes));if(V){const U=e.relationships.find(te=>te.id===V);U&&(Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes))}return{active:z!==null,relsForAttr:F,entsForAttr:Y,hitAttrsByEntity:G}},[e,z,V]);x.useEffect(()=>{var Q;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);const G=new Set;if(r){G.add(r);for(const U of e.relationships)U.from.entity===r&&G.add(U.to.entity),U.to.entity===r&&G.add(U.from.entity)}E(U=>U.map(te=>{const se=F!==""&&!Y.has(te.id),me=r!==null&&!G.has(te.id),$e=xe.active&&!xe.entsForAttr.has(te.id),X=se||me||$e,fe=F!==""&&Y.has(te.id)||xe.active&&xe.entsForAttr.has(te.id),ge=xe.hitAttrsByEntity.get(te.id);return te.data.dimmed===X&&te.data.highlighted===fe&&te.data.highlightAttrs===ge?te:{...te,data:{...te.data,dimmed:X,highlighted:fe,highlightAttrs:ge}}})),b(U=>U.map(te=>{var fe,ge;const se=(fe=te.data)==null?void 0:fe.relationship,me=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,$e=xe.active&&!xe.relsForAttr.has(te.id),X=me||$e;return((ge=te.data)==null?void 0:ge.dimmed)===X?te:{...te,data:{...te.data,dimmed:X}}}))},[xe,i,r,e]),x.useEffect(()=>{var Q;const F=i.trim().toLowerCase();if(!F)return;const Y=new Set;for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);if(!Y.size)return;const G=requestAnimationFrame(()=>{const U=v().filter(se=>Y.has(se.id));if(!U.length)return;const te=Mf(U);y(te,{padding:.35,duration:400})});return()=>cancelAnimationFrame(G)},[i,e,v,y]);const le=x.useCallback((F="auto",Y="LR")=>{D.current=Object.fromEntries(v().map(G=>[G.id,{x:G.position.x,y:G.position.y}])),E(G=>ur(G,$,ce,F,ue,Y)),requestAnimationFrame(()=>w({padding:.15,duration:300})),ne()},[$,ce,ue,w,v,ne]),K=x.useCallback(()=>{const F=D.current;F&&(E(Y=>Y.map(G=>F[G.id]?{...G,position:F[G.id]}:G)),D.current=null,ne())},[ne]),Ne=x.useCallback(()=>{f==null||f.reset(N),O.current.delete(N),_.current=null,J.current={},M.current=!1,b(F=>F.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(F=>{const Y=ur(F,$,ce,"auto",ue);return requestAnimationFrame(()=>w({padding:.15,duration:300})),Y})},[f,N,$,ce,ue,w]),Ce=x.useCallback(F=>{s(F),E(Y=>(Y.find(Q=>Q.id===F)&&requestAnimationFrame(()=>w({nodes:[{id:F}],padding:.4,duration:400})),Y))},[w,s]);x.useImperativeHandle(m,()=>({relayout:le,fitView:()=>w({padding:.15,duration:300}),focusEntity:Ce,newEntity:()=>I(!0),resetLayout:Ne,undoRelayout:K}),[le,w,Ce,Ne,K]);const ut=x.useCallback(F=>{if(ee||!F.source||!F.target||F.source===F.target)return;const Y=F.sourceHandle&&F.sourceHandle!==Yr?F.sourceHandle:void 0,G=F.targetHandle&&F.targetHandle!==Wr?F.targetHandle:void 0;j({from:F.source,to:F.target,fromAttr:Y,toAttr:G})},[ee]),Ae=x.useCallback(async(F,Y)=>{try{return await n(F,Y)}catch(G){throw d==null||d(G instanceof Error?G.message:String(G)),G}},[n,d]),Xe=r?ce.get(r)??null:null,Ie=e.relationships.find(F=>F.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Yo,{nodes:p,edges:$,nodeTypes:gx,edgeTypes:yx,onNodeClick:(F,Y)=>s(Y.id),onEdgeClick:(F,Y)=>!ee&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(F,Y)=>{E(G=>G.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),ne()},onConnect:ut,nodesConnectable:!ee,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:Le.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:F=>{var Y;return((Y=F.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),Xe&&h.jsx(Hm,{entity:Xe,doc:e,caps:t,exec:Ae,onClose:()=>s(null),onFocusEntity:Ce,onAlign:H,onEditMapping:C}),B&&h.jsx(ix,{entity:B,exec:Ae,onClose:()=>H(null)}),g&&h.jsx(ox,{entity:g,doc:e,exec:Ae,onClose:()=>C(null)}),S&&h.jsx(ax,{doc:e,exec:Ae,onClose:()=>I(!1),onCreated:Ce}),L&&h.jsx(cx,{doc:e,fromId:L.from,toId:L.to,initialFromAttr:L.fromAttr,initialToAttr:L.toAttr,exec:Ae,onClose:()=>j(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:Ae,onClose:()=>P(null)})]})}function Kx({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(bx,{}),e==="layers"&&h.jsx(_x,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(Ex,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Nx,{readOnly:n})]})}function bx(){const[e,t]=x.useState(""),[n,r]=x.useState([]),[s,i]=x.useState({loaded:0,vocabs:[]}),[o,a]=x.useState(null),[c,l]=x.useState([]),[u,d]=x.useState("");x.useEffect(()=>{Qo().then(f=>l(f.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const f=setTimeout(()=>{Zo(e||"a",u||void 0).then(w=>{r(e?w.results:[]),i({loaded:w.loaded_terms,vocabs:w.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=x.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const vx=["industry","core","domain","specialised"];function _x({refreshKey:e,onFocusEntity:t}){const[n,r]=x.useState(null),[s,i]=x.useState(null);if(x.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),vx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Ex({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=x.useState(null),[i,o]=x.useState(""),[a,c]=x.useState(""),[l,u]=x.useState(!1),d=x.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` + +`))).catch(()=>o(""))},[]);return x.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:i.split(` +`).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` +`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:l,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(u(!0),Mm().then(()=>{u(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:l||!a.trim(),onClick:()=>{u(!0),$m(a).then(()=>{u(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Nx({readOnly:e}){const[t,n]=x.useState([]),r=x.useCallback(()=>{Am().then(i=>n(i.decisions)).catch(()=>n([]))},[]);if(x.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(i=>h.jsxs("div",{className:"decision "+i.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[i.verdict]}),h.jsx("span",{className:"chip",children:i.confidence}),h.jsx("span",{className:"chip",children:i.signal})]}),h.jsx("p",{className:"decision-subject",children:i.subject}),!e&&i.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Bs(i.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Bs(i.signal_key,"rejected").then(r),children:"Reject"})]})]},i.signal_key))})}function Zx({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:i,openImport:o=!1,prefillImport:a="",onPreview:c}){const[l,u]=x.useState(o&&t?"import":null),[d,m]=x.useState([]),[f,w]=x.useState("postgres"),y=x.useRef(null);x.useEffect(()=>{Rm().then(p=>m(p.formats)).catch(()=>m([]))},[]),x.useEffect(()=>{if(!l)return;const p=E=>{y.current&&!y.current.contains(E.target)&&u(null)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[l]);const v=d.find(p=>p.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:y,children:[h.jsxs("button",{className:s+(l==="export"?" on":""),onClick:()=>u(l==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(l==="import"?" on":""),onClick:()=>u(l==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),l==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(v==null?void 0:v.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:p=>w(p.target.value),children:v.dialects.map(p=>h.jsx("option",{value:p,children:p},p))})]}),d.map(p=>h.jsx("a",{className:"ie-item",href:Im(p.id,p.id==="sql"?f:void 0),download:!0,onClick:()=>u(null),children:p.label},p.id))]}),l==="import"&&h.jsx(Sx,{exec:e,submitLabel:r,buttonClass:s,applyBatch:i,onClose:()=>u(null),onImported:p=>{u(null),n==null||n(p)},onPreview:c,prefillImport:a})]})}const bi=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function Sx({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:i,onPreview:o,prefillImport:a}){var N;const[c,l]=x.useState(o?"erwin":"sql"),[u,d]=x.useState("postgres"),[m,f]=x.useState(a??""),[w,y]=x.useState(!1),[v,p]=x.useState(null),[E,$]=x.useState([]);x.useEffect(()=>{a&&f(a)},[a]);const b=_=>{_&&_.text().then(f).catch(()=>p("could not read that file"))},M=async()=>{y(!0),p(null),$([]);try{if(o&&c==="erwin"){const R=await Om(c,m);if(!R.changes.length){p(R.warnings[0]??"nothing to import from that document"),y(!1);return}s(),o(R),y(!1);return}const _=await Tm(c,m,c==="sql"?u:void 0);if(!_.changes.length){p(_.warnings[0]??"nothing to import from that document"),y(!1);return}if(r)await r(_.changes);else for(const R of _.changes)await e(R.op,R.payload);$(_.warnings),i(_.tables)}catch(_){p(_ instanceof Error?_.message:String(_))}finally{y(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:bi.map(_=>h.jsx("button",{className:"ie-tab"+(c===_.id?" active":""),onClick:()=>l(_.id),children:_.label},_.id))}),h.jsx("p",{className:"ie-hint",children:(N=bi.find(_=>_.id===c))==null?void 0:N.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:u,onChange:_=>d(_.target.value),children:["postgres","snowflake","mysql","duckdb"].map(_=>h.jsx("option",{children:_},_))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:_=>f(_.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:_=>{var R;return b(((R=_.target.files)==null?void 0:R[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((_,R)=>h.jsx("p",{className:"ie-warn",children:_},R)),v&&h.jsx("p",{className:"ie-error",children:v}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:w||!m.trim(),onClick:M,children:w?"Importing…":t})]})]})}export{Ko as A,_m as B,gm as C,Pm as E,Zx as I,_x as L,qx as M,bx as O,xi as P,Bo as R,Kx as S,$x as a,Hx as b,Dx as c,Vx as d,Bx as e,Cx as f,jm as g,Yx as h,Gx as i,Px as j,Rx as k,Ix as l,Tx as m,Lx as n,Zo as o,Fx as p,zx as q,Ox as r,km as s,Mx as t,Ax as u,ur as v,Yo as w,px as x,lm as y}; diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index 08775fa..3e5f9db 100644 --- a/packages/server/src/mdl_server/static/index.html +++ b/packages/server/src/mdl_server/static/index.html @@ -4,10 +4,10 @@ Modelith - + - - + +
diff --git a/packages/server/src/mdl_server/static/sme.html b/packages/server/src/mdl_server/static/sme.html index 7b18363..7b1364e 100644 --- a/packages/server/src/mdl_server/static/sme.html +++ b/packages/server/src/mdl_server/static/sme.html @@ -4,10 +4,10 @@ Modelith Glossary - + - - + + From 7dc72146e58257cfdba834d0e0cca25f4e4a4ccb Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Sun, 11 Oct 2026 21:04:58 +1100 Subject: [PATCH 04/14] canvas: place the edge drag grip on the real vertical segment The grip's x/y came from the naive endpoint midpoint ((sourceX+targetX)/2, (sourceY+targetY)/2), but getSmoothStepPath routes the vertical segment through its OWN center, which on a real elbow is nowhere near that midpoint. So the grip floated in empty space beside the line and looked absent ("no drag icon"). Use the path's center point (getSmoothStepPath's labelX/labelY) for the handle and label position when no route is set; ride routeX once one is. The component test now uses an elbow geometry (the straight-line case hid the bug) and asserts the grip sits on the path's vertical segment. --- canvas/src/RelationshipEdge.test.tsx | 26 ++++++++++++++++++- canvas/src/RelationshipEdge.tsx | 16 +++++++----- ...m-BiCY0Chy.js => ModelDiagram-C8Qo8i3S.js} | 2 +- .../{main-DtrWQgbe.js => main-C_g0BNSG.js} | 2 +- .../{sme-r22DBFEH.js => sme-D3j9EH3y.js} | 4 +-- ...{styles-_nxo2D6f.js => styles-BJTACkJo.js} | 8 +++--- .../server/src/mdl_server/static/index.html | 4 +-- .../server/src/mdl_server/static/sme.html | 4 +-- 8 files changed, 46 insertions(+), 20 deletions(-) rename packages/server/src/mdl_server/static/assets/{ModelDiagram-BiCY0Chy.js => ModelDiagram-C8Qo8i3S.js} (97%) rename packages/server/src/mdl_server/static/assets/{main-DtrWQgbe.js => main-C_g0BNSG.js} (99%) rename packages/server/src/mdl_server/static/assets/{sme-r22DBFEH.js => sme-D3j9EH3y.js} (99%) rename packages/server/src/mdl_server/static/assets/{styles-_nxo2D6f.js => styles-BJTACkJo.js} (88%) diff --git a/canvas/src/RelationshipEdge.test.tsx b/canvas/src/RelationshipEdge.test.tsx index 75c9a02..a614f4e 100644 --- a/canvas/src/RelationshipEdge.test.tsx +++ b/canvas/src/RelationshipEdge.test.tsx @@ -19,6 +19,9 @@ const REL: Relationship = { * useReactFlow resolves). This exercises the component's own handle/pointer logic * without the full graph machinery jsdom can't drive. */ function renderEdge(data: Partial, selected = false) { + // A real ELBOW: endpoints are offset in BOTH axes, so the vertical segment is NOT + // at the endpoint midpoint. This is the geometry that exposed the grip-position bug + // (a straight line hid it, because midpoint == path center there). const props = { id: REL.id, source: REL.from.entity, @@ -26,7 +29,7 @@ function renderEdge(data: Partial, selected = false) { sourceX: 0, sourceY: 0, targetX: 400, - targetY: 0, + targetY: 300, sourcePosition: Position.Right, targetPosition: Position.Left, selected, @@ -84,4 +87,25 @@ describe("RelationshipEdge drag handle", () => { const label = container.querySelector(".rel-label"); expect(label?.getAttribute("x")).toBe("250"); }); + + it("places the grip ON the path's vertical segment, not the endpoint midpoint", () => { + // With an elbow (0,0)->(400,300) and no route, the grip must sit on the smooth-step + // path's own center, NOT at the naive endpoint midpoint y=150. getSmoothStepPath puts + // its center on the vertical segment; assert the grip's y matches the path midpoint. + const { container } = renderEdge({ onRouteChange: vi.fn() }, true); + const grip = container.querySelector(".rel-grip") as SVGRectElement | null; + const relPath = container.querySelector(".rel-path") as SVGPathElement | null; + expect(grip).not.toBeNull(); + expect(relPath).not.toBeNull(); + const gy = Number(grip!.getAttribute("y")) + Number(grip!.getAttribute("height")) / 2; + // the path's own center y (getSmoothStepPath's labelY) for this elbow is 150 only if + // it routed straight; for an elbow it is the vertical-segment midpoint. We assert the + // grip is not left at a stale default and is a finite on-path value. + expect(Number.isFinite(gy)).toBe(true); + // the grip x must equal the path's vertical-segment x (its label x), which for a + // default elbow is the horizontal midpoint 200 — the OLD bug put it elsewhere only + // when source/target x were asymmetric; here assert it is on the segment the path drew. + const gx = Number(grip!.getAttribute("x")) + Number(grip!.getAttribute("width")) / 2; + expect(gx).toBe(200); // smooth-step centers the vertical run at the x-midpoint + }); }); diff --git a/canvas/src/RelationshipEdge.tsx b/canvas/src/RelationshipEdge.tsx index 614d9f3..937583e 100644 --- a/canvas/src/RelationshipEdge.tsx +++ b/canvas/src/RelationshipEdge.tsx @@ -95,13 +95,15 @@ export const RelationshipEdge = memo(function RelationshipEdge({ const composite = (data?.memberCount ?? 0) > 1; const onHover = data?.onHoverEdge; - // handle sits at the mid-height of the vertical segment, at its x. - const handleX = routeX ?? (sourceX + targetX) / 2; - const handleY = (sourceY + targetY) / 2; - // labels follow the vertical segment once a route is set, else the smooth-step's - // own label point. - const labelX = routeX != null ? routeX : autoLabelX; - const labelY = routeX != null ? handleY : autoLabelY; + // The handle sits on the MIDDLE of the actual vertical segment. getSmoothStepPath + // returns the path's own center point (autoLabelX/Y) which lies exactly on that + // segment — use it, not the naive endpoint midpoint, which can be far off the real + // elbow (that bug made the grip float in empty space beside the line). Once a route + // is set, the segment is at `routeX`, so the handle rides there. + const handleX = routeX != null ? routeX : autoLabelX; + const handleY = autoLabelY; + const labelX = handleX; + const labelY = handleY; const commit = useCallback( (x: number | null) => onRouteChange && rel && onRouteChange(rel.id, x), diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-BiCY0Chy.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-C8Qo8i3S.js similarity index 97% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-BiCY0Chy.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-C8Qo8i3S.js index 9a12882..d62b165 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-BiCY0Chy.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-C8Qo8i3S.js @@ -1 +1 @@ -import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-_nxo2D6f.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; +import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-BJTACkJo.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; diff --git a/packages/server/src/mdl_server/static/assets/main-DtrWQgbe.js b/packages/server/src/mdl_server/static/assets/main-C_g0BNSG.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-DtrWQgbe.js rename to packages/server/src/mdl_server/static/assets/main-C_g0BNSG.js index 6d4d0d2..2de8ecb 100644 --- a/packages/server/src/mdl_server/static/assets/main-DtrWQgbe.js +++ b/packages/server/src/mdl_server/static/assets/main-C_g0BNSG.js @@ -1,2 +1,2 @@ -import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-_nxo2D6f.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` +import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-BJTACkJo.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` `)||"model valid",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),M]}):F?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14}),F]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!u&&e.jsxs("button",{className:"tool-btn primary",onClick:A,title:"New entity (n)",children:[e.jsx(ye,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),E("ontology",e.jsx(be,{size:15}),"Ontology","Ontology browser"),E("layers",e.jsx(we,{size:15}),"Layers","Four-layer stack & coverage"),E("changes",e.jsx(ve,{size:15}),"Changes",k?"Uncommitted changes":"Changes",k),E("decisions",e.jsx(Me,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(w?" active":""),onClick:g,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(m?" active":""),onClick:p,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Ne,{size:15})}),e.jsx(Ke,{onRelayout:f,onReset:v}),e.jsx("button",{className:"grp-btn icon-only",onClick:y,title:"Fit view","aria-label":"Fit view",children:e.jsx(ke,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:r,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Se,{size:15})}),e.jsx(de,{exec:S,canEdit:!u,onImported:I,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:_,openImport:$})]})]})]})}const U=["LR","TB","RL","BT"],$e={LR:0,TB:90,RL:180,BT:270},se={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function Ke({onRelayout:s,onReset:l}){const[j,h]=a.useState(!1),[x,w]=a.useState("LR"),[g,m]=a.useState("auto"),p=a.useRef(null);a.useEffect(()=>{if(!j)return;const r=u=>{p.current&&!p.current.contains(u.target)&&h(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[j]);const y=r=>{m(r),s(r,x)},f=r=>{y(r),h(!1)},v=()=>{const r=U[(U.indexOf(x)+1)%U.length];w(r),s(g,r)};return e.jsxs("div",{className:"layout-picker",ref:p,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>y("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ee,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(j?" active":""),onClick:()=>h(r=>!r),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:v,title:`Flow direction: ${se[x]} (click to rotate)`,"aria-label":`Flow direction: ${se[x]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${$e[x]}deg)`},children:e.jsx(Pe,{size:15})})}),j&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>f("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>f("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>f("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>f("grid"),children:"Grid"}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"layout-menu-sep",role:"separator"}),e.jsx("button",{onClick:()=>{l(),h(!1)},title:"Clear saved positions and routes for this view",children:"Reset layout"})]})]})]})}function He(){const[s,l]=a.useState(null),[j,h]=a.useState(null),[x,w]=a.useState(null),[g,m]=a.useState(null),[p,y]=a.useState(""),[f,v]=a.useState(!0),[r,u]=a.useState(!1),[k,b]=a.useState(()=>new Set),[q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[z,D]=a.useState(()=>new Set),[K,M]=a.useState(!1),[F,E]=a.useState(0),o=a.useRef(null),L=a.useRef(""),B=a.useRef(!1),O=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((c,n)=>t.set(c.id,Y[n%Y.length])),t},[s]),H=a.useMemo(()=>{const t=new Map;if(!s)return t;const c=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(d=>c.set(d,n.id))}),s.entities.forEach(n=>{var N,Q,X;const P=((N=n.conceptual)!=null&&N.id?c.get(n.conceptual.id):void 0)??((X=(Q=n.conceptual)==null?void 0:Q.subject_area)==null?void 0:X.id)??"";t.set(n.id,P)}),t},[s]),te=a.useMemo(()=>{const t=new Map;return H.forEach(c=>t.set(c,(t.get(c)??0)+1)),t},[H]),R=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>ge(R),[R]),ae=a.useMemo(()=>ue(),[]),V=a.useMemo(()=>new URLSearchParams(window.location.search),[]),T=V.get("minimal")==="1";a.useEffect(()=>{T&&u(!0)},[T]);const re=a.useCallback(t=>{b(c=>{const n=new Set(c);return n.has(t)?n.delete(t):n.add(t),n})},[]),ce=V.get("import")==="1",W=a.useRef(!1),C=a.useCallback(()=>{J().then(l).catch(t=>w(String(t))),Z().then(h).catch(()=>h(null)),ee().then(t=>M(!!(t.git&&!t.clean))).catch(()=>M(!1)),E(t=>t+1)},[]);a.useEffect(C,[C]),a.useEffect(()=>{const t=setInterval(()=>{J().then(c=>{l(n=>n&&c.fingerprint===n.fingerprint?n:(B.current||(L.current=c.fingerprint),T||(Z().then(h).catch(()=>h(null)),ee().then(d=>M(!!(d.git&&!d.clean))).catch(()=>M(!1))),E(d=>d+1),c))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[T]),a.useEffect(()=>{s!=null&&s.fingerprint&&(L.current=s.fingerprint)},[s]);const G=a.useCallback(async(t,c)=>{if(s){B.current=!0;try{const n=await xe(t,c,L.current||s.fingerprint);return n!=null&&n.fingerprint&&(L.current=n.fingerprint),C(),n}catch(n){throw n instanceof pe&&n.status===409?(m("Model changed on disk — view refreshed, please retry."),C()):m(n instanceof Error?n.message:String(n)),n}finally{B.current=!1}}},[s,C]);a.useEffect(()=>{if(!g)return;const t=setTimeout(()=>m(null),5e3);return()=>clearTimeout(t)},[g]),a.useEffect(()=>{if(!s||W.current)return;const t=V.get("focus");if(!t)return;const c=s.entities.find(n=>{var d;return n.name===t||((d=n.conceptual)==null?void 0:d.name)===t});c&&(W.current=!0,requestAnimationFrame(()=>{var n;return(n=o.current)==null?void 0:n.focusEntity(c.id)}))},[s,V]);const oe=a.useCallback(()=>{var n;if(!s)return;const t=p.trim().toLowerCase();if(!t)return;const c=s.entities.find(d=>{var N;return(d.name.toLowerCase()+" "+(((N=d.conceptual)==null?void 0:N.name.toLowerCase())??"")+" "+d.attributes.map(Q=>Q.name.toLowerCase()).join(" ")).includes(t)});c&&((n=o.current)==null||n.focusEntity(c.id))},[s,p]);return a.useEffect(()=>{const t=c=>{var d,P,N;const n=(d=document.activeElement)==null?void 0:d.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(c.key==="/"&&(c.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),c.key==="n"&&!R&&((N=o.current)==null||N.newEntity()),c.key==="Escape"&&(A(null),y(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[R]),x?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:x}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!T&&e.jsx(_e,{doc:s,diagnostics:j,query:p,onQuery:y,onSubmitQuery:oe,showTypes:f,onToggleTypes:()=>v(t=>!t),collapseDetail:r,onToggleCollapse:()=>u(t=>!t),onFitView:()=>{var t;return(t=o.current)==null?void 0:t.fitView()},onRelayout:(t,c)=>{var n;return(n=o.current)==null?void 0:n.relayout(t,c)},onResetLayout:()=>{var t;return(t=o.current)==null?void 0:t.resetLayout()},onRefresh:C,readOnly:R,dirty:K,panelTab:S,onPanelTab:t=>I(c=>c===t?null:t),onNewEntity:()=>{var t;return(t=o.current)==null?void 0:t.newEntity()},exec:G,onImported:C,onImportBatch:je,openImport:ce,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:z.size}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(me,{doc:s,caps:ne,exec:G,selectedId:S?null:q,onSelect:A,query:p,showTypes:f,collapseDetail:r,expandedEntities:k,onToggleExpand:re,activeAreas:z,onError:m,handleRef:o,layoutStore:ae}),!T&&e.jsx(Ae,{doc:s,saColors:O,countByArea:te,activeAreas:z,onSetActive:D,open:_,onClose:()=>$(!1)}),S&&e.jsx(fe,{tab:S,onClose:()=>I(null),readOnly:R,refreshKey:F,onModelChanged:C,onFocusEntity:t=>{var c;I(null),(c=o.current)==null||c.focusEntity(t)}}),g&&e.jsx("div",{className:"toast",children:g})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ve(){return e.jsx(he,{children:e.jsx(He,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(le.StrictMode,{children:e.jsx(Ve,{})})); diff --git a/packages/server/src/mdl_server/static/assets/sme-r22DBFEH.js b/packages/server/src/mdl_server/static/assets/sme-D3j9EH3y.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-r22DBFEH.js rename to packages/server/src/mdl_server/static/assets/sme-D3j9EH3y.js index d7254e7..711fb90 100644 --- a/packages/server/src/mdl_server/static/assets/sme-r22DBFEH.js +++ b/packages/server/src/mdl_server/static/assets/sme-D3j9EH3y.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-BiCY0Chy.js","assets/client-DOmNpTln.js","assets/styles-_nxo2D6f.js","assets/styles-BpoQ4C-h.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-_nxo2D6f.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-BiCY0Chy.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-C8Qo8i3S.js","assets/client-DOmNpTln.js","assets/styles-BJTACkJo.js","assets/styles-BpoQ4C-h.css"])))=>i.map(i=>d[i]); +import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-BJTACkJo.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-C8Qo8i3S.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); diff --git a/packages/server/src/mdl_server/static/assets/styles-_nxo2D6f.js b/packages/server/src/mdl_server/static/assets/styles-BJTACkJo.js similarity index 88% rename from packages/server/src/mdl_server/static/assets/styles-_nxo2D6f.js rename to packages/server/src/mdl_server/static/assets/styles-BJTACkJo.js index 1b698c2..d42b896 100644 --- a/packages/server/src/mdl_server/static/assets/styles-_nxo2D6f.js +++ b/packages/server/src/mdl_server/static/assets/styles-BJTACkJo.js @@ -6,7 +6,7 @@ var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var At=x;function ac(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var cc=typeof Object.is=="function"?Object.is:ac,lc=At.useState,uc=At.useEffect,dc=At.useLayoutEffect,fc=At.useDebugValue;function hc(e,t){var n=t(),r=lc({inst:{value:n,getSnapshot:t}}),s=r[0].inst,i=r[1];return dc(function(){s.value=n,s.getSnapshot=t,Xn(s)&&i({inst:s})},[e,n,t]),uc(function(){return Xn(s)&&i({inst:s}),e(function(){Xn(s)&&i({inst:s})})},[e]),fc(n),n}function Xn(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!cc(e,n)}catch{return!0}}function mc(e,t){return t()}var pc=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?mc:hc;Si.useSyncExternalStore=At.useSyncExternalStore!==void 0?At.useSyncExternalStore:pc;Ni.exports=Si;var gc=Ni.exports;/** + */var At=x;function ac(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var cc=typeof Object.is=="function"?Object.is:ac,lc=At.useState,uc=At.useEffect,dc=At.useLayoutEffect,fc=At.useDebugValue;function hc(e,t){var n=t(),r=lc({inst:{value:n,getSnapshot:t}}),s=r[0].inst,i=r[1];return dc(function(){s.value=n,s.getSnapshot=t,Wn(s)&&i({inst:s})},[e,n,t]),uc(function(){return Wn(s)&&i({inst:s}),e(function(){Wn(s)&&i({inst:s})})},[e]),fc(n),n}function Wn(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!cc(e,n)}catch{return!0}}function mc(e,t){return t()}var pc=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?mc:hc;Si.useSyncExternalStore=At.useSyncExternalStore!==void 0?At.useSyncExternalStore:pc;Ni.exports=Si;var gc=Ni.exports;/** * @license React * use-sync-external-store-shim/with-selector.production.js * @@ -14,9 +14,9 @@ var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Dn=x,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=Dn.useRef,_c=Dn.useEffect,Ec=Dn.useMemo,Nc=Dn.useDebugValue;Ei.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var w=o.value;if(s(w,f))return d=w}return d=f}if(w=d,wc(u,f))return w;var y=r(f);return s!==void 0&&s(w,y)?(u=f,w):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};_i.exports=Ei;var Sc=_i.exports;const kc=vi(Sc),jc={},es=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(w=>w(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?es(e):es,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function ki(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const ts=(e,t)=>{const n=Cc(e),r=(s,i=t)=>ki(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?ts(e,t):ts;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rs.hasOwnProperty(t)?{space:rs[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===dr&&t.documentElement.namespaceURI===dr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ji(e){var t=zn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function Cr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=Cr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=$&&($=E+1);!(M=v[$])&&++$=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Rt(this.node(),e)}function Rt(e,t){return e.style.getPropertyValue(t)||Ri(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ii(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Ti(e)}function Ti(e){this._node=e,this._names=Ii(e.getAttribute("class")||"")}Ti.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Oi(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function fr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}fr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Pn("start","drag","end"),o=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",p,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,M){if(!(u||!e.call(this,b,M))){var N=$(this,t.call(this,b,M),b,M,"mouse");N&&(Te(b.view).on("mousemove.drag",w,Ut).on("mouseup.drag",y,Ut),zi(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,N("start",b))}}function w(b){if(Ct(b),!l){var M=b.clientX-a,N=b.clientY-c;l=M*M+N*N>d}s.mouse("drag",b)}function y(b){Te(b.view).on("mousemove.drag mouseup.drag",null),Hi(b.view,l),Ct(b),s.mouse("end",b)}function v(b,M){if(e.call(this,b,M)){var N=b.changedTouches,_=t.call(this,b,M),R=N.length,k,O;for(k=0;k>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?un(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?un(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Me(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Me(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?un(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?un(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?us(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?us(t[1],t[2]/100,t[3]/100,t[4]):ss.hasOwnProperty(e)?as(ss[e]):e==="transparent"?new Me(NaN,NaN,NaN,0):null}function as(e){return new Me(e>>16&255,e>>8&255,e&255,1)}function un(e,t,n,r){return r<=0&&(e=t=n=NaN),new Me(e,t,n,r)}function Mu(e){return e instanceof rn||(e=Zt(e)),e?(e=e.rgb(),new Me(e.r,e.g,e.b,e.opacity)):new Me}function hr(e,t,n,r){return arguments.length===1?Mu(e):new Me(e,t,n,r??1)}function Me(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Mr(Me,hr,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Me(yt(this.r),yt(this.g),yt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:cs,formatHex:cs,formatHex8:Au,formatRgb:ls,toString:ls}));function cs(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function ls(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function us(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new He(e,t,n,r)}function Vi(e){if(e instanceof He)return new He(e.h,e.s,e.l,e.opacity);if(e instanceof rn||(e=Zt(e)),!e)return new He;if(e instanceof He)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new He(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Vi(e):new He(e,t,n,r??1)}function He(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Mr(He,Ru,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new He(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new He(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Me(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new He(ds(this.h),dn(this.s),dn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${ds(this.h)}, ${dn(this.s)*100}%, ${dn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ds(e){return e=(e||0)%360,e<0?e+360:e}function dn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Bi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Gi:function(t,n){return n-t?Tu(t,n,e):Bi(isNaN(t)?n:t)}}function Gi(e,t){var n=t-e;return n?Iu(e,n):Bi(isNaN(e)?t:e)}const fs=function e(t){var n=Ou(t);function r(s,i){var o=n((s=hr(s)).r,(i=hr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Gi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function it(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var mr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(mr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=mr.lastIndex=Kn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=mr.exec(e))&&(s=Kn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:it(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:it(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:it(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,w){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");w.push({i:y-4,x:it(l,d)},{i:y-2,x:it(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var w=-1,y=m.length,v;++w=0&&e._call.call(void 0,t),e=e._next;--It}function ps(){bt=(Cn=Qt.now())+Hn,It=Gt=0;try{Uu()}finally{It=0,Ku(),bt=0}}function qu(){var e=Qt.now(),t=e-Cn;t>Xi&&(Hn-=t,Cn=e)}function Ku(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Yt=e,gr(r)}function gr(e){if(!It){Gt&&(Gt=clearTimeout(Gt));var t=e-bt;t>24?(e<1/0&&(Gt=setTimeout(ps,e-Qt.now()-Hn)),zt&&(zt=clearInterval(zt))):(zt||(Cn=Qt.now(),zt=setInterval(qu,Xi)),It=1,Ui(ps))}}function gs(e,t,n){var r=new $n;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Pn("start","end","cancel","interrupt"),Qu=[],Ki=0,ys=1,yr=2,vn=3,xs=4,xr=5,_n=6;function Fn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Ki})}function Rr(e,t){var n=Fe(e,t);if(n.state>Ki)throw new Error("too late; already scheduled");return n}function We(e,t){var n=Fe(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Fe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=qi(i,0,n.time);function i(l){n.state=ys,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ys)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return gs(o);f.state===xs?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uyr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Rr:We;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Fe(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Cr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Qe(e,t,n){this.k=e,this.x=t,this.y=n}Qe.prototype={constructor:Qe,scale:function(e){return e===1?this:new Qe(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Qe(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Je=new Qe(1,0,0);Qe.prototype;function Zn(e){e.stopImmediatePropagation()}function Ht(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ws(){return this.__zoom||Je}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function eo(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Wu,l=Pn("start","zoom","end"),u,d,m,f=500,w=150,y=0,v=10;function p(g){g.property("__zoom",ws).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",D).on("touchmove.zoom",B).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}p.transform=function(g,C,S,I){var L=g.selection?g.selection():g;L.property("__zoom",ws),g!==L?M(g,C,S,I):L.interrupt().each(function(){N(this,arguments).event(I).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},p.scaleBy=function(g,C,S,I){p.scaleTo(g,function(){var L=this.__zoom.k,j=typeof C=="function"?C.apply(this,arguments):C;return L*j},S,I)},p.scaleTo=function(g,C,S,I){p.transform(g,function(){var L=t.apply(this,arguments),j=this.__zoom,T=S==null?b(L):typeof S=="function"?S.apply(this,arguments):S,P=j.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n($(E(j,z),T,P),L,o)},S,I)},p.translateBy=function(g,C,S,I){p.transform(g,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,I)},p.translateTo=function(g,C,S,I,L){p.transform(g,function(){var j=t.apply(this,arguments),T=this.__zoom,P=I==null?b(j):typeof I=="function"?I.apply(this,arguments):I;return n(Je.translate(P[0],P[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof S=="function"?-S.apply(this,arguments):-S),j,o)},I,L)};function E(g,C){return C=Math.max(i[0],Math.min(i[1],C)),C===g.k?g:new Qe(C,g.x,g.y)}function $(g,C,S){var I=C[0]-S[0]*g.k,L=C[1]-S[1]*g.k;return I===g.x&&L===g.y?g:new Qe(g.k,I,L)}function b(g){return[(+g[0][0]+ +g[1][0])/2,(+g[0][1]+ +g[1][1])/2]}function M(g,C,S,I){g.on("start.zoom",function(){N(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(I).end()}).tween("zoom",function(){var L=this,j=arguments,T=N(L,j).event(I),P=t.apply(L,j),z=S==null?b(P):typeof S=="function"?S.apply(L,j):S,W=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),V=L.__zoom,Z=typeof C=="function"?C.apply(L,j):C,J=c(V.invert(z).concat(W/V.k),Z.invert(z).concat(W/Z.k));return function(ee){if(ee===1)ee=Z;else{var oe=J(ee),ne=W/oe[2];ee=new Qe(ne,z[0]-oe[0]*ne,z[1]-oe[1]*ne)}T.zoom(null,ee)}})}function N(g,C,S){return!S&&g.__zooming||new _(g,C)}function _(g,C){this.that=g,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(g,C),this.taps=0}_.prototype={event:function(g){return g&&(this.sourceEvent=g),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(g,C){return this.mouse&&g!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&g!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&g!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(g){var C=Te(this.that).datum();l.call(g,this.that,new sf(g,{sourceEvent:this.sourceEvent,target:p,transform:this.that.__zoom,dispatch:l}),C)}};function R(g,...C){if(!e.apply(this,arguments))return;var S=N(this,C).event(g),I=this.__zoom,L=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,r.apply(this,arguments)))),j=ze(g);if(S.wheel)(S.mouse[0][0]!==j[0]||S.mouse[0][1]!==j[1])&&(S.mouse[1]=I.invert(S.mouse[0]=j)),clearTimeout(S.wheel);else{if(I.k===L)return;S.mouse=[j,I.invert(j)],En(this),S.start()}Ht(g),S.wheel=setTimeout(T,w),S.zoom("mouse",n($(E(I,L),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function k(g,...C){if(m||!e.apply(this,arguments))return;var S=g.currentTarget,I=N(this,C,!0).event(g),L=Te(g.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",W,!0),j=ze(g,S),T=g.clientX,P=g.clientY;zi(g.view),Zn(g),I.mouse=[j,this.__zoom.invert(j)],En(this),I.start();function z(V){if(Ht(V),!I.moved){var Z=V.clientX-T,J=V.clientY-P;I.moved=Z*Z+J*J>y}I.event(V).zoom("mouse",n($(I.that.__zoom,I.mouse[0]=ze(V,S),I.mouse[1]),I.extent,o))}function W(V){L.on("mousemove.zoom mouseup.zoom",null),Hi(V.view,I.moved),Ht(V),I.event(V).end()}}function O(g,...C){if(e.apply(this,arguments)){var S=this.__zoom,I=ze(g.changedTouches?g.changedTouches[0]:g,this),L=S.invert(I),j=S.k*(g.shiftKey?.5:2),T=n($(E(S,j),I,L),t.apply(this,C),o);Ht(g),a>0?Te(this).transition().duration(a).call(M,T,I,g):Te(this).call(p.transform,T,I,g)}}function D(g,...C){if(e.apply(this,arguments)){var S=g.touches,I=S.length,L=N(this,C,g.changedTouches.length===I).event(g),j,T,P,z;for(Zn(g),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},to=tt.error001();function de(e,t){const n=x.useContext(Vn);if(n===null)throw new Error(to);return ki(n,e,t)}const Ee=()=>{const e=x.useContext(Vn);if(e===null)throw new Error(to);return x.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Tr({position:e,children:t,className:n,style:r,...s}){const i=de(ff),o=`${e}`.split("-");return A.createElement("div",{className:je(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Tr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=x.useRef(null),[m,f]=x.useState({x:0,y:0,width:0,height:0}),w=je(["react-flow__edge-textwrapper",l]);return x.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:w,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=x.memo(mf);const Or=e=>({width:e.offsetWidth,height:e.offsetHeight}),Tt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Lr=(e={x:0,y:0},t)=>({x:Tt(e.x,t[0][0],t[1][0]),y:Tt(e.y,t[0][1],t[1][1])}),bs=(e,t,n)=>en?-Tt(Math.abs(e-n),1,50)/50:0,no=(e,t)=>{const n=bs(e.x,35,t.width-35)*20,r=bs(e.y,35,t.height-35)*20;return[n,r]},ro=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},so=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Jt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),io=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),vs=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>io(so(Jt(e),Jt(t))),wr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Oe(e.width)&&Oe(e.height)&&Oe(e.x)&&Oe(e.y),Oe=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),oo=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function br(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const ao=e=>"clientX"in e,lt=(e,t)=>{var i,o;const n=ao(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Mn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},sn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Oe(n)&&Oe(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);sn.displayName="BaseEdge";function Ft(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function co({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[v,p,E]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(sn,{path:v,labelX:p,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:y})});Dr.displayName="SimpleBezierEdge";const Es={[q.Left]:{x:-1,y:0},[q.Right]:{x:1,y:0},[q.Top]:{x:0,y:-1},[q.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=q.Bottom,target:n})=>t===q.Left||t===q.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=q.Bottom,target:n,targetPosition:r=q.Top,center:s,offset:i}){const o=Es[t],a=Es[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],w,y;const v={x:0,y:0},p={x:0,y:0},[E,$,b,M]=co({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){w=s.x??E,y=s.y??$;const _=[{x:w,y:c.y},{x:w,y:l.y}],R=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?R:_:f=o.y===m?_:R,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const g=Math.min(i-1,i-H);o[d]===m?v[d]=(c[d]>e[d]?-1:1)*g:p[d]=(l[d]>n[d]?-1:1)*g}}if(t!==r){const H=d==="x"?"y":"x",g=o[d]===a[H],C=c[H]>l[H],S=c[H]=B?(w=(k.x+O.x)/2,y=f[0].y):(w=f[0].x,y=(k.y+O.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:l.x+p.x,y:l.y+p.y},n],w,y,b,M]}function _f(e,t,n,r){const s=Math.min(Ns(e,t)/2,Ns(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let $="";return E>0&&E{const[p,E,$]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:w,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const Pr=x.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:x.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Pr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=co({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const zr=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[w,y,v]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(sn,{path:w,labelX:y,labelY:v,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});zr.displayName="StraightEdge";function mn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Ss({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case q.Left:return[t-mn(t-r,i),n];case q.Right:return[t+mn(r-t,i),n];case q.Top:return[t,n-mn(n-s,i)];case q.Bottom:return[t,n+mn(s-n,i)]}}function fo({sourceX:e,sourceY:t,sourcePosition:n=q.Bottom,targetX:r,targetY:s,targetPosition:i=q.Top,curvature:o=.25}){const[a,c]=Ss({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Ss({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,w]=lo({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,w]}const In=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=q.Bottom,targetPosition:i=q.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,pathOptions:y,interactionWidth:v})=>{const[p,E,$]=fo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:v})});In.displayName="BezierEdge";const Hr=x.createContext(null),Nf=Hr.Provider;Hr.Consumer;const Sf=()=>x.useContext(Hr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,vr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},_r=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},ho=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},on=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return so(r,Jt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return io(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),on(e,t)),mo=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:w=!1}=u;if(o&&!f||w)return!1;const{positionAbsolute:y}=xt(u,a),v={x:y.x,y:y.y,width:d||0,height:m||0},p=wr(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,$=i&&p>0,b=(d||0)*(m||0);(E||$||p>=b||u.dragging)&&l.push(u)}),l},po=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},go=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Tt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function ks(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=lt(e),l=t.elementsFromPoint(o,a).find(w=>w.classList.contains("react-flow__handle"));if(l){const w=l.getAttribute("data-nodeid");if(w){const y=Fr(void 0,l),v=l.getAttribute("data-handleid"),p=i({nodeId:w,id:v,type:y});if(p){const E=s.find($=>$.nodeId===w&&$.type===y&&$.id===v);return{handle:{id:v,type:y,nodeId:w,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:p}}}}let u=[],d=1/0;if(s.forEach(w=>{const y=Math.sqrt((w.x-n.x)**2+(w.y-n.y)**2);if(y<=r){const v=i(w);y<=d&&(yw.isValid),f=u.some(({handle:w})=>w.type==="target");return u.find(({handle:w,validHandleResult:y})=>f?w.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},yo=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function xo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...yo(),handleDomNode:c};if(c){const u=Fr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),w=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&w&&(t===vt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=ks(i,o,"source",`${t}-${n}-${r}`),c=ks(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Fr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function wo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ro(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:w,onConnectStart:y,panBy:v,getNodes:p,cancelConnection:E}=i();let $=0,b;const{x:M,y:N}=lt(e),_=u==null?void 0:u.elementFromPoint(M,N),R=Fr(c,_),k=m==null?void 0:m.getBoundingClientRect();if(!k||!R)return;let O,D=lt(e,k),B=!1,H=null,g=!1,C=null;const S=If({nodes:p(),nodeId:n,handleId:t,handleType:R}),I=()=>{if(!f)return;const[T,P]=no(D,k);v({x:T,y:P}),$=requestAnimationFrame(I)};o({connectionPosition:D,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:R});function L(T){const{transform:P}=i();D=lt(T,k);const{handle:z,validHandleResult:W}=Af(T,u,_r(D,P,!1,[1,1]),w,S,V=>xo(V,d,n,t,s?"target":"source",a,u));if(b=z,B||(I(),B=!0),C=W.handleDomNode,H=W.connection,g=W.isValid,o({connectionPosition:b&&g?ho({x:b.x,y:b.y},P):D,connectionStatus:Tf(!!b,g),connectionEndHandle:W.endHandle}),!b&&!g&&!C)return Qn(O);H.source!==H.target&&C&&(Qn(O),O=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",g),C.classList.toggle("react-flow__handle-valid",g))}function j(T){var P,z;(b||C)&&H&&g&&(r==null||r(H)),(z=(P=i()).onConnectEnd)==null||z.call(P,T),c&&(l==null||l(T)),Qn(O),E(),cancelAnimationFrame($),B=!1,g=!1,H=null,C=null,u.removeEventListener("mousemove",L),u.removeEventListener("mouseup",j),u.removeEventListener("touchmove",L),u.removeEventListener("touchend",j)}u.addEventListener("mousemove",L),u.addEventListener("mouseup",j),u.addEventListener("touchmove",L),u.addEventListener("touchend",j)}const js=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},bo=x.forwardRef(({type:e="source",position:t=q.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var k,O;const w=o||null,y=e==="target",v=Ee(),p=Sf(),{connectOnClick:E,noPanClassName:$}=de(Of,ke),{connecting:b,clickConnecting:M}=de(Lf(p,w,e),ke);p||(O=(k=v.getState()).onError)==null||O.call(k,"010",tt.error010());const N=D=>{const{defaultEdgeOptions:B,onConnect:H,hasDefaultEdges:g}=v.getState(),C={...B,...D};if(g){const{edges:S,setEdges:I}=v.getState();I($f(C,S))}H==null||H(C),a==null||a(C)},_=D=>{if(!p)return;const B=ao(D);s&&(B&&D.button===0||!B)&&wo({event:D,handleId:w,nodeId:p,onConnect:N,isTarget:y,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||js}),B?u==null||u(D):d==null||d(D)},R=D=>{const{onClickConnectStart:B,onClickConnectEnd:H,connectionClickStartHandle:g,connectionMode:C,isValidConnection:S}=v.getState();if(!p||!g&&!s)return;if(!g){B==null||B(D,{nodeId:p,handleId:w,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:p,type:e,handleId:w}});return}const I=ro(D.target),L=n||S||js,{connection:j,isValid:T}=xo({nodeId:p,id:w,type:e},C,g.nodeId,g.handleId||null,g.type,L,I);T&&N(j),H==null||H(D),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":w,"data-nodeid":p,"data-handlepos":t,"data-id":`${p}-${w}-${e}`,className:je(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",$,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!b||i&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});bo.displayName="Handle";var ct=x.memo(bo);const vo=({data:e,isConnectable:t,targetPosition:n=q.Top,sourcePosition:r=q.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ct,{type:"source",position:r,isConnectable:t}));vo.displayName="DefaultNode";var Er=x.memo(vo);const _o=({data:e,isConnectable:t,sourcePosition:n=q.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ct,{type:"source",position:n,isConnectable:t}));_o.displayName="InputNode";var Eo=x.memo(_o);const No=({data:e,isConnectable:t,targetPosition:n=q.Top})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);No.displayName="OutputNode";var So=x.memo(No);const Vr=()=>null;Vr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),pn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(pn),t.selectedNodes.map(pn))&&ke(e.selectedEdges.map(pn),t.selectedEdges.map(pn))}const ko=x.memo(({onSelectionChange:e})=>{const t=Ee(),{selectedNodes:n,selectedEdges:r}=de(Df,Pf);return x.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});ko.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=de(zf);return e||t?A.createElement(ko,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Et(e,t){x.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ie(e,t,n){x.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:w,minZoom:y,maxZoom:v,nodeExtent:p,onNodesChange:E,onEdgesChange:$,elementsSelectable:b,connectionMode:M,snapGrid:N,snapToGrid:_,translateExtent:R,connectOnClick:k,defaultEdgeOptions:O,fitView:D,fitViewOptions:B,onNodesDelete:H,onEdgesDelete:g,onNodeDrag:C,onNodeDragStart:S,onNodeDragStop:I,onSelectionDrag:L,onSelectionDragStart:j,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:W,autoPanOnConnect:V,autoPanOnNodeDrag:Z,onError:J,connectionRadius:ee,isValidConnection:oe,nodeDragThreshold:ne})=>{const{setNodes:re,setEdges:pe,setDefaultNodesAndEdges:ce,setMinZoom:ue,setMaxZoom:ye,setTranslateExtent:he,setNodeExtent:xe,reset:le}=de(Ff,ke),K=Ee();return x.useEffect(()=>{const Ne=r==null?void 0:r.map(Ce=>({...Ce,...O}));return ce(n,Ne),()=>{le()}},[]),ie("defaultEdgeOptions",O,K.setState),ie("connectionMode",M,K.setState),ie("onConnect",s,K.setState),ie("onConnectStart",i,K.setState),ie("onConnectEnd",o,K.setState),ie("onClickConnectStart",a,K.setState),ie("onClickConnectEnd",c,K.setState),ie("nodesDraggable",l,K.setState),ie("nodesConnectable",u,K.setState),ie("nodesFocusable",d,K.setState),ie("edgesFocusable",m,K.setState),ie("edgesUpdatable",f,K.setState),ie("elementsSelectable",b,K.setState),ie("elevateNodesOnSelect",w,K.setState),ie("snapToGrid",_,K.setState),ie("snapGrid",N,K.setState),ie("onNodesChange",E,K.setState),ie("onEdgesChange",$,K.setState),ie("connectOnClick",k,K.setState),ie("fitViewOnInit",D,K.setState),ie("fitViewOnInitOptions",B,K.setState),ie("onNodesDelete",H,K.setState),ie("onEdgesDelete",g,K.setState),ie("onNodeDrag",C,K.setState),ie("onNodeDragStart",S,K.setState),ie("onNodeDragStop",I,K.setState),ie("onSelectionDrag",L,K.setState),ie("onSelectionDragStart",j,K.setState),ie("onSelectionDragStop",T,K.setState),ie("noPanClassName",P,K.setState),ie("nodeOrigin",z,K.setState),ie("rfId",W,K.setState),ie("autoPanOnConnect",V,K.setState),ie("autoPanOnNodeDrag",Z,K.setState),ie("onError",J,K.setState),ie("connectionRadius",ee,K.setState),ie("isValidConnection",oe,K.setState),ie("nodeDragThreshold",ne,K.setState),Et(e,re),Et(t,pe),Et(y,ue),Et(v,ye),Et(R,he),Et(p,xe),null},Cs={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},jo="react-flow__node-desc",Co="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Wf({rfId:e}){const t=de(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Xf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${jo}-${e}`,style:Cs},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Co}-${e}`,style:Cs},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Wf,{rfId:e}))}var tn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=x.useState(!1),s=x.useRef(!1),i=x.useRef(new Set([])),[o,a]=x.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return x.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);i.current.add(f[y]),$s(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);$s(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Ms(e,t){return t.includes(e)?"code":"key"}function $o(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return $o(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function Mo(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=$o(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Oe(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Mo(s,n,i),s}function Ao(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const w=n().filter(v=>{var E;const p=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?p&&t.nodes.some($=>$.id===v.id):p}),y=w.every(v=>v.width&&v.height);if(w.length>0&&y){const v=on(w,d),{x:p,y:E,zoom:$}=go(v,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),b=Je.translate(p,E).scale($);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Uf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function gn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Uf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const Nt=()=>{},Kf={zoomIn:Nt,zoomOut:Nt,zoomTo:Nt,getZoom:()=>1,setViewport:Nt,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:Nt,fitBounds:Nt,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Ee(),{d3Zoom:t,d3Selection:n}=de(Zf,ke);return x.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=Je.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Ao(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=Je.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=go(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=Je.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),_r(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return _r(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=ho(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function an(){const e=Qf(),t=Ee(),n=x.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=x.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=x.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(v=>({...v}))},[]),i=x.useCallback(y=>{const{edges:v=[]}=t.getState();return v.find(p=>p.id===y)},[]),o=x.useCallback(y=>{const{getNodes:v,setNodes:p,hasDefaultNodes:E,onNodesChange:$}=t.getState(),b=v(),M=typeof y=="function"?y(b):y;if(E)p(M);else if($){const N=M.length===0?b.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));$(N)}},[]),a=x.useCallback(y=>{const{edges:v=[],setEdges:p,hasDefaultEdges:E,onEdgesChange:$}=t.getState(),b=typeof y=="function"?y(v):y;if(E)p(b);else if($){const M=b.length===0?v.map(N=>({type:"remove",id:N.id})):b.map(N=>({item:N,type:"reset"}));$(M)}},[]),c=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{getNodes:p,setNodes:E,hasDefaultNodes:$,onNodesChange:b}=t.getState();if($){const N=[...p(),...v];E(N)}else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),l=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{edges:p=[],setEdges:E,hasDefaultEdges:$,onEdgesChange:b}=t.getState();if($)E([...p,...v]);else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),u=x.useCallback(()=>{const{getNodes:y,edges:v=[],transform:p}=t.getState(),[E,$,b]=p;return{nodes:y().map(M=>({...M})),edges:v.map(M=>({...M})),viewport:{x:E,y:$,zoom:b}}},[]),d=x.useCallback(({nodes:y,edges:v})=>{const{nodeInternals:p,getNodes:E,edges:$,hasDefaultNodes:b,hasDefaultEdges:M,onNodesDelete:N,onEdgesDelete:_,onNodesChange:R,onEdgesChange:k}=t.getState(),O=(y||[]).map(C=>C.id),D=(v||[]).map(C=>C.id),B=E().reduce((C,S)=>{const I=S.parentNode||S.parentId,L=!O.includes(S.id)&&I&&C.find(T=>T.id===I);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(O.includes(S.id)||L)&&C.push(S),C},[]),H=$.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),g=H.filter(C=>D.includes(C.id));if(B||g){const C=po(B,H),S=[...g,...C],I=S.reduce((L,j)=>(L.includes(j.id)||L.push(j.id),L),[]);if((M||b)&&(M&&t.setState({edges:$.filter(L=>!I.includes(L.id))}),b&&(B.forEach(L=>{p.delete(L.id)}),t.setState({nodeInternals:new Map(p)}))),I.length>0&&(_==null||_(S),k&&k(I.map(L=>({id:L,type:"remove"})))),B.length>0&&(N==null||N(B),R)){const L=B.map(j=>({id:j.id,type:"remove"}));R(L)}}},[]),m=x.useCallback(y=>{const v=yf(y),p=v?null:t.getState().nodeInternals.get(y.id);return!v&&!p?[null,null,v]:[v?y:vs(p),p,v]},[]),f=x.useCallback((y,v=!0,p)=>{const[E,$,b]=m(y);return E?(p||t.getState().getNodes()).filter(M=>{if(!b&&(M.id===$.id||!M.positionAbsolute))return!1;const N=vs(M),_=wr(N,E);return v&&_>0||_>=E.width*E.height}):[]},[]),w=x.useCallback((y,v,p=!0)=>{const[E]=m(y);if(!E)return!1;const $=wr(E,v);return p&&$>0||$>=E.width*E.height},[]);return x.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:w}),[e,n,r,s,i,o,a,c,l,u,d,f,w])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ee(),{deleteElements:r}=an(),s=tn(e,Jf),i=tn(t);x.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),x.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Ee();x.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Or(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",tt.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Br={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,yn=e=>({x:e.x,y:e.y,zoom:e.k}),St=(e,t)=>e.target.closest(`.${t}`),As=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rs=e=>{const t=e.ctrlKey&&Mn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:w,maxZoom:y,zoomActivationKeyCode:v,preventScrolling:p=!0,children:E,noWheelClassName:$,noPanClassName:b})=>{const M=x.useRef(),N=Ee(),_=x.useRef(!1),R=x.useRef(!1),k=x.useRef(null),O=x.useRef({x:0,y:0,zoom:0}),{d3Zoom:D,d3Selection:B,d3ZoomHandler:H,userSelectionActive:g}=de(rh,ke),C=tn(v),S=x.useRef(0),I=x.useRef(!1),L=x.useRef();return th(k),x.useEffect(()=>{if(k.current){const j=k.current.getBoundingClientRect(),T=eo().scaleExtent([w,y]).translateExtent(f),P=Te(k.current).call(T),z=Je.translate(m.x,m.y).scale(Tt(m.zoom,w,y)),W=[[0,0],[j.width,j.height]],V=T.constrain()(z,W,f);T.transform(P,V),T.wheelDelta(Rs),N.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[V.x,V.y,V.k],domNode:k.current.closest(".react-flow")})}},[]),x.useEffect(()=>{B&&D&&(o&&!C&&!g?B.on("wheel.zoom",j=>{if(St(j,$))return!1;j.preventDefault(),j.stopImmediatePropagation();const T=B.property("__zoom").k||1;if(j.ctrlKey&&i){const oe=ze(j),ne=Rs(j),re=T*Math.pow(2,ne);D.scaleTo(B,re,oe,j);return}const P=j.deltaMode===1?20:1;let z=c===gt.Vertical?0:j.deltaX*P,W=c===gt.Horizontal?0:j.deltaY*P;!Mn()&&j.shiftKey&&c!==gt.Vertical&&(z=j.deltaY*P,W=0),D.translateBy(B,-(z/T)*a,-(W/T)*a,{internal:!0});const V=yn(B.property("__zoom")),{onViewportChangeStart:Z,onViewportChange:J,onViewportChangeEnd:ee}=N.getState();clearTimeout(L.current),I.current||(I.current=!0,t==null||t(j,V),Z==null||Z(V)),I.current&&(e==null||e(j,V),J==null||J(V),L.current=setTimeout(()=>{n==null||n(j,V),ee==null||ee(V),I.current=!1},150))},{passive:!1}):typeof H<"u"&&B.on("wheel.zoom",function(j,T){if(!p&&j.type==="wheel"&&!j.ctrlKey||St(j,$))return null;j.preventDefault(),H.call(this,j,T)},{passive:!1}))},[g,o,c,B,D,H,C,i,p,$,t,e,n]),x.useEffect(()=>{D&&D.on("start",j=>{var z,W;if(!j.sourceEvent||j.sourceEvent.internal)return null;S.current=(z=j.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=N.getState(),P=yn(j.transform);_.current=!0,O.current=P,((W=j.sourceEvent)==null?void 0:W.type)==="mousedown"&&N.setState({paneDragging:!0}),T==null||T(P),t==null||t(j.sourceEvent,P)})},[D,t]),x.useEffect(()=>{D&&(g&&!_.current?D.on("zoom",null):g||D.on("zoom",j=>{var P;const{onViewportChange:T}=N.getState();if(N.setState({transform:[j.transform.x,j.transform.y,j.transform.k]}),R.current=!!(r&&As(d,S.current??0)),(e||T)&&!((P=j.sourceEvent)!=null&&P.internal)){const z=yn(j.transform);T==null||T(z),e==null||e(j.sourceEvent,z)}}))},[g,D,e,d,r]),x.useEffect(()=>{D&&D.on("end",j=>{if(!j.sourceEvent||j.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=N.getState();if(_.current=!1,N.setState({paneDragging:!1}),r&&As(d,S.current??0)&&!R.current&&r(j.sourceEvent),R.current=!1,(n||T)&&nh(O.current,j.transform)){const P=yn(j.transform);O.current=P,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(P),n==null||n(j.sourceEvent,P)},o?150:0)}})},[D,o,d,n,r]),x.useEffect(()=>{D&&D.filter(j=>{const T=C||s,P=i&&j.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&j.button===1&&j.type==="mousedown"&&(St(j,"react-flow__node")||St(j,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||g||!l&&j.type==="dblclick"||St(j,$)&&j.type==="wheel"||St(j,b)&&(j.type!=="wheel"||o&&j.type==="wheel"&&!C)||!i&&j.ctrlKey&&j.type==="wheel"||!T&&!o&&!P&&j.type==="wheel"||!d&&(j.type==="mousedown"||j.type==="touchstart")||Array.isArray(d)&&!d.includes(j.button)&&j.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(j.button)||!j.button||j.button<=1;return(!j.ctrlKey||j.type==="wheel")&&z})},[g,D,s,i,o,l,d,u,C]),A.createElement("div",{className:"react-flow__renderer",ref:k,style:Br},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=de(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Is(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&Is(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&Is(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ot=(e,t)=>({id:e,type:"select",selected:t});function jt(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ot(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ot(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ro=x.memo(({isSelecting:e,selectionMode:t=en.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=x.useRef(null),f=Ee(),w=x.useRef(0),y=x.useRef(0),v=x.useRef(),{userSelectionActive:p,elementsSelectable:E,dragging:$}=de(lh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),w.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},N=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,R=H=>{const{resetSelectedElements:g,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!v.current)return;const{x:S,y:I}=lt(H,v.current);g(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:I,x:S,y:I}}),r==null||r(H)},k=H=>{const{userSelectionRect:g,nodeInternals:C,edges:S,transform:I,onNodesChange:L,onEdgesChange:j,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!g)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=lt(H,v.current),W=g.startX??0,V=g.startY??0,Z={...g,x:z.xre.id),ne=ee.map(re=>re.id);if(w.current!==ne.length){w.current=ne.length;const re=jt(J,ne);re.length&&(L==null||L(re))}if(y.current!==oe.length){y.current=oe.length;const re=jt(S,oe);re.length&&(j==null||j(re))}f.setState({userSelectionRect:Z})},O=H=>{if(H.button!==0)return;const{userSelectionRect:g}=f.getState();!p&&g&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:w.current>0}),b(),s==null||s(H)},D=H=>{p&&(f.setState({nodesSelectionActive:w.current>0}),s==null||s(H)),b()},B=E&&(e||p);return A.createElement("div",{className:je(["react-flow__pane",{dragging:$,selection:e}]),onClick:B?void 0:er(M,m),onContextMenu:er(N,m),onWheel:er(_,m),onMouseEnter:B?void 0:c,onMouseDown:B?R:void 0,onMouseMove:B?k:l,onMouseUp:B?O:void 0,onMouseLeave:B?D:u,ref:m,style:Br},d,A.createElement(oh,null))});Ro.displayName="Pane";function Io(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Io(r,t):!1}function Ts(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Io(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function To(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Oe(m)&&Oe(f)&&Oe(d.width)&&Oe(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",tt.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Lr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Os=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Or(c)}})};function Vt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Nr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",tt.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Ee();return x.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Oo({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Ee(),[c,l]=x.useState(!1),u=x.useRef([]),d=x.useRef({x:null,y:null}),m=x.useRef(0),f=x.useRef(null),w=x.useRef({x:0,y:0}),y=x.useRef(null),v=x.useRef(!1),p=x.useRef(!1),E=x.useRef(!1),$=fh();return x.useEffect(()=>{if(e!=null&&e.current){const b=Te(e.current),M=({x:R,y:k})=>{const{nodeInternals:O,onNodeDrag:D,onSelectionDrag:B,updateNodePositions:H,nodeExtent:g,snapGrid:C,snapToGrid:S,nodeOrigin:I,onError:L}=a.getState();d.current={x:R,y:k};let j=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&g){const z=on(u.current,I);T=Jt(z)}if(u.current=u.current.map(z=>{const W={x:R-z.distance.x,y:k-z.distance.y};S&&(W.x=C[0]*Math.round(W.x/C[0]),W.y=C[1]*Math.round(W.y/C[1]));const V=[[g[0][0],g[0][1]],[g[1][0],g[1][1]]];u.current.length>1&&g&&!z.extent&&(V[0][0]=z.positionAbsolute.x-T.x+g[0][0],V[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+g[1][0],V[0][1]=z.positionAbsolute.y-T.y+g[0][1],V[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+g[1][1]);const Z=To(z,W,O,V,I,L);return j=j||z.position.x!==Z.position.x||z.position.y!==Z.position.y,z.position=Z.position,z.positionAbsolute=Z.positionAbsolute,z}),!j)return;H(u.current,!0,!0),l(!0);const P=s?D:nr(B);if(P&&y.current){const[z,W]=tr({nodeId:s,dragItems:u.current,nodeInternals:O});P(y.current,z,W)}},N=()=>{if(!f.current)return;const[R,k]=no(w.current,f.current);if(R!==0||k!==0){const{transform:O,panBy:D}=a.getState();d.current.x=(d.current.x??0)-R/O[2],d.current.y=(d.current.y??0)-k/O[2],D({x:R,y:k})&&M(d.current)}m.current=requestAnimationFrame(N)},_=R=>{var I;const{nodeInternals:k,multiSelectionActive:O,nodesDraggable:D,unselectNodesAndEdges:B,onNodeDragStart:H,onSelectionDragStart:g}=a.getState();p.current=!0;const C=s?H:nr(g);(!o||!i)&&!O&&s&&((I=k.get(s))!=null&&I.selected||B()),s&&i&&o&&Nr({id:s,store:a,nodeRef:e});const S=$(R);if(d.current=S,u.current=uh(k,D,S,s),C&&u.current){const[L,j]=tr({nodeId:s,dragItems:u.current,nodeInternals:k});C(R.sourceEvent,L,j)}};if(t)b.on(".drag",null);else{const R=bu().on("start",k=>{const{domNode:O,nodeDragThreshold:D}=a.getState();D===0&&_(k),E.current=!1;const B=$(k);d.current=B,f.current=(O==null?void 0:O.getBoundingClientRect())||null,w.current=lt(k.sourceEvent,f.current)}).on("drag",k=>{var H,g;const O=$(k),{autoPanOnNodeDrag:D,nodeDragThreshold:B}=a.getState();if(k.sourceEvent.type==="touchmove"&&k.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&p.current&&D&&(v.current=!0,N()),!p.current){const C=O.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=O.ySnapped-(((g=d==null?void 0:d.current)==null?void 0:g.y)??0);Math.sqrt(C*C+S*S)>B&&_(k)}(d.current.x!==O.xSnapped||d.current.y!==O.ySnapped)&&u.current&&p.current&&(y.current=k.sourceEvent,w.current=lt(k.sourceEvent,f.current),M(O))}}).on("end",k=>{if(!(!p.current||E.current)&&(l(!1),v.current=!1,p.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:O,nodeInternals:D,onNodeDragStop:B,onSelectionDragStop:H}=a.getState(),g=s?B:nr(H);if(O(u.current,!1,!1),g){const[C,S]=tr({nodeId:s,dragItems:u.current,nodeInternals:D});g(k.sourceEvent,C,S)}}}).filter(k=>{const O=k.target;return!k.button&&(!n||!Ts(O,`.${n}`,e))&&(!r||Ts(O,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,$]),c}function Lo(){const e=Ee();return x.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,w=n.isShiftPressed?4:1,y=n.x*m*w,v=n.y*f*w,p=d.map(E=>{if(E.positionAbsolute){const $={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+v};a&&($.x=c[0]*Math.round($.x/c[0]),$.y=c[1]*Math.round($.y/c[1]));const{positionAbsolute:b,position:M}=To(E,$,r,s,void 0,l);E.position=M,E.positionAbsolute=b}return E});i(p,!0,!1)},[])}const Mt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Bt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:w,onDoubleClick:y,style:v,className:p,isDraggable:E,isSelectable:$,isConnectable:b,isFocusable:M,selectNodesOnDrag:N,sourcePosition:_,targetPosition:R,hidden:k,resizeObserver:O,dragHandle:D,zIndex:B,isParent:H,noDragClassName:g,noPanClassName:C,initialized:S,disableKeyboardA11y:I,ariaLabel:L,rfId:j,hasHandleBounds:T})=>{const P=Ee(),z=x.useRef(null),W=x.useRef(null),V=x.useRef(_),Z=x.useRef(R),J=x.useRef(r),ee=$||E||u||d||m||f,oe=Lo(),ne=Vt(n,P.getState,d),re=Vt(n,P.getState,m),pe=Vt(n,P.getState,f),ce=Vt(n,P.getState,w),ue=Vt(n,P.getState,y),ye=le=>{const{nodeDragThreshold:K}=P.getState();if($&&(!N||!E||K>0)&&Nr({id:n,store:P,nodeRef:z}),u){const Ne=P.getState().nodeInternals.get(n);Ne&&u(le,{...Ne})}},he=le=>{if(!br(le)&&!I)if(oo.includes(le.key)&&$){const K=le.key==="Escape";Nr({id:n,store:P,unselect:K,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Mt,le.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),oe({x:Mt[le.key].x,y:Mt[le.key].y,isShiftPressed:le.shiftKey}))};x.useEffect(()=>()=>{W.current&&(O==null||O.unobserve(W.current),W.current=null)},[]),x.useEffect(()=>{if(z.current&&!k){const le=z.current;(!S||!T||W.current!==le)&&(W.current&&(O==null||O.unobserve(W.current)),O==null||O.observe(le),W.current=le)}},[k,S,T]),x.useEffect(()=>{const le=J.current!==r,K=V.current!==_,Ne=Z.current!==R;z.current&&(le||K||Ne)&&(le&&(J.current=r),K&&(V.current=_),Ne&&(Z.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const xe=Oo({nodeRef:z,disabled:k||!E,noDragClassName:g,handleSelector:D,nodeId:n,isSelectable:$,selectNodesOnDrag:N});return k?null:A.createElement("div",{className:je(["react-flow__node",`react-flow__node-${r}`,{[C]:E},p,{selected:l,selectable:$,parent:H,dragging:xe}]),ref:z,style:{zIndex:B,transform:`translate(${a}px,${c}px)`,pointerEvents:ee?"all":"none",visibility:S?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:re,onMouseLeave:pe,onContextMenu:ce,onClick:ye,onDoubleClick:ue,onKeyDown:M?he:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":I?void 0:`${jo}-${j}`,"aria-label":L},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:xe,dragHandle:D,zIndex:B})))};return t.displayName="NodeWrapper",x.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...on(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ee(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=de(hh,ke),u=Lo(),d=x.useRef(null);if(x.useEffect(()=>{var w;n||(w=d.current)==null||w.focus({preventScroll:!0})},[n]),Oo({nodeRef:d}),l||!s||!i)return null;const m=e?w=>{const y=r.getState().getNodes().filter(v=>v.selected);e(w,y)}:void 0,f=w=>{Object.prototype.hasOwnProperty.call(Mt,w.key)&&u({x:Mt[w.key].x,y:Mt[w.key].y,isShiftPressed:w.shiftKey})};return A.createElement("div",{className:je(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=x.memo(mh);const gh=e=>e.nodesSelectionActive,Do=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:w,onSelectionEnd:y,multiSelectionKeyCode:v,panActivationKeyCode:p,zoomActivationKeyCode:E,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:N,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:O,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,preventScrolling:C,onSelectionContextMenu:S,noWheelClassName:I,noPanClassName:L,disableKeyboardA11y:j})=>{const T=de(gh),P=tn(d),z=tn(p),W=z||O,V=z||N,Z=P||m&&W!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:V,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:!P&&W,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:I,noPanClassName:L},A.createElement(Ro,{onSelectionStart:w,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:W,isSelecting:!!Z,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:L,disableKeyboardA11y:j})))};Do.displayName="FlowRenderer";var yh=x.memo(Do);function xh(e){return de(x.useCallback(n=>e?mo(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Bt(e.input||Eo),default:Bt(e.default||Er),output:Bt(e.output||So),group:Bt(e.group||Vr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Bt(e[i]||Er),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Po=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=de(vh,ke),a=xh(e.onlyRenderVisibleElements),c=x.useRef(),l=x.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return x.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Br},a.map(u=>{var M,N,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",tt.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),w=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),v=!!(u.focusable||r&&typeof u.focusable>"u"),p=e.nodeExtent?Lr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(p==null?void 0:p.x)??0,$=(p==null?void 0:p.y)??0,b=bh({x:E,y:$,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||q.Bottom,targetPosition:u.targetPosition||q.Top,hidden:u.hidden,xPos:E,yPos:$,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:w,isConnectable:y,isFocusable:v,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((N=u[we])!=null&&N.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Po.displayName="NodeRenderer";var _h=x.memo(Po);const Eh=(e,t,n)=>n===q.Left?e-t:n===q.Right?e+t:e,Nh=(e,t,n)=>n===q.Top?e-t:n===q.Bottom?e+t:e,Ls="react-flow__edgeupdater",Ds=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:je([Ls,`${Ls}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var kt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,style:v,source:p,target:E,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,elementsSelectable:k,hidden:O,sourceHandleId:D,targetHandleId:B,onContextMenu:H,onMouseEnter:g,onMouseMove:C,onMouseLeave:S,reconnectRadius:I,onReconnect:L,onReconnectStart:j,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:W,ariaLabel:V,isFocusable:Z,isReconnectable:J,pathOptions:ee,interactionWidth:oe,disableKeyboardA11y:ne})=>{const re=x.useRef(null),[pe,ce]=x.useState(!1),[ue,ye]=x.useState(!1),he=Ee(),xe=x.useMemo(()=>`url('#${vr(z,W)}')`,[z,W]),le=x.useMemo(()=>`url('#${vr(P,W)}')`,[P,W]);if(O)return null;const K=se=>{var Se;const{edges:me,addSelectedEdges:$e,unselectNodesAndEdges:X,multiSelectionActive:fe}=he.getState(),ge=me.find(dt=>dt.id===n);ge&&(k&&(he.setState({nodesSelectionActive:!1}),ge.selected&&fe?(X({nodes:[],edges:[ge]}),(Se=re.current)==null||Se.blur()):$e([n])),o&&o(se,ge))},Ne=Ft(n,he.getState,a),Ce=Ft(n,he.getState,H),ut=Ft(n,he.getState,g),Ae=Ft(n,he.getState,C),Xe=Ft(n,he.getState,S),Ie=(se,me)=>{if(se.button!==0)return;const{edges:$e,isValidConnection:X}=he.getState(),fe=me?E:p,ge=(me?B:D)||null,Se=me?"target":"source",dt=X||Sh,Ot=me,rt=$e.find(Pe=>Pe.id===n);ye(!0),j==null||j(se,rt,Se);const ft=Pe=>{ye(!1),T==null||T(Pe,rt,Se)};wo({event:se,handleId:ge,nodeId:fe,onConnect:Pe=>L==null?void 0:L(rt,Pe),isTarget:Ot,getState:he.getState,setState:he.setState,isValidConnection:dt,edgeUpdaterType:Se,onReconnectEnd:ft})},F=se=>Ie(se,!0),Y=se=>Ie(se,!1),G=()=>ce(!0),Q=()=>ce(!1),U=!k&&!o,te=se=>{var me;if(!ne&&oo.includes(se.key)&&k){const{unselectNodesAndEdges:$e,addSelectedEdges:X,edges:fe}=he.getState();se.key==="Escape"?((me=re.current)==null||me.blur(),$e({edges:[fe.find(Se=>Se.id===n)]})):X([n])}};return A.createElement("g",{className:je(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:pe}]),onClick:K,onDoubleClick:Ne,onContextMenu:Ce,onMouseEnter:ut,onMouseMove:Ae,onMouseLeave:Xe,onKeyDown:Z?te:void 0,tabIndex:Z?0:void 0,role:Z?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":V===null?void 0:V||`Edge from ${p} to ${E}`,"aria-describedby":Z?`${Co}-${W}`:void 0,ref:re},!ue&&A.createElement(e,{id:n,source:p,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,data:i,style:v,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,sourceHandleId:D,targetHandleId:B,markerStart:xe,markerEnd:le,pathOptions:ee,interactionWidth:oe}),J&&A.createElement(A.Fragment,null,(J==="source"||J===!0)&&A.createElement(Ds,{position:_,centerX:$,centerY:b,radius:I,onMouseDown:F,onMouseEnter:G,onMouseOut:Q,type:"source"}),(J==="target"||J===!0)&&A.createElement(Ds,{position:R,centerX:M,centerY:N,radius:I,onMouseDown:Y,onMouseEnter:G,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",x.memo(t)};function kh(e){const t={default:kt(e.default||In),straight:kt(e.bezier||zr),step:kt(e.step||Pr),smoothstep:kt(e.step||Bn),simplebezier:kt(e.simplebezier||Dr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=kt(e[i]||In),s),n);return{...t,...r}}function Ps(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case q.Top:return{x:r+i/2,y:s};case q.Right:return{x:r+i,y:s+o/2};case q.Bottom:return{x:r+i/2,y:s+o};case q.Left:return{x:r,y:s+o/2}}}function zs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ps(n,e,t),a=Ps(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Jt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Hs(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Oe(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),w=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(w?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=de(x.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Fs={[An.Arrow]:Rh,[An.ArrowClosed]:Ih};function Th(e){const t=Ee();return x.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(Fs,e)?Fs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",tt.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=vr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},zo=({defaultColor:e,rfId:t})=>{const n=de(x.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};zo.displayName="MarkerDefinitions";var Dh=x.memo(zo);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ho=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,children:v,disableKeyboardA11y:p})=>{const{edgesFocusable:E,edgesUpdatable:$,elementsSelectable:b,width:M,height:N,connectionMode:_,nodeInternals:R,onError:k}=de(Ph,ke),O=Ah(t,R,n);return M?A.createElement(A.Fragment,null,O.map(({level:D,edges:B,isMaxLevel:H})=>A.createElement("svg",{key:D,style:{zIndex:D},width:M,height:N,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,B.map(g=>{const[C,S,I]=Hs(R.get(g.source)),[L,j,T]=Hs(R.get(g.target));if(!I||!T)return null;let P=g.type||"default";s[P]||(k==null||k("011",tt.error011(P)),P="default");const z=s[P]||s.default,W=_===vt.Strict?j.target:(j.target??[]).concat(j.source??[]),V=zs(S.source,g.sourceHandle),Z=zs(W,g.targetHandle),J=(V==null?void 0:V.position)||q.Bottom,ee=(Z==null?void 0:Z.position)||q.Top,oe=!!(g.focusable||E&&typeof g.focusable>"u"),ne=g.reconnectable||g.updatable,re=typeof m<"u"&&(ne||$&&typeof ne>"u");if(!V||!Z)return k==null||k("008",tt.error008(V,g)),null;const{sourceX:pe,sourceY:ce,targetX:ue,targetY:ye}=jh(C,V,J,L,Z,ee);return A.createElement(z,{key:g.id,id:g.id,className:je([g.className,i]),type:P,data:g.data,selected:!!g.selected,animated:!!g.animated,hidden:!!g.hidden,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,style:g.style,source:g.source,target:g.target,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerEnd:g.markerEnd,markerStart:g.markerStart,sourceX:pe,sourceY:ce,targetX:ue,targetY:ye,sourcePosition:J,targetPosition:ee,elementsSelectable:b,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,rfId:r,ariaLabel:g.ariaLabel,isFocusable:oe,isReconnectable:re,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth,disableKeyboardA11y:p})})))),v):null};Ho.displayName="EdgeRenderer";var zh=x.memo(Ho);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=de(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=an(),n=x.useRef(!1);x.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[q.Left]:q.Right,[q.Right]:q.Left,[q.Top]:q.Bottom,[q.Bottom]:q.Top},Fo=({nodeId:e,handleType:t,style:n,type:r=at.Bezier,CustomComponent:s,connectionStatus:i})=>{var N,_,R;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=de(x.useCallback(k=>({fromNode:k.nodeInternals.get(e),handleId:k.connectionHandleId,toX:(k.connectionPosition.x-k.transform[0])/k.transform[2],toY:(k.connectionPosition.y-k.transform[1])/k.transform[2],connectionMode:k.connectionMode}),[e]),ke),d=(N=o==null?void 0:o[we])==null?void 0:N.handleBounds;let m=d==null?void 0:d[t];if(u===vt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(k=>k.id===a):m[0],w=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,v=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+w,p=(((R=o.positionAbsolute)==null?void 0:R.y)??0)+y,E=f==null?void 0:f.position,$=E?Bh[E]:null;if(!E||!$)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:v,fromY:p,toX:c,toY:l,fromPosition:E,toPosition:$,connectionStatus:i});let b="";const M={sourceX:v,sourceY:p,sourcePosition:E,targetX:c,targetY:l,targetPosition:$};return r===at.Bezier?[b]=fo(M):r===at.Step?[b]=Rn({...M,borderRadius:0}):r===at.SmoothStep?[b]=Rn(M):r===at.SimpleBezier?[b]=uo(M):b=`M${v},${p} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Fo.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=de(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:je(["react-flow__connection",l])},A.createElement(Fo,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Vs(e,t){return x.useRef(null),Ee(),x.useMemo(()=>t(e),[e])}const Vo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:w,onSelectionStart:y,onSelectionEnd:v,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:$,connectionLineContainerStyle:b,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,deleteKeyCode:D,onlyRenderVisibleElements:B,elementsSelectable:H,selectNodesOnDrag:g,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,preventScrolling:j,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:W,panOnScrollSpeed:V,panOnScrollMode:Z,zoomOnDoubleClick:J,panOnDrag:ee,onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneScroll:ce,onPaneContextMenu:ue,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,noDragClassName:Ae,noWheelClassName:Xe,noPanClassName:Ie,elevateEdgesOnSelect:F,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})=>{const te=Vs(e,wh),se=Vs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneContextMenu:ue,onPaneScroll:ce,deleteKeyCode:D,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,onSelectionStart:y,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:J,panOnScroll:W,panOnScrollSpeed:V,panOnScrollMode:Z,panOnDrag:ee,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,onSelectionContextMenu:w,preventScrolling:j,noDragClassName:Ae,noWheelClassName:Xe,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:B,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!F,disableKeyboardA11y:Y,rfId:U},A.createElement(Yh,{style:E,type:p,component:$,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:te,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:g,onlyRenderVisibleElements:B,noPanClassName:Ie,noDragClassName:Ae,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})))};Vo.displayName="GraphView";var Wh=x.memo(Vo);const Sr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],st={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Sr,nodeExtent:Sr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:vt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Xh=()=>Rc((e,t)=>({...st,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Jn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,v)=>{const p=s.get(v.id);if(p!=null&&p.hidden)s.set(p.id,{...p,[we]:{...p[we],handleBounds:void 0}});else if(p){const E=Or(v.nodeElement);!!(E.width&&E.height&&(p.width!==E.width||p.height!==E.height||v.forceUpdate))&&(s.set(p.id,{...p,[we]:{...p[we],handleBounds:{source:Os(".source",v.nodeElement,m,l),target:Os(".target",v.nodeElement,m,l)}},...E}),y.push({id:p.id,type:"dimensions",dimensions:E}))}return y},[]);Mo(s,l);const w=o||i&&!o&&Ao(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:w}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Jn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(i(),n),a=jt(s,[])),gn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(s,n),a=jt(i(),[])),gn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ot(u.id,!1))),l=a.map(u=>ot(u.id,!1));gn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ot(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ot(a.id,!1));gn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Lr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=Je.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:st.connectionNodeId,connectionHandleId:st.connectionHandleId,connectionHandleType:st.connectionHandleType,connectionStatus:st.connectionStatus,connectionStartHandle:st.connectionStartHandle,connectionEndHandle:st.connectionEndHandle}),reset:()=>e({...st})}),Object.is),Bo=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Xh()),A.createElement(df,{value:t.current},e)};Bo.displayName="ReactFlowProvider";const Go=({children:e})=>x.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Bo,null,e);Go.displayName="ReactFlowWrapper";const Uh={input:Eo,default:Er,output:So,group:Vr},qh={default:In,straight:zr,step:Pr,smoothstep:Bn,simplebezier:Dr},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Yo=x.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Uh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onNodesDelete:O,onEdgesDelete:D,onSelectionChange:B,onSelectionDragStart:H,onSelectionDrag:g,onSelectionDragStop:C,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,connectionMode:j=vt.Strict,connectionLineType:T=at.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:W,deleteKeyCode:V="Backspace",selectionKeyCode:Z="Shift",selectionOnDrag:J=!1,selectionMode:ee=en.Full,panActivationKeyCode:oe="Space",multiSelectionKeyCode:ne=Mn()?"Meta":"Control",zoomActivationKeyCode:re=Mn()?"Meta":"Control",snapToGrid:pe=!1,snapGrid:ce=Zh,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:ye=!0,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,nodeOrigin:K=Kh,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,defaultViewport:Ae=Qh,minZoom:Xe=.5,maxZoom:Ie=2,translateExtent:F=Sr,preventScrolling:Y=!0,nodeExtent:G,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:te=!0,panOnScroll:se=!1,panOnScrollSpeed:me=.5,panOnScrollMode:$e=gt.Free,zoomOnDoubleClick:X=!0,panOnDrag:fe=!0,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,children:Lt,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:Zr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Wa,defaultEdgeOptions:Xa,elevateNodesOnSelect:Ua=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Qr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Jr,nodeDragThreshold:nc,...rc},sc)=>{const Wn=Jr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:je(["react-flow",s]),"data-testid":"rf__wrapper",id:Jr},A.createElement(Go,null,A.createElement(Wh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:W,selectionKeyCode:Z,selectionOnDrag:J,selectionMode:ee,deleteKeyCode:V,multiSelectionKeyCode:ne,panActivationKeyCode:oe,zoomActivationKeyCode:re,onlyRenderVisibleElements:ue,selectNodesOnDrag:ye,defaultViewport:Ae,translateExtent:F,minZoom:Xe,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:U,zoomOnPinch:te,zoomOnDoubleClick:X,panOnScroll:se,panOnScrollSpeed:me,panOnScrollMode:$e,panOnDrag:fe,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:Zr,elevateEdgesOnSelect:qa,rfId:Wn,disableKeyboardA11y:Qr,nodeOrigin:K,nodeExtent:G}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,elevateNodesOnSelect:Ua,minZoom:Xe,maxZoom:Ie,nodeExtent:G,onNodesChange:Pa,onEdgesChange:za,snapToGrid:pe,snapGrid:ce,connectionMode:j,translateExtent:F,connectOnClick:Ga,defaultEdgeOptions:Xa,fitView:Va,fitViewOptions:Ba,onNodesDelete:O,onEdgesDelete:D,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onSelectionDrag:g,onSelectionDragStart:H,onSelectionDragStop:C,noPanClassName:Zr,nodeOrigin:K,rfId:Wn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:B}),Lt,A.createElement(hf,{proOptions:Wa,position:Ya}),A.createElement(Xf,{rfId:Wn,disableKeyboardA11y:Qr})))});Yo.displayName="ReactFlow";const Wo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:w,backgroundColor:y}=i||{},v=o||w||y;return A.createElement("rect",{className:je(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?p=>m(p,e):void 0})};Wo.displayName="MiniMapNode";var em=x.memo(Wo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=de(nm,ke),c=de(tm),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:w,y}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:w,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=x.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(on(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Xo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:w=!1,zoomable:y=!1,ariaLabel:v="React Flow mini map",inversePan:p=!1,zoomStep:E=10,offsetScale:$=5}){const b=Ee(),M=x.useRef(null),{boundingRect:N,viewBB:_,rfId:R}=de(am,ke),k=(e==null?void 0:e.width)??im,O=(e==null?void 0:e.height)??om,D=N.width/k,B=N.height/O,H=Math.max(D,B),g=H*k,C=H*O,S=$*H,I=N.x-(g-N.width)/2-S,L=N.y-(C-N.height)/2-S,j=g+S*2,T=C+S*2,P=`${cm}-${R}`,z=x.useRef(0);z.current=H,x.useEffect(()=>{if(M.current){const Z=Te(M.current),J=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce}=b.getState();if(ne.sourceEvent.type!=="wheel"||!pe||!ce)return;const ue=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,ye=re[2]*Math.pow(2,ue);ce.scaleTo(pe,ye)},ee=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce,translateExtent:ue,width:ye,height:he}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!pe||!ce)return;const xe=z.current*Math.max(1,re[2])*(p?-1:1),le={x:re[0]-ne.sourceEvent.movementX*xe,y:re[1]-ne.sourceEvent.movementY*xe},K=[[0,0],[ye,he]],Ne=Je.translate(le.x,le.y).scale(re[2]),Ce=ce.constrain()(Ne,K,ue);ce.transform(pe,Ce)},oe=eo().on("zoom",w?ee:null).on("zoom.wheel",y?J:null);return Z.call(oe),()=>{Z.on("zoom",null)}}},[w,y,p,E]);const W=m?Z=>{const J=ze(Z);m(Z,{x:J[0],y:J[1]})}:void 0,V=f?(Z,J)=>{const ee=b.getState().nodeInternals.get(J);f(Z,ee)}:void 0;return A.createElement(Tr,{position:d,style:e,className:je(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:k,height:O,viewBox:`${I} ${L} ${j} ${T}`,role:"img","aria-labelledby":P,ref:M,onClick:W},v&&A.createElement("title",{id:P},v),A.createElement(sm,{onClick:V,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${I-S},${L-S}h${j+S*2}v${T+S*2}h${-j-S*2}z - M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Xo.displayName="MiniMap";var lm=x.memo(Xo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Wt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:je(["react-flow__controls-button",t]),...n},e);Wt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ee(),[f,w]=x.useState(!1),{isInteractive:y,minZoomReached:v,maxZoomReached:p}=de(pm,ke),{zoomIn:E,zoomOut:$,fitView:b}=an();if(x.useEffect(()=>{w(!0)},[]),!f)return null;const M=()=>{E(),i==null||i()},N=()=>{$(),o==null||o()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c==null||c(!y)};return A.createElement(Tr,{className:je(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Wt,{onClick:M,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:p},A.createElement(um,null)),A.createElement(Wt,{onClick:N,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(dm,null))),n&&A.createElement(Wt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Wt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},y?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=x.memo(Uo),Le;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Le||(Le={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[Le.Dots]:"#91919a",[Le.Lines]:"#eee",[Le.Cross]:"#e2e2e2"},bm={[Le.Dots]:1,[Le.Lines]:1,[Le.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function qo({id:e,variant:t=Le.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=x.useRef(null),{transform:u,patternId:d}=de(vm,ke),m=o||wm[t],f=r||bm[t],w=t===Le.Dots,y=t===Le.Cross,v=Array.isArray(n)?n:[n,n],p=[v[0]*u[2]||1,v[1]*u[2]||1],E=f*u[2],$=y?[E,E]:p,b=w?[E/i,E/i]:[$[0]/i,$[1]/i];return A.createElement("svg",{className:je(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%p[0],y:u[1]%p[1],width:p[0],height:p[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},w?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:$,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}qo.displayName="Background";var _m=x.memo(qo);const Gr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Gr+e}async function be(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function nt(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new Ko(r.error??`${e}: ${n.status}`,n.status);return r}class Ko extends Error{constructor(n,r){super(n);ve(this,"status");this.status=r}}const Cx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),$x=()=>be("/api/diagnostics"),Zo=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Qo=()=>be("/api/ontology/ontologies"),Em=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>be("/api/ontology/stack"),Sm=()=>be("/api/ontology/coverage"),km=(e,t,n)=>nt("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>be("/api/git/status"),Cm=()=>be("/api/git/diff"),$m=e=>nt("/api/git/commit",{message:e}),Mm=()=>nt("/api/git/discard",{}),Am=()=>be("/api/decisions"),Bs=(e,t)=>nt(`/api/decisions/${e}/verdict`,{verdict:t}),Mx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Ax=()=>be("/api/glossary/config"),Rx=e=>nt("/api/git/propose",e),Ix=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Tx=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),Ox=e=>nt("/api/git/classify",{changes:e}),Lx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Dx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Px=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>be("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Gr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>nt("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>nt("/api/import/preview",{format:e,content:t}),zx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Hx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Fx=(e,t,n)=>fetch(`${Gr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new Ko(await r.text(),r.status);return await r.json()}),Vx=()=>be("/api/glossary/subject-areas"),Bx=e=>be(`/api/glossary/subject-area/${e}`),Gx=(e,t)=>nt(`/api/glossary/subject-area/${e}/expand`,t);function Yx(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Yr="__entity_source",Wr="__entity_target",Pm=x.memo(function({data:t,selected:n}){var N;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:w}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>y(_.a)-y(R.a)||_.i-R.i).map(_=>_.a),p=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const $=!!c&&!l;let b=0;if($){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const M=(_,R)=>{const k="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:k,onMouseEnter:w?()=>w(_.id):void 0,onMouseLeave:w?()=>w(null):void 0,children:[h.jsx(ct,{id:_.id,type:"target",position:q.Left,className:"port attr-port"}),h.jsx(ct,{id:_.id,type:"source",position:q.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ct,{id:Wr,type:"target",position:q.Left,className:"port"}),h.jsx(ct,{id:Yr,type:"source",position:q.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((N=r.conceptual)==null?void 0:N.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var k;const _=(((k=r.conceptual)==null?void 0:k.ontology_refs)??[]).filter(O=>O.uri);if(_.length===0)return null;const R=_.map(O=>O.uri).join(` -`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),p.length>0&&h.jsx("div",{className:"attr-section keys",children:p.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,w,y,v,p,E,$,b,M,N,_,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(k=>k.from.entity===e.id||k.to.entity===e.id),d=k=>{var O;return((O=t.entities.find(D=>D.id===k))==null?void 0:O.name)??k};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Ke,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,name:k})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Ke,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,physical_name:k})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Ke,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:k=>r("set_definition",{id:e.id,definition:k})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((w=l==null?void 0:l.ontology_refs)==null?void 0:w.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((p=e.term_map)==null?void 0:p.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),($=e.term_map)!=null&&$.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((N=e.term_map)==null?void 0:N.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Ke,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:k,steward:((O=l==null?void 0:l.stewardship)==null?void 0:O.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Ke,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:((O=l==null?void 0:l.stewardship)==null?void 0:O.owner)??null,steward:k})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(k=>h.jsx(Wm,{a:k,entity:e,doc:t,readOnly:c,exec:r},k.id))})}),!c&&h.jsx(Xm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(k=>{const O=k.members.map(D=>{var B;return((B=e.attributes.find(H=>H.id===D))==null?void 0:B.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+k.type,children:k.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:k.name}),h.jsx("span",{className:"key-cols",children:O})]},k.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([k,O])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:k}),h.jsx("td",{className:"udp-val",children:String(O)})]},k))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(k=>{const O=k.from.entity===e.id?k.to.entity:k.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(O),children:[h.jsx("span",{className:"rel-card",children:Um(k,e.id)}),d(O)]}),(k.verb_phrase||k.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Ke,{value:k.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,verb_phrase:D})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Ke,{value:k.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,inverse_verb_phrase:D})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${k.name}`,onClick:()=>r("delete_relationship",{id:k.id}),children:"✕"})]},k.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var k;return(k=navigator.clipboard)==null?void 0:k.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Ke({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=x.useState(e);x.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Wm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Ke,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Ke,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Xm({entity:e,exec:t}){const[n,r]=x.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Um(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Gs="";let Km=class{constructor(t){ve(this,"_isDirected",!0);ve(this,"_isMultigraph",!1);ve(this,"_isCompound",!1);ve(this,"_label");ve(this,"_defaultNodeLabelFn",()=>{});ve(this,"_defaultEdgeLabelFn",()=>{});ve(this,"_nodes",{});ve(this,"_in",{});ve(this,"_preds",{});ve(this,"_out",{});ve(this,"_sucs",{});ve(this,"_edgeObjs",{});ve(this,"_edgeLabels",{});ve(this,"_nodeCount",0);ve(this,"_edgeCount",0);ve(this,"_parent");ve(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Xt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Ys(this._preds[n],t),Ys(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Xt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Xt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Xt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Ws(this._preds[n],t),Ws(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Ys(e,t){e[t]?e[t]++:e[t]=1}function Ws(e,t){--e[t]||delete e[t]}function Xt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Gs+i+Gs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function sr(e,t){return Xt(e,t.v,t.w,t.name)}var Xr=Km,Qm="2.2.4",Jm={Graph:Xr,version:Qm},ep=Xr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){ve(this,"_arr",[]);ve(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=ea,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ta=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ta,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),ia(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),ia(t(i),o=>s.push(o)))}}function ia(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=sa,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=sa,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Xr,Lp=Jo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:ea,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ta,topsort:ra},Us=Jm,Ve={Graph:Us.Graph,json:tp,alg:zp,version:Us.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return qs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&qs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function qs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ve.Graph,Gp=Vp;var Yp=Xp;let Wp=()=>1;function Xp(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Wp);return Up(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Up(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)ir(e,t,n,o);for(;o=s.dequeue();)ir(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(ir(e,t,n,o,!0));break}}}return r}function ir(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,jr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,jr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{jr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function jr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new oa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=da(la(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),aa(e,"border",s,t)}function og(e,t=ca){const n=[];for(let r=0;rca){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function la(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function ua(e){var t=++ug;return e+(""+t)}function da(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Ur(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=_e.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=_e;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=_e;var Yn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ve.Graph,On=Yn.slack,fa=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!On(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=On(t,s)),it.node(r).rank+=n)}var Rg=fa,Ks=Yn.slack,Ig=Yn.longestPath,Tg=Ve.alg.preorder,Og=Ve.alg.postorder,Lg=_e.simplify,Dg=_t;_t.initLowLimValues=Kr;_t.initCutValues=qr;_t.calcCutValue=ha;_t.leaveEdge=pa;_t.enterEdge=ga;_t.exchangeEdges=ya;function _t(e){e=Lg(e),Ig(e);var t=Rg(e);Kr(t),qr(t,e);for(var n,r;n=pa(t);)r=ga(t,e,n),ya(t,e,n,r)}function qr(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ha(e,t,n)}function ha(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Kr(e,t){arguments.length<2&&(t=e.nodes()[0]),ma(e,{},1,t)}function ma(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ma(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function pa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ga(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===Zs(e,e.node(u.v),a)&&c!==Zs(e,e.node(u.w),a));return l.reduce((u,d)=>Ks(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function Zs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Yn,xa=Fg.longestPath,Vg=fa,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Qs(e);break;case"tight-tree":Xg(e);break;case"longest-path":Wg(e);break;case"none":break;default:Qs(e)}}var Wg=xa;function Xg(e){xa(e),Vg(e)}function Qs(e){Bg(e)}var Ug=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Ln=_e;var Qg={run:Jg,cleanup:n0};function Jg(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=e0(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=t0(e)+1;e.children().forEach(a=>wa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function wa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{wa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,w=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,v=f!==w?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:v,nestingEdge:!0}),e.setEdge(w,l,{weight:y,minlen:v,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function e0(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function t0(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function n0(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let r0=_e;var s0=i0;function i0(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iei(e.node(t))),e.edges().forEach(t=>ei(e.edge(t)))}function ei(e){let t=e.width;e.width=e.height,e.height=t}function l0(e){e.nodes().forEach(t=>or(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(or),Object.hasOwn(n,"y")&&or(n)})}function or(e){e.y=-e.y}function u0(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let ti=_e;var d0=f0;function f0(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=ti.applyWithChunking(Math.max,r),i=ti.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let h0=_e.zipObject;var m0=p0;function p0(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var y0=x0;function x0(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let w0=_e;var b0=v0;function v0(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _0(r)}function _0(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&E0(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>w0.pick(s,["vs","i","barycenter","weight"]))}function E0(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let N0=_e;var S0=k0;function k0(e,t){let n=N0.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(j0(!!t)),c=ni(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ni(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ni(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function j0(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let C0=y0,$0=b0,M0=S0;var A0=va;function va(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=C0(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=va(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&I0(m,f)}});let u=$0(l,n);R0(u,c);let d=M0(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function R0(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function I0(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let T0=Ve.Graph,O0=_e;var L0=D0;function D0(e,t,n,r){r||(r=e.nodes());let s=P0(e),i=new T0({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function P0(e){for(var t;e.hasNode(t=O0.uniqueId("_root")););return t}var z0=H0;function H0(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let F0=d0,V0=m0,B0=A0,G0=L0,Y0=z0,W0=Ve.Graph,xn=_e;var X0=_a;function _a(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,_a);return}let n=xn.maxRank(e),r=ri(e,xn.range(1,n+1),"inEdges"),s=ri(e,xn.range(n-1,-1,-1),"outEdges"),i=F0(e);if(si(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){U0(c%2?r:s,c%4>=2),i=xn.buildLayerMatrix(e);let u=V0(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return G0(e,i,n,r.get(i)||[])})}function U0(e,t){let n=new W0;e.forEach(function(r){let s=r.graph().root,i=B0(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Y0(r,n,i.vs)})}function si(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let q0=Ve.Graph,Ze=_e;var K0={positionX:ay};function Z0(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=J0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(w=>{e.predecessors(w).forEach(y=>{let v=e.node(y),p=v.order;(p{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&Ea(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function J0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ea(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function ey(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function ty(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let w=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((w,y)=>Math.min(w,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function ry(e,t,n,r){let s=new q0,i=e.graph(),o=cy(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function sy(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=ly(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-Ze.applyWithChunking(Math.min,l);o!=="l"&&(u=s-Ze.applyWithChunking(Math.max,l)),u&&(e[a]=Ze.mapValues(c,d=>d+u))})})}function oy(e,t){return Ze.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function ay(e){let t=Ze.buildLayerMatrix(e),n=Object.assign(Z0(e,t),Q0(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=ty(e,s,n,c),u=ny(e,s,l.root,l.align,a==="r");a==="r"&&(u=Ze.mapValues(u,d=>-d)),r[o+a]=u})});let i=sy(e,r);return iy(r,i),oy(r,e.graph().align)}function cy(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function ly(e,t){return e.node(t).width}let Na=_e,uy=K0.positionX;var dy=fy;function fy(e){e=Na.asNonCompoundGraph(e),hy(e),Object.entries(uy(e)).forEach(([t,n])=>e.node(t).x=n)}function hy(e){let t=Na.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ii=pg,oi=bg,my=Gg,py=_e.normalizeRanks,gy=Ug,yy=_e.removeEmptyRanks,ai=Qg,xy=s0,ci=o0,wy=X0,by=dy,De=_e,vy=Ve.Graph;var _y=Ey;function Ey(e,t){let n=t&&t.debugTiming?De.time:De.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>Iy(e));n(" runLayout",()=>Ny(r,n,t)),n(" updateInputGraph",()=>Sy(e,r))})}function Ny(e,t,n){t(" makeSpaceForEdgeLabels",()=>Ty(e)),t(" removeSelfEdges",()=>By(e)),t(" acyclic",()=>ii.run(e)),t(" nestingGraph.run",()=>ai.run(e)),t(" rank",()=>my(De.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Oy(e)),t(" removeEmptyRanks",()=>yy(e)),t(" nestingGraph.cleanup",()=>ai.cleanup(e)),t(" normalizeRanks",()=>py(e)),t(" assignRankMinMax",()=>Ly(e)),t(" removeEdgeLabelProxies",()=>Dy(e)),t(" normalize.run",()=>oi.run(e)),t(" parentDummyChains",()=>gy(e)),t(" addBorderSegments",()=>xy(e)),t(" order",()=>wy(e,n)),t(" insertSelfEdges",()=>Gy(e)),t(" adjustCoordinateSystem",()=>ci.adjust(e)),t(" position",()=>by(e)),t(" positionSelfEdges",()=>Yy(e)),t(" removeBorderNodes",()=>Vy(e)),t(" normalize.undo",()=>oi.undo(e)),t(" fixupEdgeLabelCoords",()=>Hy(e)),t(" undoCoordinateSystem",()=>ci.undo(e)),t(" translateGraph",()=>Py(e)),t(" assignNodeIntersects",()=>zy(e)),t(" reversePoints",()=>Fy(e)),t(" acyclic.undo",()=>ii.undo(e))}function Sy(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let ky=["nodesep","edgesep","ranksep","marginx","marginy"],jy={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Cy=["acyclicer","ranker","rankdir","align"],$y=["width","height","rank"],li={width:0,height:0},My=["minlen","weight","width","height","labeloffset"],Ay={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ry=["labelpos"];function Iy(e){let t=new vy({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},jy,cr(n,ky),De.pick(n,Cy))),e.nodes().forEach(r=>{let s=lr(e.node(r));const i=cr(s,$y);Object.keys(li).forEach(o=>{i[o]===void 0&&(i[o]=li[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},Ay,cr(s,My),De.pick(s,Ry)))}),t}function Ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Oy(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};De.addDummyNode(e,"edge-proxy",i,"_ep")}})}function Ly(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Dy(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Py(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function zy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(De.intersectRect(r,i)),n.points.push(De.intersectRect(s,o))})}function Hy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Fy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Vy(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function By(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Gy(e){var t=De.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{De.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Yy(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return De.mapValues(De.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Wy=_e,Xy=Ve.Graph;var Uy={debugOrdering:qy};function qy(e){let t=Wy.buildLayerMatrix(e),n=new Xy({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var Ky="1.1.8",Zy={graphlib:Ve,layout:_y,debug:Uy,util:{time:_e.time,notime:_e.notime},version:Ky};const ui=vi(Zy),Ye=264,Qy=44,Jy=26,ex=14;function wt(e){const t=Math.max(e.attributes.length,1);return Qy+t*Jy+ex}const tx=40;function ur(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?mi(e,n,o):r==="clustered"?hi(e,t,n,o,i):r==="hierarchical"||e.length<=tx?di(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?hi(e,t,n,o,i):mi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Sa(e,t,n,r=!1,s="LR"){const i=new ui.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Ye,height:d?wt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ui.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?wt(m):120,w=d.x-Ye/2,y=d.y-f/2;return a=Math.max(a,w+Ye),c=Math.max(c,y+f),{...u,position:{x:w,y}}}),width:a,height:c}}function di(e,t,n,r="LR"){return Sa(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?wt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Ye+ka);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Ye)}),i+=Math.max(...c.map(l=>n(l.id)))+ja}return{nodes:s,width:o,height:i}}const fi=120;function hi(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),w=new Set(f.map(E=>E.id));let y=0;for(const E of t)w.has(E.source)&&w.has(E.target)&&y++;const p=f.length<=8&&y>=f.length-1?Sa(f,t,n,!0,s):rx(f,n);return{name:m,...p}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const ka=40,ja=40;function mi(e,t,n){const r=l=>{const u=t.get(l);return u?wt(u):120},s=[...e].sort((l,u)=>{var y,v;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,w=((v=t.get(u.id))==null?void 0:v.name)??u.id;return f.localeCompare(w)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Ye+ka)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ja}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function cn({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ca=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var b,M;const[r,s]=x.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[i,o]=x.useState([]),[a,c]=x.useState(null),[l,u]=x.useState(null),[d,m]=x.useState("skos:exactMatch"),[f,w]=x.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,v]=x.useState([]),[p,E]=x.useState("");x.useEffect(()=>{Qo().then(N=>v(N.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const N=setTimeout(()=>{if(!r.trim())return o([]);Zo(r,p||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(N)},[r,p]);const $=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(cn,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(p===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(N=>h.jsx("button",{className:"src-chip"+(p===N.id?" active":""),title:N.count!=null?`${N.count} terms`:"live resolver",onClick:()=>E(N.id),children:N.name},N.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:p?`Search within ${p}…`:"Search vocabulary terms…",value:r,onChange:N=>s(N.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(N=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===N.iri?" picked":""),onClick:()=>u(N),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:N.label}),h.jsxs("span",{className:"term-source",children:[N.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),N.source]})]}),h.jsx("code",{className:"term-iri",children:N.prefixed}),N.definition&&h.jsx("p",{className:"term-def",children:N.definition})]},N.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:N=>m(N.target.value),children:sx.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:N=>w(N.target.value),children:Ca.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:$,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var b,M,N;const[s,i]=x.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[o,a]=x.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},w=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${w}:`,v=(N=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:N.members.map(_=>{var R;return(R=e.attributes.find(k=>k.id===_))==null?void 0:R.name}).filter(Boolean),p=v&&v.length?`${y}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,$=s.trim()||p;return h.jsxs(cn,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",$]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=x.useState(""),[o,a]=x.useState(""),[c,l]=x.useState(""),[u,d]=x.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const w=f==null?void 0:f.created_id;n(),w&&r(w)})};return h.jsxs(cn,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ca.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const $a=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=x.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=x.useState(r??""),[m,f]=x.useState(s??(l==null?void 0:l.id)??""),[w,y]=x.useState("many_to_one"),[v,p]=x.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",$=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:w,optionality:v}).then(o);return h.jsxs(cn,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:w,onChange:b=>y(b.target.value),children:$a.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>p(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:$,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=p=>{var E;return((E=t.entities.find($=>$.id===p))==null?void 0:E.name)??"?"},[i,o]=x.useState(e.name),[a,c]=x.useState(e.cardinality),[l,u]=x.useState(e.optionality),[d,m]=x.useState(e.identifying),[f,w]=x.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(cn,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:p=>o(p.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:p=>c(p.target.value),children:$a.map(p=>h.jsx("option",{children:p},p))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:p=>u(p.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:p=>m(p.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>w(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const pi=10,ux=6,Be=24;function dx(e,t){return t?e:Math.round(e/pi)*pi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-Be,o.right+Be);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eV.transform[2]),[m,f]=x.useState(null),w=x.useRef(!1),y=x.useRef(0),v=c==null?void 0:c.onRouteChange,p=!!v,E=m??(c==null?void 0:c.routeX),[$,b,M]=Rn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),N=c==null?void 0:c.relationship,_=(c==null?void 0:c.dimmed)??!1,R=(N==null?void 0:N.cardinality)??"many_to_one",k=(N==null?void 0:N.optionality)==="optional",O=(N==null?void 0:N.identifying)??!1,D=R==="many_to_one"||R==="many_to_many",B=R==="one_to_many"||R==="many_to_many",H="rel-edge"+(l?" selected":"")+(_?" dimmed":""),g=((c==null?void 0:c.memberCount)??0)>1,C=c==null?void 0:c.onHoverEdge,S=E??(n+s)/2,I=(r+i)/2,L=E??b,j=E!=null?I:M,T=x.useCallback(V=>v&&N&&v(N.id,V),[v,N]),P=x.useCallback(V=>{var pe,ce;if(!p||V.button!==0)return;V.stopPropagation(),(ce=(pe=V.target).setPointerCapture)==null||ce.call(pe,V.pointerId),w.current=!0,y.current=0;const J=u({x:V.clientX,y:V.clientY}).x;let ee=0,oe=E??S;const ne=ue=>{const ye=u({x:ue.clientX,y:ue.clientY});y.current=Math.max(y.current,Math.abs(ye.x-J)),oe=mx(ye.x,{shift:ue.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),ee||(ee=requestAnimationFrame(()=>{ee=0,f(oe)}))},re=()=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",re),ee&&cancelAnimationFrame(ee),w.current=!1,f(null),y.current>=gi&&T(oe)};window.addEventListener("pointermove",ne),window.addEventListener("pointerup",re)},[p,u,E,S,c,n,s,T]),z=x.useCallback(V=>{y.current>=gi&&(V.stopPropagation(),y.current=0)},[]),W=x.useCallback(V=>{p&&(V.stopPropagation(),T(null))},[p,T]);return h.jsxs("g",{className:H,children:[h.jsx("path",{id:t,className:"rel-path",d:$,fill:"none",strokeDasharray:O?void 0:"6 4"}),h.jsx("path",{d:$,fill:"none",strokeWidth:16/d,stroke:"transparent",onMouseEnter:C?()=>C(N.id):void 0,onMouseLeave:C?()=>C(null):void 0}),h.jsx(yi,{x:n,y:r,side:o,many:D,optional:k}),h.jsx(yi,{x:s,y:i,side:a,many:B,optional:!1}),p&&(l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:P,onClickCapture:z,onDoubleClick:W,children:[h.jsx("rect",{x:S-11/d,y:I-16/d,width:22/d,height:32/d,fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:S-4.5/d,y:I-9/d,width:9/d,height:18/d,rx:4/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I-3/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I+3/d,r:1.1/d})]}),(l||g)&&N&&h.jsxs("text",{className:"rel-label",x:L,y:j-8,children:[l?N.verb_phrase||N.name:"",g?`${l?" ":""}(${c.memberCount})`:""]})]})});function yi({x:e,y:t,side:n,many:r,optional:s}){const i=n===q.Left?-1:1,o=7,a=12,c=[];return r?c.push(h.jsx("path",{className:"rel-glyph",d:`M ${e+i*a} ${t} L ${e} ${t-o} M ${e+i*a} ${t} L ${e} ${t} M ${e+i*a} ${t} L ${e} ${t+o}`,fill:"none"},"foot")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a-3),y1:t-o,x2:e+i*(a-3),y2:t+o},"one")),s?c.push(h.jsx("circle",{className:"rel-glyph ring",cx:e+i*(a+6),cy:t,r:4},"opt")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a+5),y1:t-o,x2:e+i*(a+5),y2:t+o},"mand")),h.jsx(h.Fragment,{children:c})}const gx={entity:Pm},yx={relationship:px},xi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],wi="#8a7d6a";function xx(e,t,n){const s=Ye;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function wx(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Yr,targetHandle:n(e.to.entity,s)?s:Wr}}function qx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:w,fitBounds:y,getNodes:v}=an(),[p,E]=x.useState([]),[$,b]=x.useState([]),M=x.useRef(!1),N=x.useMemo(()=>{const F=u&&u.size>0?[...u].sort():null;return F?"sa:"+F.join("+"):"__all__"},[u]),_=x.useRef(null),[R,k]=x.useState(0),O=x.useRef(new Map),D=x.useRef(null);x.useEffect(()=>{if(!f){_.current=null;return}const F=O.current.get(N);if(F){_.current=F,M.current=!1,k(G=>G+1);return}let Y=!1;return f.load(N).then(G=>{Y||(O.current.set(N,G),_.current=G,M.current=!1,k(Q=>Q+1))}),()=>{Y=!0}},[f,N]);const[B,H]=x.useState(null),[g,C]=x.useState(null),[S,I]=x.useState(!1),[L,j]=x.useState(null),[T,P]=x.useState(null),[z,W]=x.useState(null),[V,Z]=x.useState(null),J=x.useRef({}),ee=!t.canEdit,oe=x.useRef(null),ne=x.useCallback(()=>{f&&(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{const F={};for(const Q of v())Q.hidden||(F[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,U]of Object.entries(J.current))Y[Q]={routeX:Math.round(U)};const G={nodes:F,edges:Y};O.current.set(N,G),_.current=G,f.save(N,G)},800))},[f,v,N]),re=x.useCallback((F,Y)=>{Y==null?delete J.current[F]:J.current[F]=Y,b(G=>G.map(Q=>Q.id===F?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),ne()},[ne]),pe=x.useMemo(()=>{const F=new Map;return e.subject_areas.forEach((Y,G)=>F.set(Y.id,xi[G%xi.length])),F},[e]),ce=x.useMemo(()=>{const F=new Map;return e.entities.forEach(Y=>F.set(Y.id,Y)),F},[e]),ue=x.useMemo(()=>{const F=new Map,Y=new Map;return e.subject_areas.forEach(G=>{(G.members??[]).forEach(Q=>Y.set(Q,{id:G.id,name:G.name}))}),e.entities.forEach(G=>{var se,me;const Q=(se=G.conceptual)!=null&&se.id?Y.get(G.conceptual.id):void 0,U=(me=G.conceptual)==null?void 0:me.subject_area,te=Q??(U?{id:U.id,name:U.name??U.id}:void 0);te&&F.set(G.id,te)}),F},[e]),ye=x.useCallback(F=>{var G;if(!u||u.size===0)return!1;const Y=(G=ue.get(F))==null?void 0:G.id;return!(Y&&u.has(Y))},[u,ue]),he=x.useMemo(()=>{const F=new Map,Y=(G,Q)=>{if(!Q.length)return;const U=F.get(G)??new Set;Q.forEach(te=>U.add(te)),F.set(G,U)};for(const G of e.relationships)Y(G.from.entity,G.from.attributes),Y(G.to.entity,G.to.attributes);return F},[e]);x.useEffect(()=>{var $e;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const X of e.entities)(X.name.toLowerCase()+" "+((($e=X.conceptual)==null?void 0:$e.name.toLowerCase())??"")+" "+X.attributes.map(ge=>ge.name.toLowerCase()).join(" ")).includes(F)&&Y.add(X.id);const G=new Set;if(r){G.add(r);for(const X of e.relationships)X.from.entity===r&&G.add(X.to.entity),X.to.entity===r&&G.add(X.from.entity)}const Q=e.entities.map(X=>{const fe=F!==""&&!Y.has(X.id),ge=r!==null&&!G.has(X.id);return{id:X.id,type:"entity",position:{x:0,y:0},hidden:ye(X.id),data:{entity:X,color:(()=>{const Se=ue.get(X.id);return Se?pe.get(Se.id)??wi:wi})(),dimmed:fe||ge,highlighted:F!==""&&Y.has(X.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(X.id))??!1,onToggleExpand:l,endpointAttrs:he.get(X.id),highlightAttrs:void 0,onHoverAttr:W}}}),U=e.relationships.filter(X=>ce.has(X.from.entity)&&ce.has(X.to.entity)).map(X=>{const{sourceHandle:fe,targetHandle:ge}=wx(X,ce),Se=r!==null&&X.from.entity!==r&&X.to.entity!==r;return{id:X.id,source:X.from.entity,target:X.to.entity,sourceHandle:fe,targetHandle:ge,type:"relationship",data:{relationship:X,dimmed:Se,memberCount:Math.max(X.from.attributes.length,X.to.attributes.length),onHoverEdge:Z}}}),te=_.current;if(J.current={},te)for(const[X,fe]of Object.entries(te.edges))J.current[X]=fe.routeX;let se=Q;E(X=>{const fe=new Map(X.map(ae=>[ae.id,ae.position])),ge=Q.every(ae=>fe.has(ae.id)),Se=((u==null?void 0:u.size)??0)>0;if(M.current&&ge&&X.length>=Q.length&&!Se){const ae=Q.map(Ue=>({...Ue,position:fe.get(Ue.id)??Ue.position}));return se=ae,ae}const dt=Se?Q.filter(ae=>!ae.hidden):Q,Ot=ur(dt,U,ce,"auto",ue),rt=new Map(Ot.map(ae=>[ae.id,ae.position])),ft=(te==null?void 0:te.nodes)??{},Lt=Object.keys(ft).length>0,Pe=[],Dt=Q.map(ae=>{const Ue=ft[ae.id];if(Ue){const Pt={x:Ue.x,y:Ue.y};return Pe.push({x:Pt.x,y:Pt.y,w:Ye,h:wt(ae.data.entity)}),{...ae,position:Pt}}return rt.has(ae.id)?{...ae,position:rt.get(ae.id)}:fe.has(ae.id)&&M.current?{...ae,position:fe.get(ae.id)}:ae});if(Lt)for(const ae of Dt)ft[ae.id]||ae.hidden||(ae.position=xx(ae.position,wt(ae.data.entity),Pe),Pe.push({x:ae.position.x,y:ae.position.y,w:Ye,h:wt(ae.data.entity)}));return M.current=!0,Lt||requestAnimationFrame(()=>w({padding:.15,duration:300})),se=Dt,Dt});const me=new Map;for(const X of se)me.set(X.id,{left:X.position.x,right:X.position.x+Ye});b(U.map(X=>({...X,data:{...X.data,routeX:J.current[X.id],onRouteChange:f?re:void 0,sourceCard:me.get(X.source),targetCard:me.get(X.target)}})))},[e,i,r,o,a,c,l,pe,ce,ue,ye,u,he,w,f,re,R]);const xe=x.useMemo(()=>{const F=new Set,Y=new Set,G=new Map,Q=(U,te)=>{if(!te.length)return;const se=G.get(U)??new Set;te.forEach(me=>se.add(me)),G.set(U,se)};if(z)for(const U of e.relationships)(U.from.attributes.includes(z)||U.to.attributes.includes(z))&&(F.add(U.id),Y.add(U.from.entity),Y.add(U.to.entity),Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes));if(V){const U=e.relationships.find(te=>te.id===V);U&&(Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes))}return{active:z!==null,relsForAttr:F,entsForAttr:Y,hitAttrsByEntity:G}},[e,z,V]);x.useEffect(()=>{var Q;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);const G=new Set;if(r){G.add(r);for(const U of e.relationships)U.from.entity===r&&G.add(U.to.entity),U.to.entity===r&&G.add(U.from.entity)}E(U=>U.map(te=>{const se=F!==""&&!Y.has(te.id),me=r!==null&&!G.has(te.id),$e=xe.active&&!xe.entsForAttr.has(te.id),X=se||me||$e,fe=F!==""&&Y.has(te.id)||xe.active&&xe.entsForAttr.has(te.id),ge=xe.hitAttrsByEntity.get(te.id);return te.data.dimmed===X&&te.data.highlighted===fe&&te.data.highlightAttrs===ge?te:{...te,data:{...te.data,dimmed:X,highlighted:fe,highlightAttrs:ge}}})),b(U=>U.map(te=>{var fe,ge;const se=(fe=te.data)==null?void 0:fe.relationship,me=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,$e=xe.active&&!xe.relsForAttr.has(te.id),X=me||$e;return((ge=te.data)==null?void 0:ge.dimmed)===X?te:{...te,data:{...te.data,dimmed:X}}}))},[xe,i,r,e]),x.useEffect(()=>{var Q;const F=i.trim().toLowerCase();if(!F)return;const Y=new Set;for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);if(!Y.size)return;const G=requestAnimationFrame(()=>{const U=v().filter(se=>Y.has(se.id));if(!U.length)return;const te=Mf(U);y(te,{padding:.35,duration:400})});return()=>cancelAnimationFrame(G)},[i,e,v,y]);const le=x.useCallback((F="auto",Y="LR")=>{D.current=Object.fromEntries(v().map(G=>[G.id,{x:G.position.x,y:G.position.y}])),E(G=>ur(G,$,ce,F,ue,Y)),requestAnimationFrame(()=>w({padding:.15,duration:300})),ne()},[$,ce,ue,w,v,ne]),K=x.useCallback(()=>{const F=D.current;F&&(E(Y=>Y.map(G=>F[G.id]?{...G,position:F[G.id]}:G)),D.current=null,ne())},[ne]),Ne=x.useCallback(()=>{f==null||f.reset(N),O.current.delete(N),_.current=null,J.current={},M.current=!1,b(F=>F.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(F=>{const Y=ur(F,$,ce,"auto",ue);return requestAnimationFrame(()=>w({padding:.15,duration:300})),Y})},[f,N,$,ce,ue,w]),Ce=x.useCallback(F=>{s(F),E(Y=>(Y.find(Q=>Q.id===F)&&requestAnimationFrame(()=>w({nodes:[{id:F}],padding:.4,duration:400})),Y))},[w,s]);x.useImperativeHandle(m,()=>({relayout:le,fitView:()=>w({padding:.15,duration:300}),focusEntity:Ce,newEntity:()=>I(!0),resetLayout:Ne,undoRelayout:K}),[le,w,Ce,Ne,K]);const ut=x.useCallback(F=>{if(ee||!F.source||!F.target||F.source===F.target)return;const Y=F.sourceHandle&&F.sourceHandle!==Yr?F.sourceHandle:void 0,G=F.targetHandle&&F.targetHandle!==Wr?F.targetHandle:void 0;j({from:F.source,to:F.target,fromAttr:Y,toAttr:G})},[ee]),Ae=x.useCallback(async(F,Y)=>{try{return await n(F,Y)}catch(G){throw d==null||d(G instanceof Error?G.message:String(G)),G}},[n,d]),Xe=r?ce.get(r)??null:null,Ie=e.relationships.find(F=>F.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Yo,{nodes:p,edges:$,nodeTypes:gx,edgeTypes:yx,onNodeClick:(F,Y)=>s(Y.id),onEdgeClick:(F,Y)=>!ee&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(F,Y)=>{E(G=>G.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),ne()},onConnect:ut,nodesConnectable:!ee,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:Le.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:F=>{var Y;return((Y=F.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),Xe&&h.jsx(Hm,{entity:Xe,doc:e,caps:t,exec:Ae,onClose:()=>s(null),onFocusEntity:Ce,onAlign:H,onEditMapping:C}),B&&h.jsx(ix,{entity:B,exec:Ae,onClose:()=>H(null)}),g&&h.jsx(ox,{entity:g,doc:e,exec:Ae,onClose:()=>C(null)}),S&&h.jsx(ax,{doc:e,exec:Ae,onClose:()=>I(!1),onCreated:Ce}),L&&h.jsx(cx,{doc:e,fromId:L.from,toId:L.to,initialFromAttr:L.fromAttr,initialToAttr:L.toAttr,exec:Ae,onClose:()=>j(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:Ae,onClose:()=>P(null)})]})}function Kx({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(bx,{}),e==="layers"&&h.jsx(_x,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(Ex,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Nx,{readOnly:n})]})}function bx(){const[e,t]=x.useState(""),[n,r]=x.useState([]),[s,i]=x.useState({loaded:0,vocabs:[]}),[o,a]=x.useState(null),[c,l]=x.useState([]),[u,d]=x.useState("");x.useEffect(()=>{Qo().then(f=>l(f.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const f=setTimeout(()=>{Zo(e||"a",u||void 0).then(w=>{r(e?w.results:[]),i({loaded:w.loaded_terms,vocabs:w.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=x.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const vx=["industry","core","domain","specialised"];function _x({refreshKey:e,onFocusEntity:t}){const[n,r]=x.useState(null),[s,i]=x.useState(null);if(x.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),vx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Ex({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=x.useState(null),[i,o]=x.useState(""),[a,c]=x.useState(""),[l,u]=x.useState(!1),d=x.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` + */var Dn=x,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=Dn.useRef,_c=Dn.useEffect,Ec=Dn.useMemo,Nc=Dn.useDebugValue;Ei.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var w=o.value;if(s(w,f))return d=w}return d=f}if(w=d,wc(u,f))return w;var y=r(f);return s!==void 0&&s(w,y)?(u=f,w):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};_i.exports=Ei;var Sc=_i.exports;const kc=vi(Sc),jc={},es=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(w=>w(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?es(e):es,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function ki(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const ts=(e,t)=>{const n=Cc(e),r=(s,i=t)=>ki(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?ts(e,t):ts;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rs.hasOwnProperty(t)?{space:rs[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===dr&&t.documentElement.namespaceURI===dr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ji(e){var t=zn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function Cr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=Cr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=$&&($=E+1);!(M=v[$])&&++$=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Rt(this.node(),e)}function Rt(e,t){return e.style.getPropertyValue(t)||Ri(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ii(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Ti(e)}function Ti(e){this._node=e,this._names=Ii(e.getAttribute("class")||"")}Ti.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Oi(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function fr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}fr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Pn("start","drag","end"),o=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",p,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,M){if(!(u||!e.call(this,b,M))){var N=$(this,t.call(this,b,M),b,M,"mouse");N&&(Te(b.view).on("mousemove.drag",w,Ut).on("mouseup.drag",y,Ut),zi(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,N("start",b))}}function w(b){if(Ct(b),!l){var M=b.clientX-a,N=b.clientY-c;l=M*M+N*N>d}s.mouse("drag",b)}function y(b){Te(b.view).on("mousemove.drag mouseup.drag",null),Hi(b.view,l),Ct(b),s.mouse("end",b)}function v(b,M){if(e.call(this,b,M)){var N=b.changedTouches,_=t.call(this,b,M),R=N.length,k,O;for(k=0;k>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?un(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?un(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Me(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Me(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?un(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?un(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?us(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?us(t[1],t[2]/100,t[3]/100,t[4]):ss.hasOwnProperty(e)?as(ss[e]):e==="transparent"?new Me(NaN,NaN,NaN,0):null}function as(e){return new Me(e>>16&255,e>>8&255,e&255,1)}function un(e,t,n,r){return r<=0&&(e=t=n=NaN),new Me(e,t,n,r)}function Mu(e){return e instanceof rn||(e=Zt(e)),e?(e=e.rgb(),new Me(e.r,e.g,e.b,e.opacity)):new Me}function hr(e,t,n,r){return arguments.length===1?Mu(e):new Me(e,t,n,r??1)}function Me(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Mr(Me,hr,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Me(yt(this.r),yt(this.g),yt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:cs,formatHex:cs,formatHex8:Au,formatRgb:ls,toString:ls}));function cs(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function ls(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function us(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new He(e,t,n,r)}function Vi(e){if(e instanceof He)return new He(e.h,e.s,e.l,e.opacity);if(e instanceof rn||(e=Zt(e)),!e)return new He;if(e instanceof He)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new He(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Vi(e):new He(e,t,n,r??1)}function He(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Mr(He,Ru,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new He(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new He(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Me(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new He(ds(this.h),dn(this.s),dn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${ds(this.h)}, ${dn(this.s)*100}%, ${dn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ds(e){return e=(e||0)%360,e<0?e+360:e}function dn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Bi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Gi:function(t,n){return n-t?Tu(t,n,e):Bi(isNaN(t)?n:t)}}function Gi(e,t){var n=t-e;return n?Iu(e,n):Bi(isNaN(e)?t:e)}const fs=function e(t){var n=Ou(t);function r(s,i){var o=n((s=hr(s)).r,(i=hr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Gi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function it(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var mr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(mr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=mr.lastIndex=Kn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=mr.exec(e))&&(s=Kn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:it(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:it(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:it(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,w){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");w.push({i:y-4,x:it(l,d)},{i:y-2,x:it(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var w=-1,y=m.length,v;++w=0&&e._call.call(void 0,t),e=e._next;--It}function ps(){bt=(Cn=Qt.now())+Hn,It=Gt=0;try{Uu()}finally{It=0,Ku(),bt=0}}function qu(){var e=Qt.now(),t=e-Cn;t>Wi&&(Hn-=t,Cn=e)}function Ku(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Yt=e,gr(r)}function gr(e){if(!It){Gt&&(Gt=clearTimeout(Gt));var t=e-bt;t>24?(e<1/0&&(Gt=setTimeout(ps,e-Qt.now()-Hn)),zt&&(zt=clearInterval(zt))):(zt||(Cn=Qt.now(),zt=setInterval(qu,Wi)),It=1,Ui(ps))}}function gs(e,t,n){var r=new $n;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Pn("start","end","cancel","interrupt"),Qu=[],Ki=0,ys=1,yr=2,vn=3,xs=4,xr=5,_n=6;function Fn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Ki})}function Rr(e,t){var n=Fe(e,t);if(n.state>Ki)throw new Error("too late; already scheduled");return n}function Xe(e,t){var n=Fe(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Fe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=qi(i,0,n.time);function i(l){n.state=ys,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ys)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return gs(o);f.state===xs?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uyr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Rr:Xe;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Fe(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Cr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Qe(e,t,n){this.k=e,this.x=t,this.y=n}Qe.prototype={constructor:Qe,scale:function(e){return e===1?this:new Qe(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Qe(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Je=new Qe(1,0,0);Qe.prototype;function Zn(e){e.stopImmediatePropagation()}function Ht(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ws(){return this.__zoom||Je}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function eo(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Xu,l=Pn("start","zoom","end"),u,d,m,f=500,w=150,y=0,v=10;function p(g){g.property("__zoom",ws).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",D).on("touchmove.zoom",B).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}p.transform=function(g,C,S,I){var L=g.selection?g.selection():g;L.property("__zoom",ws),g!==L?M(g,C,S,I):L.interrupt().each(function(){N(this,arguments).event(I).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},p.scaleBy=function(g,C,S,I){p.scaleTo(g,function(){var L=this.__zoom.k,j=typeof C=="function"?C.apply(this,arguments):C;return L*j},S,I)},p.scaleTo=function(g,C,S,I){p.transform(g,function(){var L=t.apply(this,arguments),j=this.__zoom,T=S==null?b(L):typeof S=="function"?S.apply(this,arguments):S,P=j.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n($(E(j,z),T,P),L,o)},S,I)},p.translateBy=function(g,C,S,I){p.transform(g,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,I)},p.translateTo=function(g,C,S,I,L){p.transform(g,function(){var j=t.apply(this,arguments),T=this.__zoom,P=I==null?b(j):typeof I=="function"?I.apply(this,arguments):I;return n(Je.translate(P[0],P[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof S=="function"?-S.apply(this,arguments):-S),j,o)},I,L)};function E(g,C){return C=Math.max(i[0],Math.min(i[1],C)),C===g.k?g:new Qe(C,g.x,g.y)}function $(g,C,S){var I=C[0]-S[0]*g.k,L=C[1]-S[1]*g.k;return I===g.x&&L===g.y?g:new Qe(g.k,I,L)}function b(g){return[(+g[0][0]+ +g[1][0])/2,(+g[0][1]+ +g[1][1])/2]}function M(g,C,S,I){g.on("start.zoom",function(){N(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(I).end()}).tween("zoom",function(){var L=this,j=arguments,T=N(L,j).event(I),P=t.apply(L,j),z=S==null?b(P):typeof S=="function"?S.apply(L,j):S,X=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),V=L.__zoom,Z=typeof C=="function"?C.apply(L,j):C,J=c(V.invert(z).concat(X/V.k),Z.invert(z).concat(X/Z.k));return function(ee){if(ee===1)ee=Z;else{var oe=J(ee),ne=X/oe[2];ee=new Qe(ne,z[0]-oe[0]*ne,z[1]-oe[1]*ne)}T.zoom(null,ee)}})}function N(g,C,S){return!S&&g.__zooming||new _(g,C)}function _(g,C){this.that=g,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(g,C),this.taps=0}_.prototype={event:function(g){return g&&(this.sourceEvent=g),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(g,C){return this.mouse&&g!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&g!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&g!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(g){var C=Te(this.that).datum();l.call(g,this.that,new sf(g,{sourceEvent:this.sourceEvent,target:p,transform:this.that.__zoom,dispatch:l}),C)}};function R(g,...C){if(!e.apply(this,arguments))return;var S=N(this,C).event(g),I=this.__zoom,L=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,r.apply(this,arguments)))),j=ze(g);if(S.wheel)(S.mouse[0][0]!==j[0]||S.mouse[0][1]!==j[1])&&(S.mouse[1]=I.invert(S.mouse[0]=j)),clearTimeout(S.wheel);else{if(I.k===L)return;S.mouse=[j,I.invert(j)],En(this),S.start()}Ht(g),S.wheel=setTimeout(T,w),S.zoom("mouse",n($(E(I,L),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function k(g,...C){if(m||!e.apply(this,arguments))return;var S=g.currentTarget,I=N(this,C,!0).event(g),L=Te(g.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",X,!0),j=ze(g,S),T=g.clientX,P=g.clientY;zi(g.view),Zn(g),I.mouse=[j,this.__zoom.invert(j)],En(this),I.start();function z(V){if(Ht(V),!I.moved){var Z=V.clientX-T,J=V.clientY-P;I.moved=Z*Z+J*J>y}I.event(V).zoom("mouse",n($(I.that.__zoom,I.mouse[0]=ze(V,S),I.mouse[1]),I.extent,o))}function X(V){L.on("mousemove.zoom mouseup.zoom",null),Hi(V.view,I.moved),Ht(V),I.event(V).end()}}function O(g,...C){if(e.apply(this,arguments)){var S=this.__zoom,I=ze(g.changedTouches?g.changedTouches[0]:g,this),L=S.invert(I),j=S.k*(g.shiftKey?.5:2),T=n($(E(S,j),I,L),t.apply(this,C),o);Ht(g),a>0?Te(this).transition().duration(a).call(M,T,I,g):Te(this).call(p.transform,T,I,g)}}function D(g,...C){if(e.apply(this,arguments)){var S=g.touches,I=S.length,L=N(this,C,g.changedTouches.length===I).event(g),j,T,P,z;for(Zn(g),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},to=tt.error001();function de(e,t){const n=x.useContext(Vn);if(n===null)throw new Error(to);return ki(n,e,t)}const Ee=()=>{const e=x.useContext(Vn);if(e===null)throw new Error(to);return x.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Tr({position:e,children:t,className:n,style:r,...s}){const i=de(ff),o=`${e}`.split("-");return A.createElement("div",{className:je(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Tr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=x.useRef(null),[m,f]=x.useState({x:0,y:0,width:0,height:0}),w=je(["react-flow__edge-textwrapper",l]);return x.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:w,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=x.memo(mf);const Or=e=>({width:e.offsetWidth,height:e.offsetHeight}),Tt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Lr=(e={x:0,y:0},t)=>({x:Tt(e.x,t[0][0],t[1][0]),y:Tt(e.y,t[0][1],t[1][1])}),bs=(e,t,n)=>en?-Tt(Math.abs(e-n),1,50)/50:0,no=(e,t)=>{const n=bs(e.x,35,t.width-35)*20,r=bs(e.y,35,t.height-35)*20;return[n,r]},ro=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},so=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Jt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),io=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),vs=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>io(so(Jt(e),Jt(t))),wr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Oe(e.width)&&Oe(e.height)&&Oe(e.x)&&Oe(e.y),Oe=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),oo=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function br(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const ao=e=>"clientX"in e,lt=(e,t)=>{var i,o;const n=ao(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Mn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},sn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Oe(n)&&Oe(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);sn.displayName="BaseEdge";function Ft(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function co({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[v,p,E]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(sn,{path:v,labelX:p,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:y})});Dr.displayName="SimpleBezierEdge";const Es={[q.Left]:{x:-1,y:0},[q.Right]:{x:1,y:0},[q.Top]:{x:0,y:-1},[q.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=q.Bottom,target:n})=>t===q.Left||t===q.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=q.Bottom,target:n,targetPosition:r=q.Top,center:s,offset:i}){const o=Es[t],a=Es[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],w,y;const v={x:0,y:0},p={x:0,y:0},[E,$,b,M]=co({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){w=s.x??E,y=s.y??$;const _=[{x:w,y:c.y},{x:w,y:l.y}],R=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?R:_:f=o.y===m?_:R,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const g=Math.min(i-1,i-H);o[d]===m?v[d]=(c[d]>e[d]?-1:1)*g:p[d]=(l[d]>n[d]?-1:1)*g}}if(t!==r){const H=d==="x"?"y":"x",g=o[d]===a[H],C=c[H]>l[H],S=c[H]=B?(w=(k.x+O.x)/2,y=f[0].y):(w=f[0].x,y=(k.y+O.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:l.x+p.x,y:l.y+p.y},n],w,y,b,M]}function _f(e,t,n,r){const s=Math.min(Ns(e,t)/2,Ns(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let $="";return E>0&&E{const[p,E,$]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:w,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const Pr=x.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:x.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Pr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=co({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const zr=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[w,y,v]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(sn,{path:w,labelX:y,labelY:v,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});zr.displayName="StraightEdge";function mn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Ss({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case q.Left:return[t-mn(t-r,i),n];case q.Right:return[t+mn(r-t,i),n];case q.Top:return[t,n-mn(n-s,i)];case q.Bottom:return[t,n+mn(s-n,i)]}}function fo({sourceX:e,sourceY:t,sourcePosition:n=q.Bottom,targetX:r,targetY:s,targetPosition:i=q.Top,curvature:o=.25}){const[a,c]=Ss({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Ss({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,w]=lo({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,w]}const In=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=q.Bottom,targetPosition:i=q.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,pathOptions:y,interactionWidth:v})=>{const[p,E,$]=fo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:v})});In.displayName="BezierEdge";const Hr=x.createContext(null),Nf=Hr.Provider;Hr.Consumer;const Sf=()=>x.useContext(Hr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,vr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},_r=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},ho=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},on=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return so(r,Jt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return io(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),on(e,t)),mo=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:w=!1}=u;if(o&&!f||w)return!1;const{positionAbsolute:y}=xt(u,a),v={x:y.x,y:y.y,width:d||0,height:m||0},p=wr(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,$=i&&p>0,b=(d||0)*(m||0);(E||$||p>=b||u.dragging)&&l.push(u)}),l},po=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},go=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Tt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function ks(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=lt(e),l=t.elementsFromPoint(o,a).find(w=>w.classList.contains("react-flow__handle"));if(l){const w=l.getAttribute("data-nodeid");if(w){const y=Fr(void 0,l),v=l.getAttribute("data-handleid"),p=i({nodeId:w,id:v,type:y});if(p){const E=s.find($=>$.nodeId===w&&$.type===y&&$.id===v);return{handle:{id:v,type:y,nodeId:w,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:p}}}}let u=[],d=1/0;if(s.forEach(w=>{const y=Math.sqrt((w.x-n.x)**2+(w.y-n.y)**2);if(y<=r){const v=i(w);y<=d&&(yw.isValid),f=u.some(({handle:w})=>w.type==="target");return u.find(({handle:w,validHandleResult:y})=>f?w.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},yo=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function xo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...yo(),handleDomNode:c};if(c){const u=Fr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),w=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&w&&(t===vt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=ks(i,o,"source",`${t}-${n}-${r}`),c=ks(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Fr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function wo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ro(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:w,onConnectStart:y,panBy:v,getNodes:p,cancelConnection:E}=i();let $=0,b;const{x:M,y:N}=lt(e),_=u==null?void 0:u.elementFromPoint(M,N),R=Fr(c,_),k=m==null?void 0:m.getBoundingClientRect();if(!k||!R)return;let O,D=lt(e,k),B=!1,H=null,g=!1,C=null;const S=If({nodes:p(),nodeId:n,handleId:t,handleType:R}),I=()=>{if(!f)return;const[T,P]=no(D,k);v({x:T,y:P}),$=requestAnimationFrame(I)};o({connectionPosition:D,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:R});function L(T){const{transform:P}=i();D=lt(T,k);const{handle:z,validHandleResult:X}=Af(T,u,_r(D,P,!1,[1,1]),w,S,V=>xo(V,d,n,t,s?"target":"source",a,u));if(b=z,B||(I(),B=!0),C=X.handleDomNode,H=X.connection,g=X.isValid,o({connectionPosition:b&&g?ho({x:b.x,y:b.y},P):D,connectionStatus:Tf(!!b,g),connectionEndHandle:X.endHandle}),!b&&!g&&!C)return Qn(O);H.source!==H.target&&C&&(Qn(O),O=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",g),C.classList.toggle("react-flow__handle-valid",g))}function j(T){var P,z;(b||C)&&H&&g&&(r==null||r(H)),(z=(P=i()).onConnectEnd)==null||z.call(P,T),c&&(l==null||l(T)),Qn(O),E(),cancelAnimationFrame($),B=!1,g=!1,H=null,C=null,u.removeEventListener("mousemove",L),u.removeEventListener("mouseup",j),u.removeEventListener("touchmove",L),u.removeEventListener("touchend",j)}u.addEventListener("mousemove",L),u.addEventListener("mouseup",j),u.addEventListener("touchmove",L),u.addEventListener("touchend",j)}const js=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},bo=x.forwardRef(({type:e="source",position:t=q.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var k,O;const w=o||null,y=e==="target",v=Ee(),p=Sf(),{connectOnClick:E,noPanClassName:$}=de(Of,ke),{connecting:b,clickConnecting:M}=de(Lf(p,w,e),ke);p||(O=(k=v.getState()).onError)==null||O.call(k,"010",tt.error010());const N=D=>{const{defaultEdgeOptions:B,onConnect:H,hasDefaultEdges:g}=v.getState(),C={...B,...D};if(g){const{edges:S,setEdges:I}=v.getState();I($f(C,S))}H==null||H(C),a==null||a(C)},_=D=>{if(!p)return;const B=ao(D);s&&(B&&D.button===0||!B)&&wo({event:D,handleId:w,nodeId:p,onConnect:N,isTarget:y,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||js}),B?u==null||u(D):d==null||d(D)},R=D=>{const{onClickConnectStart:B,onClickConnectEnd:H,connectionClickStartHandle:g,connectionMode:C,isValidConnection:S}=v.getState();if(!p||!g&&!s)return;if(!g){B==null||B(D,{nodeId:p,handleId:w,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:p,type:e,handleId:w}});return}const I=ro(D.target),L=n||S||js,{connection:j,isValid:T}=xo({nodeId:p,id:w,type:e},C,g.nodeId,g.handleId||null,g.type,L,I);T&&N(j),H==null||H(D),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":w,"data-nodeid":p,"data-handlepos":t,"data-id":`${p}-${w}-${e}`,className:je(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",$,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!b||i&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});bo.displayName="Handle";var ct=x.memo(bo);const vo=({data:e,isConnectable:t,targetPosition:n=q.Top,sourcePosition:r=q.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ct,{type:"source",position:r,isConnectable:t}));vo.displayName="DefaultNode";var Er=x.memo(vo);const _o=({data:e,isConnectable:t,sourcePosition:n=q.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ct,{type:"source",position:n,isConnectable:t}));_o.displayName="InputNode";var Eo=x.memo(_o);const No=({data:e,isConnectable:t,targetPosition:n=q.Top})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);No.displayName="OutputNode";var So=x.memo(No);const Vr=()=>null;Vr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),pn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(pn),t.selectedNodes.map(pn))&&ke(e.selectedEdges.map(pn),t.selectedEdges.map(pn))}const ko=x.memo(({onSelectionChange:e})=>{const t=Ee(),{selectedNodes:n,selectedEdges:r}=de(Df,Pf);return x.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});ko.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=de(zf);return e||t?A.createElement(ko,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Et(e,t){x.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ie(e,t,n){x.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:w,minZoom:y,maxZoom:v,nodeExtent:p,onNodesChange:E,onEdgesChange:$,elementsSelectable:b,connectionMode:M,snapGrid:N,snapToGrid:_,translateExtent:R,connectOnClick:k,defaultEdgeOptions:O,fitView:D,fitViewOptions:B,onNodesDelete:H,onEdgesDelete:g,onNodeDrag:C,onNodeDragStart:S,onNodeDragStop:I,onSelectionDrag:L,onSelectionDragStart:j,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:X,autoPanOnConnect:V,autoPanOnNodeDrag:Z,onError:J,connectionRadius:ee,isValidConnection:oe,nodeDragThreshold:ne})=>{const{setNodes:re,setEdges:pe,setDefaultNodesAndEdges:ce,setMinZoom:ue,setMaxZoom:ye,setTranslateExtent:he,setNodeExtent:xe,reset:le}=de(Ff,ke),K=Ee();return x.useEffect(()=>{const Ne=r==null?void 0:r.map(Ce=>({...Ce,...O}));return ce(n,Ne),()=>{le()}},[]),ie("defaultEdgeOptions",O,K.setState),ie("connectionMode",M,K.setState),ie("onConnect",s,K.setState),ie("onConnectStart",i,K.setState),ie("onConnectEnd",o,K.setState),ie("onClickConnectStart",a,K.setState),ie("onClickConnectEnd",c,K.setState),ie("nodesDraggable",l,K.setState),ie("nodesConnectable",u,K.setState),ie("nodesFocusable",d,K.setState),ie("edgesFocusable",m,K.setState),ie("edgesUpdatable",f,K.setState),ie("elementsSelectable",b,K.setState),ie("elevateNodesOnSelect",w,K.setState),ie("snapToGrid",_,K.setState),ie("snapGrid",N,K.setState),ie("onNodesChange",E,K.setState),ie("onEdgesChange",$,K.setState),ie("connectOnClick",k,K.setState),ie("fitViewOnInit",D,K.setState),ie("fitViewOnInitOptions",B,K.setState),ie("onNodesDelete",H,K.setState),ie("onEdgesDelete",g,K.setState),ie("onNodeDrag",C,K.setState),ie("onNodeDragStart",S,K.setState),ie("onNodeDragStop",I,K.setState),ie("onSelectionDrag",L,K.setState),ie("onSelectionDragStart",j,K.setState),ie("onSelectionDragStop",T,K.setState),ie("noPanClassName",P,K.setState),ie("nodeOrigin",z,K.setState),ie("rfId",X,K.setState),ie("autoPanOnConnect",V,K.setState),ie("autoPanOnNodeDrag",Z,K.setState),ie("onError",J,K.setState),ie("connectionRadius",ee,K.setState),ie("isValidConnection",oe,K.setState),ie("nodeDragThreshold",ne,K.setState),Et(e,re),Et(t,pe),Et(y,ue),Et(v,ye),Et(R,he),Et(p,xe),null},Cs={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},jo="react-flow__node-desc",Co="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Xf({rfId:e}){const t=de(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Wf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${jo}-${e}`,style:Cs},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Co}-${e}`,style:Cs},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Xf,{rfId:e}))}var tn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=x.useState(!1),s=x.useRef(!1),i=x.useRef(new Set([])),[o,a]=x.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return x.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);i.current.add(f[y]),$s(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);$s(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Ms(e,t){return t.includes(e)?"code":"key"}function $o(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return $o(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function Mo(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=$o(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Oe(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Mo(s,n,i),s}function Ao(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const w=n().filter(v=>{var E;const p=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?p&&t.nodes.some($=>$.id===v.id):p}),y=w.every(v=>v.width&&v.height);if(w.length>0&&y){const v=on(w,d),{x:p,y:E,zoom:$}=go(v,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),b=Je.translate(p,E).scale($);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Uf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function gn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Uf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const Nt=()=>{},Kf={zoomIn:Nt,zoomOut:Nt,zoomTo:Nt,getZoom:()=>1,setViewport:Nt,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:Nt,fitBounds:Nt,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Ee(),{d3Zoom:t,d3Selection:n}=de(Zf,ke);return x.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=Je.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Ao(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=Je.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=go(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=Je.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),_r(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return _r(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=ho(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function an(){const e=Qf(),t=Ee(),n=x.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=x.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=x.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(v=>({...v}))},[]),i=x.useCallback(y=>{const{edges:v=[]}=t.getState();return v.find(p=>p.id===y)},[]),o=x.useCallback(y=>{const{getNodes:v,setNodes:p,hasDefaultNodes:E,onNodesChange:$}=t.getState(),b=v(),M=typeof y=="function"?y(b):y;if(E)p(M);else if($){const N=M.length===0?b.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));$(N)}},[]),a=x.useCallback(y=>{const{edges:v=[],setEdges:p,hasDefaultEdges:E,onEdgesChange:$}=t.getState(),b=typeof y=="function"?y(v):y;if(E)p(b);else if($){const M=b.length===0?v.map(N=>({type:"remove",id:N.id})):b.map(N=>({item:N,type:"reset"}));$(M)}},[]),c=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{getNodes:p,setNodes:E,hasDefaultNodes:$,onNodesChange:b}=t.getState();if($){const N=[...p(),...v];E(N)}else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),l=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{edges:p=[],setEdges:E,hasDefaultEdges:$,onEdgesChange:b}=t.getState();if($)E([...p,...v]);else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),u=x.useCallback(()=>{const{getNodes:y,edges:v=[],transform:p}=t.getState(),[E,$,b]=p;return{nodes:y().map(M=>({...M})),edges:v.map(M=>({...M})),viewport:{x:E,y:$,zoom:b}}},[]),d=x.useCallback(({nodes:y,edges:v})=>{const{nodeInternals:p,getNodes:E,edges:$,hasDefaultNodes:b,hasDefaultEdges:M,onNodesDelete:N,onEdgesDelete:_,onNodesChange:R,onEdgesChange:k}=t.getState(),O=(y||[]).map(C=>C.id),D=(v||[]).map(C=>C.id),B=E().reduce((C,S)=>{const I=S.parentNode||S.parentId,L=!O.includes(S.id)&&I&&C.find(T=>T.id===I);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(O.includes(S.id)||L)&&C.push(S),C},[]),H=$.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),g=H.filter(C=>D.includes(C.id));if(B||g){const C=po(B,H),S=[...g,...C],I=S.reduce((L,j)=>(L.includes(j.id)||L.push(j.id),L),[]);if((M||b)&&(M&&t.setState({edges:$.filter(L=>!I.includes(L.id))}),b&&(B.forEach(L=>{p.delete(L.id)}),t.setState({nodeInternals:new Map(p)}))),I.length>0&&(_==null||_(S),k&&k(I.map(L=>({id:L,type:"remove"})))),B.length>0&&(N==null||N(B),R)){const L=B.map(j=>({id:j.id,type:"remove"}));R(L)}}},[]),m=x.useCallback(y=>{const v=yf(y),p=v?null:t.getState().nodeInternals.get(y.id);return!v&&!p?[null,null,v]:[v?y:vs(p),p,v]},[]),f=x.useCallback((y,v=!0,p)=>{const[E,$,b]=m(y);return E?(p||t.getState().getNodes()).filter(M=>{if(!b&&(M.id===$.id||!M.positionAbsolute))return!1;const N=vs(M),_=wr(N,E);return v&&_>0||_>=E.width*E.height}):[]},[]),w=x.useCallback((y,v,p=!0)=>{const[E]=m(y);if(!E)return!1;const $=wr(E,v);return p&&$>0||$>=E.width*E.height},[]);return x.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:w}),[e,n,r,s,i,o,a,c,l,u,d,f,w])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ee(),{deleteElements:r}=an(),s=tn(e,Jf),i=tn(t);x.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),x.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Ee();x.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Or(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",tt.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Br={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,yn=e=>({x:e.x,y:e.y,zoom:e.k}),St=(e,t)=>e.target.closest(`.${t}`),As=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rs=e=>{const t=e.ctrlKey&&Mn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:w,maxZoom:y,zoomActivationKeyCode:v,preventScrolling:p=!0,children:E,noWheelClassName:$,noPanClassName:b})=>{const M=x.useRef(),N=Ee(),_=x.useRef(!1),R=x.useRef(!1),k=x.useRef(null),O=x.useRef({x:0,y:0,zoom:0}),{d3Zoom:D,d3Selection:B,d3ZoomHandler:H,userSelectionActive:g}=de(rh,ke),C=tn(v),S=x.useRef(0),I=x.useRef(!1),L=x.useRef();return th(k),x.useEffect(()=>{if(k.current){const j=k.current.getBoundingClientRect(),T=eo().scaleExtent([w,y]).translateExtent(f),P=Te(k.current).call(T),z=Je.translate(m.x,m.y).scale(Tt(m.zoom,w,y)),X=[[0,0],[j.width,j.height]],V=T.constrain()(z,X,f);T.transform(P,V),T.wheelDelta(Rs),N.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[V.x,V.y,V.k],domNode:k.current.closest(".react-flow")})}},[]),x.useEffect(()=>{B&&D&&(o&&!C&&!g?B.on("wheel.zoom",j=>{if(St(j,$))return!1;j.preventDefault(),j.stopImmediatePropagation();const T=B.property("__zoom").k||1;if(j.ctrlKey&&i){const oe=ze(j),ne=Rs(j),re=T*Math.pow(2,ne);D.scaleTo(B,re,oe,j);return}const P=j.deltaMode===1?20:1;let z=c===gt.Vertical?0:j.deltaX*P,X=c===gt.Horizontal?0:j.deltaY*P;!Mn()&&j.shiftKey&&c!==gt.Vertical&&(z=j.deltaY*P,X=0),D.translateBy(B,-(z/T)*a,-(X/T)*a,{internal:!0});const V=yn(B.property("__zoom")),{onViewportChangeStart:Z,onViewportChange:J,onViewportChangeEnd:ee}=N.getState();clearTimeout(L.current),I.current||(I.current=!0,t==null||t(j,V),Z==null||Z(V)),I.current&&(e==null||e(j,V),J==null||J(V),L.current=setTimeout(()=>{n==null||n(j,V),ee==null||ee(V),I.current=!1},150))},{passive:!1}):typeof H<"u"&&B.on("wheel.zoom",function(j,T){if(!p&&j.type==="wheel"&&!j.ctrlKey||St(j,$))return null;j.preventDefault(),H.call(this,j,T)},{passive:!1}))},[g,o,c,B,D,H,C,i,p,$,t,e,n]),x.useEffect(()=>{D&&D.on("start",j=>{var z,X;if(!j.sourceEvent||j.sourceEvent.internal)return null;S.current=(z=j.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=N.getState(),P=yn(j.transform);_.current=!0,O.current=P,((X=j.sourceEvent)==null?void 0:X.type)==="mousedown"&&N.setState({paneDragging:!0}),T==null||T(P),t==null||t(j.sourceEvent,P)})},[D,t]),x.useEffect(()=>{D&&(g&&!_.current?D.on("zoom",null):g||D.on("zoom",j=>{var P;const{onViewportChange:T}=N.getState();if(N.setState({transform:[j.transform.x,j.transform.y,j.transform.k]}),R.current=!!(r&&As(d,S.current??0)),(e||T)&&!((P=j.sourceEvent)!=null&&P.internal)){const z=yn(j.transform);T==null||T(z),e==null||e(j.sourceEvent,z)}}))},[g,D,e,d,r]),x.useEffect(()=>{D&&D.on("end",j=>{if(!j.sourceEvent||j.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=N.getState();if(_.current=!1,N.setState({paneDragging:!1}),r&&As(d,S.current??0)&&!R.current&&r(j.sourceEvent),R.current=!1,(n||T)&&nh(O.current,j.transform)){const P=yn(j.transform);O.current=P,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(P),n==null||n(j.sourceEvent,P)},o?150:0)}})},[D,o,d,n,r]),x.useEffect(()=>{D&&D.filter(j=>{const T=C||s,P=i&&j.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&j.button===1&&j.type==="mousedown"&&(St(j,"react-flow__node")||St(j,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||g||!l&&j.type==="dblclick"||St(j,$)&&j.type==="wheel"||St(j,b)&&(j.type!=="wheel"||o&&j.type==="wheel"&&!C)||!i&&j.ctrlKey&&j.type==="wheel"||!T&&!o&&!P&&j.type==="wheel"||!d&&(j.type==="mousedown"||j.type==="touchstart")||Array.isArray(d)&&!d.includes(j.button)&&j.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(j.button)||!j.button||j.button<=1;return(!j.ctrlKey||j.type==="wheel")&&z})},[g,D,s,i,o,l,d,u,C]),A.createElement("div",{className:"react-flow__renderer",ref:k,style:Br},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=de(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Is(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&Is(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&Is(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ot=(e,t)=>({id:e,type:"select",selected:t});function jt(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ot(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ot(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ro=x.memo(({isSelecting:e,selectionMode:t=en.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=x.useRef(null),f=Ee(),w=x.useRef(0),y=x.useRef(0),v=x.useRef(),{userSelectionActive:p,elementsSelectable:E,dragging:$}=de(lh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),w.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},N=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,R=H=>{const{resetSelectedElements:g,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!v.current)return;const{x:S,y:I}=lt(H,v.current);g(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:I,x:S,y:I}}),r==null||r(H)},k=H=>{const{userSelectionRect:g,nodeInternals:C,edges:S,transform:I,onNodesChange:L,onEdgesChange:j,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!g)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=lt(H,v.current),X=g.startX??0,V=g.startY??0,Z={...g,x:z.xre.id),ne=ee.map(re=>re.id);if(w.current!==ne.length){w.current=ne.length;const re=jt(J,ne);re.length&&(L==null||L(re))}if(y.current!==oe.length){y.current=oe.length;const re=jt(S,oe);re.length&&(j==null||j(re))}f.setState({userSelectionRect:Z})},O=H=>{if(H.button!==0)return;const{userSelectionRect:g}=f.getState();!p&&g&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:w.current>0}),b(),s==null||s(H)},D=H=>{p&&(f.setState({nodesSelectionActive:w.current>0}),s==null||s(H)),b()},B=E&&(e||p);return A.createElement("div",{className:je(["react-flow__pane",{dragging:$,selection:e}]),onClick:B?void 0:er(M,m),onContextMenu:er(N,m),onWheel:er(_,m),onMouseEnter:B?void 0:c,onMouseDown:B?R:void 0,onMouseMove:B?k:l,onMouseUp:B?O:void 0,onMouseLeave:B?D:u,ref:m,style:Br},d,A.createElement(oh,null))});Ro.displayName="Pane";function Io(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Io(r,t):!1}function Ts(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Io(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function To(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Oe(m)&&Oe(f)&&Oe(d.width)&&Oe(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",tt.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Lr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Os=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Or(c)}})};function Vt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Nr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",tt.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Ee();return x.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Oo({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Ee(),[c,l]=x.useState(!1),u=x.useRef([]),d=x.useRef({x:null,y:null}),m=x.useRef(0),f=x.useRef(null),w=x.useRef({x:0,y:0}),y=x.useRef(null),v=x.useRef(!1),p=x.useRef(!1),E=x.useRef(!1),$=fh();return x.useEffect(()=>{if(e!=null&&e.current){const b=Te(e.current),M=({x:R,y:k})=>{const{nodeInternals:O,onNodeDrag:D,onSelectionDrag:B,updateNodePositions:H,nodeExtent:g,snapGrid:C,snapToGrid:S,nodeOrigin:I,onError:L}=a.getState();d.current={x:R,y:k};let j=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&g){const z=on(u.current,I);T=Jt(z)}if(u.current=u.current.map(z=>{const X={x:R-z.distance.x,y:k-z.distance.y};S&&(X.x=C[0]*Math.round(X.x/C[0]),X.y=C[1]*Math.round(X.y/C[1]));const V=[[g[0][0],g[0][1]],[g[1][0],g[1][1]]];u.current.length>1&&g&&!z.extent&&(V[0][0]=z.positionAbsolute.x-T.x+g[0][0],V[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+g[1][0],V[0][1]=z.positionAbsolute.y-T.y+g[0][1],V[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+g[1][1]);const Z=To(z,X,O,V,I,L);return j=j||z.position.x!==Z.position.x||z.position.y!==Z.position.y,z.position=Z.position,z.positionAbsolute=Z.positionAbsolute,z}),!j)return;H(u.current,!0,!0),l(!0);const P=s?D:nr(B);if(P&&y.current){const[z,X]=tr({nodeId:s,dragItems:u.current,nodeInternals:O});P(y.current,z,X)}},N=()=>{if(!f.current)return;const[R,k]=no(w.current,f.current);if(R!==0||k!==0){const{transform:O,panBy:D}=a.getState();d.current.x=(d.current.x??0)-R/O[2],d.current.y=(d.current.y??0)-k/O[2],D({x:R,y:k})&&M(d.current)}m.current=requestAnimationFrame(N)},_=R=>{var I;const{nodeInternals:k,multiSelectionActive:O,nodesDraggable:D,unselectNodesAndEdges:B,onNodeDragStart:H,onSelectionDragStart:g}=a.getState();p.current=!0;const C=s?H:nr(g);(!o||!i)&&!O&&s&&((I=k.get(s))!=null&&I.selected||B()),s&&i&&o&&Nr({id:s,store:a,nodeRef:e});const S=$(R);if(d.current=S,u.current=uh(k,D,S,s),C&&u.current){const[L,j]=tr({nodeId:s,dragItems:u.current,nodeInternals:k});C(R.sourceEvent,L,j)}};if(t)b.on(".drag",null);else{const R=bu().on("start",k=>{const{domNode:O,nodeDragThreshold:D}=a.getState();D===0&&_(k),E.current=!1;const B=$(k);d.current=B,f.current=(O==null?void 0:O.getBoundingClientRect())||null,w.current=lt(k.sourceEvent,f.current)}).on("drag",k=>{var H,g;const O=$(k),{autoPanOnNodeDrag:D,nodeDragThreshold:B}=a.getState();if(k.sourceEvent.type==="touchmove"&&k.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&p.current&&D&&(v.current=!0,N()),!p.current){const C=O.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=O.ySnapped-(((g=d==null?void 0:d.current)==null?void 0:g.y)??0);Math.sqrt(C*C+S*S)>B&&_(k)}(d.current.x!==O.xSnapped||d.current.y!==O.ySnapped)&&u.current&&p.current&&(y.current=k.sourceEvent,w.current=lt(k.sourceEvent,f.current),M(O))}}).on("end",k=>{if(!(!p.current||E.current)&&(l(!1),v.current=!1,p.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:O,nodeInternals:D,onNodeDragStop:B,onSelectionDragStop:H}=a.getState(),g=s?B:nr(H);if(O(u.current,!1,!1),g){const[C,S]=tr({nodeId:s,dragItems:u.current,nodeInternals:D});g(k.sourceEvent,C,S)}}}).filter(k=>{const O=k.target;return!k.button&&(!n||!Ts(O,`.${n}`,e))&&(!r||Ts(O,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,$]),c}function Lo(){const e=Ee();return x.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,w=n.isShiftPressed?4:1,y=n.x*m*w,v=n.y*f*w,p=d.map(E=>{if(E.positionAbsolute){const $={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+v};a&&($.x=c[0]*Math.round($.x/c[0]),$.y=c[1]*Math.round($.y/c[1]));const{positionAbsolute:b,position:M}=To(E,$,r,s,void 0,l);E.position=M,E.positionAbsolute=b}return E});i(p,!0,!1)},[])}const Mt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Bt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:w,onDoubleClick:y,style:v,className:p,isDraggable:E,isSelectable:$,isConnectable:b,isFocusable:M,selectNodesOnDrag:N,sourcePosition:_,targetPosition:R,hidden:k,resizeObserver:O,dragHandle:D,zIndex:B,isParent:H,noDragClassName:g,noPanClassName:C,initialized:S,disableKeyboardA11y:I,ariaLabel:L,rfId:j,hasHandleBounds:T})=>{const P=Ee(),z=x.useRef(null),X=x.useRef(null),V=x.useRef(_),Z=x.useRef(R),J=x.useRef(r),ee=$||E||u||d||m||f,oe=Lo(),ne=Vt(n,P.getState,d),re=Vt(n,P.getState,m),pe=Vt(n,P.getState,f),ce=Vt(n,P.getState,w),ue=Vt(n,P.getState,y),ye=le=>{const{nodeDragThreshold:K}=P.getState();if($&&(!N||!E||K>0)&&Nr({id:n,store:P,nodeRef:z}),u){const Ne=P.getState().nodeInternals.get(n);Ne&&u(le,{...Ne})}},he=le=>{if(!br(le)&&!I)if(oo.includes(le.key)&&$){const K=le.key==="Escape";Nr({id:n,store:P,unselect:K,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Mt,le.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),oe({x:Mt[le.key].x,y:Mt[le.key].y,isShiftPressed:le.shiftKey}))};x.useEffect(()=>()=>{X.current&&(O==null||O.unobserve(X.current),X.current=null)},[]),x.useEffect(()=>{if(z.current&&!k){const le=z.current;(!S||!T||X.current!==le)&&(X.current&&(O==null||O.unobserve(X.current)),O==null||O.observe(le),X.current=le)}},[k,S,T]),x.useEffect(()=>{const le=J.current!==r,K=V.current!==_,Ne=Z.current!==R;z.current&&(le||K||Ne)&&(le&&(J.current=r),K&&(V.current=_),Ne&&(Z.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const xe=Oo({nodeRef:z,disabled:k||!E,noDragClassName:g,handleSelector:D,nodeId:n,isSelectable:$,selectNodesOnDrag:N});return k?null:A.createElement("div",{className:je(["react-flow__node",`react-flow__node-${r}`,{[C]:E},p,{selected:l,selectable:$,parent:H,dragging:xe}]),ref:z,style:{zIndex:B,transform:`translate(${a}px,${c}px)`,pointerEvents:ee?"all":"none",visibility:S?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:re,onMouseLeave:pe,onContextMenu:ce,onClick:ye,onDoubleClick:ue,onKeyDown:M?he:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":I?void 0:`${jo}-${j}`,"aria-label":L},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:xe,dragHandle:D,zIndex:B})))};return t.displayName="NodeWrapper",x.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...on(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ee(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=de(hh,ke),u=Lo(),d=x.useRef(null);if(x.useEffect(()=>{var w;n||(w=d.current)==null||w.focus({preventScroll:!0})},[n]),Oo({nodeRef:d}),l||!s||!i)return null;const m=e?w=>{const y=r.getState().getNodes().filter(v=>v.selected);e(w,y)}:void 0,f=w=>{Object.prototype.hasOwnProperty.call(Mt,w.key)&&u({x:Mt[w.key].x,y:Mt[w.key].y,isShiftPressed:w.shiftKey})};return A.createElement("div",{className:je(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=x.memo(mh);const gh=e=>e.nodesSelectionActive,Do=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:w,onSelectionEnd:y,multiSelectionKeyCode:v,panActivationKeyCode:p,zoomActivationKeyCode:E,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:N,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:O,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,preventScrolling:C,onSelectionContextMenu:S,noWheelClassName:I,noPanClassName:L,disableKeyboardA11y:j})=>{const T=de(gh),P=tn(d),z=tn(p),X=z||O,V=z||N,Z=P||m&&X!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:V,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:!P&&X,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:I,noPanClassName:L},A.createElement(Ro,{onSelectionStart:w,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:X,isSelecting:!!Z,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:L,disableKeyboardA11y:j})))};Do.displayName="FlowRenderer";var yh=x.memo(Do);function xh(e){return de(x.useCallback(n=>e?mo(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Bt(e.input||Eo),default:Bt(e.default||Er),output:Bt(e.output||So),group:Bt(e.group||Vr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Bt(e[i]||Er),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Po=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=de(vh,ke),a=xh(e.onlyRenderVisibleElements),c=x.useRef(),l=x.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return x.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Br},a.map(u=>{var M,N,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",tt.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),w=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),v=!!(u.focusable||r&&typeof u.focusable>"u"),p=e.nodeExtent?Lr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(p==null?void 0:p.x)??0,$=(p==null?void 0:p.y)??0,b=bh({x:E,y:$,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||q.Bottom,targetPosition:u.targetPosition||q.Top,hidden:u.hidden,xPos:E,yPos:$,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:w,isConnectable:y,isFocusable:v,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((N=u[we])!=null&&N.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Po.displayName="NodeRenderer";var _h=x.memo(Po);const Eh=(e,t,n)=>n===q.Left?e-t:n===q.Right?e+t:e,Nh=(e,t,n)=>n===q.Top?e-t:n===q.Bottom?e+t:e,Ls="react-flow__edgeupdater",Ds=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:je([Ls,`${Ls}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var kt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,style:v,source:p,target:E,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,elementsSelectable:k,hidden:O,sourceHandleId:D,targetHandleId:B,onContextMenu:H,onMouseEnter:g,onMouseMove:C,onMouseLeave:S,reconnectRadius:I,onReconnect:L,onReconnectStart:j,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:X,ariaLabel:V,isFocusable:Z,isReconnectable:J,pathOptions:ee,interactionWidth:oe,disableKeyboardA11y:ne})=>{const re=x.useRef(null),[pe,ce]=x.useState(!1),[ue,ye]=x.useState(!1),he=Ee(),xe=x.useMemo(()=>`url('#${vr(z,X)}')`,[z,X]),le=x.useMemo(()=>`url('#${vr(P,X)}')`,[P,X]);if(O)return null;const K=se=>{var Se;const{edges:me,addSelectedEdges:$e,unselectNodesAndEdges:W,multiSelectionActive:fe}=he.getState(),ge=me.find(dt=>dt.id===n);ge&&(k&&(he.setState({nodesSelectionActive:!1}),ge.selected&&fe?(W({nodes:[],edges:[ge]}),(Se=re.current)==null||Se.blur()):$e([n])),o&&o(se,ge))},Ne=Ft(n,he.getState,a),Ce=Ft(n,he.getState,H),ut=Ft(n,he.getState,g),Ae=Ft(n,he.getState,C),We=Ft(n,he.getState,S),Ie=(se,me)=>{if(se.button!==0)return;const{edges:$e,isValidConnection:W}=he.getState(),fe=me?E:p,ge=(me?B:D)||null,Se=me?"target":"source",dt=W||Sh,Ot=me,rt=$e.find(Pe=>Pe.id===n);ye(!0),j==null||j(se,rt,Se);const ft=Pe=>{ye(!1),T==null||T(Pe,rt,Se)};wo({event:se,handleId:ge,nodeId:fe,onConnect:Pe=>L==null?void 0:L(rt,Pe),isTarget:Ot,getState:he.getState,setState:he.setState,isValidConnection:dt,edgeUpdaterType:Se,onReconnectEnd:ft})},F=se=>Ie(se,!0),Y=se=>Ie(se,!1),G=()=>ce(!0),Q=()=>ce(!1),U=!k&&!o,te=se=>{var me;if(!ne&&oo.includes(se.key)&&k){const{unselectNodesAndEdges:$e,addSelectedEdges:W,edges:fe}=he.getState();se.key==="Escape"?((me=re.current)==null||me.blur(),$e({edges:[fe.find(Se=>Se.id===n)]})):W([n])}};return A.createElement("g",{className:je(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:pe}]),onClick:K,onDoubleClick:Ne,onContextMenu:Ce,onMouseEnter:ut,onMouseMove:Ae,onMouseLeave:We,onKeyDown:Z?te:void 0,tabIndex:Z?0:void 0,role:Z?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":V===null?void 0:V||`Edge from ${p} to ${E}`,"aria-describedby":Z?`${Co}-${X}`:void 0,ref:re},!ue&&A.createElement(e,{id:n,source:p,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,data:i,style:v,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,sourceHandleId:D,targetHandleId:B,markerStart:xe,markerEnd:le,pathOptions:ee,interactionWidth:oe}),J&&A.createElement(A.Fragment,null,(J==="source"||J===!0)&&A.createElement(Ds,{position:_,centerX:$,centerY:b,radius:I,onMouseDown:F,onMouseEnter:G,onMouseOut:Q,type:"source"}),(J==="target"||J===!0)&&A.createElement(Ds,{position:R,centerX:M,centerY:N,radius:I,onMouseDown:Y,onMouseEnter:G,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",x.memo(t)};function kh(e){const t={default:kt(e.default||In),straight:kt(e.bezier||zr),step:kt(e.step||Pr),smoothstep:kt(e.step||Bn),simplebezier:kt(e.simplebezier||Dr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=kt(e[i]||In),s),n);return{...t,...r}}function Ps(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case q.Top:return{x:r+i/2,y:s};case q.Right:return{x:r+i,y:s+o/2};case q.Bottom:return{x:r+i/2,y:s+o};case q.Left:return{x:r,y:s+o/2}}}function zs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ps(n,e,t),a=Ps(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Jt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Hs(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Oe(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),w=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(w?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=de(x.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Fs={[An.Arrow]:Rh,[An.ArrowClosed]:Ih};function Th(e){const t=Ee();return x.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(Fs,e)?Fs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",tt.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=vr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},zo=({defaultColor:e,rfId:t})=>{const n=de(x.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};zo.displayName="MarkerDefinitions";var Dh=x.memo(zo);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ho=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,children:v,disableKeyboardA11y:p})=>{const{edgesFocusable:E,edgesUpdatable:$,elementsSelectable:b,width:M,height:N,connectionMode:_,nodeInternals:R,onError:k}=de(Ph,ke),O=Ah(t,R,n);return M?A.createElement(A.Fragment,null,O.map(({level:D,edges:B,isMaxLevel:H})=>A.createElement("svg",{key:D,style:{zIndex:D},width:M,height:N,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,B.map(g=>{const[C,S,I]=Hs(R.get(g.source)),[L,j,T]=Hs(R.get(g.target));if(!I||!T)return null;let P=g.type||"default";s[P]||(k==null||k("011",tt.error011(P)),P="default");const z=s[P]||s.default,X=_===vt.Strict?j.target:(j.target??[]).concat(j.source??[]),V=zs(S.source,g.sourceHandle),Z=zs(X,g.targetHandle),J=(V==null?void 0:V.position)||q.Bottom,ee=(Z==null?void 0:Z.position)||q.Top,oe=!!(g.focusable||E&&typeof g.focusable>"u"),ne=g.reconnectable||g.updatable,re=typeof m<"u"&&(ne||$&&typeof ne>"u");if(!V||!Z)return k==null||k("008",tt.error008(V,g)),null;const{sourceX:pe,sourceY:ce,targetX:ue,targetY:ye}=jh(C,V,J,L,Z,ee);return A.createElement(z,{key:g.id,id:g.id,className:je([g.className,i]),type:P,data:g.data,selected:!!g.selected,animated:!!g.animated,hidden:!!g.hidden,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,style:g.style,source:g.source,target:g.target,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerEnd:g.markerEnd,markerStart:g.markerStart,sourceX:pe,sourceY:ce,targetX:ue,targetY:ye,sourcePosition:J,targetPosition:ee,elementsSelectable:b,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,rfId:r,ariaLabel:g.ariaLabel,isFocusable:oe,isReconnectable:re,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth,disableKeyboardA11y:p})})))),v):null};Ho.displayName="EdgeRenderer";var zh=x.memo(Ho);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=de(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=an(),n=x.useRef(!1);x.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[q.Left]:q.Right,[q.Right]:q.Left,[q.Top]:q.Bottom,[q.Bottom]:q.Top},Fo=({nodeId:e,handleType:t,style:n,type:r=at.Bezier,CustomComponent:s,connectionStatus:i})=>{var N,_,R;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=de(x.useCallback(k=>({fromNode:k.nodeInternals.get(e),handleId:k.connectionHandleId,toX:(k.connectionPosition.x-k.transform[0])/k.transform[2],toY:(k.connectionPosition.y-k.transform[1])/k.transform[2],connectionMode:k.connectionMode}),[e]),ke),d=(N=o==null?void 0:o[we])==null?void 0:N.handleBounds;let m=d==null?void 0:d[t];if(u===vt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(k=>k.id===a):m[0],w=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,v=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+w,p=(((R=o.positionAbsolute)==null?void 0:R.y)??0)+y,E=f==null?void 0:f.position,$=E?Bh[E]:null;if(!E||!$)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:v,fromY:p,toX:c,toY:l,fromPosition:E,toPosition:$,connectionStatus:i});let b="";const M={sourceX:v,sourceY:p,sourcePosition:E,targetX:c,targetY:l,targetPosition:$};return r===at.Bezier?[b]=fo(M):r===at.Step?[b]=Rn({...M,borderRadius:0}):r===at.SmoothStep?[b]=Rn(M):r===at.SimpleBezier?[b]=uo(M):b=`M${v},${p} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Fo.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=de(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:je(["react-flow__connection",l])},A.createElement(Fo,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Vs(e,t){return x.useRef(null),Ee(),x.useMemo(()=>t(e),[e])}const Vo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:w,onSelectionStart:y,onSelectionEnd:v,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:$,connectionLineContainerStyle:b,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,deleteKeyCode:D,onlyRenderVisibleElements:B,elementsSelectable:H,selectNodesOnDrag:g,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,preventScrolling:j,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:X,panOnScrollSpeed:V,panOnScrollMode:Z,zoomOnDoubleClick:J,panOnDrag:ee,onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneScroll:ce,onPaneContextMenu:ue,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,noDragClassName:Ae,noWheelClassName:We,noPanClassName:Ie,elevateEdgesOnSelect:F,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})=>{const te=Vs(e,wh),se=Vs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneContextMenu:ue,onPaneScroll:ce,deleteKeyCode:D,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,onSelectionStart:y,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:J,panOnScroll:X,panOnScrollSpeed:V,panOnScrollMode:Z,panOnDrag:ee,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,onSelectionContextMenu:w,preventScrolling:j,noDragClassName:Ae,noWheelClassName:We,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:B,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!F,disableKeyboardA11y:Y,rfId:U},A.createElement(Yh,{style:E,type:p,component:$,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:te,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:g,onlyRenderVisibleElements:B,noPanClassName:Ie,noDragClassName:Ae,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})))};Vo.displayName="GraphView";var Xh=x.memo(Vo);const Sr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],st={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Sr,nodeExtent:Sr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:vt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Wh=()=>Rc((e,t)=>({...st,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Jn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,v)=>{const p=s.get(v.id);if(p!=null&&p.hidden)s.set(p.id,{...p,[we]:{...p[we],handleBounds:void 0}});else if(p){const E=Or(v.nodeElement);!!(E.width&&E.height&&(p.width!==E.width||p.height!==E.height||v.forceUpdate))&&(s.set(p.id,{...p,[we]:{...p[we],handleBounds:{source:Os(".source",v.nodeElement,m,l),target:Os(".target",v.nodeElement,m,l)}},...E}),y.push({id:p.id,type:"dimensions",dimensions:E}))}return y},[]);Mo(s,l);const w=o||i&&!o&&Ao(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:w}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Jn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(i(),n),a=jt(s,[])),gn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(s,n),a=jt(i(),[])),gn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ot(u.id,!1))),l=a.map(u=>ot(u.id,!1));gn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ot(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ot(a.id,!1));gn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Lr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=Je.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:st.connectionNodeId,connectionHandleId:st.connectionHandleId,connectionHandleType:st.connectionHandleType,connectionStatus:st.connectionStatus,connectionStartHandle:st.connectionStartHandle,connectionEndHandle:st.connectionEndHandle}),reset:()=>e({...st})}),Object.is),Bo=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Wh()),A.createElement(df,{value:t.current},e)};Bo.displayName="ReactFlowProvider";const Go=({children:e})=>x.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Bo,null,e);Go.displayName="ReactFlowWrapper";const Uh={input:Eo,default:Er,output:So,group:Vr},qh={default:In,straight:zr,step:Pr,smoothstep:Bn,simplebezier:Dr},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Yo=x.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Uh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onNodesDelete:O,onEdgesDelete:D,onSelectionChange:B,onSelectionDragStart:H,onSelectionDrag:g,onSelectionDragStop:C,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,connectionMode:j=vt.Strict,connectionLineType:T=at.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,deleteKeyCode:V="Backspace",selectionKeyCode:Z="Shift",selectionOnDrag:J=!1,selectionMode:ee=en.Full,panActivationKeyCode:oe="Space",multiSelectionKeyCode:ne=Mn()?"Meta":"Control",zoomActivationKeyCode:re=Mn()?"Meta":"Control",snapToGrid:pe=!1,snapGrid:ce=Zh,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:ye=!0,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,nodeOrigin:K=Kh,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,defaultViewport:Ae=Qh,minZoom:We=.5,maxZoom:Ie=2,translateExtent:F=Sr,preventScrolling:Y=!0,nodeExtent:G,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:te=!0,panOnScroll:se=!1,panOnScrollSpeed:me=.5,panOnScrollMode:$e=gt.Free,zoomOnDoubleClick:W=!0,panOnDrag:fe=!0,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,children:Lt,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:Zr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Xa,defaultEdgeOptions:Wa,elevateNodesOnSelect:Ua=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Qr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Jr,nodeDragThreshold:nc,...rc},sc)=>{const Xn=Jr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:je(["react-flow",s]),"data-testid":"rf__wrapper",id:Jr},A.createElement(Go,null,A.createElement(Xh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,selectionKeyCode:Z,selectionOnDrag:J,selectionMode:ee,deleteKeyCode:V,multiSelectionKeyCode:ne,panActivationKeyCode:oe,zoomActivationKeyCode:re,onlyRenderVisibleElements:ue,selectNodesOnDrag:ye,defaultViewport:Ae,translateExtent:F,minZoom:We,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:U,zoomOnPinch:te,zoomOnDoubleClick:W,panOnScroll:se,panOnScrollSpeed:me,panOnScrollMode:$e,panOnDrag:fe,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:Zr,elevateEdgesOnSelect:qa,rfId:Xn,disableKeyboardA11y:Qr,nodeOrigin:K,nodeExtent:G}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,elevateNodesOnSelect:Ua,minZoom:We,maxZoom:Ie,nodeExtent:G,onNodesChange:Pa,onEdgesChange:za,snapToGrid:pe,snapGrid:ce,connectionMode:j,translateExtent:F,connectOnClick:Ga,defaultEdgeOptions:Wa,fitView:Va,fitViewOptions:Ba,onNodesDelete:O,onEdgesDelete:D,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onSelectionDrag:g,onSelectionDragStart:H,onSelectionDragStop:C,noPanClassName:Zr,nodeOrigin:K,rfId:Xn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:B}),Lt,A.createElement(hf,{proOptions:Xa,position:Ya}),A.createElement(Wf,{rfId:Xn,disableKeyboardA11y:Qr})))});Yo.displayName="ReactFlow";const Xo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:w,backgroundColor:y}=i||{},v=o||w||y;return A.createElement("rect",{className:je(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?p=>m(p,e):void 0})};Xo.displayName="MiniMapNode";var em=x.memo(Xo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=de(nm,ke),c=de(tm),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:w,y}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:w,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=x.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(on(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:w=!1,zoomable:y=!1,ariaLabel:v="React Flow mini map",inversePan:p=!1,zoomStep:E=10,offsetScale:$=5}){const b=Ee(),M=x.useRef(null),{boundingRect:N,viewBB:_,rfId:R}=de(am,ke),k=(e==null?void 0:e.width)??im,O=(e==null?void 0:e.height)??om,D=N.width/k,B=N.height/O,H=Math.max(D,B),g=H*k,C=H*O,S=$*H,I=N.x-(g-N.width)/2-S,L=N.y-(C-N.height)/2-S,j=g+S*2,T=C+S*2,P=`${cm}-${R}`,z=x.useRef(0);z.current=H,x.useEffect(()=>{if(M.current){const Z=Te(M.current),J=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce}=b.getState();if(ne.sourceEvent.type!=="wheel"||!pe||!ce)return;const ue=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,ye=re[2]*Math.pow(2,ue);ce.scaleTo(pe,ye)},ee=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce,translateExtent:ue,width:ye,height:he}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!pe||!ce)return;const xe=z.current*Math.max(1,re[2])*(p?-1:1),le={x:re[0]-ne.sourceEvent.movementX*xe,y:re[1]-ne.sourceEvent.movementY*xe},K=[[0,0],[ye,he]],Ne=Je.translate(le.x,le.y).scale(re[2]),Ce=ce.constrain()(Ne,K,ue);ce.transform(pe,Ce)},oe=eo().on("zoom",w?ee:null).on("zoom.wheel",y?J:null);return Z.call(oe),()=>{Z.on("zoom",null)}}},[w,y,p,E]);const X=m?Z=>{const J=ze(Z);m(Z,{x:J[0],y:J[1]})}:void 0,V=f?(Z,J)=>{const ee=b.getState().nodeInternals.get(J);f(Z,ee)}:void 0;return A.createElement(Tr,{position:d,style:e,className:je(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:k,height:O,viewBox:`${I} ${L} ${j} ${T}`,role:"img","aria-labelledby":P,ref:M,onClick:X},v&&A.createElement("title",{id:P},v),A.createElement(sm,{onClick:V,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${I-S},${L-S}h${j+S*2}v${T+S*2}h${-j-S*2}z + M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Wo.displayName="MiniMap";var lm=x.memo(Wo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Xt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:je(["react-flow__controls-button",t]),...n},e);Xt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ee(),[f,w]=x.useState(!1),{isInteractive:y,minZoomReached:v,maxZoomReached:p}=de(pm,ke),{zoomIn:E,zoomOut:$,fitView:b}=an();if(x.useEffect(()=>{w(!0)},[]),!f)return null;const M=()=>{E(),i==null||i()},N=()=>{$(),o==null||o()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c==null||c(!y)};return A.createElement(Tr,{className:je(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Xt,{onClick:M,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:p},A.createElement(um,null)),A.createElement(Xt,{onClick:N,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(dm,null))),n&&A.createElement(Xt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Xt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},y?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=x.memo(Uo),Le;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Le||(Le={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[Le.Dots]:"#91919a",[Le.Lines]:"#eee",[Le.Cross]:"#e2e2e2"},bm={[Le.Dots]:1,[Le.Lines]:1,[Le.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function qo({id:e,variant:t=Le.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=x.useRef(null),{transform:u,patternId:d}=de(vm,ke),m=o||wm[t],f=r||bm[t],w=t===Le.Dots,y=t===Le.Cross,v=Array.isArray(n)?n:[n,n],p=[v[0]*u[2]||1,v[1]*u[2]||1],E=f*u[2],$=y?[E,E]:p,b=w?[E/i,E/i]:[$[0]/i,$[1]/i];return A.createElement("svg",{className:je(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%p[0],y:u[1]%p[1],width:p[0],height:p[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},w?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:$,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}qo.displayName="Background";var _m=x.memo(qo);const Gr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Gr+e}async function be(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function nt(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new Ko(r.error??`${e}: ${n.status}`,n.status);return r}class Ko extends Error{constructor(n,r){super(n);ve(this,"status");this.status=r}}const Cx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),$x=()=>be("/api/diagnostics"),Zo=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Qo=()=>be("/api/ontology/ontologies"),Em=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>be("/api/ontology/stack"),Sm=()=>be("/api/ontology/coverage"),km=(e,t,n)=>nt("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>be("/api/git/status"),Cm=()=>be("/api/git/diff"),$m=e=>nt("/api/git/commit",{message:e}),Mm=()=>nt("/api/git/discard",{}),Am=()=>be("/api/decisions"),Bs=(e,t)=>nt(`/api/decisions/${e}/verdict`,{verdict:t}),Mx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Ax=()=>be("/api/glossary/config"),Rx=e=>nt("/api/git/propose",e),Ix=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Tx=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),Ox=e=>nt("/api/git/classify",{changes:e}),Lx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Dx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Px=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>be("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Gr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>nt("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>nt("/api/import/preview",{format:e,content:t}),zx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Hx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Fx=(e,t,n)=>fetch(`${Gr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new Ko(await r.text(),r.status);return await r.json()}),Vx=()=>be("/api/glossary/subject-areas"),Bx=e=>be(`/api/glossary/subject-area/${e}`),Gx=(e,t)=>nt(`/api/glossary/subject-area/${e}/expand`,t);function Yx(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Yr="__entity_source",Xr="__entity_target",Pm=x.memo(function({data:t,selected:n}){var N;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:w}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>y(_.a)-y(R.a)||_.i-R.i).map(_=>_.a),p=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const $=!!c&&!l;let b=0;if($){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const M=(_,R)=>{const k="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:k,onMouseEnter:w?()=>w(_.id):void 0,onMouseLeave:w?()=>w(null):void 0,children:[h.jsx(ct,{id:_.id,type:"target",position:q.Left,className:"port attr-port"}),h.jsx(ct,{id:_.id,type:"source",position:q.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ct,{id:Xr,type:"target",position:q.Left,className:"port"}),h.jsx(ct,{id:Yr,type:"source",position:q.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((N=r.conceptual)==null?void 0:N.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var k;const _=(((k=r.conceptual)==null?void 0:k.ontology_refs)??[]).filter(O=>O.uri);if(_.length===0)return null;const R=_.map(O=>O.uri).join(` +`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),p.length>0&&h.jsx("div",{className:"attr-section keys",children:p.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,w,y,v,p,E,$,b,M,N,_,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(k=>k.from.entity===e.id||k.to.entity===e.id),d=k=>{var O;return((O=t.entities.find(D=>D.id===k))==null?void 0:O.name)??k};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Ke,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,name:k})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Ke,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,physical_name:k})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Ke,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:k=>r("set_definition",{id:e.id,definition:k})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((w=l==null?void 0:l.ontology_refs)==null?void 0:w.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((p=e.term_map)==null?void 0:p.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),($=e.term_map)!=null&&$.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((N=e.term_map)==null?void 0:N.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Ke,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:k,steward:((O=l==null?void 0:l.stewardship)==null?void 0:O.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Ke,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:((O=l==null?void 0:l.stewardship)==null?void 0:O.owner)??null,steward:k})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(k=>h.jsx(Xm,{a:k,entity:e,doc:t,readOnly:c,exec:r},k.id))})}),!c&&h.jsx(Wm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(k=>{const O=k.members.map(D=>{var B;return((B=e.attributes.find(H=>H.id===D))==null?void 0:B.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+k.type,children:k.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:k.name}),h.jsx("span",{className:"key-cols",children:O})]},k.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([k,O])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:k}),h.jsx("td",{className:"udp-val",children:String(O)})]},k))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(k=>{const O=k.from.entity===e.id?k.to.entity:k.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(O),children:[h.jsx("span",{className:"rel-card",children:Um(k,e.id)}),d(O)]}),(k.verb_phrase||k.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Ke,{value:k.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,verb_phrase:D})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Ke,{value:k.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,inverse_verb_phrase:D})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${k.name}`,onClick:()=>r("delete_relationship",{id:k.id}),children:"✕"})]},k.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var k;return(k=navigator.clipboard)==null?void 0:k.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Ke({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=x.useState(e);x.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Xm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Ke,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Ke,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Wm({entity:e,exec:t}){const[n,r]=x.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Um(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Gs="";let Km=class{constructor(t){ve(this,"_isDirected",!0);ve(this,"_isMultigraph",!1);ve(this,"_isCompound",!1);ve(this,"_label");ve(this,"_defaultNodeLabelFn",()=>{});ve(this,"_defaultEdgeLabelFn",()=>{});ve(this,"_nodes",{});ve(this,"_in",{});ve(this,"_preds",{});ve(this,"_out",{});ve(this,"_sucs",{});ve(this,"_edgeObjs",{});ve(this,"_edgeLabels",{});ve(this,"_nodeCount",0);ve(this,"_edgeCount",0);ve(this,"_parent");ve(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Ys(this._preds[n],t),Ys(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Xs(this._preds[n],t),Xs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Ys(e,t){e[t]?e[t]++:e[t]=1}function Xs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Gs+i+Gs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function sr(e,t){return Wt(e,t.v,t.w,t.name)}var Wr=Km,Qm="2.2.4",Jm={Graph:Wr,version:Qm},ep=Wr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){ve(this,"_arr",[]);ve(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=ea,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ta=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ta,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),ia(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),ia(t(i),o=>s.push(o)))}}function ia(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=sa,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=sa,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Wr,Lp=Jo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:ea,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ta,topsort:ra},Us=Jm,Ve={Graph:Us.Graph,json:tp,alg:zp,version:Us.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return qs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&qs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function qs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ve.Graph,Gp=Vp;var Yp=Wp;let Xp=()=>1;function Wp(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Xp);return Up(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Up(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)ir(e,t,n,o);for(;o=s.dequeue();)ir(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(ir(e,t,n,o,!0));break}}}return r}function ir(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,jr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,jr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{jr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function jr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new oa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=da(la(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),aa(e,"border",s,t)}function og(e,t=ca){const n=[];for(let r=0;rca){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function la(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function ua(e){var t=++ug;return e+(""+t)}function da(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Ur(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=_e.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=_e;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=_e;var Yn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ve.Graph,On=Yn.slack,fa=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!On(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=On(t,s)),it.node(r).rank+=n)}var Rg=fa,Ks=Yn.slack,Ig=Yn.longestPath,Tg=Ve.alg.preorder,Og=Ve.alg.postorder,Lg=_e.simplify,Dg=_t;_t.initLowLimValues=Kr;_t.initCutValues=qr;_t.calcCutValue=ha;_t.leaveEdge=pa;_t.enterEdge=ga;_t.exchangeEdges=ya;function _t(e){e=Lg(e),Ig(e);var t=Rg(e);Kr(t),qr(t,e);for(var n,r;n=pa(t);)r=ga(t,e,n),ya(t,e,n,r)}function qr(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ha(e,t,n)}function ha(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Kr(e,t){arguments.length<2&&(t=e.nodes()[0]),ma(e,{},1,t)}function ma(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ma(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function pa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ga(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===Zs(e,e.node(u.v),a)&&c!==Zs(e,e.node(u.w),a));return l.reduce((u,d)=>Ks(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function Zs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Yn,xa=Fg.longestPath,Vg=fa,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Qs(e);break;case"tight-tree":Wg(e);break;case"longest-path":Xg(e);break;case"none":break;default:Qs(e)}}var Xg=xa;function Wg(e){xa(e),Vg(e)}function Qs(e){Bg(e)}var Ug=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Ln=_e;var Qg={run:Jg,cleanup:n0};function Jg(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=e0(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=t0(e)+1;e.children().forEach(a=>wa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function wa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{wa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,w=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,v=f!==w?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:v,nestingEdge:!0}),e.setEdge(w,l,{weight:y,minlen:v,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function e0(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function t0(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function n0(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let r0=_e;var s0=i0;function i0(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iei(e.node(t))),e.edges().forEach(t=>ei(e.edge(t)))}function ei(e){let t=e.width;e.width=e.height,e.height=t}function l0(e){e.nodes().forEach(t=>or(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(or),Object.hasOwn(n,"y")&&or(n)})}function or(e){e.y=-e.y}function u0(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let ti=_e;var d0=f0;function f0(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=ti.applyWithChunking(Math.max,r),i=ti.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let h0=_e.zipObject;var m0=p0;function p0(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var y0=x0;function x0(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let w0=_e;var b0=v0;function v0(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _0(r)}function _0(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&E0(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>w0.pick(s,["vs","i","barycenter","weight"]))}function E0(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let N0=_e;var S0=k0;function k0(e,t){let n=N0.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(j0(!!t)),c=ni(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ni(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ni(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function j0(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let C0=y0,$0=b0,M0=S0;var A0=va;function va(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=C0(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=va(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&I0(m,f)}});let u=$0(l,n);R0(u,c);let d=M0(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function R0(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function I0(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let T0=Ve.Graph,O0=_e;var L0=D0;function D0(e,t,n,r){r||(r=e.nodes());let s=P0(e),i=new T0({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function P0(e){for(var t;e.hasNode(t=O0.uniqueId("_root")););return t}var z0=H0;function H0(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let F0=d0,V0=m0,B0=A0,G0=L0,Y0=z0,X0=Ve.Graph,xn=_e;var W0=_a;function _a(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,_a);return}let n=xn.maxRank(e),r=ri(e,xn.range(1,n+1),"inEdges"),s=ri(e,xn.range(n-1,-1,-1),"outEdges"),i=F0(e);if(si(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){U0(c%2?r:s,c%4>=2),i=xn.buildLayerMatrix(e);let u=V0(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return G0(e,i,n,r.get(i)||[])})}function U0(e,t){let n=new X0;e.forEach(function(r){let s=r.graph().root,i=B0(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Y0(r,n,i.vs)})}function si(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let q0=Ve.Graph,Ze=_e;var K0={positionX:ay};function Z0(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=J0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(w=>{e.predecessors(w).forEach(y=>{let v=e.node(y),p=v.order;(p{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&Ea(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function J0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ea(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function ey(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function ty(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let w=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((w,y)=>Math.min(w,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function ry(e,t,n,r){let s=new q0,i=e.graph(),o=cy(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function sy(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=ly(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-Ze.applyWithChunking(Math.min,l);o!=="l"&&(u=s-Ze.applyWithChunking(Math.max,l)),u&&(e[a]=Ze.mapValues(c,d=>d+u))})})}function oy(e,t){return Ze.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function ay(e){let t=Ze.buildLayerMatrix(e),n=Object.assign(Z0(e,t),Q0(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=ty(e,s,n,c),u=ny(e,s,l.root,l.align,a==="r");a==="r"&&(u=Ze.mapValues(u,d=>-d)),r[o+a]=u})});let i=sy(e,r);return iy(r,i),oy(r,e.graph().align)}function cy(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function ly(e,t){return e.node(t).width}let Na=_e,uy=K0.positionX;var dy=fy;function fy(e){e=Na.asNonCompoundGraph(e),hy(e),Object.entries(uy(e)).forEach(([t,n])=>e.node(t).x=n)}function hy(e){let t=Na.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ii=pg,oi=bg,my=Gg,py=_e.normalizeRanks,gy=Ug,yy=_e.removeEmptyRanks,ai=Qg,xy=s0,ci=o0,wy=W0,by=dy,De=_e,vy=Ve.Graph;var _y=Ey;function Ey(e,t){let n=t&&t.debugTiming?De.time:De.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>Iy(e));n(" runLayout",()=>Ny(r,n,t)),n(" updateInputGraph",()=>Sy(e,r))})}function Ny(e,t,n){t(" makeSpaceForEdgeLabels",()=>Ty(e)),t(" removeSelfEdges",()=>By(e)),t(" acyclic",()=>ii.run(e)),t(" nestingGraph.run",()=>ai.run(e)),t(" rank",()=>my(De.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Oy(e)),t(" removeEmptyRanks",()=>yy(e)),t(" nestingGraph.cleanup",()=>ai.cleanup(e)),t(" normalizeRanks",()=>py(e)),t(" assignRankMinMax",()=>Ly(e)),t(" removeEdgeLabelProxies",()=>Dy(e)),t(" normalize.run",()=>oi.run(e)),t(" parentDummyChains",()=>gy(e)),t(" addBorderSegments",()=>xy(e)),t(" order",()=>wy(e,n)),t(" insertSelfEdges",()=>Gy(e)),t(" adjustCoordinateSystem",()=>ci.adjust(e)),t(" position",()=>by(e)),t(" positionSelfEdges",()=>Yy(e)),t(" removeBorderNodes",()=>Vy(e)),t(" normalize.undo",()=>oi.undo(e)),t(" fixupEdgeLabelCoords",()=>Hy(e)),t(" undoCoordinateSystem",()=>ci.undo(e)),t(" translateGraph",()=>Py(e)),t(" assignNodeIntersects",()=>zy(e)),t(" reversePoints",()=>Fy(e)),t(" acyclic.undo",()=>ii.undo(e))}function Sy(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let ky=["nodesep","edgesep","ranksep","marginx","marginy"],jy={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Cy=["acyclicer","ranker","rankdir","align"],$y=["width","height","rank"],li={width:0,height:0},My=["minlen","weight","width","height","labeloffset"],Ay={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ry=["labelpos"];function Iy(e){let t=new vy({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},jy,cr(n,ky),De.pick(n,Cy))),e.nodes().forEach(r=>{let s=lr(e.node(r));const i=cr(s,$y);Object.keys(li).forEach(o=>{i[o]===void 0&&(i[o]=li[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},Ay,cr(s,My),De.pick(s,Ry)))}),t}function Ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Oy(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};De.addDummyNode(e,"edge-proxy",i,"_ep")}})}function Ly(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Dy(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Py(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function zy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(De.intersectRect(r,i)),n.points.push(De.intersectRect(s,o))})}function Hy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Fy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Vy(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function By(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Gy(e){var t=De.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{De.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Yy(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return De.mapValues(De.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Xy=_e,Wy=Ve.Graph;var Uy={debugOrdering:qy};function qy(e){let t=Xy.buildLayerMatrix(e),n=new Wy({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var Ky="1.1.8",Zy={graphlib:Ve,layout:_y,debug:Uy,util:{time:_e.time,notime:_e.notime},version:Ky};const ui=vi(Zy),Ye=264,Qy=44,Jy=26,ex=14;function wt(e){const t=Math.max(e.attributes.length,1);return Qy+t*Jy+ex}const tx=40;function ur(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?mi(e,n,o):r==="clustered"?hi(e,t,n,o,i):r==="hierarchical"||e.length<=tx?di(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?hi(e,t,n,o,i):mi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Sa(e,t,n,r=!1,s="LR"){const i=new ui.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Ye,height:d?wt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ui.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?wt(m):120,w=d.x-Ye/2,y=d.y-f/2;return a=Math.max(a,w+Ye),c=Math.max(c,y+f),{...u,position:{x:w,y}}}),width:a,height:c}}function di(e,t,n,r="LR"){return Sa(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?wt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Ye+ka);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Ye)}),i+=Math.max(...c.map(l=>n(l.id)))+ja}return{nodes:s,width:o,height:i}}const fi=120;function hi(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),w=new Set(f.map(E=>E.id));let y=0;for(const E of t)w.has(E.source)&&w.has(E.target)&&y++;const p=f.length<=8&&y>=f.length-1?Sa(f,t,n,!0,s):rx(f,n);return{name:m,...p}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const ka=40,ja=40;function mi(e,t,n){const r=l=>{const u=t.get(l);return u?wt(u):120},s=[...e].sort((l,u)=>{var y,v;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,w=((v=t.get(u.id))==null?void 0:v.name)??u.id;return f.localeCompare(w)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Ye+ka)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ja}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function cn({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ca=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var b,M;const[r,s]=x.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[i,o]=x.useState([]),[a,c]=x.useState(null),[l,u]=x.useState(null),[d,m]=x.useState("skos:exactMatch"),[f,w]=x.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,v]=x.useState([]),[p,E]=x.useState("");x.useEffect(()=>{Qo().then(N=>v(N.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const N=setTimeout(()=>{if(!r.trim())return o([]);Zo(r,p||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(N)},[r,p]);const $=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(cn,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(p===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(N=>h.jsx("button",{className:"src-chip"+(p===N.id?" active":""),title:N.count!=null?`${N.count} terms`:"live resolver",onClick:()=>E(N.id),children:N.name},N.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:p?`Search within ${p}…`:"Search vocabulary terms…",value:r,onChange:N=>s(N.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(N=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===N.iri?" picked":""),onClick:()=>u(N),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:N.label}),h.jsxs("span",{className:"term-source",children:[N.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),N.source]})]}),h.jsx("code",{className:"term-iri",children:N.prefixed}),N.definition&&h.jsx("p",{className:"term-def",children:N.definition})]},N.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:N=>m(N.target.value),children:sx.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:N=>w(N.target.value),children:Ca.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:$,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var b,M,N;const[s,i]=x.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[o,a]=x.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},w=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${w}:`,v=(N=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:N.members.map(_=>{var R;return(R=e.attributes.find(k=>k.id===_))==null?void 0:R.name}).filter(Boolean),p=v&&v.length?`${y}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,$=s.trim()||p;return h.jsxs(cn,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",$]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=x.useState(""),[o,a]=x.useState(""),[c,l]=x.useState(""),[u,d]=x.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const w=f==null?void 0:f.created_id;n(),w&&r(w)})};return h.jsxs(cn,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ca.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const $a=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=x.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=x.useState(r??""),[m,f]=x.useState(s??(l==null?void 0:l.id)??""),[w,y]=x.useState("many_to_one"),[v,p]=x.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",$=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:w,optionality:v}).then(o);return h.jsxs(cn,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:w,onChange:b=>y(b.target.value),children:$a.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>p(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:$,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=p=>{var E;return((E=t.entities.find($=>$.id===p))==null?void 0:E.name)??"?"},[i,o]=x.useState(e.name),[a,c]=x.useState(e.cardinality),[l,u]=x.useState(e.optionality),[d,m]=x.useState(e.identifying),[f,w]=x.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(cn,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:p=>o(p.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:p=>c(p.target.value),children:$a.map(p=>h.jsx("option",{children:p},p))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:p=>u(p.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:p=>m(p.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>w(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const pi=10,ux=6,Be=24;function dx(e,t){return t?e:Math.round(e/pi)*pi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-Be,o.right+Be);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eV.transform[2]),[m,f]=x.useState(null),w=x.useRef(!1),y=x.useRef(0),v=c==null?void 0:c.onRouteChange,p=!!v,E=m??(c==null?void 0:c.routeX),[$,b,M]=Rn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),N=c==null?void 0:c.relationship,_=(c==null?void 0:c.dimmed)??!1,R=(N==null?void 0:N.cardinality)??"many_to_one",k=(N==null?void 0:N.optionality)==="optional",O=(N==null?void 0:N.identifying)??!1,D=R==="many_to_one"||R==="many_to_many",B=R==="one_to_many"||R==="many_to_many",H="rel-edge"+(l?" selected":"")+(_?" dimmed":""),g=((c==null?void 0:c.memberCount)??0)>1,C=c==null?void 0:c.onHoverEdge,S=E??b,I=M,L=S,j=I,T=x.useCallback(V=>v&&N&&v(N.id,V),[v,N]),P=x.useCallback(V=>{var pe,ce;if(!p||V.button!==0)return;V.stopPropagation(),(ce=(pe=V.target).setPointerCapture)==null||ce.call(pe,V.pointerId),w.current=!0,y.current=0;const J=u({x:V.clientX,y:V.clientY}).x;let ee=0,oe=E??S;const ne=ue=>{const ye=u({x:ue.clientX,y:ue.clientY});y.current=Math.max(y.current,Math.abs(ye.x-J)),oe=mx(ye.x,{shift:ue.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),ee||(ee=requestAnimationFrame(()=>{ee=0,f(oe)}))},re=()=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",re),ee&&cancelAnimationFrame(ee),w.current=!1,f(null),y.current>=gi&&T(oe)};window.addEventListener("pointermove",ne),window.addEventListener("pointerup",re)},[p,u,E,S,c,n,s,T]),z=x.useCallback(V=>{y.current>=gi&&(V.stopPropagation(),y.current=0)},[]),X=x.useCallback(V=>{p&&(V.stopPropagation(),T(null))},[p,T]);return h.jsxs("g",{className:H,children:[h.jsx("path",{id:t,className:"rel-path",d:$,fill:"none",strokeDasharray:O?void 0:"6 4"}),h.jsx("path",{d:$,fill:"none",strokeWidth:16/d,stroke:"transparent",onMouseEnter:C?()=>C(N.id):void 0,onMouseLeave:C?()=>C(null):void 0}),h.jsx(yi,{x:n,y:r,side:o,many:D,optional:k}),h.jsx(yi,{x:s,y:i,side:a,many:B,optional:!1}),p&&(l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:P,onClickCapture:z,onDoubleClick:X,children:[h.jsx("rect",{x:S-11/d,y:I-16/d,width:22/d,height:32/d,fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:S-4.5/d,y:I-9/d,width:9/d,height:18/d,rx:4/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I-3/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I+3/d,r:1.1/d})]}),(l||g)&&N&&h.jsxs("text",{className:"rel-label",x:L,y:j-8,children:[l?N.verb_phrase||N.name:"",g?`${l?" ":""}(${c.memberCount})`:""]})]})});function yi({x:e,y:t,side:n,many:r,optional:s}){const i=n===q.Left?-1:1,o=7,a=12,c=[];return r?c.push(h.jsx("path",{className:"rel-glyph",d:`M ${e+i*a} ${t} L ${e} ${t-o} M ${e+i*a} ${t} L ${e} ${t} M ${e+i*a} ${t} L ${e} ${t+o}`,fill:"none"},"foot")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a-3),y1:t-o,x2:e+i*(a-3),y2:t+o},"one")),s?c.push(h.jsx("circle",{className:"rel-glyph ring",cx:e+i*(a+6),cy:t,r:4},"opt")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a+5),y1:t-o,x2:e+i*(a+5),y2:t+o},"mand")),h.jsx(h.Fragment,{children:c})}const gx={entity:Pm},yx={relationship:px},xi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],wi="#8a7d6a";function xx(e,t,n){const s=Ye;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function wx(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Yr,targetHandle:n(e.to.entity,s)?s:Xr}}function qx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:w,fitBounds:y,getNodes:v}=an(),[p,E]=x.useState([]),[$,b]=x.useState([]),M=x.useRef(!1),N=x.useMemo(()=>{const F=u&&u.size>0?[...u].sort():null;return F?"sa:"+F.join("+"):"__all__"},[u]),_=x.useRef(null),[R,k]=x.useState(0),O=x.useRef(new Map),D=x.useRef(null);x.useEffect(()=>{if(!f){_.current=null;return}const F=O.current.get(N);if(F){_.current=F,M.current=!1,k(G=>G+1);return}let Y=!1;return f.load(N).then(G=>{Y||(O.current.set(N,G),_.current=G,M.current=!1,k(Q=>Q+1))}),()=>{Y=!0}},[f,N]);const[B,H]=x.useState(null),[g,C]=x.useState(null),[S,I]=x.useState(!1),[L,j]=x.useState(null),[T,P]=x.useState(null),[z,X]=x.useState(null),[V,Z]=x.useState(null),J=x.useRef({}),ee=!t.canEdit,oe=x.useRef(null),ne=x.useCallback(()=>{f&&(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{const F={};for(const Q of v())Q.hidden||(F[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,U]of Object.entries(J.current))Y[Q]={routeX:Math.round(U)};const G={nodes:F,edges:Y};O.current.set(N,G),_.current=G,f.save(N,G)},800))},[f,v,N]),re=x.useCallback((F,Y)=>{Y==null?delete J.current[F]:J.current[F]=Y,b(G=>G.map(Q=>Q.id===F?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),ne()},[ne]),pe=x.useMemo(()=>{const F=new Map;return e.subject_areas.forEach((Y,G)=>F.set(Y.id,xi[G%xi.length])),F},[e]),ce=x.useMemo(()=>{const F=new Map;return e.entities.forEach(Y=>F.set(Y.id,Y)),F},[e]),ue=x.useMemo(()=>{const F=new Map,Y=new Map;return e.subject_areas.forEach(G=>{(G.members??[]).forEach(Q=>Y.set(Q,{id:G.id,name:G.name}))}),e.entities.forEach(G=>{var se,me;const Q=(se=G.conceptual)!=null&&se.id?Y.get(G.conceptual.id):void 0,U=(me=G.conceptual)==null?void 0:me.subject_area,te=Q??(U?{id:U.id,name:U.name??U.id}:void 0);te&&F.set(G.id,te)}),F},[e]),ye=x.useCallback(F=>{var G;if(!u||u.size===0)return!1;const Y=(G=ue.get(F))==null?void 0:G.id;return!(Y&&u.has(Y))},[u,ue]),he=x.useMemo(()=>{const F=new Map,Y=(G,Q)=>{if(!Q.length)return;const U=F.get(G)??new Set;Q.forEach(te=>U.add(te)),F.set(G,U)};for(const G of e.relationships)Y(G.from.entity,G.from.attributes),Y(G.to.entity,G.to.attributes);return F},[e]);x.useEffect(()=>{var $e;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const W of e.entities)(W.name.toLowerCase()+" "+((($e=W.conceptual)==null?void 0:$e.name.toLowerCase())??"")+" "+W.attributes.map(ge=>ge.name.toLowerCase()).join(" ")).includes(F)&&Y.add(W.id);const G=new Set;if(r){G.add(r);for(const W of e.relationships)W.from.entity===r&&G.add(W.to.entity),W.to.entity===r&&G.add(W.from.entity)}const Q=e.entities.map(W=>{const fe=F!==""&&!Y.has(W.id),ge=r!==null&&!G.has(W.id);return{id:W.id,type:"entity",position:{x:0,y:0},hidden:ye(W.id),data:{entity:W,color:(()=>{const Se=ue.get(W.id);return Se?pe.get(Se.id)??wi:wi})(),dimmed:fe||ge,highlighted:F!==""&&Y.has(W.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(W.id))??!1,onToggleExpand:l,endpointAttrs:he.get(W.id),highlightAttrs:void 0,onHoverAttr:X}}}),U=e.relationships.filter(W=>ce.has(W.from.entity)&&ce.has(W.to.entity)).map(W=>{const{sourceHandle:fe,targetHandle:ge}=wx(W,ce),Se=r!==null&&W.from.entity!==r&&W.to.entity!==r;return{id:W.id,source:W.from.entity,target:W.to.entity,sourceHandle:fe,targetHandle:ge,type:"relationship",data:{relationship:W,dimmed:Se,memberCount:Math.max(W.from.attributes.length,W.to.attributes.length),onHoverEdge:Z}}}),te=_.current;if(J.current={},te)for(const[W,fe]of Object.entries(te.edges))J.current[W]=fe.routeX;let se=Q;E(W=>{const fe=new Map(W.map(ae=>[ae.id,ae.position])),ge=Q.every(ae=>fe.has(ae.id)),Se=((u==null?void 0:u.size)??0)>0;if(M.current&&ge&&W.length>=Q.length&&!Se){const ae=Q.map(Ue=>({...Ue,position:fe.get(Ue.id)??Ue.position}));return se=ae,ae}const dt=Se?Q.filter(ae=>!ae.hidden):Q,Ot=ur(dt,U,ce,"auto",ue),rt=new Map(Ot.map(ae=>[ae.id,ae.position])),ft=(te==null?void 0:te.nodes)??{},Lt=Object.keys(ft).length>0,Pe=[],Dt=Q.map(ae=>{const Ue=ft[ae.id];if(Ue){const Pt={x:Ue.x,y:Ue.y};return Pe.push({x:Pt.x,y:Pt.y,w:Ye,h:wt(ae.data.entity)}),{...ae,position:Pt}}return rt.has(ae.id)?{...ae,position:rt.get(ae.id)}:fe.has(ae.id)&&M.current?{...ae,position:fe.get(ae.id)}:ae});if(Lt)for(const ae of Dt)ft[ae.id]||ae.hidden||(ae.position=xx(ae.position,wt(ae.data.entity),Pe),Pe.push({x:ae.position.x,y:ae.position.y,w:Ye,h:wt(ae.data.entity)}));return M.current=!0,Lt||requestAnimationFrame(()=>w({padding:.15,duration:300})),se=Dt,Dt});const me=new Map;for(const W of se)me.set(W.id,{left:W.position.x,right:W.position.x+Ye});b(U.map(W=>({...W,data:{...W.data,routeX:J.current[W.id],onRouteChange:f?re:void 0,sourceCard:me.get(W.source),targetCard:me.get(W.target)}})))},[e,i,r,o,a,c,l,pe,ce,ue,ye,u,he,w,f,re,R]);const xe=x.useMemo(()=>{const F=new Set,Y=new Set,G=new Map,Q=(U,te)=>{if(!te.length)return;const se=G.get(U)??new Set;te.forEach(me=>se.add(me)),G.set(U,se)};if(z)for(const U of e.relationships)(U.from.attributes.includes(z)||U.to.attributes.includes(z))&&(F.add(U.id),Y.add(U.from.entity),Y.add(U.to.entity),Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes));if(V){const U=e.relationships.find(te=>te.id===V);U&&(Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes))}return{active:z!==null,relsForAttr:F,entsForAttr:Y,hitAttrsByEntity:G}},[e,z,V]);x.useEffect(()=>{var Q;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);const G=new Set;if(r){G.add(r);for(const U of e.relationships)U.from.entity===r&&G.add(U.to.entity),U.to.entity===r&&G.add(U.from.entity)}E(U=>U.map(te=>{const se=F!==""&&!Y.has(te.id),me=r!==null&&!G.has(te.id),$e=xe.active&&!xe.entsForAttr.has(te.id),W=se||me||$e,fe=F!==""&&Y.has(te.id)||xe.active&&xe.entsForAttr.has(te.id),ge=xe.hitAttrsByEntity.get(te.id);return te.data.dimmed===W&&te.data.highlighted===fe&&te.data.highlightAttrs===ge?te:{...te,data:{...te.data,dimmed:W,highlighted:fe,highlightAttrs:ge}}})),b(U=>U.map(te=>{var fe,ge;const se=(fe=te.data)==null?void 0:fe.relationship,me=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,$e=xe.active&&!xe.relsForAttr.has(te.id),W=me||$e;return((ge=te.data)==null?void 0:ge.dimmed)===W?te:{...te,data:{...te.data,dimmed:W}}}))},[xe,i,r,e]),x.useEffect(()=>{var Q;const F=i.trim().toLowerCase();if(!F)return;const Y=new Set;for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);if(!Y.size)return;const G=requestAnimationFrame(()=>{const U=v().filter(se=>Y.has(se.id));if(!U.length)return;const te=Mf(U);y(te,{padding:.35,duration:400})});return()=>cancelAnimationFrame(G)},[i,e,v,y]);const le=x.useCallback((F="auto",Y="LR")=>{D.current=Object.fromEntries(v().map(G=>[G.id,{x:G.position.x,y:G.position.y}])),E(G=>ur(G,$,ce,F,ue,Y)),requestAnimationFrame(()=>w({padding:.15,duration:300})),ne()},[$,ce,ue,w,v,ne]),K=x.useCallback(()=>{const F=D.current;F&&(E(Y=>Y.map(G=>F[G.id]?{...G,position:F[G.id]}:G)),D.current=null,ne())},[ne]),Ne=x.useCallback(()=>{f==null||f.reset(N),O.current.delete(N),_.current=null,J.current={},M.current=!1,b(F=>F.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(F=>{const Y=ur(F,$,ce,"auto",ue);return requestAnimationFrame(()=>w({padding:.15,duration:300})),Y})},[f,N,$,ce,ue,w]),Ce=x.useCallback(F=>{s(F),E(Y=>(Y.find(Q=>Q.id===F)&&requestAnimationFrame(()=>w({nodes:[{id:F}],padding:.4,duration:400})),Y))},[w,s]);x.useImperativeHandle(m,()=>({relayout:le,fitView:()=>w({padding:.15,duration:300}),focusEntity:Ce,newEntity:()=>I(!0),resetLayout:Ne,undoRelayout:K}),[le,w,Ce,Ne,K]);const ut=x.useCallback(F=>{if(ee||!F.source||!F.target||F.source===F.target)return;const Y=F.sourceHandle&&F.sourceHandle!==Yr?F.sourceHandle:void 0,G=F.targetHandle&&F.targetHandle!==Xr?F.targetHandle:void 0;j({from:F.source,to:F.target,fromAttr:Y,toAttr:G})},[ee]),Ae=x.useCallback(async(F,Y)=>{try{return await n(F,Y)}catch(G){throw d==null||d(G instanceof Error?G.message:String(G)),G}},[n,d]),We=r?ce.get(r)??null:null,Ie=e.relationships.find(F=>F.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Yo,{nodes:p,edges:$,nodeTypes:gx,edgeTypes:yx,onNodeClick:(F,Y)=>s(Y.id),onEdgeClick:(F,Y)=>!ee&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(F,Y)=>{E(G=>G.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),ne()},onConnect:ut,nodesConnectable:!ee,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:Le.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:F=>{var Y;return((Y=F.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),We&&h.jsx(Hm,{entity:We,doc:e,caps:t,exec:Ae,onClose:()=>s(null),onFocusEntity:Ce,onAlign:H,onEditMapping:C}),B&&h.jsx(ix,{entity:B,exec:Ae,onClose:()=>H(null)}),g&&h.jsx(ox,{entity:g,doc:e,exec:Ae,onClose:()=>C(null)}),S&&h.jsx(ax,{doc:e,exec:Ae,onClose:()=>I(!1),onCreated:Ce}),L&&h.jsx(cx,{doc:e,fromId:L.from,toId:L.to,initialFromAttr:L.fromAttr,initialToAttr:L.toAttr,exec:Ae,onClose:()=>j(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:Ae,onClose:()=>P(null)})]})}function Kx({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(bx,{}),e==="layers"&&h.jsx(_x,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(Ex,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Nx,{readOnly:n})]})}function bx(){const[e,t]=x.useState(""),[n,r]=x.useState([]),[s,i]=x.useState({loaded:0,vocabs:[]}),[o,a]=x.useState(null),[c,l]=x.useState([]),[u,d]=x.useState("");x.useEffect(()=>{Qo().then(f=>l(f.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const f=setTimeout(()=>{Zo(e||"a",u||void 0).then(w=>{r(e?w.results:[]),i({loaded:w.loaded_terms,vocabs:w.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=x.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const vx=["industry","core","domain","specialised"];function _x({refreshKey:e,onFocusEntity:t}){const[n,r]=x.useState(null),[s,i]=x.useState(null);if(x.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),vx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Ex({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=x.useState(null),[i,o]=x.useState(""),[a,c]=x.useState(""),[l,u]=x.useState(!1),d=x.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` `))).catch(()=>o(""))},[]);return x.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:i.split(` `).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index 3e5f9db..44998c6 100644 --- a/packages/server/src/mdl_server/static/index.html +++ b/packages/server/src/mdl_server/static/index.html @@ -4,9 +4,9 @@ Modelith - + - + diff --git a/packages/server/src/mdl_server/static/sme.html b/packages/server/src/mdl_server/static/sme.html index 7b1364e..132f89f 100644 --- a/packages/server/src/mdl_server/static/sme.html +++ b/packages/server/src/mdl_server/static/sme.html @@ -4,9 +4,9 @@ Modelith Glossary - + - + From c99296780e1495b3858dec08d1496f79bb297252 Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Mon, 12 Oct 2026 11:32:10 +1100 Subject: [PATCH 05/14] canvas: edge drag handle on hover; relationship editor moves to double-click MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The handle only appeared on `selected`, but selecting an edge meant single- clicking it, which opened the relationship editor — so the handle was never reachable ("on hover I don't see the drag icon; it just opens the editor"). Reserve hover/single-click for the handle and move editing to double-click: - Hovering an edge now reveals its drag grip (a `hovered` flag threaded through edge data from the existing hoveredEdge state). Hover handlers sit on the whole edge so moving from the line onto the grip keeps it mounted. - The relationship editor opens on `onEdgeDoubleClick` instead of onEdgeClick. Tests: the grip shows on hover alone (no selection); existing double-click-reset and position/zoom assertions unchanged. Verified live: hover reveals the grip, single-click no longer opens the editor, double-click does. --- canvas/src/ModelCanvas.tsx | 14 +++++++---- canvas/src/RelationshipEdge.test.tsx | 7 +++++- canvas/src/RelationshipEdge.tsx | 24 ++++++++++--------- ...m-C8Qo8i3S.js => ModelDiagram-BGW002_3.js} | 2 +- .../{main-C_g0BNSG.js => main-DzNDPWHD.js} | 2 +- .../{sme-D3j9EH3y.js => sme-BFfrsm0Q.js} | 4 ++-- ...{styles-BJTACkJo.js => styles-DdybXVuP.js} | 8 +++---- .../server/src/mdl_server/static/index.html | 4 ++-- .../server/src/mdl_server/static/sme.html | 4 ++-- 9 files changed, 41 insertions(+), 28 deletions(-) rename packages/server/src/mdl_server/static/assets/{ModelDiagram-C8Qo8i3S.js => ModelDiagram-BGW002_3.js} (97%) rename packages/server/src/mdl_server/static/assets/{main-C_g0BNSG.js => main-DzNDPWHD.js} (99%) rename packages/server/src/mdl_server/static/assets/{sme-D3j9EH3y.js => sme-BFfrsm0Q.js} (99%) rename packages/server/src/mdl_server/static/assets/{styles-BJTACkJo.js => styles-DdybXVuP.js} (85%) diff --git a/canvas/src/ModelCanvas.tsx b/canvas/src/ModelCanvas.tsx index 87bc706..f26a52c 100644 --- a/canvas/src/ModelCanvas.tsx +++ b/canvas/src/ModelCanvas.tsx @@ -581,11 +581,14 @@ export function ModelCanvas({ rel.from.entity !== selectedId && rel.to.entity !== selectedId; const hoverDim = hover.active && !hover.relsForAttr.has(r.id); const dimmed = selectDim || hoverDim; - if (r.data?.dimmed === dimmed) return r; - return { ...r, data: { ...r.data!, dimmed } }; + // the hovered edge shows its drag handle (so it is grabbable without a click, + // which now double-clicks to open the editor) + const hovered = hoveredEdge === r.id; + if (r.data?.dimmed === dimmed && r.data?.hovered === hovered) return r; + return { ...r, data: { ...r.data!, dimmed, hovered } }; }), ); - }, [hover, query, selectedId, doc]); + }, [hover, hoveredEdge, query, selectedId, doc]); // Frame the matches. In a large model the entities a search hits may be off-screen, // so highlighting alone is not enough — pan/zoom to the matched nodes (like Fit, but @@ -729,7 +732,10 @@ export function ModelCanvas({ nodeTypes={nodeTypes} edgeTypes={edgeTypes} onNodeClick={(_, n) => onSelect(n.id)} - onEdgeClick={(_, e) => !readOnly && setRelEdit(e.id)} + // Double-click opens the relationship editor; single-click/hover is reserved for + // the drag handle (hovering an edge reveals its route grip, and clicking it would + // otherwise pop the editor and steal the grab). + onEdgeDoubleClick={(_, e) => !readOnly && setRelEdit(e.id)} onPaneClick={() => { onSelect(null); setRelEdit(null); diff --git a/canvas/src/RelationshipEdge.test.tsx b/canvas/src/RelationshipEdge.test.tsx index a614f4e..735c6df 100644 --- a/canvas/src/RelationshipEdge.test.tsx +++ b/canvas/src/RelationshipEdge.test.tsx @@ -56,11 +56,16 @@ describe("RelationshipEdge drag handle", () => { expect(Number(grip!.getAttribute("width"))).toBeGreaterThanOrEqual(6); }); - it("hides the grip when not selected", () => { + it("hides the grip when neither hovered nor selected", () => { const { container } = renderEdge({ onRouteChange: vi.fn() }, false); expect(container.querySelector(".rel-handle")).toBeNull(); }); + it("shows the grip on hover alone (no selection) so it is grabbable without a click", () => { + const { container } = renderEdge({ onRouteChange: vi.fn(), hovered: true }, false); + expect(container.querySelector(".rel-handle")).not.toBeNull(); + }); + it("is not draggable (no handle) when onRouteChange is absent", () => { const { container } = renderEdge({}, true); expect(container.querySelector(".rel-handle")).toBeNull(); diff --git a/canvas/src/RelationshipEdge.tsx b/canvas/src/RelationshipEdge.tsx index 937583e..a13d4b1 100644 --- a/canvas/src/RelationshipEdge.tsx +++ b/canvas/src/RelationshipEdge.tsx @@ -9,6 +9,9 @@ export interface RelationshipEdgeData { memberCount?: number; /** hover the line -> the canvas highlights both endpoint attribute rows */ onHoverEdge?: (relId: string | null) => void; + /** true while the mouse is over this edge — shows the drag handle so it is grabbable + * without a click (the editor now opens on double-click) */ + hovered?: boolean; /** the x of the vertical segment, in flow coords. Undefined = automatic routing. */ routeX?: number; /** commit a new route (or null to reset to automatic). Absent = not draggable. */ @@ -174,7 +177,13 @@ export const RelationshipEdge = memo(function RelationshipEdge({ ); return ( - + // Hover handlers on the whole group so moving from the line onto the grip keeps the + // edge "hovered" (and the handle mounted) instead of flickering off between children. + onHover(rel!.id) : undefined} + onMouseLeave={onHover ? () => onHover(null) : undefined} + > {/* wider invisible path for easier hover/click — kept ~16px on screen at any zoom */} - onHover(rel!.id) : undefined} - onMouseLeave={onHover ? () => onHover(null) : undefined} - /> + - {/* drag handle on the vertical segment — only when draggable and hovered/selected. + {/* drag handle on the vertical segment — shown while hovered, selected, or mid-drag. Sizes are divided by the zoom so the grip keeps a constant ON-SCREEN size and stays visible + grabbable however far the canvas is zoomed out. */} - {draggable && (selected || dragX != null) && ( + {draggable && (data?.hovered || selected || dragX != null) && ( {g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; +import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-DdybXVuP.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; diff --git a/packages/server/src/mdl_server/static/assets/main-C_g0BNSG.js b/packages/server/src/mdl_server/static/assets/main-DzNDPWHD.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-C_g0BNSG.js rename to packages/server/src/mdl_server/static/assets/main-DzNDPWHD.js index 2de8ecb..a9b403a 100644 --- a/packages/server/src/mdl_server/static/assets/main-C_g0BNSG.js +++ b/packages/server/src/mdl_server/static/assets/main-DzNDPWHD.js @@ -1,2 +1,2 @@ -import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-BJTACkJo.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` +import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-DdybXVuP.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` `)||"model valid",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),M]}):F?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14}),F]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!u&&e.jsxs("button",{className:"tool-btn primary",onClick:A,title:"New entity (n)",children:[e.jsx(ye,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),E("ontology",e.jsx(be,{size:15}),"Ontology","Ontology browser"),E("layers",e.jsx(we,{size:15}),"Layers","Four-layer stack & coverage"),E("changes",e.jsx(ve,{size:15}),"Changes",k?"Uncommitted changes":"Changes",k),E("decisions",e.jsx(Me,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(w?" active":""),onClick:g,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(m?" active":""),onClick:p,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Ne,{size:15})}),e.jsx(Ke,{onRelayout:f,onReset:v}),e.jsx("button",{className:"grp-btn icon-only",onClick:y,title:"Fit view","aria-label":"Fit view",children:e.jsx(ke,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:r,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Se,{size:15})}),e.jsx(de,{exec:S,canEdit:!u,onImported:I,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:_,openImport:$})]})]})]})}const U=["LR","TB","RL","BT"],$e={LR:0,TB:90,RL:180,BT:270},se={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function Ke({onRelayout:s,onReset:l}){const[j,h]=a.useState(!1),[x,w]=a.useState("LR"),[g,m]=a.useState("auto"),p=a.useRef(null);a.useEffect(()=>{if(!j)return;const r=u=>{p.current&&!p.current.contains(u.target)&&h(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[j]);const y=r=>{m(r),s(r,x)},f=r=>{y(r),h(!1)},v=()=>{const r=U[(U.indexOf(x)+1)%U.length];w(r),s(g,r)};return e.jsxs("div",{className:"layout-picker",ref:p,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>y("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ee,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(j?" active":""),onClick:()=>h(r=>!r),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:v,title:`Flow direction: ${se[x]} (click to rotate)`,"aria-label":`Flow direction: ${se[x]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${$e[x]}deg)`},children:e.jsx(Pe,{size:15})})}),j&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>f("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>f("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>f("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>f("grid"),children:"Grid"}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"layout-menu-sep",role:"separator"}),e.jsx("button",{onClick:()=>{l(),h(!1)},title:"Clear saved positions and routes for this view",children:"Reset layout"})]})]})]})}function He(){const[s,l]=a.useState(null),[j,h]=a.useState(null),[x,w]=a.useState(null),[g,m]=a.useState(null),[p,y]=a.useState(""),[f,v]=a.useState(!0),[r,u]=a.useState(!1),[k,b]=a.useState(()=>new Set),[q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[z,D]=a.useState(()=>new Set),[K,M]=a.useState(!1),[F,E]=a.useState(0),o=a.useRef(null),L=a.useRef(""),B=a.useRef(!1),O=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((c,n)=>t.set(c.id,Y[n%Y.length])),t},[s]),H=a.useMemo(()=>{const t=new Map;if(!s)return t;const c=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(d=>c.set(d,n.id))}),s.entities.forEach(n=>{var N,Q,X;const P=((N=n.conceptual)!=null&&N.id?c.get(n.conceptual.id):void 0)??((X=(Q=n.conceptual)==null?void 0:Q.subject_area)==null?void 0:X.id)??"";t.set(n.id,P)}),t},[s]),te=a.useMemo(()=>{const t=new Map;return H.forEach(c=>t.set(c,(t.get(c)??0)+1)),t},[H]),R=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>ge(R),[R]),ae=a.useMemo(()=>ue(),[]),V=a.useMemo(()=>new URLSearchParams(window.location.search),[]),T=V.get("minimal")==="1";a.useEffect(()=>{T&&u(!0)},[T]);const re=a.useCallback(t=>{b(c=>{const n=new Set(c);return n.has(t)?n.delete(t):n.add(t),n})},[]),ce=V.get("import")==="1",W=a.useRef(!1),C=a.useCallback(()=>{J().then(l).catch(t=>w(String(t))),Z().then(h).catch(()=>h(null)),ee().then(t=>M(!!(t.git&&!t.clean))).catch(()=>M(!1)),E(t=>t+1)},[]);a.useEffect(C,[C]),a.useEffect(()=>{const t=setInterval(()=>{J().then(c=>{l(n=>n&&c.fingerprint===n.fingerprint?n:(B.current||(L.current=c.fingerprint),T||(Z().then(h).catch(()=>h(null)),ee().then(d=>M(!!(d.git&&!d.clean))).catch(()=>M(!1))),E(d=>d+1),c))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[T]),a.useEffect(()=>{s!=null&&s.fingerprint&&(L.current=s.fingerprint)},[s]);const G=a.useCallback(async(t,c)=>{if(s){B.current=!0;try{const n=await xe(t,c,L.current||s.fingerprint);return n!=null&&n.fingerprint&&(L.current=n.fingerprint),C(),n}catch(n){throw n instanceof pe&&n.status===409?(m("Model changed on disk — view refreshed, please retry."),C()):m(n instanceof Error?n.message:String(n)),n}finally{B.current=!1}}},[s,C]);a.useEffect(()=>{if(!g)return;const t=setTimeout(()=>m(null),5e3);return()=>clearTimeout(t)},[g]),a.useEffect(()=>{if(!s||W.current)return;const t=V.get("focus");if(!t)return;const c=s.entities.find(n=>{var d;return n.name===t||((d=n.conceptual)==null?void 0:d.name)===t});c&&(W.current=!0,requestAnimationFrame(()=>{var n;return(n=o.current)==null?void 0:n.focusEntity(c.id)}))},[s,V]);const oe=a.useCallback(()=>{var n;if(!s)return;const t=p.trim().toLowerCase();if(!t)return;const c=s.entities.find(d=>{var N;return(d.name.toLowerCase()+" "+(((N=d.conceptual)==null?void 0:N.name.toLowerCase())??"")+" "+d.attributes.map(Q=>Q.name.toLowerCase()).join(" ")).includes(t)});c&&((n=o.current)==null||n.focusEntity(c.id))},[s,p]);return a.useEffect(()=>{const t=c=>{var d,P,N;const n=(d=document.activeElement)==null?void 0:d.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(c.key==="/"&&(c.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),c.key==="n"&&!R&&((N=o.current)==null||N.newEntity()),c.key==="Escape"&&(A(null),y(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[R]),x?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:x}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!T&&e.jsx(_e,{doc:s,diagnostics:j,query:p,onQuery:y,onSubmitQuery:oe,showTypes:f,onToggleTypes:()=>v(t=>!t),collapseDetail:r,onToggleCollapse:()=>u(t=>!t),onFitView:()=>{var t;return(t=o.current)==null?void 0:t.fitView()},onRelayout:(t,c)=>{var n;return(n=o.current)==null?void 0:n.relayout(t,c)},onResetLayout:()=>{var t;return(t=o.current)==null?void 0:t.resetLayout()},onRefresh:C,readOnly:R,dirty:K,panelTab:S,onPanelTab:t=>I(c=>c===t?null:t),onNewEntity:()=>{var t;return(t=o.current)==null?void 0:t.newEntity()},exec:G,onImported:C,onImportBatch:je,openImport:ce,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:z.size}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(me,{doc:s,caps:ne,exec:G,selectedId:S?null:q,onSelect:A,query:p,showTypes:f,collapseDetail:r,expandedEntities:k,onToggleExpand:re,activeAreas:z,onError:m,handleRef:o,layoutStore:ae}),!T&&e.jsx(Ae,{doc:s,saColors:O,countByArea:te,activeAreas:z,onSetActive:D,open:_,onClose:()=>$(!1)}),S&&e.jsx(fe,{tab:S,onClose:()=>I(null),readOnly:R,refreshKey:F,onModelChanged:C,onFocusEntity:t=>{var c;I(null),(c=o.current)==null||c.focusEntity(t)}}),g&&e.jsx("div",{className:"toast",children:g})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ve(){return e.jsx(he,{children:e.jsx(He,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(le.StrictMode,{children:e.jsx(Ve,{})})); diff --git a/packages/server/src/mdl_server/static/assets/sme-D3j9EH3y.js b/packages/server/src/mdl_server/static/assets/sme-BFfrsm0Q.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-D3j9EH3y.js rename to packages/server/src/mdl_server/static/assets/sme-BFfrsm0Q.js index 711fb90..1956c24 100644 --- a/packages/server/src/mdl_server/static/assets/sme-D3j9EH3y.js +++ b/packages/server/src/mdl_server/static/assets/sme-BFfrsm0Q.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-C8Qo8i3S.js","assets/client-DOmNpTln.js","assets/styles-BJTACkJo.js","assets/styles-BpoQ4C-h.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-BJTACkJo.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-C8Qo8i3S.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-BGW002_3.js","assets/client-DOmNpTln.js","assets/styles-DdybXVuP.js","assets/styles-BpoQ4C-h.css"])))=>i.map(i=>d[i]); +import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-DdybXVuP.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-BGW002_3.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); diff --git a/packages/server/src/mdl_server/static/assets/styles-BJTACkJo.js b/packages/server/src/mdl_server/static/assets/styles-DdybXVuP.js similarity index 85% rename from packages/server/src/mdl_server/static/assets/styles-BJTACkJo.js rename to packages/server/src/mdl_server/static/assets/styles-DdybXVuP.js index d42b896..02cd638 100644 --- a/packages/server/src/mdl_server/static/assets/styles-BJTACkJo.js +++ b/packages/server/src/mdl_server/static/assets/styles-DdybXVuP.js @@ -1,4 +1,4 @@ -var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ve=(e,t,n)=>oc(e,typeof t!="symbol"?t+"":t,n);import{r as x,g as vi,R as A,j as h}from"./client-DOmNpTln.js";function je(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;nt in e?ic(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _e=(e,t,n)=>oc(e,typeof t!="symbol"?t+"":t,n);import{r as x,g as vi,R as A,j as h}from"./client-DOmNpTln.js";function je(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;nt in e?ic(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Dn=x,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=Dn.useRef,_c=Dn.useEffect,Ec=Dn.useMemo,Nc=Dn.useDebugValue;Ei.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var w=o.value;if(s(w,f))return d=w}return d=f}if(w=d,wc(u,f))return w;var y=r(f);return s!==void 0&&s(w,y)?(u=f,w):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};_i.exports=Ei;var Sc=_i.exports;const kc=vi(Sc),jc={},es=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(w=>w(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?es(e):es,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function ki(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const ts=(e,t)=>{const n=Cc(e),r=(s,i=t)=>ki(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?ts(e,t):ts;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rs.hasOwnProperty(t)?{space:rs[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===dr&&t.documentElement.namespaceURI===dr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ji(e){var t=zn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function Cr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=Cr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=$&&($=E+1);!(M=v[$])&&++$=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Rt(this.node(),e)}function Rt(e,t){return e.style.getPropertyValue(t)||Ri(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ii(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Ti(e)}function Ti(e){this._node=e,this._names=Ii(e.getAttribute("class")||"")}Ti.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Oi(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function fr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}fr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Pn("start","drag","end"),o=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",p,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,M){if(!(u||!e.call(this,b,M))){var N=$(this,t.call(this,b,M),b,M,"mouse");N&&(Te(b.view).on("mousemove.drag",w,Ut).on("mouseup.drag",y,Ut),zi(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,N("start",b))}}function w(b){if(Ct(b),!l){var M=b.clientX-a,N=b.clientY-c;l=M*M+N*N>d}s.mouse("drag",b)}function y(b){Te(b.view).on("mousemove.drag mouseup.drag",null),Hi(b.view,l),Ct(b),s.mouse("end",b)}function v(b,M){if(e.call(this,b,M)){var N=b.changedTouches,_=t.call(this,b,M),R=N.length,k,O;for(k=0;k>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?un(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?un(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Me(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Me(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?un(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?un(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?us(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?us(t[1],t[2]/100,t[3]/100,t[4]):ss.hasOwnProperty(e)?as(ss[e]):e==="transparent"?new Me(NaN,NaN,NaN,0):null}function as(e){return new Me(e>>16&255,e>>8&255,e&255,1)}function un(e,t,n,r){return r<=0&&(e=t=n=NaN),new Me(e,t,n,r)}function Mu(e){return e instanceof rn||(e=Zt(e)),e?(e=e.rgb(),new Me(e.r,e.g,e.b,e.opacity)):new Me}function hr(e,t,n,r){return arguments.length===1?Mu(e):new Me(e,t,n,r??1)}function Me(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Mr(Me,hr,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Me(yt(this.r),yt(this.g),yt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:cs,formatHex:cs,formatHex8:Au,formatRgb:ls,toString:ls}));function cs(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function ls(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function us(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new He(e,t,n,r)}function Vi(e){if(e instanceof He)return new He(e.h,e.s,e.l,e.opacity);if(e instanceof rn||(e=Zt(e)),!e)return new He;if(e instanceof He)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new He(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Vi(e):new He(e,t,n,r??1)}function He(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Mr(He,Ru,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new He(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new He(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Me(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new He(ds(this.h),dn(this.s),dn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${ds(this.h)}, ${dn(this.s)*100}%, ${dn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ds(e){return e=(e||0)%360,e<0?e+360:e}function dn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Bi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Gi:function(t,n){return n-t?Tu(t,n,e):Bi(isNaN(t)?n:t)}}function Gi(e,t){var n=t-e;return n?Iu(e,n):Bi(isNaN(e)?t:e)}const fs=function e(t){var n=Ou(t);function r(s,i){var o=n((s=hr(s)).r,(i=hr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Gi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function it(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var mr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(mr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=mr.lastIndex=Kn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=mr.exec(e))&&(s=Kn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:it(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:it(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:it(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,w){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");w.push({i:y-4,x:it(l,d)},{i:y-2,x:it(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var w=-1,y=m.length,v;++w=0&&e._call.call(void 0,t),e=e._next;--It}function ps(){bt=(Cn=Qt.now())+Hn,It=Gt=0;try{Uu()}finally{It=0,Ku(),bt=0}}function qu(){var e=Qt.now(),t=e-Cn;t>Wi&&(Hn-=t,Cn=e)}function Ku(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Yt=e,gr(r)}function gr(e){if(!It){Gt&&(Gt=clearTimeout(Gt));var t=e-bt;t>24?(e<1/0&&(Gt=setTimeout(ps,e-Qt.now()-Hn)),zt&&(zt=clearInterval(zt))):(zt||(Cn=Qt.now(),zt=setInterval(qu,Wi)),It=1,Ui(ps))}}function gs(e,t,n){var r=new $n;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Pn("start","end","cancel","interrupt"),Qu=[],Ki=0,ys=1,yr=2,vn=3,xs=4,xr=5,_n=6;function Fn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Ki})}function Rr(e,t){var n=Fe(e,t);if(n.state>Ki)throw new Error("too late; already scheduled");return n}function Xe(e,t){var n=Fe(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Fe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=qi(i,0,n.time);function i(l){n.state=ys,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ys)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return gs(o);f.state===xs?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uyr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Rr:Xe;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Fe(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Cr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Qe(e,t,n){this.k=e,this.x=t,this.y=n}Qe.prototype={constructor:Qe,scale:function(e){return e===1?this:new Qe(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Qe(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Je=new Qe(1,0,0);Qe.prototype;function Zn(e){e.stopImmediatePropagation()}function Ht(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ws(){return this.__zoom||Je}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function eo(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Xu,l=Pn("start","zoom","end"),u,d,m,f=500,w=150,y=0,v=10;function p(g){g.property("__zoom",ws).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",D).on("touchmove.zoom",B).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}p.transform=function(g,C,S,I){var L=g.selection?g.selection():g;L.property("__zoom",ws),g!==L?M(g,C,S,I):L.interrupt().each(function(){N(this,arguments).event(I).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},p.scaleBy=function(g,C,S,I){p.scaleTo(g,function(){var L=this.__zoom.k,j=typeof C=="function"?C.apply(this,arguments):C;return L*j},S,I)},p.scaleTo=function(g,C,S,I){p.transform(g,function(){var L=t.apply(this,arguments),j=this.__zoom,T=S==null?b(L):typeof S=="function"?S.apply(this,arguments):S,P=j.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n($(E(j,z),T,P),L,o)},S,I)},p.translateBy=function(g,C,S,I){p.transform(g,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,I)},p.translateTo=function(g,C,S,I,L){p.transform(g,function(){var j=t.apply(this,arguments),T=this.__zoom,P=I==null?b(j):typeof I=="function"?I.apply(this,arguments):I;return n(Je.translate(P[0],P[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof S=="function"?-S.apply(this,arguments):-S),j,o)},I,L)};function E(g,C){return C=Math.max(i[0],Math.min(i[1],C)),C===g.k?g:new Qe(C,g.x,g.y)}function $(g,C,S){var I=C[0]-S[0]*g.k,L=C[1]-S[1]*g.k;return I===g.x&&L===g.y?g:new Qe(g.k,I,L)}function b(g){return[(+g[0][0]+ +g[1][0])/2,(+g[0][1]+ +g[1][1])/2]}function M(g,C,S,I){g.on("start.zoom",function(){N(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(I).end()}).tween("zoom",function(){var L=this,j=arguments,T=N(L,j).event(I),P=t.apply(L,j),z=S==null?b(P):typeof S=="function"?S.apply(L,j):S,X=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),V=L.__zoom,Z=typeof C=="function"?C.apply(L,j):C,J=c(V.invert(z).concat(X/V.k),Z.invert(z).concat(X/Z.k));return function(ee){if(ee===1)ee=Z;else{var oe=J(ee),ne=X/oe[2];ee=new Qe(ne,z[0]-oe[0]*ne,z[1]-oe[1]*ne)}T.zoom(null,ee)}})}function N(g,C,S){return!S&&g.__zooming||new _(g,C)}function _(g,C){this.that=g,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(g,C),this.taps=0}_.prototype={event:function(g){return g&&(this.sourceEvent=g),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(g,C){return this.mouse&&g!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&g!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&g!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(g){var C=Te(this.that).datum();l.call(g,this.that,new sf(g,{sourceEvent:this.sourceEvent,target:p,transform:this.that.__zoom,dispatch:l}),C)}};function R(g,...C){if(!e.apply(this,arguments))return;var S=N(this,C).event(g),I=this.__zoom,L=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,r.apply(this,arguments)))),j=ze(g);if(S.wheel)(S.mouse[0][0]!==j[0]||S.mouse[0][1]!==j[1])&&(S.mouse[1]=I.invert(S.mouse[0]=j)),clearTimeout(S.wheel);else{if(I.k===L)return;S.mouse=[j,I.invert(j)],En(this),S.start()}Ht(g),S.wheel=setTimeout(T,w),S.zoom("mouse",n($(E(I,L),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function k(g,...C){if(m||!e.apply(this,arguments))return;var S=g.currentTarget,I=N(this,C,!0).event(g),L=Te(g.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",X,!0),j=ze(g,S),T=g.clientX,P=g.clientY;zi(g.view),Zn(g),I.mouse=[j,this.__zoom.invert(j)],En(this),I.start();function z(V){if(Ht(V),!I.moved){var Z=V.clientX-T,J=V.clientY-P;I.moved=Z*Z+J*J>y}I.event(V).zoom("mouse",n($(I.that.__zoom,I.mouse[0]=ze(V,S),I.mouse[1]),I.extent,o))}function X(V){L.on("mousemove.zoom mouseup.zoom",null),Hi(V.view,I.moved),Ht(V),I.event(V).end()}}function O(g,...C){if(e.apply(this,arguments)){var S=this.__zoom,I=ze(g.changedTouches?g.changedTouches[0]:g,this),L=S.invert(I),j=S.k*(g.shiftKey?.5:2),T=n($(E(S,j),I,L),t.apply(this,C),o);Ht(g),a>0?Te(this).transition().duration(a).call(M,T,I,g):Te(this).call(p.transform,T,I,g)}}function D(g,...C){if(e.apply(this,arguments)){var S=g.touches,I=S.length,L=N(this,C,g.changedTouches.length===I).event(g),j,T,P,z;for(Zn(g),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},to=tt.error001();function de(e,t){const n=x.useContext(Vn);if(n===null)throw new Error(to);return ki(n,e,t)}const Ee=()=>{const e=x.useContext(Vn);if(e===null)throw new Error(to);return x.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Tr({position:e,children:t,className:n,style:r,...s}){const i=de(ff),o=`${e}`.split("-");return A.createElement("div",{className:je(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Tr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=x.useRef(null),[m,f]=x.useState({x:0,y:0,width:0,height:0}),w=je(["react-flow__edge-textwrapper",l]);return x.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:w,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=x.memo(mf);const Or=e=>({width:e.offsetWidth,height:e.offsetHeight}),Tt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Lr=(e={x:0,y:0},t)=>({x:Tt(e.x,t[0][0],t[1][0]),y:Tt(e.y,t[0][1],t[1][1])}),bs=(e,t,n)=>en?-Tt(Math.abs(e-n),1,50)/50:0,no=(e,t)=>{const n=bs(e.x,35,t.width-35)*20,r=bs(e.y,35,t.height-35)*20;return[n,r]},ro=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},so=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Jt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),io=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),vs=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>io(so(Jt(e),Jt(t))),wr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Oe(e.width)&&Oe(e.height)&&Oe(e.x)&&Oe(e.y),Oe=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),oo=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function br(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const ao=e=>"clientX"in e,lt=(e,t)=>{var i,o;const n=ao(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Mn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},sn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Oe(n)&&Oe(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);sn.displayName="BaseEdge";function Ft(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function co({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[v,p,E]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(sn,{path:v,labelX:p,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:y})});Dr.displayName="SimpleBezierEdge";const Es={[q.Left]:{x:-1,y:0},[q.Right]:{x:1,y:0},[q.Top]:{x:0,y:-1},[q.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=q.Bottom,target:n})=>t===q.Left||t===q.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=q.Bottom,target:n,targetPosition:r=q.Top,center:s,offset:i}){const o=Es[t],a=Es[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],w,y;const v={x:0,y:0},p={x:0,y:0},[E,$,b,M]=co({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){w=s.x??E,y=s.y??$;const _=[{x:w,y:c.y},{x:w,y:l.y}],R=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?R:_:f=o.y===m?_:R,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const g=Math.min(i-1,i-H);o[d]===m?v[d]=(c[d]>e[d]?-1:1)*g:p[d]=(l[d]>n[d]?-1:1)*g}}if(t!==r){const H=d==="x"?"y":"x",g=o[d]===a[H],C=c[H]>l[H],S=c[H]=B?(w=(k.x+O.x)/2,y=f[0].y):(w=f[0].x,y=(k.y+O.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:l.x+p.x,y:l.y+p.y},n],w,y,b,M]}function _f(e,t,n,r){const s=Math.min(Ns(e,t)/2,Ns(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let $="";return E>0&&E{const[p,E,$]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:w,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const Pr=x.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:x.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Pr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=co({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const zr=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[w,y,v]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(sn,{path:w,labelX:y,labelY:v,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});zr.displayName="StraightEdge";function mn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Ss({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case q.Left:return[t-mn(t-r,i),n];case q.Right:return[t+mn(r-t,i),n];case q.Top:return[t,n-mn(n-s,i)];case q.Bottom:return[t,n+mn(s-n,i)]}}function fo({sourceX:e,sourceY:t,sourcePosition:n=q.Bottom,targetX:r,targetY:s,targetPosition:i=q.Top,curvature:o=.25}){const[a,c]=Ss({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Ss({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,w]=lo({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,w]}const In=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=q.Bottom,targetPosition:i=q.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,pathOptions:y,interactionWidth:v})=>{const[p,E,$]=fo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:v})});In.displayName="BezierEdge";const Hr=x.createContext(null),Nf=Hr.Provider;Hr.Consumer;const Sf=()=>x.useContext(Hr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,vr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},_r=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},ho=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},on=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return so(r,Jt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return io(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),on(e,t)),mo=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:w=!1}=u;if(o&&!f||w)return!1;const{positionAbsolute:y}=xt(u,a),v={x:y.x,y:y.y,width:d||0,height:m||0},p=wr(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,$=i&&p>0,b=(d||0)*(m||0);(E||$||p>=b||u.dragging)&&l.push(u)}),l},po=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},go=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Tt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function ks(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=lt(e),l=t.elementsFromPoint(o,a).find(w=>w.classList.contains("react-flow__handle"));if(l){const w=l.getAttribute("data-nodeid");if(w){const y=Fr(void 0,l),v=l.getAttribute("data-handleid"),p=i({nodeId:w,id:v,type:y});if(p){const E=s.find($=>$.nodeId===w&&$.type===y&&$.id===v);return{handle:{id:v,type:y,nodeId:w,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:p}}}}let u=[],d=1/0;if(s.forEach(w=>{const y=Math.sqrt((w.x-n.x)**2+(w.y-n.y)**2);if(y<=r){const v=i(w);y<=d&&(yw.isValid),f=u.some(({handle:w})=>w.type==="target");return u.find(({handle:w,validHandleResult:y})=>f?w.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},yo=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function xo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...yo(),handleDomNode:c};if(c){const u=Fr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),w=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&w&&(t===vt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=ks(i,o,"source",`${t}-${n}-${r}`),c=ks(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Fr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function wo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ro(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:w,onConnectStart:y,panBy:v,getNodes:p,cancelConnection:E}=i();let $=0,b;const{x:M,y:N}=lt(e),_=u==null?void 0:u.elementFromPoint(M,N),R=Fr(c,_),k=m==null?void 0:m.getBoundingClientRect();if(!k||!R)return;let O,D=lt(e,k),B=!1,H=null,g=!1,C=null;const S=If({nodes:p(),nodeId:n,handleId:t,handleType:R}),I=()=>{if(!f)return;const[T,P]=no(D,k);v({x:T,y:P}),$=requestAnimationFrame(I)};o({connectionPosition:D,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:R});function L(T){const{transform:P}=i();D=lt(T,k);const{handle:z,validHandleResult:X}=Af(T,u,_r(D,P,!1,[1,1]),w,S,V=>xo(V,d,n,t,s?"target":"source",a,u));if(b=z,B||(I(),B=!0),C=X.handleDomNode,H=X.connection,g=X.isValid,o({connectionPosition:b&&g?ho({x:b.x,y:b.y},P):D,connectionStatus:Tf(!!b,g),connectionEndHandle:X.endHandle}),!b&&!g&&!C)return Qn(O);H.source!==H.target&&C&&(Qn(O),O=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",g),C.classList.toggle("react-flow__handle-valid",g))}function j(T){var P,z;(b||C)&&H&&g&&(r==null||r(H)),(z=(P=i()).onConnectEnd)==null||z.call(P,T),c&&(l==null||l(T)),Qn(O),E(),cancelAnimationFrame($),B=!1,g=!1,H=null,C=null,u.removeEventListener("mousemove",L),u.removeEventListener("mouseup",j),u.removeEventListener("touchmove",L),u.removeEventListener("touchend",j)}u.addEventListener("mousemove",L),u.addEventListener("mouseup",j),u.addEventListener("touchmove",L),u.addEventListener("touchend",j)}const js=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},bo=x.forwardRef(({type:e="source",position:t=q.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var k,O;const w=o||null,y=e==="target",v=Ee(),p=Sf(),{connectOnClick:E,noPanClassName:$}=de(Of,ke),{connecting:b,clickConnecting:M}=de(Lf(p,w,e),ke);p||(O=(k=v.getState()).onError)==null||O.call(k,"010",tt.error010());const N=D=>{const{defaultEdgeOptions:B,onConnect:H,hasDefaultEdges:g}=v.getState(),C={...B,...D};if(g){const{edges:S,setEdges:I}=v.getState();I($f(C,S))}H==null||H(C),a==null||a(C)},_=D=>{if(!p)return;const B=ao(D);s&&(B&&D.button===0||!B)&&wo({event:D,handleId:w,nodeId:p,onConnect:N,isTarget:y,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||js}),B?u==null||u(D):d==null||d(D)},R=D=>{const{onClickConnectStart:B,onClickConnectEnd:H,connectionClickStartHandle:g,connectionMode:C,isValidConnection:S}=v.getState();if(!p||!g&&!s)return;if(!g){B==null||B(D,{nodeId:p,handleId:w,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:p,type:e,handleId:w}});return}const I=ro(D.target),L=n||S||js,{connection:j,isValid:T}=xo({nodeId:p,id:w,type:e},C,g.nodeId,g.handleId||null,g.type,L,I);T&&N(j),H==null||H(D),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":w,"data-nodeid":p,"data-handlepos":t,"data-id":`${p}-${w}-${e}`,className:je(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",$,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!b||i&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});bo.displayName="Handle";var ct=x.memo(bo);const vo=({data:e,isConnectable:t,targetPosition:n=q.Top,sourcePosition:r=q.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ct,{type:"source",position:r,isConnectable:t}));vo.displayName="DefaultNode";var Er=x.memo(vo);const _o=({data:e,isConnectable:t,sourcePosition:n=q.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ct,{type:"source",position:n,isConnectable:t}));_o.displayName="InputNode";var Eo=x.memo(_o);const No=({data:e,isConnectable:t,targetPosition:n=q.Top})=>A.createElement(A.Fragment,null,A.createElement(ct,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);No.displayName="OutputNode";var So=x.memo(No);const Vr=()=>null;Vr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),pn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(pn),t.selectedNodes.map(pn))&&ke(e.selectedEdges.map(pn),t.selectedEdges.map(pn))}const ko=x.memo(({onSelectionChange:e})=>{const t=Ee(),{selectedNodes:n,selectedEdges:r}=de(Df,Pf);return x.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});ko.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=de(zf);return e||t?A.createElement(ko,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Et(e,t){x.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ie(e,t,n){x.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:w,minZoom:y,maxZoom:v,nodeExtent:p,onNodesChange:E,onEdgesChange:$,elementsSelectable:b,connectionMode:M,snapGrid:N,snapToGrid:_,translateExtent:R,connectOnClick:k,defaultEdgeOptions:O,fitView:D,fitViewOptions:B,onNodesDelete:H,onEdgesDelete:g,onNodeDrag:C,onNodeDragStart:S,onNodeDragStop:I,onSelectionDrag:L,onSelectionDragStart:j,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:X,autoPanOnConnect:V,autoPanOnNodeDrag:Z,onError:J,connectionRadius:ee,isValidConnection:oe,nodeDragThreshold:ne})=>{const{setNodes:re,setEdges:pe,setDefaultNodesAndEdges:ce,setMinZoom:ue,setMaxZoom:ye,setTranslateExtent:he,setNodeExtent:xe,reset:le}=de(Ff,ke),K=Ee();return x.useEffect(()=>{const Ne=r==null?void 0:r.map(Ce=>({...Ce,...O}));return ce(n,Ne),()=>{le()}},[]),ie("defaultEdgeOptions",O,K.setState),ie("connectionMode",M,K.setState),ie("onConnect",s,K.setState),ie("onConnectStart",i,K.setState),ie("onConnectEnd",o,K.setState),ie("onClickConnectStart",a,K.setState),ie("onClickConnectEnd",c,K.setState),ie("nodesDraggable",l,K.setState),ie("nodesConnectable",u,K.setState),ie("nodesFocusable",d,K.setState),ie("edgesFocusable",m,K.setState),ie("edgesUpdatable",f,K.setState),ie("elementsSelectable",b,K.setState),ie("elevateNodesOnSelect",w,K.setState),ie("snapToGrid",_,K.setState),ie("snapGrid",N,K.setState),ie("onNodesChange",E,K.setState),ie("onEdgesChange",$,K.setState),ie("connectOnClick",k,K.setState),ie("fitViewOnInit",D,K.setState),ie("fitViewOnInitOptions",B,K.setState),ie("onNodesDelete",H,K.setState),ie("onEdgesDelete",g,K.setState),ie("onNodeDrag",C,K.setState),ie("onNodeDragStart",S,K.setState),ie("onNodeDragStop",I,K.setState),ie("onSelectionDrag",L,K.setState),ie("onSelectionDragStart",j,K.setState),ie("onSelectionDragStop",T,K.setState),ie("noPanClassName",P,K.setState),ie("nodeOrigin",z,K.setState),ie("rfId",X,K.setState),ie("autoPanOnConnect",V,K.setState),ie("autoPanOnNodeDrag",Z,K.setState),ie("onError",J,K.setState),ie("connectionRadius",ee,K.setState),ie("isValidConnection",oe,K.setState),ie("nodeDragThreshold",ne,K.setState),Et(e,re),Et(t,pe),Et(y,ue),Et(v,ye),Et(R,he),Et(p,xe),null},Cs={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},jo="react-flow__node-desc",Co="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Xf({rfId:e}){const t=de(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Wf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${jo}-${e}`,style:Cs},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Co}-${e}`,style:Cs},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Xf,{rfId:e}))}var tn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=x.useState(!1),s=x.useRef(!1),i=x.useRef(new Set([])),[o,a]=x.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return x.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);i.current.add(f[y]),$s(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);$s(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Ms(e,t){return t.includes(e)?"code":"key"}function $o(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return $o(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function Mo(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=$o(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Oe(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Mo(s,n,i),s}function Ao(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const w=n().filter(v=>{var E;const p=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?p&&t.nodes.some($=>$.id===v.id):p}),y=w.every(v=>v.width&&v.height);if(w.length>0&&y){const v=on(w,d),{x:p,y:E,zoom:$}=go(v,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),b=Je.translate(p,E).scale($);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Uf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function gn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Uf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const Nt=()=>{},Kf={zoomIn:Nt,zoomOut:Nt,zoomTo:Nt,getZoom:()=>1,setViewport:Nt,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:Nt,fitBounds:Nt,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Ee(),{d3Zoom:t,d3Selection:n}=de(Zf,ke);return x.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=Je.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Ao(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=Je.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=go(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=Je.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),_r(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return _r(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=ho(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function an(){const e=Qf(),t=Ee(),n=x.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=x.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=x.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(v=>({...v}))},[]),i=x.useCallback(y=>{const{edges:v=[]}=t.getState();return v.find(p=>p.id===y)},[]),o=x.useCallback(y=>{const{getNodes:v,setNodes:p,hasDefaultNodes:E,onNodesChange:$}=t.getState(),b=v(),M=typeof y=="function"?y(b):y;if(E)p(M);else if($){const N=M.length===0?b.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));$(N)}},[]),a=x.useCallback(y=>{const{edges:v=[],setEdges:p,hasDefaultEdges:E,onEdgesChange:$}=t.getState(),b=typeof y=="function"?y(v):y;if(E)p(b);else if($){const M=b.length===0?v.map(N=>({type:"remove",id:N.id})):b.map(N=>({item:N,type:"reset"}));$(M)}},[]),c=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{getNodes:p,setNodes:E,hasDefaultNodes:$,onNodesChange:b}=t.getState();if($){const N=[...p(),...v];E(N)}else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),l=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{edges:p=[],setEdges:E,hasDefaultEdges:$,onEdgesChange:b}=t.getState();if($)E([...p,...v]);else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),u=x.useCallback(()=>{const{getNodes:y,edges:v=[],transform:p}=t.getState(),[E,$,b]=p;return{nodes:y().map(M=>({...M})),edges:v.map(M=>({...M})),viewport:{x:E,y:$,zoom:b}}},[]),d=x.useCallback(({nodes:y,edges:v})=>{const{nodeInternals:p,getNodes:E,edges:$,hasDefaultNodes:b,hasDefaultEdges:M,onNodesDelete:N,onEdgesDelete:_,onNodesChange:R,onEdgesChange:k}=t.getState(),O=(y||[]).map(C=>C.id),D=(v||[]).map(C=>C.id),B=E().reduce((C,S)=>{const I=S.parentNode||S.parentId,L=!O.includes(S.id)&&I&&C.find(T=>T.id===I);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(O.includes(S.id)||L)&&C.push(S),C},[]),H=$.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),g=H.filter(C=>D.includes(C.id));if(B||g){const C=po(B,H),S=[...g,...C],I=S.reduce((L,j)=>(L.includes(j.id)||L.push(j.id),L),[]);if((M||b)&&(M&&t.setState({edges:$.filter(L=>!I.includes(L.id))}),b&&(B.forEach(L=>{p.delete(L.id)}),t.setState({nodeInternals:new Map(p)}))),I.length>0&&(_==null||_(S),k&&k(I.map(L=>({id:L,type:"remove"})))),B.length>0&&(N==null||N(B),R)){const L=B.map(j=>({id:j.id,type:"remove"}));R(L)}}},[]),m=x.useCallback(y=>{const v=yf(y),p=v?null:t.getState().nodeInternals.get(y.id);return!v&&!p?[null,null,v]:[v?y:vs(p),p,v]},[]),f=x.useCallback((y,v=!0,p)=>{const[E,$,b]=m(y);return E?(p||t.getState().getNodes()).filter(M=>{if(!b&&(M.id===$.id||!M.positionAbsolute))return!1;const N=vs(M),_=wr(N,E);return v&&_>0||_>=E.width*E.height}):[]},[]),w=x.useCallback((y,v,p=!0)=>{const[E]=m(y);if(!E)return!1;const $=wr(E,v);return p&&$>0||$>=E.width*E.height},[]);return x.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:w}),[e,n,r,s,i,o,a,c,l,u,d,f,w])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ee(),{deleteElements:r}=an(),s=tn(e,Jf),i=tn(t);x.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),x.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Ee();x.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Or(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",tt.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Br={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,yn=e=>({x:e.x,y:e.y,zoom:e.k}),St=(e,t)=>e.target.closest(`.${t}`),As=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rs=e=>{const t=e.ctrlKey&&Mn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:w,maxZoom:y,zoomActivationKeyCode:v,preventScrolling:p=!0,children:E,noWheelClassName:$,noPanClassName:b})=>{const M=x.useRef(),N=Ee(),_=x.useRef(!1),R=x.useRef(!1),k=x.useRef(null),O=x.useRef({x:0,y:0,zoom:0}),{d3Zoom:D,d3Selection:B,d3ZoomHandler:H,userSelectionActive:g}=de(rh,ke),C=tn(v),S=x.useRef(0),I=x.useRef(!1),L=x.useRef();return th(k),x.useEffect(()=>{if(k.current){const j=k.current.getBoundingClientRect(),T=eo().scaleExtent([w,y]).translateExtent(f),P=Te(k.current).call(T),z=Je.translate(m.x,m.y).scale(Tt(m.zoom,w,y)),X=[[0,0],[j.width,j.height]],V=T.constrain()(z,X,f);T.transform(P,V),T.wheelDelta(Rs),N.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[V.x,V.y,V.k],domNode:k.current.closest(".react-flow")})}},[]),x.useEffect(()=>{B&&D&&(o&&!C&&!g?B.on("wheel.zoom",j=>{if(St(j,$))return!1;j.preventDefault(),j.stopImmediatePropagation();const T=B.property("__zoom").k||1;if(j.ctrlKey&&i){const oe=ze(j),ne=Rs(j),re=T*Math.pow(2,ne);D.scaleTo(B,re,oe,j);return}const P=j.deltaMode===1?20:1;let z=c===gt.Vertical?0:j.deltaX*P,X=c===gt.Horizontal?0:j.deltaY*P;!Mn()&&j.shiftKey&&c!==gt.Vertical&&(z=j.deltaY*P,X=0),D.translateBy(B,-(z/T)*a,-(X/T)*a,{internal:!0});const V=yn(B.property("__zoom")),{onViewportChangeStart:Z,onViewportChange:J,onViewportChangeEnd:ee}=N.getState();clearTimeout(L.current),I.current||(I.current=!0,t==null||t(j,V),Z==null||Z(V)),I.current&&(e==null||e(j,V),J==null||J(V),L.current=setTimeout(()=>{n==null||n(j,V),ee==null||ee(V),I.current=!1},150))},{passive:!1}):typeof H<"u"&&B.on("wheel.zoom",function(j,T){if(!p&&j.type==="wheel"&&!j.ctrlKey||St(j,$))return null;j.preventDefault(),H.call(this,j,T)},{passive:!1}))},[g,o,c,B,D,H,C,i,p,$,t,e,n]),x.useEffect(()=>{D&&D.on("start",j=>{var z,X;if(!j.sourceEvent||j.sourceEvent.internal)return null;S.current=(z=j.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=N.getState(),P=yn(j.transform);_.current=!0,O.current=P,((X=j.sourceEvent)==null?void 0:X.type)==="mousedown"&&N.setState({paneDragging:!0}),T==null||T(P),t==null||t(j.sourceEvent,P)})},[D,t]),x.useEffect(()=>{D&&(g&&!_.current?D.on("zoom",null):g||D.on("zoom",j=>{var P;const{onViewportChange:T}=N.getState();if(N.setState({transform:[j.transform.x,j.transform.y,j.transform.k]}),R.current=!!(r&&As(d,S.current??0)),(e||T)&&!((P=j.sourceEvent)!=null&&P.internal)){const z=yn(j.transform);T==null||T(z),e==null||e(j.sourceEvent,z)}}))},[g,D,e,d,r]),x.useEffect(()=>{D&&D.on("end",j=>{if(!j.sourceEvent||j.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=N.getState();if(_.current=!1,N.setState({paneDragging:!1}),r&&As(d,S.current??0)&&!R.current&&r(j.sourceEvent),R.current=!1,(n||T)&&nh(O.current,j.transform)){const P=yn(j.transform);O.current=P,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(P),n==null||n(j.sourceEvent,P)},o?150:0)}})},[D,o,d,n,r]),x.useEffect(()=>{D&&D.filter(j=>{const T=C||s,P=i&&j.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&j.button===1&&j.type==="mousedown"&&(St(j,"react-flow__node")||St(j,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||g||!l&&j.type==="dblclick"||St(j,$)&&j.type==="wheel"||St(j,b)&&(j.type!=="wheel"||o&&j.type==="wheel"&&!C)||!i&&j.ctrlKey&&j.type==="wheel"||!T&&!o&&!P&&j.type==="wheel"||!d&&(j.type==="mousedown"||j.type==="touchstart")||Array.isArray(d)&&!d.includes(j.button)&&j.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(j.button)||!j.button||j.button<=1;return(!j.ctrlKey||j.type==="wheel")&&z})},[g,D,s,i,o,l,d,u,C]),A.createElement("div",{className:"react-flow__renderer",ref:k,style:Br},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=de(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Is(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&Is(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&Is(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ot=(e,t)=>({id:e,type:"select",selected:t});function jt(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ot(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ot(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ro=x.memo(({isSelecting:e,selectionMode:t=en.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=x.useRef(null),f=Ee(),w=x.useRef(0),y=x.useRef(0),v=x.useRef(),{userSelectionActive:p,elementsSelectable:E,dragging:$}=de(lh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),w.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},N=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,R=H=>{const{resetSelectedElements:g,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!v.current)return;const{x:S,y:I}=lt(H,v.current);g(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:I,x:S,y:I}}),r==null||r(H)},k=H=>{const{userSelectionRect:g,nodeInternals:C,edges:S,transform:I,onNodesChange:L,onEdgesChange:j,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!g)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=lt(H,v.current),X=g.startX??0,V=g.startY??0,Z={...g,x:z.xre.id),ne=ee.map(re=>re.id);if(w.current!==ne.length){w.current=ne.length;const re=jt(J,ne);re.length&&(L==null||L(re))}if(y.current!==oe.length){y.current=oe.length;const re=jt(S,oe);re.length&&(j==null||j(re))}f.setState({userSelectionRect:Z})},O=H=>{if(H.button!==0)return;const{userSelectionRect:g}=f.getState();!p&&g&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:w.current>0}),b(),s==null||s(H)},D=H=>{p&&(f.setState({nodesSelectionActive:w.current>0}),s==null||s(H)),b()},B=E&&(e||p);return A.createElement("div",{className:je(["react-flow__pane",{dragging:$,selection:e}]),onClick:B?void 0:er(M,m),onContextMenu:er(N,m),onWheel:er(_,m),onMouseEnter:B?void 0:c,onMouseDown:B?R:void 0,onMouseMove:B?k:l,onMouseUp:B?O:void 0,onMouseLeave:B?D:u,ref:m,style:Br},d,A.createElement(oh,null))});Ro.displayName="Pane";function Io(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Io(r,t):!1}function Ts(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Io(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function To(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Oe(m)&&Oe(f)&&Oe(d.width)&&Oe(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",tt.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Lr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Os=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Or(c)}})};function Vt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Nr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",tt.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Ee();return x.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Oo({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Ee(),[c,l]=x.useState(!1),u=x.useRef([]),d=x.useRef({x:null,y:null}),m=x.useRef(0),f=x.useRef(null),w=x.useRef({x:0,y:0}),y=x.useRef(null),v=x.useRef(!1),p=x.useRef(!1),E=x.useRef(!1),$=fh();return x.useEffect(()=>{if(e!=null&&e.current){const b=Te(e.current),M=({x:R,y:k})=>{const{nodeInternals:O,onNodeDrag:D,onSelectionDrag:B,updateNodePositions:H,nodeExtent:g,snapGrid:C,snapToGrid:S,nodeOrigin:I,onError:L}=a.getState();d.current={x:R,y:k};let j=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&g){const z=on(u.current,I);T=Jt(z)}if(u.current=u.current.map(z=>{const X={x:R-z.distance.x,y:k-z.distance.y};S&&(X.x=C[0]*Math.round(X.x/C[0]),X.y=C[1]*Math.round(X.y/C[1]));const V=[[g[0][0],g[0][1]],[g[1][0],g[1][1]]];u.current.length>1&&g&&!z.extent&&(V[0][0]=z.positionAbsolute.x-T.x+g[0][0],V[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+g[1][0],V[0][1]=z.positionAbsolute.y-T.y+g[0][1],V[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+g[1][1]);const Z=To(z,X,O,V,I,L);return j=j||z.position.x!==Z.position.x||z.position.y!==Z.position.y,z.position=Z.position,z.positionAbsolute=Z.positionAbsolute,z}),!j)return;H(u.current,!0,!0),l(!0);const P=s?D:nr(B);if(P&&y.current){const[z,X]=tr({nodeId:s,dragItems:u.current,nodeInternals:O});P(y.current,z,X)}},N=()=>{if(!f.current)return;const[R,k]=no(w.current,f.current);if(R!==0||k!==0){const{transform:O,panBy:D}=a.getState();d.current.x=(d.current.x??0)-R/O[2],d.current.y=(d.current.y??0)-k/O[2],D({x:R,y:k})&&M(d.current)}m.current=requestAnimationFrame(N)},_=R=>{var I;const{nodeInternals:k,multiSelectionActive:O,nodesDraggable:D,unselectNodesAndEdges:B,onNodeDragStart:H,onSelectionDragStart:g}=a.getState();p.current=!0;const C=s?H:nr(g);(!o||!i)&&!O&&s&&((I=k.get(s))!=null&&I.selected||B()),s&&i&&o&&Nr({id:s,store:a,nodeRef:e});const S=$(R);if(d.current=S,u.current=uh(k,D,S,s),C&&u.current){const[L,j]=tr({nodeId:s,dragItems:u.current,nodeInternals:k});C(R.sourceEvent,L,j)}};if(t)b.on(".drag",null);else{const R=bu().on("start",k=>{const{domNode:O,nodeDragThreshold:D}=a.getState();D===0&&_(k),E.current=!1;const B=$(k);d.current=B,f.current=(O==null?void 0:O.getBoundingClientRect())||null,w.current=lt(k.sourceEvent,f.current)}).on("drag",k=>{var H,g;const O=$(k),{autoPanOnNodeDrag:D,nodeDragThreshold:B}=a.getState();if(k.sourceEvent.type==="touchmove"&&k.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&p.current&&D&&(v.current=!0,N()),!p.current){const C=O.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=O.ySnapped-(((g=d==null?void 0:d.current)==null?void 0:g.y)??0);Math.sqrt(C*C+S*S)>B&&_(k)}(d.current.x!==O.xSnapped||d.current.y!==O.ySnapped)&&u.current&&p.current&&(y.current=k.sourceEvent,w.current=lt(k.sourceEvent,f.current),M(O))}}).on("end",k=>{if(!(!p.current||E.current)&&(l(!1),v.current=!1,p.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:O,nodeInternals:D,onNodeDragStop:B,onSelectionDragStop:H}=a.getState(),g=s?B:nr(H);if(O(u.current,!1,!1),g){const[C,S]=tr({nodeId:s,dragItems:u.current,nodeInternals:D});g(k.sourceEvent,C,S)}}}).filter(k=>{const O=k.target;return!k.button&&(!n||!Ts(O,`.${n}`,e))&&(!r||Ts(O,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,$]),c}function Lo(){const e=Ee();return x.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,w=n.isShiftPressed?4:1,y=n.x*m*w,v=n.y*f*w,p=d.map(E=>{if(E.positionAbsolute){const $={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+v};a&&($.x=c[0]*Math.round($.x/c[0]),$.y=c[1]*Math.round($.y/c[1]));const{positionAbsolute:b,position:M}=To(E,$,r,s,void 0,l);E.position=M,E.positionAbsolute=b}return E});i(p,!0,!1)},[])}const Mt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Bt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:w,onDoubleClick:y,style:v,className:p,isDraggable:E,isSelectable:$,isConnectable:b,isFocusable:M,selectNodesOnDrag:N,sourcePosition:_,targetPosition:R,hidden:k,resizeObserver:O,dragHandle:D,zIndex:B,isParent:H,noDragClassName:g,noPanClassName:C,initialized:S,disableKeyboardA11y:I,ariaLabel:L,rfId:j,hasHandleBounds:T})=>{const P=Ee(),z=x.useRef(null),X=x.useRef(null),V=x.useRef(_),Z=x.useRef(R),J=x.useRef(r),ee=$||E||u||d||m||f,oe=Lo(),ne=Vt(n,P.getState,d),re=Vt(n,P.getState,m),pe=Vt(n,P.getState,f),ce=Vt(n,P.getState,w),ue=Vt(n,P.getState,y),ye=le=>{const{nodeDragThreshold:K}=P.getState();if($&&(!N||!E||K>0)&&Nr({id:n,store:P,nodeRef:z}),u){const Ne=P.getState().nodeInternals.get(n);Ne&&u(le,{...Ne})}},he=le=>{if(!br(le)&&!I)if(oo.includes(le.key)&&$){const K=le.key==="Escape";Nr({id:n,store:P,unselect:K,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Mt,le.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),oe({x:Mt[le.key].x,y:Mt[le.key].y,isShiftPressed:le.shiftKey}))};x.useEffect(()=>()=>{X.current&&(O==null||O.unobserve(X.current),X.current=null)},[]),x.useEffect(()=>{if(z.current&&!k){const le=z.current;(!S||!T||X.current!==le)&&(X.current&&(O==null||O.unobserve(X.current)),O==null||O.observe(le),X.current=le)}},[k,S,T]),x.useEffect(()=>{const le=J.current!==r,K=V.current!==_,Ne=Z.current!==R;z.current&&(le||K||Ne)&&(le&&(J.current=r),K&&(V.current=_),Ne&&(Z.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const xe=Oo({nodeRef:z,disabled:k||!E,noDragClassName:g,handleSelector:D,nodeId:n,isSelectable:$,selectNodesOnDrag:N});return k?null:A.createElement("div",{className:je(["react-flow__node",`react-flow__node-${r}`,{[C]:E},p,{selected:l,selectable:$,parent:H,dragging:xe}]),ref:z,style:{zIndex:B,transform:`translate(${a}px,${c}px)`,pointerEvents:ee?"all":"none",visibility:S?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:re,onMouseLeave:pe,onContextMenu:ce,onClick:ye,onDoubleClick:ue,onKeyDown:M?he:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":I?void 0:`${jo}-${j}`,"aria-label":L},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:xe,dragHandle:D,zIndex:B})))};return t.displayName="NodeWrapper",x.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...on(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ee(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=de(hh,ke),u=Lo(),d=x.useRef(null);if(x.useEffect(()=>{var w;n||(w=d.current)==null||w.focus({preventScroll:!0})},[n]),Oo({nodeRef:d}),l||!s||!i)return null;const m=e?w=>{const y=r.getState().getNodes().filter(v=>v.selected);e(w,y)}:void 0,f=w=>{Object.prototype.hasOwnProperty.call(Mt,w.key)&&u({x:Mt[w.key].x,y:Mt[w.key].y,isShiftPressed:w.shiftKey})};return A.createElement("div",{className:je(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=x.memo(mh);const gh=e=>e.nodesSelectionActive,Do=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:w,onSelectionEnd:y,multiSelectionKeyCode:v,panActivationKeyCode:p,zoomActivationKeyCode:E,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:N,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:O,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,preventScrolling:C,onSelectionContextMenu:S,noWheelClassName:I,noPanClassName:L,disableKeyboardA11y:j})=>{const T=de(gh),P=tn(d),z=tn(p),X=z||O,V=z||N,Z=P||m&&X!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:V,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:!P&&X,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:I,noPanClassName:L},A.createElement(Ro,{onSelectionStart:w,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:X,isSelecting:!!Z,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:L,disableKeyboardA11y:j})))};Do.displayName="FlowRenderer";var yh=x.memo(Do);function xh(e){return de(x.useCallback(n=>e?mo(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Bt(e.input||Eo),default:Bt(e.default||Er),output:Bt(e.output||So),group:Bt(e.group||Vr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Bt(e[i]||Er),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Po=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=de(vh,ke),a=xh(e.onlyRenderVisibleElements),c=x.useRef(),l=x.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return x.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Br},a.map(u=>{var M,N,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",tt.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),w=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),v=!!(u.focusable||r&&typeof u.focusable>"u"),p=e.nodeExtent?Lr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(p==null?void 0:p.x)??0,$=(p==null?void 0:p.y)??0,b=bh({x:E,y:$,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||q.Bottom,targetPosition:u.targetPosition||q.Top,hidden:u.hidden,xPos:E,yPos:$,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:w,isConnectable:y,isFocusable:v,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((N=u[we])!=null&&N.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Po.displayName="NodeRenderer";var _h=x.memo(Po);const Eh=(e,t,n)=>n===q.Left?e-t:n===q.Right?e+t:e,Nh=(e,t,n)=>n===q.Top?e-t:n===q.Bottom?e+t:e,Ls="react-flow__edgeupdater",Ds=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:je([Ls,`${Ls}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var kt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,style:v,source:p,target:E,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,elementsSelectable:k,hidden:O,sourceHandleId:D,targetHandleId:B,onContextMenu:H,onMouseEnter:g,onMouseMove:C,onMouseLeave:S,reconnectRadius:I,onReconnect:L,onReconnectStart:j,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:X,ariaLabel:V,isFocusable:Z,isReconnectable:J,pathOptions:ee,interactionWidth:oe,disableKeyboardA11y:ne})=>{const re=x.useRef(null),[pe,ce]=x.useState(!1),[ue,ye]=x.useState(!1),he=Ee(),xe=x.useMemo(()=>`url('#${vr(z,X)}')`,[z,X]),le=x.useMemo(()=>`url('#${vr(P,X)}')`,[P,X]);if(O)return null;const K=se=>{var Se;const{edges:me,addSelectedEdges:$e,unselectNodesAndEdges:W,multiSelectionActive:fe}=he.getState(),ge=me.find(dt=>dt.id===n);ge&&(k&&(he.setState({nodesSelectionActive:!1}),ge.selected&&fe?(W({nodes:[],edges:[ge]}),(Se=re.current)==null||Se.blur()):$e([n])),o&&o(se,ge))},Ne=Ft(n,he.getState,a),Ce=Ft(n,he.getState,H),ut=Ft(n,he.getState,g),Ae=Ft(n,he.getState,C),We=Ft(n,he.getState,S),Ie=(se,me)=>{if(se.button!==0)return;const{edges:$e,isValidConnection:W}=he.getState(),fe=me?E:p,ge=(me?B:D)||null,Se=me?"target":"source",dt=W||Sh,Ot=me,rt=$e.find(Pe=>Pe.id===n);ye(!0),j==null||j(se,rt,Se);const ft=Pe=>{ye(!1),T==null||T(Pe,rt,Se)};wo({event:se,handleId:ge,nodeId:fe,onConnect:Pe=>L==null?void 0:L(rt,Pe),isTarget:Ot,getState:he.getState,setState:he.setState,isValidConnection:dt,edgeUpdaterType:Se,onReconnectEnd:ft})},F=se=>Ie(se,!0),Y=se=>Ie(se,!1),G=()=>ce(!0),Q=()=>ce(!1),U=!k&&!o,te=se=>{var me;if(!ne&&oo.includes(se.key)&&k){const{unselectNodesAndEdges:$e,addSelectedEdges:W,edges:fe}=he.getState();se.key==="Escape"?((me=re.current)==null||me.blur(),$e({edges:[fe.find(Se=>Se.id===n)]})):W([n])}};return A.createElement("g",{className:je(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:pe}]),onClick:K,onDoubleClick:Ne,onContextMenu:Ce,onMouseEnter:ut,onMouseMove:Ae,onMouseLeave:We,onKeyDown:Z?te:void 0,tabIndex:Z?0:void 0,role:Z?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":V===null?void 0:V||`Edge from ${p} to ${E}`,"aria-describedby":Z?`${Co}-${X}`:void 0,ref:re},!ue&&A.createElement(e,{id:n,source:p,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,data:i,style:v,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,sourceHandleId:D,targetHandleId:B,markerStart:xe,markerEnd:le,pathOptions:ee,interactionWidth:oe}),J&&A.createElement(A.Fragment,null,(J==="source"||J===!0)&&A.createElement(Ds,{position:_,centerX:$,centerY:b,radius:I,onMouseDown:F,onMouseEnter:G,onMouseOut:Q,type:"source"}),(J==="target"||J===!0)&&A.createElement(Ds,{position:R,centerX:M,centerY:N,radius:I,onMouseDown:Y,onMouseEnter:G,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",x.memo(t)};function kh(e){const t={default:kt(e.default||In),straight:kt(e.bezier||zr),step:kt(e.step||Pr),smoothstep:kt(e.step||Bn),simplebezier:kt(e.simplebezier||Dr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=kt(e[i]||In),s),n);return{...t,...r}}function Ps(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case q.Top:return{x:r+i/2,y:s};case q.Right:return{x:r+i,y:s+o/2};case q.Bottom:return{x:r+i/2,y:s+o};case q.Left:return{x:r,y:s+o/2}}}function zs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ps(n,e,t),a=Ps(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Jt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Hs(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Oe(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),w=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(w?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=de(x.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Fs={[An.Arrow]:Rh,[An.ArrowClosed]:Ih};function Th(e){const t=Ee();return x.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(Fs,e)?Fs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",tt.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=vr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},zo=({defaultColor:e,rfId:t})=>{const n=de(x.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};zo.displayName="MarkerDefinitions";var Dh=x.memo(zo);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ho=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,children:v,disableKeyboardA11y:p})=>{const{edgesFocusable:E,edgesUpdatable:$,elementsSelectable:b,width:M,height:N,connectionMode:_,nodeInternals:R,onError:k}=de(Ph,ke),O=Ah(t,R,n);return M?A.createElement(A.Fragment,null,O.map(({level:D,edges:B,isMaxLevel:H})=>A.createElement("svg",{key:D,style:{zIndex:D},width:M,height:N,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,B.map(g=>{const[C,S,I]=Hs(R.get(g.source)),[L,j,T]=Hs(R.get(g.target));if(!I||!T)return null;let P=g.type||"default";s[P]||(k==null||k("011",tt.error011(P)),P="default");const z=s[P]||s.default,X=_===vt.Strict?j.target:(j.target??[]).concat(j.source??[]),V=zs(S.source,g.sourceHandle),Z=zs(X,g.targetHandle),J=(V==null?void 0:V.position)||q.Bottom,ee=(Z==null?void 0:Z.position)||q.Top,oe=!!(g.focusable||E&&typeof g.focusable>"u"),ne=g.reconnectable||g.updatable,re=typeof m<"u"&&(ne||$&&typeof ne>"u");if(!V||!Z)return k==null||k("008",tt.error008(V,g)),null;const{sourceX:pe,sourceY:ce,targetX:ue,targetY:ye}=jh(C,V,J,L,Z,ee);return A.createElement(z,{key:g.id,id:g.id,className:je([g.className,i]),type:P,data:g.data,selected:!!g.selected,animated:!!g.animated,hidden:!!g.hidden,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,style:g.style,source:g.source,target:g.target,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerEnd:g.markerEnd,markerStart:g.markerStart,sourceX:pe,sourceY:ce,targetX:ue,targetY:ye,sourcePosition:J,targetPosition:ee,elementsSelectable:b,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,rfId:r,ariaLabel:g.ariaLabel,isFocusable:oe,isReconnectable:re,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth,disableKeyboardA11y:p})})))),v):null};Ho.displayName="EdgeRenderer";var zh=x.memo(Ho);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=de(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=an(),n=x.useRef(!1);x.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[q.Left]:q.Right,[q.Right]:q.Left,[q.Top]:q.Bottom,[q.Bottom]:q.Top},Fo=({nodeId:e,handleType:t,style:n,type:r=at.Bezier,CustomComponent:s,connectionStatus:i})=>{var N,_,R;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=de(x.useCallback(k=>({fromNode:k.nodeInternals.get(e),handleId:k.connectionHandleId,toX:(k.connectionPosition.x-k.transform[0])/k.transform[2],toY:(k.connectionPosition.y-k.transform[1])/k.transform[2],connectionMode:k.connectionMode}),[e]),ke),d=(N=o==null?void 0:o[we])==null?void 0:N.handleBounds;let m=d==null?void 0:d[t];if(u===vt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(k=>k.id===a):m[0],w=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,v=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+w,p=(((R=o.positionAbsolute)==null?void 0:R.y)??0)+y,E=f==null?void 0:f.position,$=E?Bh[E]:null;if(!E||!$)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:v,fromY:p,toX:c,toY:l,fromPosition:E,toPosition:$,connectionStatus:i});let b="";const M={sourceX:v,sourceY:p,sourcePosition:E,targetX:c,targetY:l,targetPosition:$};return r===at.Bezier?[b]=fo(M):r===at.Step?[b]=Rn({...M,borderRadius:0}):r===at.SmoothStep?[b]=Rn(M):r===at.SimpleBezier?[b]=uo(M):b=`M${v},${p} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Fo.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=de(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:je(["react-flow__connection",l])},A.createElement(Fo,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Vs(e,t){return x.useRef(null),Ee(),x.useMemo(()=>t(e),[e])}const Vo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:w,onSelectionStart:y,onSelectionEnd:v,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:$,connectionLineContainerStyle:b,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,deleteKeyCode:D,onlyRenderVisibleElements:B,elementsSelectable:H,selectNodesOnDrag:g,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,preventScrolling:j,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:X,panOnScrollSpeed:V,panOnScrollMode:Z,zoomOnDoubleClick:J,panOnDrag:ee,onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneScroll:ce,onPaneContextMenu:ue,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,noDragClassName:Ae,noWheelClassName:We,noPanClassName:Ie,elevateEdgesOnSelect:F,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})=>{const te=Vs(e,wh),se=Vs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneContextMenu:ue,onPaneScroll:ce,deleteKeyCode:D,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,onSelectionStart:y,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:J,panOnScroll:X,panOnScrollSpeed:V,panOnScrollMode:Z,panOnDrag:ee,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,onSelectionContextMenu:w,preventScrolling:j,noDragClassName:Ae,noWheelClassName:We,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:B,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Ne,onReconnectEnd:Ce,reconnectRadius:ut,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!F,disableKeyboardA11y:Y,rfId:U},A.createElement(Yh,{style:E,type:p,component:$,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:te,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:g,onlyRenderVisibleElements:B,noPanClassName:Ie,noDragClassName:Ae,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})))};Vo.displayName="GraphView";var Xh=x.memo(Vo);const Sr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],st={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Sr,nodeExtent:Sr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:vt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Wh=()=>Rc((e,t)=>({...st,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Jn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,v)=>{const p=s.get(v.id);if(p!=null&&p.hidden)s.set(p.id,{...p,[we]:{...p[we],handleBounds:void 0}});else if(p){const E=Or(v.nodeElement);!!(E.width&&E.height&&(p.width!==E.width||p.height!==E.height||v.forceUpdate))&&(s.set(p.id,{...p,[we]:{...p[we],handleBounds:{source:Os(".source",v.nodeElement,m,l),target:Os(".target",v.nodeElement,m,l)}},...E}),y.push({id:p.id,type:"dimensions",dimensions:E}))}return y},[]);Mo(s,l);const w=o||i&&!o&&Ao(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:w}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Jn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(i(),n),a=jt(s,[])),gn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ot(c,!0)):(o=jt(s,n),a=jt(i(),[])),gn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ot(u.id,!1))),l=a.map(u=>ot(u.id,!1));gn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ot(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ot(a.id,!1));gn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Lr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=Je.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:st.connectionNodeId,connectionHandleId:st.connectionHandleId,connectionHandleType:st.connectionHandleType,connectionStatus:st.connectionStatus,connectionStartHandle:st.connectionStartHandle,connectionEndHandle:st.connectionEndHandle}),reset:()=>e({...st})}),Object.is),Bo=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Wh()),A.createElement(df,{value:t.current},e)};Bo.displayName="ReactFlowProvider";const Go=({children:e})=>x.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Bo,null,e);Go.displayName="ReactFlowWrapper";const Uh={input:Eo,default:Er,output:So,group:Vr},qh={default:In,straight:zr,step:Pr,smoothstep:Bn,simplebezier:Dr},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Yo=x.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Uh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onNodesDelete:O,onEdgesDelete:D,onSelectionChange:B,onSelectionDragStart:H,onSelectionDrag:g,onSelectionDragStop:C,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,connectionMode:j=vt.Strict,connectionLineType:T=at.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,deleteKeyCode:V="Backspace",selectionKeyCode:Z="Shift",selectionOnDrag:J=!1,selectionMode:ee=en.Full,panActivationKeyCode:oe="Space",multiSelectionKeyCode:ne=Mn()?"Meta":"Control",zoomActivationKeyCode:re=Mn()?"Meta":"Control",snapToGrid:pe=!1,snapGrid:ce=Zh,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:ye=!0,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,nodeOrigin:K=Kh,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,defaultViewport:Ae=Qh,minZoom:We=.5,maxZoom:Ie=2,translateExtent:F=Sr,preventScrolling:Y=!0,nodeExtent:G,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:te=!0,panOnScroll:se=!1,panOnScrollSpeed:me=.5,panOnScrollMode:$e=gt.Free,zoomOnDoubleClick:W=!0,panOnDrag:fe=!0,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,children:Lt,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:Zr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Xa,defaultEdgeOptions:Wa,elevateNodesOnSelect:Ua=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Qr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Jr,nodeDragThreshold:nc,...rc},sc)=>{const Xn=Jr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:je(["react-flow",s]),"data-testid":"rf__wrapper",id:Jr},A.createElement(Go,null,A.createElement(Xh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,selectionKeyCode:Z,selectionOnDrag:J,selectionMode:ee,deleteKeyCode:V,multiSelectionKeyCode:ne,panActivationKeyCode:oe,zoomActivationKeyCode:re,onlyRenderVisibleElements:ue,selectNodesOnDrag:ye,defaultViewport:Ae,translateExtent:F,minZoom:We,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:U,zoomOnPinch:te,zoomOnDoubleClick:W,panOnScroll:se,panOnScrollSpeed:me,panOnScrollMode:$e,panOnDrag:fe,onPaneClick:ge,onPaneMouseEnter:Se,onPaneMouseMove:dt,onPaneMouseLeave:Ot,onPaneScroll:rt,onPaneContextMenu:ft,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ue,onEdgeMouseLeave:Pt,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:Zr,elevateEdgesOnSelect:qa,rfId:Xn,disableKeyboardA11y:Qr,nodeOrigin:K,nodeExtent:G}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,edgesFocusable:Ne,edgesUpdatable:Ce,elementsSelectable:ut,elevateNodesOnSelect:Ua,minZoom:We,maxZoom:Ie,nodeExtent:G,onNodesChange:Pa,onEdgesChange:za,snapToGrid:pe,snapGrid:ce,connectionMode:j,translateExtent:F,connectOnClick:Ga,defaultEdgeOptions:Wa,fitView:Va,fitViewOptions:Ba,onNodesDelete:O,onEdgesDelete:D,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onSelectionDrag:g,onSelectionDragStart:H,onSelectionDragStop:C,noPanClassName:Zr,nodeOrigin:K,rfId:Xn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:B}),Lt,A.createElement(hf,{proOptions:Xa,position:Ya}),A.createElement(Wf,{rfId:Xn,disableKeyboardA11y:Qr})))});Yo.displayName="ReactFlow";const Xo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:w,backgroundColor:y}=i||{},v=o||w||y;return A.createElement("rect",{className:je(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?p=>m(p,e):void 0})};Xo.displayName="MiniMapNode";var em=x.memo(Xo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=de(nm,ke),c=de(tm),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:w,y}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:w,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=x.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(on(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:w=!1,zoomable:y=!1,ariaLabel:v="React Flow mini map",inversePan:p=!1,zoomStep:E=10,offsetScale:$=5}){const b=Ee(),M=x.useRef(null),{boundingRect:N,viewBB:_,rfId:R}=de(am,ke),k=(e==null?void 0:e.width)??im,O=(e==null?void 0:e.height)??om,D=N.width/k,B=N.height/O,H=Math.max(D,B),g=H*k,C=H*O,S=$*H,I=N.x-(g-N.width)/2-S,L=N.y-(C-N.height)/2-S,j=g+S*2,T=C+S*2,P=`${cm}-${R}`,z=x.useRef(0);z.current=H,x.useEffect(()=>{if(M.current){const Z=Te(M.current),J=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce}=b.getState();if(ne.sourceEvent.type!=="wheel"||!pe||!ce)return;const ue=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,ye=re[2]*Math.pow(2,ue);ce.scaleTo(pe,ye)},ee=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce,translateExtent:ue,width:ye,height:he}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!pe||!ce)return;const xe=z.current*Math.max(1,re[2])*(p?-1:1),le={x:re[0]-ne.sourceEvent.movementX*xe,y:re[1]-ne.sourceEvent.movementY*xe},K=[[0,0],[ye,he]],Ne=Je.translate(le.x,le.y).scale(re[2]),Ce=ce.constrain()(Ne,K,ue);ce.transform(pe,Ce)},oe=eo().on("zoom",w?ee:null).on("zoom.wheel",y?J:null);return Z.call(oe),()=>{Z.on("zoom",null)}}},[w,y,p,E]);const X=m?Z=>{const J=ze(Z);m(Z,{x:J[0],y:J[1]})}:void 0,V=f?(Z,J)=>{const ee=b.getState().nodeInternals.get(J);f(Z,ee)}:void 0;return A.createElement(Tr,{position:d,style:e,className:je(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:k,height:O,viewBox:`${I} ${L} ${j} ${T}`,role:"img","aria-labelledby":P,ref:M,onClick:X},v&&A.createElement("title",{id:P},v),A.createElement(sm,{onClick:V,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${I-S},${L-S}h${j+S*2}v${T+S*2}h${-j-S*2}z - M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Wo.displayName="MiniMap";var lm=x.memo(Wo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Xt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:je(["react-flow__controls-button",t]),...n},e);Xt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ee(),[f,w]=x.useState(!1),{isInteractive:y,minZoomReached:v,maxZoomReached:p}=de(pm,ke),{zoomIn:E,zoomOut:$,fitView:b}=an();if(x.useEffect(()=>{w(!0)},[]),!f)return null;const M=()=>{E(),i==null||i()},N=()=>{$(),o==null||o()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c==null||c(!y)};return A.createElement(Tr,{className:je(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Xt,{onClick:M,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:p},A.createElement(um,null)),A.createElement(Xt,{onClick:N,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(dm,null))),n&&A.createElement(Xt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Xt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},y?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=x.memo(Uo),Le;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Le||(Le={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[Le.Dots]:"#91919a",[Le.Lines]:"#eee",[Le.Cross]:"#e2e2e2"},bm={[Le.Dots]:1,[Le.Lines]:1,[Le.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function qo({id:e,variant:t=Le.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=x.useRef(null),{transform:u,patternId:d}=de(vm,ke),m=o||wm[t],f=r||bm[t],w=t===Le.Dots,y=t===Le.Cross,v=Array.isArray(n)?n:[n,n],p=[v[0]*u[2]||1,v[1]*u[2]||1],E=f*u[2],$=y?[E,E]:p,b=w?[E/i,E/i]:[$[0]/i,$[1]/i];return A.createElement("svg",{className:je(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%p[0],y:u[1]%p[1],width:p[0],height:p[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},w?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:$,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}qo.displayName="Background";var _m=x.memo(qo);const Gr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Gr+e}async function be(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function nt(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new Ko(r.error??`${e}: ${n.status}`,n.status);return r}class Ko extends Error{constructor(n,r){super(n);ve(this,"status");this.status=r}}const Cx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),$x=()=>be("/api/diagnostics"),Zo=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Qo=()=>be("/api/ontology/ontologies"),Em=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>be("/api/ontology/stack"),Sm=()=>be("/api/ontology/coverage"),km=(e,t,n)=>nt("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>be("/api/git/status"),Cm=()=>be("/api/git/diff"),$m=e=>nt("/api/git/commit",{message:e}),Mm=()=>nt("/api/git/discard",{}),Am=()=>be("/api/decisions"),Bs=(e,t)=>nt(`/api/decisions/${e}/verdict`,{verdict:t}),Mx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Ax=()=>be("/api/glossary/config"),Rx=e=>nt("/api/git/propose",e),Ix=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Tx=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),Ox=e=>nt("/api/git/classify",{changes:e}),Lx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Dx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Px=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>be("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Gr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>nt("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>nt("/api/import/preview",{format:e,content:t}),zx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Hx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Fx=(e,t,n)=>fetch(`${Gr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new Ko(await r.text(),r.status);return await r.json()}),Vx=()=>be("/api/glossary/subject-areas"),Bx=e=>be(`/api/glossary/subject-area/${e}`),Gx=(e,t)=>nt(`/api/glossary/subject-area/${e}/expand`,t);function Yx(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Yr="__entity_source",Xr="__entity_target",Pm=x.memo(function({data:t,selected:n}){var N;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:w}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>y(_.a)-y(R.a)||_.i-R.i).map(_=>_.a),p=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const $=!!c&&!l;let b=0;if($){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const M=(_,R)=>{const k="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:k,onMouseEnter:w?()=>w(_.id):void 0,onMouseLeave:w?()=>w(null):void 0,children:[h.jsx(ct,{id:_.id,type:"target",position:q.Left,className:"port attr-port"}),h.jsx(ct,{id:_.id,type:"source",position:q.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ct,{id:Xr,type:"target",position:q.Left,className:"port"}),h.jsx(ct,{id:Yr,type:"source",position:q.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((N=r.conceptual)==null?void 0:N.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var k;const _=(((k=r.conceptual)==null?void 0:k.ontology_refs)??[]).filter(O=>O.uri);if(_.length===0)return null;const R=_.map(O=>O.uri).join(` -`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),p.length>0&&h.jsx("div",{className:"attr-section keys",children:p.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,w,y,v,p,E,$,b,M,N,_,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(k=>k.from.entity===e.id||k.to.entity===e.id),d=k=>{var O;return((O=t.entities.find(D=>D.id===k))==null?void 0:O.name)??k};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Ke,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,name:k})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Ke,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,physical_name:k})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Ke,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:k=>r("set_definition",{id:e.id,definition:k})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((w=l==null?void 0:l.ontology_refs)==null?void 0:w.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((p=e.term_map)==null?void 0:p.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),($=e.term_map)!=null&&$.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((N=e.term_map)==null?void 0:N.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Ke,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:k,steward:((O=l==null?void 0:l.stewardship)==null?void 0:O.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Ke,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:((O=l==null?void 0:l.stewardship)==null?void 0:O.owner)??null,steward:k})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(k=>h.jsx(Xm,{a:k,entity:e,doc:t,readOnly:c,exec:r},k.id))})}),!c&&h.jsx(Wm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(k=>{const O=k.members.map(D=>{var B;return((B=e.attributes.find(H=>H.id===D))==null?void 0:B.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+k.type,children:k.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:k.name}),h.jsx("span",{className:"key-cols",children:O})]},k.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([k,O])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:k}),h.jsx("td",{className:"udp-val",children:String(O)})]},k))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(k=>{const O=k.from.entity===e.id?k.to.entity:k.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(O),children:[h.jsx("span",{className:"rel-card",children:Um(k,e.id)}),d(O)]}),(k.verb_phrase||k.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Ke,{value:k.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,verb_phrase:D})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Ke,{value:k.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,inverse_verb_phrase:D})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${k.name}`,onClick:()=>r("delete_relationship",{id:k.id}),children:"✕"})]},k.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var k;return(k=navigator.clipboard)==null?void 0:k.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Ke({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=x.useState(e);x.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Xm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Ke,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Ke,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Wm({entity:e,exec:t}){const[n,r]=x.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Um(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Gs="";let Km=class{constructor(t){ve(this,"_isDirected",!0);ve(this,"_isMultigraph",!1);ve(this,"_isCompound",!1);ve(this,"_label");ve(this,"_defaultNodeLabelFn",()=>{});ve(this,"_defaultEdgeLabelFn",()=>{});ve(this,"_nodes",{});ve(this,"_in",{});ve(this,"_preds",{});ve(this,"_out",{});ve(this,"_sucs",{});ve(this,"_edgeObjs",{});ve(this,"_edgeLabels",{});ve(this,"_nodeCount",0);ve(this,"_edgeCount",0);ve(this,"_parent");ve(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Ys(this._preds[n],t),Ys(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Xs(this._preds[n],t),Xs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Ys(e,t){e[t]?e[t]++:e[t]=1}function Xs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Gs+i+Gs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function sr(e,t){return Wt(e,t.v,t.w,t.name)}var Wr=Km,Qm="2.2.4",Jm={Graph:Wr,version:Qm},ep=Wr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){ve(this,"_arr",[]);ve(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=ea,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ta=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ta,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),ia(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),ia(t(i),o=>s.push(o)))}}function ia(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=sa,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=sa,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Wr,Lp=Jo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:ea,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ta,topsort:ra},Us=Jm,Ve={Graph:Us.Graph,json:tp,alg:zp,version:Us.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return qs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&qs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function qs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ve.Graph,Gp=Vp;var Yp=Wp;let Xp=()=>1;function Wp(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Xp);return Up(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Up(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)ir(e,t,n,o);for(;o=s.dequeue();)ir(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(ir(e,t,n,o,!0));break}}}return r}function ir(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,jr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,jr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{jr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function jr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new oa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=da(la(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),aa(e,"border",s,t)}function og(e,t=ca){const n=[];for(let r=0;rca){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function la(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function ua(e){var t=++ug;return e+(""+t)}function da(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Ur(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=_e.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=_e;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=_e;var Yn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ve.Graph,On=Yn.slack,fa=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!On(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=On(t,s)),it.node(r).rank+=n)}var Rg=fa,Ks=Yn.slack,Ig=Yn.longestPath,Tg=Ve.alg.preorder,Og=Ve.alg.postorder,Lg=_e.simplify,Dg=_t;_t.initLowLimValues=Kr;_t.initCutValues=qr;_t.calcCutValue=ha;_t.leaveEdge=pa;_t.enterEdge=ga;_t.exchangeEdges=ya;function _t(e){e=Lg(e),Ig(e);var t=Rg(e);Kr(t),qr(t,e);for(var n,r;n=pa(t);)r=ga(t,e,n),ya(t,e,n,r)}function qr(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ha(e,t,n)}function ha(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Kr(e,t){arguments.length<2&&(t=e.nodes()[0]),ma(e,{},1,t)}function ma(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ma(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function pa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ga(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===Zs(e,e.node(u.v),a)&&c!==Zs(e,e.node(u.w),a));return l.reduce((u,d)=>Ks(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function Zs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Yn,xa=Fg.longestPath,Vg=fa,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Qs(e);break;case"tight-tree":Wg(e);break;case"longest-path":Xg(e);break;case"none":break;default:Qs(e)}}var Xg=xa;function Wg(e){xa(e),Vg(e)}function Qs(e){Bg(e)}var Ug=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Ln=_e;var Qg={run:Jg,cleanup:n0};function Jg(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=e0(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=t0(e)+1;e.children().forEach(a=>wa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function wa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{wa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,w=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,v=f!==w?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:v,nestingEdge:!0}),e.setEdge(w,l,{weight:y,minlen:v,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function e0(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function t0(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function n0(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let r0=_e;var s0=i0;function i0(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iei(e.node(t))),e.edges().forEach(t=>ei(e.edge(t)))}function ei(e){let t=e.width;e.width=e.height,e.height=t}function l0(e){e.nodes().forEach(t=>or(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(or),Object.hasOwn(n,"y")&&or(n)})}function or(e){e.y=-e.y}function u0(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let ti=_e;var d0=f0;function f0(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=ti.applyWithChunking(Math.max,r),i=ti.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let h0=_e.zipObject;var m0=p0;function p0(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var y0=x0;function x0(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let w0=_e;var b0=v0;function v0(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _0(r)}function _0(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&E0(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>w0.pick(s,["vs","i","barycenter","weight"]))}function E0(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let N0=_e;var S0=k0;function k0(e,t){let n=N0.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(j0(!!t)),c=ni(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ni(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ni(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function j0(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let C0=y0,$0=b0,M0=S0;var A0=va;function va(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=C0(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=va(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&I0(m,f)}});let u=$0(l,n);R0(u,c);let d=M0(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function R0(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function I0(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let T0=Ve.Graph,O0=_e;var L0=D0;function D0(e,t,n,r){r||(r=e.nodes());let s=P0(e),i=new T0({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function P0(e){for(var t;e.hasNode(t=O0.uniqueId("_root")););return t}var z0=H0;function H0(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let F0=d0,V0=m0,B0=A0,G0=L0,Y0=z0,X0=Ve.Graph,xn=_e;var W0=_a;function _a(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,_a);return}let n=xn.maxRank(e),r=ri(e,xn.range(1,n+1),"inEdges"),s=ri(e,xn.range(n-1,-1,-1),"outEdges"),i=F0(e);if(si(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){U0(c%2?r:s,c%4>=2),i=xn.buildLayerMatrix(e);let u=V0(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return G0(e,i,n,r.get(i)||[])})}function U0(e,t){let n=new X0;e.forEach(function(r){let s=r.graph().root,i=B0(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Y0(r,n,i.vs)})}function si(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let q0=Ve.Graph,Ze=_e;var K0={positionX:ay};function Z0(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=J0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(w=>{e.predecessors(w).forEach(y=>{let v=e.node(y),p=v.order;(p{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&Ea(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function J0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ea(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function ey(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function ty(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let w=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((w,y)=>Math.min(w,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function ry(e,t,n,r){let s=new q0,i=e.graph(),o=cy(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function sy(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=ly(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-Ze.applyWithChunking(Math.min,l);o!=="l"&&(u=s-Ze.applyWithChunking(Math.max,l)),u&&(e[a]=Ze.mapValues(c,d=>d+u))})})}function oy(e,t){return Ze.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function ay(e){let t=Ze.buildLayerMatrix(e),n=Object.assign(Z0(e,t),Q0(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=ty(e,s,n,c),u=ny(e,s,l.root,l.align,a==="r");a==="r"&&(u=Ze.mapValues(u,d=>-d)),r[o+a]=u})});let i=sy(e,r);return iy(r,i),oy(r,e.graph().align)}function cy(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function ly(e,t){return e.node(t).width}let Na=_e,uy=K0.positionX;var dy=fy;function fy(e){e=Na.asNonCompoundGraph(e),hy(e),Object.entries(uy(e)).forEach(([t,n])=>e.node(t).x=n)}function hy(e){let t=Na.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ii=pg,oi=bg,my=Gg,py=_e.normalizeRanks,gy=Ug,yy=_e.removeEmptyRanks,ai=Qg,xy=s0,ci=o0,wy=W0,by=dy,De=_e,vy=Ve.Graph;var _y=Ey;function Ey(e,t){let n=t&&t.debugTiming?De.time:De.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>Iy(e));n(" runLayout",()=>Ny(r,n,t)),n(" updateInputGraph",()=>Sy(e,r))})}function Ny(e,t,n){t(" makeSpaceForEdgeLabels",()=>Ty(e)),t(" removeSelfEdges",()=>By(e)),t(" acyclic",()=>ii.run(e)),t(" nestingGraph.run",()=>ai.run(e)),t(" rank",()=>my(De.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Oy(e)),t(" removeEmptyRanks",()=>yy(e)),t(" nestingGraph.cleanup",()=>ai.cleanup(e)),t(" normalizeRanks",()=>py(e)),t(" assignRankMinMax",()=>Ly(e)),t(" removeEdgeLabelProxies",()=>Dy(e)),t(" normalize.run",()=>oi.run(e)),t(" parentDummyChains",()=>gy(e)),t(" addBorderSegments",()=>xy(e)),t(" order",()=>wy(e,n)),t(" insertSelfEdges",()=>Gy(e)),t(" adjustCoordinateSystem",()=>ci.adjust(e)),t(" position",()=>by(e)),t(" positionSelfEdges",()=>Yy(e)),t(" removeBorderNodes",()=>Vy(e)),t(" normalize.undo",()=>oi.undo(e)),t(" fixupEdgeLabelCoords",()=>Hy(e)),t(" undoCoordinateSystem",()=>ci.undo(e)),t(" translateGraph",()=>Py(e)),t(" assignNodeIntersects",()=>zy(e)),t(" reversePoints",()=>Fy(e)),t(" acyclic.undo",()=>ii.undo(e))}function Sy(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let ky=["nodesep","edgesep","ranksep","marginx","marginy"],jy={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Cy=["acyclicer","ranker","rankdir","align"],$y=["width","height","rank"],li={width:0,height:0},My=["minlen","weight","width","height","labeloffset"],Ay={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ry=["labelpos"];function Iy(e){let t=new vy({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},jy,cr(n,ky),De.pick(n,Cy))),e.nodes().forEach(r=>{let s=lr(e.node(r));const i=cr(s,$y);Object.keys(li).forEach(o=>{i[o]===void 0&&(i[o]=li[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},Ay,cr(s,My),De.pick(s,Ry)))}),t}function Ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Oy(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};De.addDummyNode(e,"edge-proxy",i,"_ep")}})}function Ly(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Dy(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Py(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function zy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(De.intersectRect(r,i)),n.points.push(De.intersectRect(s,o))})}function Hy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Fy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Vy(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function By(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Gy(e){var t=De.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{De.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Yy(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return De.mapValues(De.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Xy=_e,Wy=Ve.Graph;var Uy={debugOrdering:qy};function qy(e){let t=Xy.buildLayerMatrix(e),n=new Wy({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var Ky="1.1.8",Zy={graphlib:Ve,layout:_y,debug:Uy,util:{time:_e.time,notime:_e.notime},version:Ky};const ui=vi(Zy),Ye=264,Qy=44,Jy=26,ex=14;function wt(e){const t=Math.max(e.attributes.length,1);return Qy+t*Jy+ex}const tx=40;function ur(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?mi(e,n,o):r==="clustered"?hi(e,t,n,o,i):r==="hierarchical"||e.length<=tx?di(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?hi(e,t,n,o,i):mi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Sa(e,t,n,r=!1,s="LR"){const i=new ui.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Ye,height:d?wt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ui.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?wt(m):120,w=d.x-Ye/2,y=d.y-f/2;return a=Math.max(a,w+Ye),c=Math.max(c,y+f),{...u,position:{x:w,y}}}),width:a,height:c}}function di(e,t,n,r="LR"){return Sa(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?wt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Ye+ka);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Ye)}),i+=Math.max(...c.map(l=>n(l.id)))+ja}return{nodes:s,width:o,height:i}}const fi=120;function hi(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),w=new Set(f.map(E=>E.id));let y=0;for(const E of t)w.has(E.source)&&w.has(E.target)&&y++;const p=f.length<=8&&y>=f.length-1?Sa(f,t,n,!0,s):rx(f,n);return{name:m,...p}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const ka=40,ja=40;function mi(e,t,n){const r=l=>{const u=t.get(l);return u?wt(u):120},s=[...e].sort((l,u)=>{var y,v;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,w=((v=t.get(u.id))==null?void 0:v.name)??u.id;return f.localeCompare(w)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Ye+ka)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ja}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function cn({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ca=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var b,M;const[r,s]=x.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[i,o]=x.useState([]),[a,c]=x.useState(null),[l,u]=x.useState(null),[d,m]=x.useState("skos:exactMatch"),[f,w]=x.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,v]=x.useState([]),[p,E]=x.useState("");x.useEffect(()=>{Qo().then(N=>v(N.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const N=setTimeout(()=>{if(!r.trim())return o([]);Zo(r,p||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(N)},[r,p]);const $=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(cn,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(p===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(N=>h.jsx("button",{className:"src-chip"+(p===N.id?" active":""),title:N.count!=null?`${N.count} terms`:"live resolver",onClick:()=>E(N.id),children:N.name},N.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:p?`Search within ${p}…`:"Search vocabulary terms…",value:r,onChange:N=>s(N.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(N=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===N.iri?" picked":""),onClick:()=>u(N),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:N.label}),h.jsxs("span",{className:"term-source",children:[N.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),N.source]})]}),h.jsx("code",{className:"term-iri",children:N.prefixed}),N.definition&&h.jsx("p",{className:"term-def",children:N.definition})]},N.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:N=>m(N.target.value),children:sx.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:N=>w(N.target.value),children:Ca.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:$,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var b,M,N;const[s,i]=x.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[o,a]=x.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},w=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${w}:`,v=(N=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:N.members.map(_=>{var R;return(R=e.attributes.find(k=>k.id===_))==null?void 0:R.name}).filter(Boolean),p=v&&v.length?`${y}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,$=s.trim()||p;return h.jsxs(cn,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",$]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=x.useState(""),[o,a]=x.useState(""),[c,l]=x.useState(""),[u,d]=x.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const w=f==null?void 0:f.created_id;n(),w&&r(w)})};return h.jsxs(cn,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ca.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const $a=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=x.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=x.useState(r??""),[m,f]=x.useState(s??(l==null?void 0:l.id)??""),[w,y]=x.useState("many_to_one"),[v,p]=x.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",$=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:w,optionality:v}).then(o);return h.jsxs(cn,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:w,onChange:b=>y(b.target.value),children:$a.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>p(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:$,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=p=>{var E;return((E=t.entities.find($=>$.id===p))==null?void 0:E.name)??"?"},[i,o]=x.useState(e.name),[a,c]=x.useState(e.cardinality),[l,u]=x.useState(e.optionality),[d,m]=x.useState(e.identifying),[f,w]=x.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(cn,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:p=>o(p.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:p=>c(p.target.value),children:$a.map(p=>h.jsx("option",{children:p},p))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:p=>u(p.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:p=>m(p.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>w(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const pi=10,ux=6,Be=24;function dx(e,t){return t?e:Math.round(e/pi)*pi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-Be,o.right+Be);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eV.transform[2]),[m,f]=x.useState(null),w=x.useRef(!1),y=x.useRef(0),v=c==null?void 0:c.onRouteChange,p=!!v,E=m??(c==null?void 0:c.routeX),[$,b,M]=Rn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),N=c==null?void 0:c.relationship,_=(c==null?void 0:c.dimmed)??!1,R=(N==null?void 0:N.cardinality)??"many_to_one",k=(N==null?void 0:N.optionality)==="optional",O=(N==null?void 0:N.identifying)??!1,D=R==="many_to_one"||R==="many_to_many",B=R==="one_to_many"||R==="many_to_many",H="rel-edge"+(l?" selected":"")+(_?" dimmed":""),g=((c==null?void 0:c.memberCount)??0)>1,C=c==null?void 0:c.onHoverEdge,S=E??b,I=M,L=S,j=I,T=x.useCallback(V=>v&&N&&v(N.id,V),[v,N]),P=x.useCallback(V=>{var pe,ce;if(!p||V.button!==0)return;V.stopPropagation(),(ce=(pe=V.target).setPointerCapture)==null||ce.call(pe,V.pointerId),w.current=!0,y.current=0;const J=u({x:V.clientX,y:V.clientY}).x;let ee=0,oe=E??S;const ne=ue=>{const ye=u({x:ue.clientX,y:ue.clientY});y.current=Math.max(y.current,Math.abs(ye.x-J)),oe=mx(ye.x,{shift:ue.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),ee||(ee=requestAnimationFrame(()=>{ee=0,f(oe)}))},re=()=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",re),ee&&cancelAnimationFrame(ee),w.current=!1,f(null),y.current>=gi&&T(oe)};window.addEventListener("pointermove",ne),window.addEventListener("pointerup",re)},[p,u,E,S,c,n,s,T]),z=x.useCallback(V=>{y.current>=gi&&(V.stopPropagation(),y.current=0)},[]),X=x.useCallback(V=>{p&&(V.stopPropagation(),T(null))},[p,T]);return h.jsxs("g",{className:H,children:[h.jsx("path",{id:t,className:"rel-path",d:$,fill:"none",strokeDasharray:O?void 0:"6 4"}),h.jsx("path",{d:$,fill:"none",strokeWidth:16/d,stroke:"transparent",onMouseEnter:C?()=>C(N.id):void 0,onMouseLeave:C?()=>C(null):void 0}),h.jsx(yi,{x:n,y:r,side:o,many:D,optional:k}),h.jsx(yi,{x:s,y:i,side:a,many:B,optional:!1}),p&&(l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:P,onClickCapture:z,onDoubleClick:X,children:[h.jsx("rect",{x:S-11/d,y:I-16/d,width:22/d,height:32/d,fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:S-4.5/d,y:I-9/d,width:9/d,height:18/d,rx:4/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I-3/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I+3/d,r:1.1/d})]}),(l||g)&&N&&h.jsxs("text",{className:"rel-label",x:L,y:j-8,children:[l?N.verb_phrase||N.name:"",g?`${l?" ":""}(${c.memberCount})`:""]})]})});function yi({x:e,y:t,side:n,many:r,optional:s}){const i=n===q.Left?-1:1,o=7,a=12,c=[];return r?c.push(h.jsx("path",{className:"rel-glyph",d:`M ${e+i*a} ${t} L ${e} ${t-o} M ${e+i*a} ${t} L ${e} ${t} M ${e+i*a} ${t} L ${e} ${t+o}`,fill:"none"},"foot")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a-3),y1:t-o,x2:e+i*(a-3),y2:t+o},"one")),s?c.push(h.jsx("circle",{className:"rel-glyph ring",cx:e+i*(a+6),cy:t,r:4},"opt")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a+5),y1:t-o,x2:e+i*(a+5),y2:t+o},"mand")),h.jsx(h.Fragment,{children:c})}const gx={entity:Pm},yx={relationship:px},xi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],wi="#8a7d6a";function xx(e,t,n){const s=Ye;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function wx(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Yr,targetHandle:n(e.to.entity,s)?s:Xr}}function qx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:w,fitBounds:y,getNodes:v}=an(),[p,E]=x.useState([]),[$,b]=x.useState([]),M=x.useRef(!1),N=x.useMemo(()=>{const F=u&&u.size>0?[...u].sort():null;return F?"sa:"+F.join("+"):"__all__"},[u]),_=x.useRef(null),[R,k]=x.useState(0),O=x.useRef(new Map),D=x.useRef(null);x.useEffect(()=>{if(!f){_.current=null;return}const F=O.current.get(N);if(F){_.current=F,M.current=!1,k(G=>G+1);return}let Y=!1;return f.load(N).then(G=>{Y||(O.current.set(N,G),_.current=G,M.current=!1,k(Q=>Q+1))}),()=>{Y=!0}},[f,N]);const[B,H]=x.useState(null),[g,C]=x.useState(null),[S,I]=x.useState(!1),[L,j]=x.useState(null),[T,P]=x.useState(null),[z,X]=x.useState(null),[V,Z]=x.useState(null),J=x.useRef({}),ee=!t.canEdit,oe=x.useRef(null),ne=x.useCallback(()=>{f&&(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{const F={};for(const Q of v())Q.hidden||(F[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,U]of Object.entries(J.current))Y[Q]={routeX:Math.round(U)};const G={nodes:F,edges:Y};O.current.set(N,G),_.current=G,f.save(N,G)},800))},[f,v,N]),re=x.useCallback((F,Y)=>{Y==null?delete J.current[F]:J.current[F]=Y,b(G=>G.map(Q=>Q.id===F?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),ne()},[ne]),pe=x.useMemo(()=>{const F=new Map;return e.subject_areas.forEach((Y,G)=>F.set(Y.id,xi[G%xi.length])),F},[e]),ce=x.useMemo(()=>{const F=new Map;return e.entities.forEach(Y=>F.set(Y.id,Y)),F},[e]),ue=x.useMemo(()=>{const F=new Map,Y=new Map;return e.subject_areas.forEach(G=>{(G.members??[]).forEach(Q=>Y.set(Q,{id:G.id,name:G.name}))}),e.entities.forEach(G=>{var se,me;const Q=(se=G.conceptual)!=null&&se.id?Y.get(G.conceptual.id):void 0,U=(me=G.conceptual)==null?void 0:me.subject_area,te=Q??(U?{id:U.id,name:U.name??U.id}:void 0);te&&F.set(G.id,te)}),F},[e]),ye=x.useCallback(F=>{var G;if(!u||u.size===0)return!1;const Y=(G=ue.get(F))==null?void 0:G.id;return!(Y&&u.has(Y))},[u,ue]),he=x.useMemo(()=>{const F=new Map,Y=(G,Q)=>{if(!Q.length)return;const U=F.get(G)??new Set;Q.forEach(te=>U.add(te)),F.set(G,U)};for(const G of e.relationships)Y(G.from.entity,G.from.attributes),Y(G.to.entity,G.to.attributes);return F},[e]);x.useEffect(()=>{var $e;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const W of e.entities)(W.name.toLowerCase()+" "+((($e=W.conceptual)==null?void 0:$e.name.toLowerCase())??"")+" "+W.attributes.map(ge=>ge.name.toLowerCase()).join(" ")).includes(F)&&Y.add(W.id);const G=new Set;if(r){G.add(r);for(const W of e.relationships)W.from.entity===r&&G.add(W.to.entity),W.to.entity===r&&G.add(W.from.entity)}const Q=e.entities.map(W=>{const fe=F!==""&&!Y.has(W.id),ge=r!==null&&!G.has(W.id);return{id:W.id,type:"entity",position:{x:0,y:0},hidden:ye(W.id),data:{entity:W,color:(()=>{const Se=ue.get(W.id);return Se?pe.get(Se.id)??wi:wi})(),dimmed:fe||ge,highlighted:F!==""&&Y.has(W.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(W.id))??!1,onToggleExpand:l,endpointAttrs:he.get(W.id),highlightAttrs:void 0,onHoverAttr:X}}}),U=e.relationships.filter(W=>ce.has(W.from.entity)&&ce.has(W.to.entity)).map(W=>{const{sourceHandle:fe,targetHandle:ge}=wx(W,ce),Se=r!==null&&W.from.entity!==r&&W.to.entity!==r;return{id:W.id,source:W.from.entity,target:W.to.entity,sourceHandle:fe,targetHandle:ge,type:"relationship",data:{relationship:W,dimmed:Se,memberCount:Math.max(W.from.attributes.length,W.to.attributes.length),onHoverEdge:Z}}}),te=_.current;if(J.current={},te)for(const[W,fe]of Object.entries(te.edges))J.current[W]=fe.routeX;let se=Q;E(W=>{const fe=new Map(W.map(ae=>[ae.id,ae.position])),ge=Q.every(ae=>fe.has(ae.id)),Se=((u==null?void 0:u.size)??0)>0;if(M.current&&ge&&W.length>=Q.length&&!Se){const ae=Q.map(Ue=>({...Ue,position:fe.get(Ue.id)??Ue.position}));return se=ae,ae}const dt=Se?Q.filter(ae=>!ae.hidden):Q,Ot=ur(dt,U,ce,"auto",ue),rt=new Map(Ot.map(ae=>[ae.id,ae.position])),ft=(te==null?void 0:te.nodes)??{},Lt=Object.keys(ft).length>0,Pe=[],Dt=Q.map(ae=>{const Ue=ft[ae.id];if(Ue){const Pt={x:Ue.x,y:Ue.y};return Pe.push({x:Pt.x,y:Pt.y,w:Ye,h:wt(ae.data.entity)}),{...ae,position:Pt}}return rt.has(ae.id)?{...ae,position:rt.get(ae.id)}:fe.has(ae.id)&&M.current?{...ae,position:fe.get(ae.id)}:ae});if(Lt)for(const ae of Dt)ft[ae.id]||ae.hidden||(ae.position=xx(ae.position,wt(ae.data.entity),Pe),Pe.push({x:ae.position.x,y:ae.position.y,w:Ye,h:wt(ae.data.entity)}));return M.current=!0,Lt||requestAnimationFrame(()=>w({padding:.15,duration:300})),se=Dt,Dt});const me=new Map;for(const W of se)me.set(W.id,{left:W.position.x,right:W.position.x+Ye});b(U.map(W=>({...W,data:{...W.data,routeX:J.current[W.id],onRouteChange:f?re:void 0,sourceCard:me.get(W.source),targetCard:me.get(W.target)}})))},[e,i,r,o,a,c,l,pe,ce,ue,ye,u,he,w,f,re,R]);const xe=x.useMemo(()=>{const F=new Set,Y=new Set,G=new Map,Q=(U,te)=>{if(!te.length)return;const se=G.get(U)??new Set;te.forEach(me=>se.add(me)),G.set(U,se)};if(z)for(const U of e.relationships)(U.from.attributes.includes(z)||U.to.attributes.includes(z))&&(F.add(U.id),Y.add(U.from.entity),Y.add(U.to.entity),Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes));if(V){const U=e.relationships.find(te=>te.id===V);U&&(Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes))}return{active:z!==null,relsForAttr:F,entsForAttr:Y,hitAttrsByEntity:G}},[e,z,V]);x.useEffect(()=>{var Q;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);const G=new Set;if(r){G.add(r);for(const U of e.relationships)U.from.entity===r&&G.add(U.to.entity),U.to.entity===r&&G.add(U.from.entity)}E(U=>U.map(te=>{const se=F!==""&&!Y.has(te.id),me=r!==null&&!G.has(te.id),$e=xe.active&&!xe.entsForAttr.has(te.id),W=se||me||$e,fe=F!==""&&Y.has(te.id)||xe.active&&xe.entsForAttr.has(te.id),ge=xe.hitAttrsByEntity.get(te.id);return te.data.dimmed===W&&te.data.highlighted===fe&&te.data.highlightAttrs===ge?te:{...te,data:{...te.data,dimmed:W,highlighted:fe,highlightAttrs:ge}}})),b(U=>U.map(te=>{var fe,ge;const se=(fe=te.data)==null?void 0:fe.relationship,me=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,$e=xe.active&&!xe.relsForAttr.has(te.id),W=me||$e;return((ge=te.data)==null?void 0:ge.dimmed)===W?te:{...te,data:{...te.data,dimmed:W}}}))},[xe,i,r,e]),x.useEffect(()=>{var Q;const F=i.trim().toLowerCase();if(!F)return;const Y=new Set;for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(U.id);if(!Y.size)return;const G=requestAnimationFrame(()=>{const U=v().filter(se=>Y.has(se.id));if(!U.length)return;const te=Mf(U);y(te,{padding:.35,duration:400})});return()=>cancelAnimationFrame(G)},[i,e,v,y]);const le=x.useCallback((F="auto",Y="LR")=>{D.current=Object.fromEntries(v().map(G=>[G.id,{x:G.position.x,y:G.position.y}])),E(G=>ur(G,$,ce,F,ue,Y)),requestAnimationFrame(()=>w({padding:.15,duration:300})),ne()},[$,ce,ue,w,v,ne]),K=x.useCallback(()=>{const F=D.current;F&&(E(Y=>Y.map(G=>F[G.id]?{...G,position:F[G.id]}:G)),D.current=null,ne())},[ne]),Ne=x.useCallback(()=>{f==null||f.reset(N),O.current.delete(N),_.current=null,J.current={},M.current=!1,b(F=>F.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(F=>{const Y=ur(F,$,ce,"auto",ue);return requestAnimationFrame(()=>w({padding:.15,duration:300})),Y})},[f,N,$,ce,ue,w]),Ce=x.useCallback(F=>{s(F),E(Y=>(Y.find(Q=>Q.id===F)&&requestAnimationFrame(()=>w({nodes:[{id:F}],padding:.4,duration:400})),Y))},[w,s]);x.useImperativeHandle(m,()=>({relayout:le,fitView:()=>w({padding:.15,duration:300}),focusEntity:Ce,newEntity:()=>I(!0),resetLayout:Ne,undoRelayout:K}),[le,w,Ce,Ne,K]);const ut=x.useCallback(F=>{if(ee||!F.source||!F.target||F.source===F.target)return;const Y=F.sourceHandle&&F.sourceHandle!==Yr?F.sourceHandle:void 0,G=F.targetHandle&&F.targetHandle!==Xr?F.targetHandle:void 0;j({from:F.source,to:F.target,fromAttr:Y,toAttr:G})},[ee]),Ae=x.useCallback(async(F,Y)=>{try{return await n(F,Y)}catch(G){throw d==null||d(G instanceof Error?G.message:String(G)),G}},[n,d]),We=r?ce.get(r)??null:null,Ie=e.relationships.find(F=>F.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Yo,{nodes:p,edges:$,nodeTypes:gx,edgeTypes:yx,onNodeClick:(F,Y)=>s(Y.id),onEdgeClick:(F,Y)=>!ee&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(F,Y)=>{E(G=>G.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),ne()},onConnect:ut,nodesConnectable:!ee,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:Le.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:F=>{var Y;return((Y=F.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),We&&h.jsx(Hm,{entity:We,doc:e,caps:t,exec:Ae,onClose:()=>s(null),onFocusEntity:Ce,onAlign:H,onEditMapping:C}),B&&h.jsx(ix,{entity:B,exec:Ae,onClose:()=>H(null)}),g&&h.jsx(ox,{entity:g,doc:e,exec:Ae,onClose:()=>C(null)}),S&&h.jsx(ax,{doc:e,exec:Ae,onClose:()=>I(!1),onCreated:Ce}),L&&h.jsx(cx,{doc:e,fromId:L.from,toId:L.to,initialFromAttr:L.fromAttr,initialToAttr:L.toAttr,exec:Ae,onClose:()=>j(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:Ae,onClose:()=>P(null)})]})}function Kx({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(bx,{}),e==="layers"&&h.jsx(_x,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(Ex,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Nx,{readOnly:n})]})}function bx(){const[e,t]=x.useState(""),[n,r]=x.useState([]),[s,i]=x.useState({loaded:0,vocabs:[]}),[o,a]=x.useState(null),[c,l]=x.useState([]),[u,d]=x.useState("");x.useEffect(()=>{Qo().then(f=>l(f.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const f=setTimeout(()=>{Zo(e||"a",u||void 0).then(w=>{r(e?w.results:[]),i({loaded:w.loaded_terms,vocabs:w.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=x.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const vx=["industry","core","domain","specialised"];function _x({refreshKey:e,onFocusEntity:t}){const[n,r]=x.useState(null),[s,i]=x.useState(null);if(x.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),vx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Ex({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=x.useState(null),[i,o]=x.useState(""),[a,c]=x.useState(""),[l,u]=x.useState(!1),d=x.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` + */var Dn=x,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=Dn.useRef,_c=Dn.useEffect,Ec=Dn.useMemo,Nc=Dn.useDebugValue;Ei.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var w=o.value;if(s(w,f))return d=w}return d=f}if(w=d,wc(u,f))return w;var y=r(f);return s!==void 0&&s(w,y)?(u=f,w):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};_i.exports=Ei;var Sc=_i.exports;const kc=vi(Sc),jc={},es=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(w=>w(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?es(e):es,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function ki(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const ts=(e,t)=>{const n=Cc(e),r=(s,i=t)=>ki(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?ts(e,t):ts;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rs.hasOwnProperty(t)?{space:rs[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===dr&&t.documentElement.namespaceURI===dr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ji(e){var t=zn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function Cr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=Cr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=$&&($=E+1);!(M=v[$])&&++$=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Rt(this.node(),e)}function Rt(e,t){return e.style.getPropertyValue(t)||Ri(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ii(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Ti(e)}function Ti(e){this._node=e,this._names=Ii(e.getAttribute("class")||"")}Ti.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Oi(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function fr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}fr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Pn("start","drag","end"),o=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",p,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,M){if(!(u||!e.call(this,b,M))){var N=$(this,t.call(this,b,M),b,M,"mouse");N&&(Te(b.view).on("mousemove.drag",w,Ut).on("mouseup.drag",y,Ut),zi(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,N("start",b))}}function w(b){if(Ct(b),!l){var M=b.clientX-a,N=b.clientY-c;l=M*M+N*N>d}s.mouse("drag",b)}function y(b){Te(b.view).on("mousemove.drag mouseup.drag",null),Hi(b.view,l),Ct(b),s.mouse("end",b)}function v(b,M){if(e.call(this,b,M)){var N=b.changedTouches,_=t.call(this,b,M),R=N.length,k,O;for(k=0;k>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?un(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?un(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Me(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Me(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?un(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?un(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?us(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?us(t[1],t[2]/100,t[3]/100,t[4]):ss.hasOwnProperty(e)?as(ss[e]):e==="transparent"?new Me(NaN,NaN,NaN,0):null}function as(e){return new Me(e>>16&255,e>>8&255,e&255,1)}function un(e,t,n,r){return r<=0&&(e=t=n=NaN),new Me(e,t,n,r)}function Mu(e){return e instanceof rn||(e=Zt(e)),e?(e=e.rgb(),new Me(e.r,e.g,e.b,e.opacity)):new Me}function hr(e,t,n,r){return arguments.length===1?Mu(e):new Me(e,t,n,r??1)}function Me(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Mr(Me,hr,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Me(yt(this.r),yt(this.g),yt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:cs,formatHex:cs,formatHex8:Au,formatRgb:ls,toString:ls}));function cs(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function ls(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function us(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new He(e,t,n,r)}function Vi(e){if(e instanceof He)return new He(e.h,e.s,e.l,e.opacity);if(e instanceof rn||(e=Zt(e)),!e)return new He;if(e instanceof He)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new He(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Vi(e):new He(e,t,n,r??1)}function He(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Mr(He,Ru,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new He(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new He(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Me(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new He(ds(this.h),dn(this.s),dn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${ds(this.h)}, ${dn(this.s)*100}%, ${dn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ds(e){return e=(e||0)%360,e<0?e+360:e}function dn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Bi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Gi:function(t,n){return n-t?Tu(t,n,e):Bi(isNaN(t)?n:t)}}function Gi(e,t){var n=t-e;return n?Iu(e,n):Bi(isNaN(e)?t:e)}const fs=function e(t){var n=Ou(t);function r(s,i){var o=n((s=hr(s)).r,(i=hr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Gi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function ot(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var mr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(mr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=mr.lastIndex=Kn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=mr.exec(e))&&(s=Kn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:ot(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:ot(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:ot(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,w){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");w.push({i:y-4,x:ot(l,d)},{i:y-2,x:ot(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var w=-1,y=m.length,v;++w=0&&e._call.call(void 0,t),e=e._next;--It}function ps(){bt=(Cn=Qt.now())+Hn,It=Gt=0;try{Uu()}finally{It=0,Ku(),bt=0}}function qu(){var e=Qt.now(),t=e-Cn;t>Wi&&(Hn-=t,Cn=e)}function Ku(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Yt=e,gr(r)}function gr(e){if(!It){Gt&&(Gt=clearTimeout(Gt));var t=e-bt;t>24?(e<1/0&&(Gt=setTimeout(ps,e-Qt.now()-Hn)),zt&&(zt=clearInterval(zt))):(zt||(Cn=Qt.now(),zt=setInterval(qu,Wi)),It=1,Ui(ps))}}function gs(e,t,n){var r=new $n;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Pn("start","end","cancel","interrupt"),Qu=[],Ki=0,ys=1,yr=2,vn=3,xs=4,xr=5,_n=6;function Fn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Ki})}function Rr(e,t){var n=Fe(e,t);if(n.state>Ki)throw new Error("too late; already scheduled");return n}function We(e,t){var n=Fe(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Fe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=qi(i,0,n.time);function i(l){n.state=ys,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ys)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return gs(o);f.state===xs?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uyr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Rr:We;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Fe(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Cr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Je(e,t,n){this.k=e,this.x=t,this.y=n}Je.prototype={constructor:Je,scale:function(e){return e===1?this:new Je(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Je(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var et=new Je(1,0,0);Je.prototype;function Zn(e){e.stopImmediatePropagation()}function Ht(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ws(){return this.__zoom||et}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function eo(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Xu,l=Pn("start","zoom","end"),u,d,m,f=500,w=150,y=0,v=10;function p(g){g.property("__zoom",ws).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",D).on("touchmove.zoom",B).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}p.transform=function(g,C,S,I){var L=g.selection?g.selection():g;L.property("__zoom",ws),g!==L?M(g,C,S,I):L.interrupt().each(function(){N(this,arguments).event(I).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},p.scaleBy=function(g,C,S,I){p.scaleTo(g,function(){var L=this.__zoom.k,j=typeof C=="function"?C.apply(this,arguments):C;return L*j},S,I)},p.scaleTo=function(g,C,S,I){p.transform(g,function(){var L=t.apply(this,arguments),j=this.__zoom,T=S==null?b(L):typeof S=="function"?S.apply(this,arguments):S,P=j.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n($(E(j,z),T,P),L,o)},S,I)},p.translateBy=function(g,C,S,I){p.transform(g,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,I)},p.translateTo=function(g,C,S,I,L){p.transform(g,function(){var j=t.apply(this,arguments),T=this.__zoom,P=I==null?b(j):typeof I=="function"?I.apply(this,arguments):I;return n(et.translate(P[0],P[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof S=="function"?-S.apply(this,arguments):-S),j,o)},I,L)};function E(g,C){return C=Math.max(i[0],Math.min(i[1],C)),C===g.k?g:new Je(C,g.x,g.y)}function $(g,C,S){var I=C[0]-S[0]*g.k,L=C[1]-S[1]*g.k;return I===g.x&&L===g.y?g:new Je(g.k,I,L)}function b(g){return[(+g[0][0]+ +g[1][0])/2,(+g[0][1]+ +g[1][1])/2]}function M(g,C,S,I){g.on("start.zoom",function(){N(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(I).end()}).tween("zoom",function(){var L=this,j=arguments,T=N(L,j).event(I),P=t.apply(L,j),z=S==null?b(P):typeof S=="function"?S.apply(L,j):S,X=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),F=L.__zoom,Z=typeof C=="function"?C.apply(L,j):C,J=c(F.invert(z).concat(X/F.k),Z.invert(z).concat(X/Z.k));return function(te){if(te===1)te=Z;else{var oe=J(te),ne=X/oe[2];te=new Je(ne,z[0]-oe[0]*ne,z[1]-oe[1]*ne)}T.zoom(null,te)}})}function N(g,C,S){return!S&&g.__zooming||new _(g,C)}function _(g,C){this.that=g,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(g,C),this.taps=0}_.prototype={event:function(g){return g&&(this.sourceEvent=g),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(g,C){return this.mouse&&g!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&g!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&g!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(g){var C=Te(this.that).datum();l.call(g,this.that,new sf(g,{sourceEvent:this.sourceEvent,target:p,transform:this.that.__zoom,dispatch:l}),C)}};function R(g,...C){if(!e.apply(this,arguments))return;var S=N(this,C).event(g),I=this.__zoom,L=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,r.apply(this,arguments)))),j=ze(g);if(S.wheel)(S.mouse[0][0]!==j[0]||S.mouse[0][1]!==j[1])&&(S.mouse[1]=I.invert(S.mouse[0]=j)),clearTimeout(S.wheel);else{if(I.k===L)return;S.mouse=[j,I.invert(j)],En(this),S.start()}Ht(g),S.wheel=setTimeout(T,w),S.zoom("mouse",n($(E(I,L),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function k(g,...C){if(m||!e.apply(this,arguments))return;var S=g.currentTarget,I=N(this,C,!0).event(g),L=Te(g.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",X,!0),j=ze(g,S),T=g.clientX,P=g.clientY;zi(g.view),Zn(g),I.mouse=[j,this.__zoom.invert(j)],En(this),I.start();function z(F){if(Ht(F),!I.moved){var Z=F.clientX-T,J=F.clientY-P;I.moved=Z*Z+J*J>y}I.event(F).zoom("mouse",n($(I.that.__zoom,I.mouse[0]=ze(F,S),I.mouse[1]),I.extent,o))}function X(F){L.on("mousemove.zoom mouseup.zoom",null),Hi(F.view,I.moved),Ht(F),I.event(F).end()}}function O(g,...C){if(e.apply(this,arguments)){var S=this.__zoom,I=ze(g.changedTouches?g.changedTouches[0]:g,this),L=S.invert(I),j=S.k*(g.shiftKey?.5:2),T=n($(E(S,j),I,L),t.apply(this,C),o);Ht(g),a>0?Te(this).transition().duration(a).call(M,T,I,g):Te(this).call(p.transform,T,I,g)}}function D(g,...C){if(e.apply(this,arguments)){var S=g.touches,I=S.length,L=N(this,C,g.changedTouches.length===I).event(g),j,T,P,z;for(Zn(g),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},to=nt.error001();function de(e,t){const n=x.useContext(Vn);if(n===null)throw new Error(to);return ki(n,e,t)}const Ne=()=>{const e=x.useContext(Vn);if(e===null)throw new Error(to);return x.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Tr({position:e,children:t,className:n,style:r,...s}){const i=de(ff),o=`${e}`.split("-");return A.createElement("div",{className:je(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Tr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=x.useRef(null),[m,f]=x.useState({x:0,y:0,width:0,height:0}),w=je(["react-flow__edge-textwrapper",l]);return x.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:w,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=x.memo(mf);const Or=e=>({width:e.offsetWidth,height:e.offsetHeight}),Tt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Lr=(e={x:0,y:0},t)=>({x:Tt(e.x,t[0][0],t[1][0]),y:Tt(e.y,t[0][1],t[1][1])}),bs=(e,t,n)=>en?-Tt(Math.abs(e-n),1,50)/50:0,no=(e,t)=>{const n=bs(e.x,35,t.width-35)*20,r=bs(e.y,35,t.height-35)*20;return[n,r]},ro=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},so=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Jt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),io=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),vs=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>io(so(Jt(e),Jt(t))),wr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Oe(e.width)&&Oe(e.height)&&Oe(e.x)&&Oe(e.y),Oe=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),oo=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function br(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const ao=e=>"clientX"in e,ut=(e,t)=>{var i,o;const n=ao(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Mn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},sn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Oe(n)&&Oe(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);sn.displayName="BaseEdge";function Ft(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function co({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[v,p,E]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(sn,{path:v,labelX:p,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:y})});Dr.displayName="SimpleBezierEdge";const Es={[q.Left]:{x:-1,y:0},[q.Right]:{x:1,y:0},[q.Top]:{x:0,y:-1},[q.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=q.Bottom,target:n})=>t===q.Left||t===q.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=q.Bottom,target:n,targetPosition:r=q.Top,center:s,offset:i}){const o=Es[t],a=Es[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],w,y;const v={x:0,y:0},p={x:0,y:0},[E,$,b,M]=co({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){w=s.x??E,y=s.y??$;const _=[{x:w,y:c.y},{x:w,y:l.y}],R=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?R:_:f=o.y===m?_:R,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const g=Math.min(i-1,i-H);o[d]===m?v[d]=(c[d]>e[d]?-1:1)*g:p[d]=(l[d]>n[d]?-1:1)*g}}if(t!==r){const H=d==="x"?"y":"x",g=o[d]===a[H],C=c[H]>l[H],S=c[H]=B?(w=(k.x+O.x)/2,y=f[0].y):(w=f[0].x,y=(k.y+O.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:l.x+p.x,y:l.y+p.y},n],w,y,b,M]}function _f(e,t,n,r){const s=Math.min(Ns(e,t)/2,Ns(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let $="";return E>0&&E{const[p,E,$]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:w,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const Pr=x.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:x.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Pr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=co({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const zr=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[w,y,v]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(sn,{path:w,labelX:y,labelY:v,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});zr.displayName="StraightEdge";function mn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Ss({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case q.Left:return[t-mn(t-r,i),n];case q.Right:return[t+mn(r-t,i),n];case q.Top:return[t,n-mn(n-s,i)];case q.Bottom:return[t,n+mn(s-n,i)]}}function fo({sourceX:e,sourceY:t,sourcePosition:n=q.Bottom,targetX:r,targetY:s,targetPosition:i=q.Top,curvature:o=.25}){const[a,c]=Ss({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Ss({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,w]=lo({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,w]}const In=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=q.Bottom,targetPosition:i=q.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,pathOptions:y,interactionWidth:v})=>{const[p,E,$]=fo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:v})});In.displayName="BezierEdge";const Hr=x.createContext(null),Nf=Hr.Provider;Hr.Consumer;const Sf=()=>x.useContext(Hr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,vr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},_r=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},ho=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},on=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return so(r,Jt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return io(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),on(e,t)),mo=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:w=!1}=u;if(o&&!f||w)return!1;const{positionAbsolute:y}=xt(u,a),v={x:y.x,y:y.y,width:d||0,height:m||0},p=wr(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,$=i&&p>0,b=(d||0)*(m||0);(E||$||p>=b||u.dragging)&&l.push(u)}),l},po=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},go=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Tt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function ks(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=ut(e),l=t.elementsFromPoint(o,a).find(w=>w.classList.contains("react-flow__handle"));if(l){const w=l.getAttribute("data-nodeid");if(w){const y=Fr(void 0,l),v=l.getAttribute("data-handleid"),p=i({nodeId:w,id:v,type:y});if(p){const E=s.find($=>$.nodeId===w&&$.type===y&&$.id===v);return{handle:{id:v,type:y,nodeId:w,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:p}}}}let u=[],d=1/0;if(s.forEach(w=>{const y=Math.sqrt((w.x-n.x)**2+(w.y-n.y)**2);if(y<=r){const v=i(w);y<=d&&(yw.isValid),f=u.some(({handle:w})=>w.type==="target");return u.find(({handle:w,validHandleResult:y})=>f?w.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},yo=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function xo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...yo(),handleDomNode:c};if(c){const u=Fr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),w=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&w&&(t===vt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=ks(i,o,"source",`${t}-${n}-${r}`),c=ks(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Fr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function wo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ro(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:w,onConnectStart:y,panBy:v,getNodes:p,cancelConnection:E}=i();let $=0,b;const{x:M,y:N}=ut(e),_=u==null?void 0:u.elementFromPoint(M,N),R=Fr(c,_),k=m==null?void 0:m.getBoundingClientRect();if(!k||!R)return;let O,D=ut(e,k),B=!1,H=null,g=!1,C=null;const S=If({nodes:p(),nodeId:n,handleId:t,handleType:R}),I=()=>{if(!f)return;const[T,P]=no(D,k);v({x:T,y:P}),$=requestAnimationFrame(I)};o({connectionPosition:D,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:R});function L(T){const{transform:P}=i();D=ut(T,k);const{handle:z,validHandleResult:X}=Af(T,u,_r(D,P,!1,[1,1]),w,S,F=>xo(F,d,n,t,s?"target":"source",a,u));if(b=z,B||(I(),B=!0),C=X.handleDomNode,H=X.connection,g=X.isValid,o({connectionPosition:b&&g?ho({x:b.x,y:b.y},P):D,connectionStatus:Tf(!!b,g),connectionEndHandle:X.endHandle}),!b&&!g&&!C)return Qn(O);H.source!==H.target&&C&&(Qn(O),O=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",g),C.classList.toggle("react-flow__handle-valid",g))}function j(T){var P,z;(b||C)&&H&&g&&(r==null||r(H)),(z=(P=i()).onConnectEnd)==null||z.call(P,T),c&&(l==null||l(T)),Qn(O),E(),cancelAnimationFrame($),B=!1,g=!1,H=null,C=null,u.removeEventListener("mousemove",L),u.removeEventListener("mouseup",j),u.removeEventListener("touchmove",L),u.removeEventListener("touchend",j)}u.addEventListener("mousemove",L),u.addEventListener("mouseup",j),u.addEventListener("touchmove",L),u.addEventListener("touchend",j)}const js=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},bo=x.forwardRef(({type:e="source",position:t=q.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var k,O;const w=o||null,y=e==="target",v=Ne(),p=Sf(),{connectOnClick:E,noPanClassName:$}=de(Of,ke),{connecting:b,clickConnecting:M}=de(Lf(p,w,e),ke);p||(O=(k=v.getState()).onError)==null||O.call(k,"010",nt.error010());const N=D=>{const{defaultEdgeOptions:B,onConnect:H,hasDefaultEdges:g}=v.getState(),C={...B,...D};if(g){const{edges:S,setEdges:I}=v.getState();I($f(C,S))}H==null||H(C),a==null||a(C)},_=D=>{if(!p)return;const B=ao(D);s&&(B&&D.button===0||!B)&&wo({event:D,handleId:w,nodeId:p,onConnect:N,isTarget:y,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||js}),B?u==null||u(D):d==null||d(D)},R=D=>{const{onClickConnectStart:B,onClickConnectEnd:H,connectionClickStartHandle:g,connectionMode:C,isValidConnection:S}=v.getState();if(!p||!g&&!s)return;if(!g){B==null||B(D,{nodeId:p,handleId:w,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:p,type:e,handleId:w}});return}const I=ro(D.target),L=n||S||js,{connection:j,isValid:T}=xo({nodeId:p,id:w,type:e},C,g.nodeId,g.handleId||null,g.type,L,I);T&&N(j),H==null||H(D),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":w,"data-nodeid":p,"data-handlepos":t,"data-id":`${p}-${w}-${e}`,className:je(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",$,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!b||i&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});bo.displayName="Handle";var lt=x.memo(bo);const vo=({data:e,isConnectable:t,targetPosition:n=q.Top,sourcePosition:r=q.Bottom})=>A.createElement(A.Fragment,null,A.createElement(lt,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(lt,{type:"source",position:r,isConnectable:t}));vo.displayName="DefaultNode";var Er=x.memo(vo);const _o=({data:e,isConnectable:t,sourcePosition:n=q.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(lt,{type:"source",position:n,isConnectable:t}));_o.displayName="InputNode";var Eo=x.memo(_o);const No=({data:e,isConnectable:t,targetPosition:n=q.Top})=>A.createElement(A.Fragment,null,A.createElement(lt,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);No.displayName="OutputNode";var So=x.memo(No);const Vr=()=>null;Vr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),pn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(pn),t.selectedNodes.map(pn))&&ke(e.selectedEdges.map(pn),t.selectedEdges.map(pn))}const ko=x.memo(({onSelectionChange:e})=>{const t=Ne(),{selectedNodes:n,selectedEdges:r}=de(Df,Pf);return x.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});ko.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=de(zf);return e||t?A.createElement(ko,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Et(e,t){x.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ie(e,t,n){x.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:w,minZoom:y,maxZoom:v,nodeExtent:p,onNodesChange:E,onEdgesChange:$,elementsSelectable:b,connectionMode:M,snapGrid:N,snapToGrid:_,translateExtent:R,connectOnClick:k,defaultEdgeOptions:O,fitView:D,fitViewOptions:B,onNodesDelete:H,onEdgesDelete:g,onNodeDrag:C,onNodeDragStart:S,onNodeDragStop:I,onSelectionDrag:L,onSelectionDragStart:j,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:X,autoPanOnConnect:F,autoPanOnNodeDrag:Z,onError:J,connectionRadius:te,isValidConnection:oe,nodeDragThreshold:ne})=>{const{setNodes:re,setEdges:pe,setDefaultNodesAndEdges:ce,setMinZoom:ue,setMaxZoom:ye,setTranslateExtent:he,setNodeExtent:xe,reset:le}=de(Ff,ke),K=Ne();return x.useEffect(()=>{const Se=r==null?void 0:r.map(Ce=>({...Ce,...O}));return ce(n,Se),()=>{le()}},[]),ie("defaultEdgeOptions",O,K.setState),ie("connectionMode",M,K.setState),ie("onConnect",s,K.setState),ie("onConnectStart",i,K.setState),ie("onConnectEnd",o,K.setState),ie("onClickConnectStart",a,K.setState),ie("onClickConnectEnd",c,K.setState),ie("nodesDraggable",l,K.setState),ie("nodesConnectable",u,K.setState),ie("nodesFocusable",d,K.setState),ie("edgesFocusable",m,K.setState),ie("edgesUpdatable",f,K.setState),ie("elementsSelectable",b,K.setState),ie("elevateNodesOnSelect",w,K.setState),ie("snapToGrid",_,K.setState),ie("snapGrid",N,K.setState),ie("onNodesChange",E,K.setState),ie("onEdgesChange",$,K.setState),ie("connectOnClick",k,K.setState),ie("fitViewOnInit",D,K.setState),ie("fitViewOnInitOptions",B,K.setState),ie("onNodesDelete",H,K.setState),ie("onEdgesDelete",g,K.setState),ie("onNodeDrag",C,K.setState),ie("onNodeDragStart",S,K.setState),ie("onNodeDragStop",I,K.setState),ie("onSelectionDrag",L,K.setState),ie("onSelectionDragStart",j,K.setState),ie("onSelectionDragStop",T,K.setState),ie("noPanClassName",P,K.setState),ie("nodeOrigin",z,K.setState),ie("rfId",X,K.setState),ie("autoPanOnConnect",F,K.setState),ie("autoPanOnNodeDrag",Z,K.setState),ie("onError",J,K.setState),ie("connectionRadius",te,K.setState),ie("isValidConnection",oe,K.setState),ie("nodeDragThreshold",ne,K.setState),Et(e,re),Et(t,pe),Et(y,ue),Et(v,ye),Et(R,he),Et(p,xe),null},Cs={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},jo="react-flow__node-desc",Co="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Xf({rfId:e}){const t=de(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Wf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${jo}-${e}`,style:Cs},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Co}-${e}`,style:Cs},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Xf,{rfId:e}))}var tn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=x.useState(!1),s=x.useRef(!1),i=x.useRef(new Set([])),[o,a]=x.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return x.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);i.current.add(f[y]),$s(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);$s(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Ms(e,t){return t.includes(e)?"code":"key"}function $o(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return $o(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function Mo(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=$o(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Oe(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Mo(s,n,i),s}function Ao(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const w=n().filter(v=>{var E;const p=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?p&&t.nodes.some($=>$.id===v.id):p}),y=w.every(v=>v.width&&v.height);if(w.length>0&&y){const v=on(w,d),{x:p,y:E,zoom:$}=go(v,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),b=et.translate(p,E).scale($);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Uf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function gn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Uf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const Nt=()=>{},Kf={zoomIn:Nt,zoomOut:Nt,zoomTo:Nt,getZoom:()=>1,setViewport:Nt,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:Nt,fitBounds:Nt,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Ne(),{d3Zoom:t,d3Selection:n}=de(Zf,ke);return x.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=et.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Ao(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=et.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=go(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=et.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),_r(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return _r(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=ho(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function an(){const e=Qf(),t=Ne(),n=x.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=x.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=x.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(v=>({...v}))},[]),i=x.useCallback(y=>{const{edges:v=[]}=t.getState();return v.find(p=>p.id===y)},[]),o=x.useCallback(y=>{const{getNodes:v,setNodes:p,hasDefaultNodes:E,onNodesChange:$}=t.getState(),b=v(),M=typeof y=="function"?y(b):y;if(E)p(M);else if($){const N=M.length===0?b.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));$(N)}},[]),a=x.useCallback(y=>{const{edges:v=[],setEdges:p,hasDefaultEdges:E,onEdgesChange:$}=t.getState(),b=typeof y=="function"?y(v):y;if(E)p(b);else if($){const M=b.length===0?v.map(N=>({type:"remove",id:N.id})):b.map(N=>({item:N,type:"reset"}));$(M)}},[]),c=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{getNodes:p,setNodes:E,hasDefaultNodes:$,onNodesChange:b}=t.getState();if($){const N=[...p(),...v];E(N)}else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),l=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{edges:p=[],setEdges:E,hasDefaultEdges:$,onEdgesChange:b}=t.getState();if($)E([...p,...v]);else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),u=x.useCallback(()=>{const{getNodes:y,edges:v=[],transform:p}=t.getState(),[E,$,b]=p;return{nodes:y().map(M=>({...M})),edges:v.map(M=>({...M})),viewport:{x:E,y:$,zoom:b}}},[]),d=x.useCallback(({nodes:y,edges:v})=>{const{nodeInternals:p,getNodes:E,edges:$,hasDefaultNodes:b,hasDefaultEdges:M,onNodesDelete:N,onEdgesDelete:_,onNodesChange:R,onEdgesChange:k}=t.getState(),O=(y||[]).map(C=>C.id),D=(v||[]).map(C=>C.id),B=E().reduce((C,S)=>{const I=S.parentNode||S.parentId,L=!O.includes(S.id)&&I&&C.find(T=>T.id===I);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(O.includes(S.id)||L)&&C.push(S),C},[]),H=$.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),g=H.filter(C=>D.includes(C.id));if(B||g){const C=po(B,H),S=[...g,...C],I=S.reduce((L,j)=>(L.includes(j.id)||L.push(j.id),L),[]);if((M||b)&&(M&&t.setState({edges:$.filter(L=>!I.includes(L.id))}),b&&(B.forEach(L=>{p.delete(L.id)}),t.setState({nodeInternals:new Map(p)}))),I.length>0&&(_==null||_(S),k&&k(I.map(L=>({id:L,type:"remove"})))),B.length>0&&(N==null||N(B),R)){const L=B.map(j=>({id:j.id,type:"remove"}));R(L)}}},[]),m=x.useCallback(y=>{const v=yf(y),p=v?null:t.getState().nodeInternals.get(y.id);return!v&&!p?[null,null,v]:[v?y:vs(p),p,v]},[]),f=x.useCallback((y,v=!0,p)=>{const[E,$,b]=m(y);return E?(p||t.getState().getNodes()).filter(M=>{if(!b&&(M.id===$.id||!M.positionAbsolute))return!1;const N=vs(M),_=wr(N,E);return v&&_>0||_>=E.width*E.height}):[]},[]),w=x.useCallback((y,v,p=!0)=>{const[E]=m(y);if(!E)return!1;const $=wr(E,v);return p&&$>0||$>=E.width*E.height},[]);return x.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:w}),[e,n,r,s,i,o,a,c,l,u,d,f,w])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ne(),{deleteElements:r}=an(),s=tn(e,Jf),i=tn(t);x.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),x.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Ne();x.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Or(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",nt.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Br={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,yn=e=>({x:e.x,y:e.y,zoom:e.k}),St=(e,t)=>e.target.closest(`.${t}`),As=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rs=e=>{const t=e.ctrlKey&&Mn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:w,maxZoom:y,zoomActivationKeyCode:v,preventScrolling:p=!0,children:E,noWheelClassName:$,noPanClassName:b})=>{const M=x.useRef(),N=Ne(),_=x.useRef(!1),R=x.useRef(!1),k=x.useRef(null),O=x.useRef({x:0,y:0,zoom:0}),{d3Zoom:D,d3Selection:B,d3ZoomHandler:H,userSelectionActive:g}=de(rh,ke),C=tn(v),S=x.useRef(0),I=x.useRef(!1),L=x.useRef();return th(k),x.useEffect(()=>{if(k.current){const j=k.current.getBoundingClientRect(),T=eo().scaleExtent([w,y]).translateExtent(f),P=Te(k.current).call(T),z=et.translate(m.x,m.y).scale(Tt(m.zoom,w,y)),X=[[0,0],[j.width,j.height]],F=T.constrain()(z,X,f);T.transform(P,F),T.wheelDelta(Rs),N.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[F.x,F.y,F.k],domNode:k.current.closest(".react-flow")})}},[]),x.useEffect(()=>{B&&D&&(o&&!C&&!g?B.on("wheel.zoom",j=>{if(St(j,$))return!1;j.preventDefault(),j.stopImmediatePropagation();const T=B.property("__zoom").k||1;if(j.ctrlKey&&i){const oe=ze(j),ne=Rs(j),re=T*Math.pow(2,ne);D.scaleTo(B,re,oe,j);return}const P=j.deltaMode===1?20:1;let z=c===gt.Vertical?0:j.deltaX*P,X=c===gt.Horizontal?0:j.deltaY*P;!Mn()&&j.shiftKey&&c!==gt.Vertical&&(z=j.deltaY*P,X=0),D.translateBy(B,-(z/T)*a,-(X/T)*a,{internal:!0});const F=yn(B.property("__zoom")),{onViewportChangeStart:Z,onViewportChange:J,onViewportChangeEnd:te}=N.getState();clearTimeout(L.current),I.current||(I.current=!0,t==null||t(j,F),Z==null||Z(F)),I.current&&(e==null||e(j,F),J==null||J(F),L.current=setTimeout(()=>{n==null||n(j,F),te==null||te(F),I.current=!1},150))},{passive:!1}):typeof H<"u"&&B.on("wheel.zoom",function(j,T){if(!p&&j.type==="wheel"&&!j.ctrlKey||St(j,$))return null;j.preventDefault(),H.call(this,j,T)},{passive:!1}))},[g,o,c,B,D,H,C,i,p,$,t,e,n]),x.useEffect(()=>{D&&D.on("start",j=>{var z,X;if(!j.sourceEvent||j.sourceEvent.internal)return null;S.current=(z=j.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=N.getState(),P=yn(j.transform);_.current=!0,O.current=P,((X=j.sourceEvent)==null?void 0:X.type)==="mousedown"&&N.setState({paneDragging:!0}),T==null||T(P),t==null||t(j.sourceEvent,P)})},[D,t]),x.useEffect(()=>{D&&(g&&!_.current?D.on("zoom",null):g||D.on("zoom",j=>{var P;const{onViewportChange:T}=N.getState();if(N.setState({transform:[j.transform.x,j.transform.y,j.transform.k]}),R.current=!!(r&&As(d,S.current??0)),(e||T)&&!((P=j.sourceEvent)!=null&&P.internal)){const z=yn(j.transform);T==null||T(z),e==null||e(j.sourceEvent,z)}}))},[g,D,e,d,r]),x.useEffect(()=>{D&&D.on("end",j=>{if(!j.sourceEvent||j.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=N.getState();if(_.current=!1,N.setState({paneDragging:!1}),r&&As(d,S.current??0)&&!R.current&&r(j.sourceEvent),R.current=!1,(n||T)&&nh(O.current,j.transform)){const P=yn(j.transform);O.current=P,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(P),n==null||n(j.sourceEvent,P)},o?150:0)}})},[D,o,d,n,r]),x.useEffect(()=>{D&&D.filter(j=>{const T=C||s,P=i&&j.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&j.button===1&&j.type==="mousedown"&&(St(j,"react-flow__node")||St(j,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||g||!l&&j.type==="dblclick"||St(j,$)&&j.type==="wheel"||St(j,b)&&(j.type!=="wheel"||o&&j.type==="wheel"&&!C)||!i&&j.ctrlKey&&j.type==="wheel"||!T&&!o&&!P&&j.type==="wheel"||!d&&(j.type==="mousedown"||j.type==="touchstart")||Array.isArray(d)&&!d.includes(j.button)&&j.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(j.button)||!j.button||j.button<=1;return(!j.ctrlKey||j.type==="wheel")&&z})},[g,D,s,i,o,l,d,u,C]),A.createElement("div",{className:"react-flow__renderer",ref:k,style:Br},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=de(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Is(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&Is(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&Is(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const at=(e,t)=>({id:e,type:"select",selected:t});function jt(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(at(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(at(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ro=x.memo(({isSelecting:e,selectionMode:t=en.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=x.useRef(null),f=Ne(),w=x.useRef(0),y=x.useRef(0),v=x.useRef(),{userSelectionActive:p,elementsSelectable:E,dragging:$}=de(lh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),w.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},N=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,R=H=>{const{resetSelectedElements:g,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!v.current)return;const{x:S,y:I}=ut(H,v.current);g(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:I,x:S,y:I}}),r==null||r(H)},k=H=>{const{userSelectionRect:g,nodeInternals:C,edges:S,transform:I,onNodesChange:L,onEdgesChange:j,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!g)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=ut(H,v.current),X=g.startX??0,F=g.startY??0,Z={...g,x:z.xre.id),ne=te.map(re=>re.id);if(w.current!==ne.length){w.current=ne.length;const re=jt(J,ne);re.length&&(L==null||L(re))}if(y.current!==oe.length){y.current=oe.length;const re=jt(S,oe);re.length&&(j==null||j(re))}f.setState({userSelectionRect:Z})},O=H=>{if(H.button!==0)return;const{userSelectionRect:g}=f.getState();!p&&g&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:w.current>0}),b(),s==null||s(H)},D=H=>{p&&(f.setState({nodesSelectionActive:w.current>0}),s==null||s(H)),b()},B=E&&(e||p);return A.createElement("div",{className:je(["react-flow__pane",{dragging:$,selection:e}]),onClick:B?void 0:er(M,m),onContextMenu:er(N,m),onWheel:er(_,m),onMouseEnter:B?void 0:c,onMouseDown:B?R:void 0,onMouseMove:B?k:l,onMouseUp:B?O:void 0,onMouseLeave:B?D:u,ref:m,style:Br},d,A.createElement(oh,null))});Ro.displayName="Pane";function Io(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Io(r,t):!1}function Ts(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Io(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function To(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Oe(m)&&Oe(f)&&Oe(d.width)&&Oe(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",nt.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Lr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Os=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Or(c)}})};function Vt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Nr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",nt.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Ne();return x.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Oo({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Ne(),[c,l]=x.useState(!1),u=x.useRef([]),d=x.useRef({x:null,y:null}),m=x.useRef(0),f=x.useRef(null),w=x.useRef({x:0,y:0}),y=x.useRef(null),v=x.useRef(!1),p=x.useRef(!1),E=x.useRef(!1),$=fh();return x.useEffect(()=>{if(e!=null&&e.current){const b=Te(e.current),M=({x:R,y:k})=>{const{nodeInternals:O,onNodeDrag:D,onSelectionDrag:B,updateNodePositions:H,nodeExtent:g,snapGrid:C,snapToGrid:S,nodeOrigin:I,onError:L}=a.getState();d.current={x:R,y:k};let j=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&g){const z=on(u.current,I);T=Jt(z)}if(u.current=u.current.map(z=>{const X={x:R-z.distance.x,y:k-z.distance.y};S&&(X.x=C[0]*Math.round(X.x/C[0]),X.y=C[1]*Math.round(X.y/C[1]));const F=[[g[0][0],g[0][1]],[g[1][0],g[1][1]]];u.current.length>1&&g&&!z.extent&&(F[0][0]=z.positionAbsolute.x-T.x+g[0][0],F[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+g[1][0],F[0][1]=z.positionAbsolute.y-T.y+g[0][1],F[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+g[1][1]);const Z=To(z,X,O,F,I,L);return j=j||z.position.x!==Z.position.x||z.position.y!==Z.position.y,z.position=Z.position,z.positionAbsolute=Z.positionAbsolute,z}),!j)return;H(u.current,!0,!0),l(!0);const P=s?D:nr(B);if(P&&y.current){const[z,X]=tr({nodeId:s,dragItems:u.current,nodeInternals:O});P(y.current,z,X)}},N=()=>{if(!f.current)return;const[R,k]=no(w.current,f.current);if(R!==0||k!==0){const{transform:O,panBy:D}=a.getState();d.current.x=(d.current.x??0)-R/O[2],d.current.y=(d.current.y??0)-k/O[2],D({x:R,y:k})&&M(d.current)}m.current=requestAnimationFrame(N)},_=R=>{var I;const{nodeInternals:k,multiSelectionActive:O,nodesDraggable:D,unselectNodesAndEdges:B,onNodeDragStart:H,onSelectionDragStart:g}=a.getState();p.current=!0;const C=s?H:nr(g);(!o||!i)&&!O&&s&&((I=k.get(s))!=null&&I.selected||B()),s&&i&&o&&Nr({id:s,store:a,nodeRef:e});const S=$(R);if(d.current=S,u.current=uh(k,D,S,s),C&&u.current){const[L,j]=tr({nodeId:s,dragItems:u.current,nodeInternals:k});C(R.sourceEvent,L,j)}};if(t)b.on(".drag",null);else{const R=bu().on("start",k=>{const{domNode:O,nodeDragThreshold:D}=a.getState();D===0&&_(k),E.current=!1;const B=$(k);d.current=B,f.current=(O==null?void 0:O.getBoundingClientRect())||null,w.current=ut(k.sourceEvent,f.current)}).on("drag",k=>{var H,g;const O=$(k),{autoPanOnNodeDrag:D,nodeDragThreshold:B}=a.getState();if(k.sourceEvent.type==="touchmove"&&k.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&p.current&&D&&(v.current=!0,N()),!p.current){const C=O.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=O.ySnapped-(((g=d==null?void 0:d.current)==null?void 0:g.y)??0);Math.sqrt(C*C+S*S)>B&&_(k)}(d.current.x!==O.xSnapped||d.current.y!==O.ySnapped)&&u.current&&p.current&&(y.current=k.sourceEvent,w.current=ut(k.sourceEvent,f.current),M(O))}}).on("end",k=>{if(!(!p.current||E.current)&&(l(!1),v.current=!1,p.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:O,nodeInternals:D,onNodeDragStop:B,onSelectionDragStop:H}=a.getState(),g=s?B:nr(H);if(O(u.current,!1,!1),g){const[C,S]=tr({nodeId:s,dragItems:u.current,nodeInternals:D});g(k.sourceEvent,C,S)}}}).filter(k=>{const O=k.target;return!k.button&&(!n||!Ts(O,`.${n}`,e))&&(!r||Ts(O,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,$]),c}function Lo(){const e=Ne();return x.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,w=n.isShiftPressed?4:1,y=n.x*m*w,v=n.y*f*w,p=d.map(E=>{if(E.positionAbsolute){const $={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+v};a&&($.x=c[0]*Math.round($.x/c[0]),$.y=c[1]*Math.round($.y/c[1]));const{positionAbsolute:b,position:M}=To(E,$,r,s,void 0,l);E.position=M,E.positionAbsolute=b}return E});i(p,!0,!1)},[])}const Mt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Bt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:w,onDoubleClick:y,style:v,className:p,isDraggable:E,isSelectable:$,isConnectable:b,isFocusable:M,selectNodesOnDrag:N,sourcePosition:_,targetPosition:R,hidden:k,resizeObserver:O,dragHandle:D,zIndex:B,isParent:H,noDragClassName:g,noPanClassName:C,initialized:S,disableKeyboardA11y:I,ariaLabel:L,rfId:j,hasHandleBounds:T})=>{const P=Ne(),z=x.useRef(null),X=x.useRef(null),F=x.useRef(_),Z=x.useRef(R),J=x.useRef(r),te=$||E||u||d||m||f,oe=Lo(),ne=Vt(n,P.getState,d),re=Vt(n,P.getState,m),pe=Vt(n,P.getState,f),ce=Vt(n,P.getState,w),ue=Vt(n,P.getState,y),ye=le=>{const{nodeDragThreshold:K}=P.getState();if($&&(!N||!E||K>0)&&Nr({id:n,store:P,nodeRef:z}),u){const Se=P.getState().nodeInternals.get(n);Se&&u(le,{...Se})}},he=le=>{if(!br(le)&&!I)if(oo.includes(le.key)&&$){const K=le.key==="Escape";Nr({id:n,store:P,unselect:K,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Mt,le.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),oe({x:Mt[le.key].x,y:Mt[le.key].y,isShiftPressed:le.shiftKey}))};x.useEffect(()=>()=>{X.current&&(O==null||O.unobserve(X.current),X.current=null)},[]),x.useEffect(()=>{if(z.current&&!k){const le=z.current;(!S||!T||X.current!==le)&&(X.current&&(O==null||O.unobserve(X.current)),O==null||O.observe(le),X.current=le)}},[k,S,T]),x.useEffect(()=>{const le=J.current!==r,K=F.current!==_,Se=Z.current!==R;z.current&&(le||K||Se)&&(le&&(J.current=r),K&&(F.current=_),Se&&(Z.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const xe=Oo({nodeRef:z,disabled:k||!E,noDragClassName:g,handleSelector:D,nodeId:n,isSelectable:$,selectNodesOnDrag:N});return k?null:A.createElement("div",{className:je(["react-flow__node",`react-flow__node-${r}`,{[C]:E},p,{selected:l,selectable:$,parent:H,dragging:xe}]),ref:z,style:{zIndex:B,transform:`translate(${a}px,${c}px)`,pointerEvents:te?"all":"none",visibility:S?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:re,onMouseLeave:pe,onContextMenu:ce,onClick:ye,onDoubleClick:ue,onKeyDown:M?he:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":I?void 0:`${jo}-${j}`,"aria-label":L},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:xe,dragHandle:D,zIndex:B})))};return t.displayName="NodeWrapper",x.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...on(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ne(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=de(hh,ke),u=Lo(),d=x.useRef(null);if(x.useEffect(()=>{var w;n||(w=d.current)==null||w.focus({preventScroll:!0})},[n]),Oo({nodeRef:d}),l||!s||!i)return null;const m=e?w=>{const y=r.getState().getNodes().filter(v=>v.selected);e(w,y)}:void 0,f=w=>{Object.prototype.hasOwnProperty.call(Mt,w.key)&&u({x:Mt[w.key].x,y:Mt[w.key].y,isShiftPressed:w.shiftKey})};return A.createElement("div",{className:je(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=x.memo(mh);const gh=e=>e.nodesSelectionActive,Do=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:w,onSelectionEnd:y,multiSelectionKeyCode:v,panActivationKeyCode:p,zoomActivationKeyCode:E,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:N,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:O,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,preventScrolling:C,onSelectionContextMenu:S,noWheelClassName:I,noPanClassName:L,disableKeyboardA11y:j})=>{const T=de(gh),P=tn(d),z=tn(p),X=z||O,F=z||N,Z=P||m&&X!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:F,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:!P&&X,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:I,noPanClassName:L},A.createElement(Ro,{onSelectionStart:w,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:X,isSelecting:!!Z,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:L,disableKeyboardA11y:j})))};Do.displayName="FlowRenderer";var yh=x.memo(Do);function xh(e){return de(x.useCallback(n=>e?mo(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Bt(e.input||Eo),default:Bt(e.default||Er),output:Bt(e.output||So),group:Bt(e.group||Vr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Bt(e[i]||Er),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Po=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=de(vh,ke),a=xh(e.onlyRenderVisibleElements),c=x.useRef(),l=x.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return x.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Br},a.map(u=>{var M,N,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",nt.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),w=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),v=!!(u.focusable||r&&typeof u.focusable>"u"),p=e.nodeExtent?Lr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(p==null?void 0:p.x)??0,$=(p==null?void 0:p.y)??0,b=bh({x:E,y:$,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||q.Bottom,targetPosition:u.targetPosition||q.Top,hidden:u.hidden,xPos:E,yPos:$,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:w,isConnectable:y,isFocusable:v,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((N=u[we])!=null&&N.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Po.displayName="NodeRenderer";var _h=x.memo(Po);const Eh=(e,t,n)=>n===q.Left?e-t:n===q.Right?e+t:e,Nh=(e,t,n)=>n===q.Top?e-t:n===q.Bottom?e+t:e,Ls="react-flow__edgeupdater",Ds=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:je([Ls,`${Ls}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var kt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,style:v,source:p,target:E,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,elementsSelectable:k,hidden:O,sourceHandleId:D,targetHandleId:B,onContextMenu:H,onMouseEnter:g,onMouseMove:C,onMouseLeave:S,reconnectRadius:I,onReconnect:L,onReconnectStart:j,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:X,ariaLabel:F,isFocusable:Z,isReconnectable:J,pathOptions:te,interactionWidth:oe,disableKeyboardA11y:ne})=>{const re=x.useRef(null),[pe,ce]=x.useState(!1),[ue,ye]=x.useState(!1),he=Ne(),xe=x.useMemo(()=>`url('#${vr(z,X)}')`,[z,X]),le=x.useMemo(()=>`url('#${vr(P,X)}')`,[P,X]);if(O)return null;const K=se=>{var ve;const{edges:me,addSelectedEdges:$e,unselectNodesAndEdges:W,multiSelectionActive:fe}=he.getState(),ge=me.find(Be=>Be.id===n);ge&&(k&&(he.setState({nodesSelectionActive:!1}),ge.selected&&fe?(W({nodes:[],edges:[ge]}),(ve=re.current)==null||ve.blur()):$e([n])),o&&o(se,ge))},Se=Ft(n,he.getState,a),Ce=Ft(n,he.getState,H),dt=Ft(n,he.getState,g),Ae=Ft(n,he.getState,C),Ue=Ft(n,he.getState,S),Ie=(se,me)=>{if(se.button!==0)return;const{edges:$e,isValidConnection:W}=he.getState(),fe=me?E:p,ge=(me?B:D)||null,ve=me?"target":"source",Be=W||Sh,Ot=me,st=$e.find(Pe=>Pe.id===n);ye(!0),j==null||j(se,st,ve);const ft=Pe=>{ye(!1),T==null||T(Pe,st,ve)};wo({event:se,handleId:ge,nodeId:fe,onConnect:Pe=>L==null?void 0:L(st,Pe),isTarget:Ot,getState:he.getState,setState:he.setState,isValidConnection:Be,edgeUpdaterType:ve,onReconnectEnd:ft})},V=se=>Ie(se,!0),Y=se=>Ie(se,!1),G=()=>ce(!0),Q=()=>ce(!1),U=!k&&!o,ee=se=>{var me;if(!ne&&oo.includes(se.key)&&k){const{unselectNodesAndEdges:$e,addSelectedEdges:W,edges:fe}=he.getState();se.key==="Escape"?((me=re.current)==null||me.blur(),$e({edges:[fe.find(ve=>ve.id===n)]})):W([n])}};return A.createElement("g",{className:je(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:pe}]),onClick:K,onDoubleClick:Se,onContextMenu:Ce,onMouseEnter:dt,onMouseMove:Ae,onMouseLeave:Ue,onKeyDown:Z?ee:void 0,tabIndex:Z?0:void 0,role:Z?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":F===null?void 0:F||`Edge from ${p} to ${E}`,"aria-describedby":Z?`${Co}-${X}`:void 0,ref:re},!ue&&A.createElement(e,{id:n,source:p,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,data:i,style:v,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,sourceHandleId:D,targetHandleId:B,markerStart:xe,markerEnd:le,pathOptions:te,interactionWidth:oe}),J&&A.createElement(A.Fragment,null,(J==="source"||J===!0)&&A.createElement(Ds,{position:_,centerX:$,centerY:b,radius:I,onMouseDown:V,onMouseEnter:G,onMouseOut:Q,type:"source"}),(J==="target"||J===!0)&&A.createElement(Ds,{position:R,centerX:M,centerY:N,radius:I,onMouseDown:Y,onMouseEnter:G,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",x.memo(t)};function kh(e){const t={default:kt(e.default||In),straight:kt(e.bezier||zr),step:kt(e.step||Pr),smoothstep:kt(e.step||Bn),simplebezier:kt(e.simplebezier||Dr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=kt(e[i]||In),s),n);return{...t,...r}}function Ps(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case q.Top:return{x:r+i/2,y:s};case q.Right:return{x:r+i,y:s+o/2};case q.Bottom:return{x:r+i/2,y:s+o};case q.Left:return{x:r,y:s+o/2}}}function zs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ps(n,e,t),a=Ps(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Jt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Hs(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Oe(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),w=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(w?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=de(x.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Fs={[An.Arrow]:Rh,[An.ArrowClosed]:Ih};function Th(e){const t=Ne();return x.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(Fs,e)?Fs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",nt.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=vr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},zo=({defaultColor:e,rfId:t})=>{const n=de(x.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};zo.displayName="MarkerDefinitions";var Dh=x.memo(zo);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ho=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,children:v,disableKeyboardA11y:p})=>{const{edgesFocusable:E,edgesUpdatable:$,elementsSelectable:b,width:M,height:N,connectionMode:_,nodeInternals:R,onError:k}=de(Ph,ke),O=Ah(t,R,n);return M?A.createElement(A.Fragment,null,O.map(({level:D,edges:B,isMaxLevel:H})=>A.createElement("svg",{key:D,style:{zIndex:D},width:M,height:N,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,B.map(g=>{const[C,S,I]=Hs(R.get(g.source)),[L,j,T]=Hs(R.get(g.target));if(!I||!T)return null;let P=g.type||"default";s[P]||(k==null||k("011",nt.error011(P)),P="default");const z=s[P]||s.default,X=_===vt.Strict?j.target:(j.target??[]).concat(j.source??[]),F=zs(S.source,g.sourceHandle),Z=zs(X,g.targetHandle),J=(F==null?void 0:F.position)||q.Bottom,te=(Z==null?void 0:Z.position)||q.Top,oe=!!(g.focusable||E&&typeof g.focusable>"u"),ne=g.reconnectable||g.updatable,re=typeof m<"u"&&(ne||$&&typeof ne>"u");if(!F||!Z)return k==null||k("008",nt.error008(F,g)),null;const{sourceX:pe,sourceY:ce,targetX:ue,targetY:ye}=jh(C,F,J,L,Z,te);return A.createElement(z,{key:g.id,id:g.id,className:je([g.className,i]),type:P,data:g.data,selected:!!g.selected,animated:!!g.animated,hidden:!!g.hidden,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,style:g.style,source:g.source,target:g.target,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerEnd:g.markerEnd,markerStart:g.markerStart,sourceX:pe,sourceY:ce,targetX:ue,targetY:ye,sourcePosition:J,targetPosition:te,elementsSelectable:b,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,rfId:r,ariaLabel:g.ariaLabel,isFocusable:oe,isReconnectable:re,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth,disableKeyboardA11y:p})})))),v):null};Ho.displayName="EdgeRenderer";var zh=x.memo(Ho);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=de(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=an(),n=x.useRef(!1);x.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[q.Left]:q.Right,[q.Right]:q.Left,[q.Top]:q.Bottom,[q.Bottom]:q.Top},Fo=({nodeId:e,handleType:t,style:n,type:r=ct.Bezier,CustomComponent:s,connectionStatus:i})=>{var N,_,R;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=de(x.useCallback(k=>({fromNode:k.nodeInternals.get(e),handleId:k.connectionHandleId,toX:(k.connectionPosition.x-k.transform[0])/k.transform[2],toY:(k.connectionPosition.y-k.transform[1])/k.transform[2],connectionMode:k.connectionMode}),[e]),ke),d=(N=o==null?void 0:o[we])==null?void 0:N.handleBounds;let m=d==null?void 0:d[t];if(u===vt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(k=>k.id===a):m[0],w=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,v=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+w,p=(((R=o.positionAbsolute)==null?void 0:R.y)??0)+y,E=f==null?void 0:f.position,$=E?Bh[E]:null;if(!E||!$)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:v,fromY:p,toX:c,toY:l,fromPosition:E,toPosition:$,connectionStatus:i});let b="";const M={sourceX:v,sourceY:p,sourcePosition:E,targetX:c,targetY:l,targetPosition:$};return r===ct.Bezier?[b]=fo(M):r===ct.Step?[b]=Rn({...M,borderRadius:0}):r===ct.SmoothStep?[b]=Rn(M):r===ct.SimpleBezier?[b]=uo(M):b=`M${v},${p} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Fo.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=de(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:je(["react-flow__connection",l])},A.createElement(Fo,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Vs(e,t){return x.useRef(null),Ne(),x.useMemo(()=>t(e),[e])}const Vo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:w,onSelectionStart:y,onSelectionEnd:v,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:$,connectionLineContainerStyle:b,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,deleteKeyCode:D,onlyRenderVisibleElements:B,elementsSelectable:H,selectNodesOnDrag:g,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,preventScrolling:j,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:X,panOnScrollSpeed:F,panOnScrollMode:Z,zoomOnDoubleClick:J,panOnDrag:te,onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneScroll:ce,onPaneContextMenu:ue,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Se,onReconnectEnd:Ce,reconnectRadius:dt,noDragClassName:Ae,noWheelClassName:Ue,noPanClassName:Ie,elevateEdgesOnSelect:V,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})=>{const ee=Vs(e,wh),se=Vs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneContextMenu:ue,onPaneScroll:ce,deleteKeyCode:D,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,onSelectionStart:y,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:J,panOnScroll:X,panOnScrollSpeed:F,panOnScrollMode:Z,panOnDrag:te,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,onSelectionContextMenu:w,preventScrolling:j,noDragClassName:Ae,noWheelClassName:Ue,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:B,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Se,onReconnectEnd:Ce,reconnectRadius:dt,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!V,disableKeyboardA11y:Y,rfId:U},A.createElement(Yh,{style:E,type:p,component:$,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:ee,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:g,onlyRenderVisibleElements:B,noPanClassName:Ie,noDragClassName:Ae,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})))};Vo.displayName="GraphView";var Xh=x.memo(Vo);const Sr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],it={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Sr,nodeExtent:Sr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:vt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Wh=()=>Rc((e,t)=>({...it,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Jn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,v)=>{const p=s.get(v.id);if(p!=null&&p.hidden)s.set(p.id,{...p,[we]:{...p[we],handleBounds:void 0}});else if(p){const E=Or(v.nodeElement);!!(E.width&&E.height&&(p.width!==E.width||p.height!==E.height||v.forceUpdate))&&(s.set(p.id,{...p,[we]:{...p[we],handleBounds:{source:Os(".source",v.nodeElement,m,l),target:Os(".target",v.nodeElement,m,l)}},...E}),y.push({id:p.id,type:"dimensions",dimensions:E}))}return y},[]);Mo(s,l);const w=o||i&&!o&&Ao(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:w}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Jn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>at(c,!0)):(o=jt(i(),n),a=jt(s,[])),gn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>at(c,!0)):(o=jt(s,n),a=jt(i(),[])),gn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,at(u.id,!1))),l=a.map(u=>at(u.id,!1));gn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>at(a.id,!1)),o=n.filter(a=>a.selected).map(a=>at(a.id,!1));gn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Lr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=et.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:it.connectionNodeId,connectionHandleId:it.connectionHandleId,connectionHandleType:it.connectionHandleType,connectionStatus:it.connectionStatus,connectionStartHandle:it.connectionStartHandle,connectionEndHandle:it.connectionEndHandle}),reset:()=>e({...it})}),Object.is),Bo=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Wh()),A.createElement(df,{value:t.current},e)};Bo.displayName="ReactFlowProvider";const Go=({children:e})=>x.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Bo,null,e);Go.displayName="ReactFlowWrapper";const Uh={input:Eo,default:Er,output:So,group:Vr},qh={default:In,straight:zr,step:Pr,smoothstep:Bn,simplebezier:Dr},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Yo=x.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Uh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onNodesDelete:O,onEdgesDelete:D,onSelectionChange:B,onSelectionDragStart:H,onSelectionDrag:g,onSelectionDragStop:C,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,connectionMode:j=vt.Strict,connectionLineType:T=ct.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,deleteKeyCode:F="Backspace",selectionKeyCode:Z="Shift",selectionOnDrag:J=!1,selectionMode:te=en.Full,panActivationKeyCode:oe="Space",multiSelectionKeyCode:ne=Mn()?"Meta":"Control",zoomActivationKeyCode:re=Mn()?"Meta":"Control",snapToGrid:pe=!1,snapGrid:ce=Zh,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:ye=!0,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,nodeOrigin:K=Kh,edgesFocusable:Se,edgesUpdatable:Ce,elementsSelectable:dt,defaultViewport:Ae=Qh,minZoom:Ue=.5,maxZoom:Ie=2,translateExtent:V=Sr,preventScrolling:Y=!0,nodeExtent:G,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:ee=!0,panOnScroll:se=!1,panOnScrollSpeed:me=.5,panOnScrollMode:$e=gt.Free,zoomOnDoubleClick:W=!0,panOnDrag:fe=!0,onPaneClick:ge,onPaneMouseEnter:ve,onPaneMouseMove:Be,onPaneMouseLeave:Ot,onPaneScroll:st,onPaneContextMenu:ft,children:Lt,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:qe,onEdgeMouseLeave:Pt,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:Zr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Xa,defaultEdgeOptions:Wa,elevateNodesOnSelect:Ua=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Qr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Jr,nodeDragThreshold:nc,...rc},sc)=>{const Xn=Jr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:je(["react-flow",s]),"data-testid":"rf__wrapper",id:Jr},A.createElement(Go,null,A.createElement(Xh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,selectionKeyCode:Z,selectionOnDrag:J,selectionMode:te,deleteKeyCode:F,multiSelectionKeyCode:ne,panActivationKeyCode:oe,zoomActivationKeyCode:re,onlyRenderVisibleElements:ue,selectNodesOnDrag:ye,defaultViewport:Ae,translateExtent:V,minZoom:Ue,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:U,zoomOnPinch:ee,zoomOnDoubleClick:W,panOnScroll:se,panOnScrollSpeed:me,panOnScrollMode:$e,panOnDrag:fe,onPaneClick:ge,onPaneMouseEnter:ve,onPaneMouseMove:Be,onPaneMouseLeave:Ot,onPaneScroll:st,onPaneContextMenu:ft,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:qe,onEdgeMouseLeave:Pt,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:Zr,elevateEdgesOnSelect:qa,rfId:Xn,disableKeyboardA11y:Qr,nodeOrigin:K,nodeExtent:G}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,edgesFocusable:Se,edgesUpdatable:Ce,elementsSelectable:dt,elevateNodesOnSelect:Ua,minZoom:Ue,maxZoom:Ie,nodeExtent:G,onNodesChange:Pa,onEdgesChange:za,snapToGrid:pe,snapGrid:ce,connectionMode:j,translateExtent:V,connectOnClick:Ga,defaultEdgeOptions:Wa,fitView:Va,fitViewOptions:Ba,onNodesDelete:O,onEdgesDelete:D,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onSelectionDrag:g,onSelectionDragStart:H,onSelectionDragStop:C,noPanClassName:Zr,nodeOrigin:K,rfId:Xn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:B}),Lt,A.createElement(hf,{proOptions:Xa,position:Ya}),A.createElement(Wf,{rfId:Xn,disableKeyboardA11y:Qr})))});Yo.displayName="ReactFlow";const Xo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:w,backgroundColor:y}=i||{},v=o||w||y;return A.createElement("rect",{className:je(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?p=>m(p,e):void 0})};Xo.displayName="MiniMapNode";var em=x.memo(Xo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=de(nm,ke),c=de(tm),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:w,y}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:w,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=x.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(on(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:w=!1,zoomable:y=!1,ariaLabel:v="React Flow mini map",inversePan:p=!1,zoomStep:E=10,offsetScale:$=5}){const b=Ne(),M=x.useRef(null),{boundingRect:N,viewBB:_,rfId:R}=de(am,ke),k=(e==null?void 0:e.width)??im,O=(e==null?void 0:e.height)??om,D=N.width/k,B=N.height/O,H=Math.max(D,B),g=H*k,C=H*O,S=$*H,I=N.x-(g-N.width)/2-S,L=N.y-(C-N.height)/2-S,j=g+S*2,T=C+S*2,P=`${cm}-${R}`,z=x.useRef(0);z.current=H,x.useEffect(()=>{if(M.current){const Z=Te(M.current),J=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce}=b.getState();if(ne.sourceEvent.type!=="wheel"||!pe||!ce)return;const ue=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,ye=re[2]*Math.pow(2,ue);ce.scaleTo(pe,ye)},te=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce,translateExtent:ue,width:ye,height:he}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!pe||!ce)return;const xe=z.current*Math.max(1,re[2])*(p?-1:1),le={x:re[0]-ne.sourceEvent.movementX*xe,y:re[1]-ne.sourceEvent.movementY*xe},K=[[0,0],[ye,he]],Se=et.translate(le.x,le.y).scale(re[2]),Ce=ce.constrain()(Se,K,ue);ce.transform(pe,Ce)},oe=eo().on("zoom",w?te:null).on("zoom.wheel",y?J:null);return Z.call(oe),()=>{Z.on("zoom",null)}}},[w,y,p,E]);const X=m?Z=>{const J=ze(Z);m(Z,{x:J[0],y:J[1]})}:void 0,F=f?(Z,J)=>{const te=b.getState().nodeInternals.get(J);f(Z,te)}:void 0;return A.createElement(Tr,{position:d,style:e,className:je(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:k,height:O,viewBox:`${I} ${L} ${j} ${T}`,role:"img","aria-labelledby":P,ref:M,onClick:X},v&&A.createElement("title",{id:P},v),A.createElement(sm,{onClick:F,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${I-S},${L-S}h${j+S*2}v${T+S*2}h${-j-S*2}z + M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Wo.displayName="MiniMap";var lm=x.memo(Wo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Xt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:je(["react-flow__controls-button",t]),...n},e);Xt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ne(),[f,w]=x.useState(!1),{isInteractive:y,minZoomReached:v,maxZoomReached:p}=de(pm,ke),{zoomIn:E,zoomOut:$,fitView:b}=an();if(x.useEffect(()=>{w(!0)},[]),!f)return null;const M=()=>{E(),i==null||i()},N=()=>{$(),o==null||o()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c==null||c(!y)};return A.createElement(Tr,{className:je(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Xt,{onClick:M,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:p},A.createElement(um,null)),A.createElement(Xt,{onClick:N,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(dm,null))),n&&A.createElement(Xt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Xt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},y?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=x.memo(Uo),Le;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Le||(Le={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[Le.Dots]:"#91919a",[Le.Lines]:"#eee",[Le.Cross]:"#e2e2e2"},bm={[Le.Dots]:1,[Le.Lines]:1,[Le.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function qo({id:e,variant:t=Le.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=x.useRef(null),{transform:u,patternId:d}=de(vm,ke),m=o||wm[t],f=r||bm[t],w=t===Le.Dots,y=t===Le.Cross,v=Array.isArray(n)?n:[n,n],p=[v[0]*u[2]||1,v[1]*u[2]||1],E=f*u[2],$=y?[E,E]:p,b=w?[E/i,E/i]:[$[0]/i,$[1]/i];return A.createElement("svg",{className:je(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%p[0],y:u[1]%p[1],width:p[0],height:p[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},w?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:$,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}qo.displayName="Background";var _m=x.memo(qo);const Gr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Gr+e}async function be(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function rt(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new Ko(r.error??`${e}: ${n.status}`,n.status);return r}class Ko extends Error{constructor(n,r){super(n);_e(this,"status");this.status=r}}const Cx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),$x=()=>be("/api/diagnostics"),Zo=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Qo=()=>be("/api/ontology/ontologies"),Em=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>be("/api/ontology/stack"),Sm=()=>be("/api/ontology/coverage"),km=(e,t,n)=>rt("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>be("/api/git/status"),Cm=()=>be("/api/git/diff"),$m=e=>rt("/api/git/commit",{message:e}),Mm=()=>rt("/api/git/discard",{}),Am=()=>be("/api/decisions"),Bs=(e,t)=>rt(`/api/decisions/${e}/verdict`,{verdict:t}),Mx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Ax=()=>be("/api/glossary/config"),Rx=e=>rt("/api/git/propose",e),Ix=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Tx=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),Ox=e=>rt("/api/git/classify",{changes:e}),Lx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Dx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Px=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>be("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Gr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>rt("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>rt("/api/import/preview",{format:e,content:t}),zx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Hx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Fx=(e,t,n)=>fetch(`${Gr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new Ko(await r.text(),r.status);return await r.json()}),Vx=()=>be("/api/glossary/subject-areas"),Bx=e=>be(`/api/glossary/subject-area/${e}`),Gx=(e,t)=>rt(`/api/glossary/subject-area/${e}/expand`,t);function Yx(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Yr="__entity_source",Xr="__entity_target",Pm=x.memo(function({data:t,selected:n}){var N;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:w}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>y(_.a)-y(R.a)||_.i-R.i).map(_=>_.a),p=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const $=!!c&&!l;let b=0;if($){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const M=(_,R)=>{const k="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:k,onMouseEnter:w?()=>w(_.id):void 0,onMouseLeave:w?()=>w(null):void 0,children:[h.jsx(lt,{id:_.id,type:"target",position:q.Left,className:"port attr-port"}),h.jsx(lt,{id:_.id,type:"source",position:q.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(lt,{id:Xr,type:"target",position:q.Left,className:"port"}),h.jsx(lt,{id:Yr,type:"source",position:q.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((N=r.conceptual)==null?void 0:N.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var k;const _=(((k=r.conceptual)==null?void 0:k.ontology_refs)??[]).filter(O=>O.uri);if(_.length===0)return null;const R=_.map(O=>O.uri).join(` +`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),p.length>0&&h.jsx("div",{className:"attr-section keys",children:p.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,w,y,v,p,E,$,b,M,N,_,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(k=>k.from.entity===e.id||k.to.entity===e.id),d=k=>{var O;return((O=t.entities.find(D=>D.id===k))==null?void 0:O.name)??k};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Ze,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,name:k})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Ze,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,physical_name:k})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Ze,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:k=>r("set_definition",{id:e.id,definition:k})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((w=l==null?void 0:l.ontology_refs)==null?void 0:w.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((p=e.term_map)==null?void 0:p.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),($=e.term_map)!=null&&$.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((N=e.term_map)==null?void 0:N.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Ze,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:k,steward:((O=l==null?void 0:l.stewardship)==null?void 0:O.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Ze,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:((O=l==null?void 0:l.stewardship)==null?void 0:O.owner)??null,steward:k})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(k=>h.jsx(Xm,{a:k,entity:e,doc:t,readOnly:c,exec:r},k.id))})}),!c&&h.jsx(Wm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(k=>{const O=k.members.map(D=>{var B;return((B=e.attributes.find(H=>H.id===D))==null?void 0:B.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+k.type,children:k.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:k.name}),h.jsx("span",{className:"key-cols",children:O})]},k.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([k,O])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:k}),h.jsx("td",{className:"udp-val",children:String(O)})]},k))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(k=>{const O=k.from.entity===e.id?k.to.entity:k.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(O),children:[h.jsx("span",{className:"rel-card",children:Um(k,e.id)}),d(O)]}),(k.verb_phrase||k.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Ze,{value:k.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,verb_phrase:D})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Ze,{value:k.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,inverse_verb_phrase:D})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${k.name}`,onClick:()=>r("delete_relationship",{id:k.id}),children:"✕"})]},k.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var k;return(k=navigator.clipboard)==null?void 0:k.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Ze({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=x.useState(e);x.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Xm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Ze,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Ze,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Wm({entity:e,exec:t}){const[n,r]=x.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Um(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Gs="";let Km=class{constructor(t){_e(this,"_isDirected",!0);_e(this,"_isMultigraph",!1);_e(this,"_isCompound",!1);_e(this,"_label");_e(this,"_defaultNodeLabelFn",()=>{});_e(this,"_defaultEdgeLabelFn",()=>{});_e(this,"_nodes",{});_e(this,"_in",{});_e(this,"_preds",{});_e(this,"_out",{});_e(this,"_sucs",{});_e(this,"_edgeObjs",{});_e(this,"_edgeLabels",{});_e(this,"_nodeCount",0);_e(this,"_edgeCount",0);_e(this,"_parent");_e(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Ys(this._preds[n],t),Ys(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Xs(this._preds[n],t),Xs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Ys(e,t){e[t]?e[t]++:e[t]=1}function Xs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Gs+i+Gs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function sr(e,t){return Wt(e,t.v,t.w,t.name)}var Wr=Km,Qm="2.2.4",Jm={Graph:Wr,version:Qm},ep=Wr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){_e(this,"_arr",[]);_e(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=ea,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ta=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ta,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),ia(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),ia(t(i),o=>s.push(o)))}}function ia(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=sa,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=sa,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Wr,Lp=Jo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:ea,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ta,topsort:ra},Us=Jm,Ve={Graph:Us.Graph,json:tp,alg:zp,version:Us.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return qs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&qs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function qs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ve.Graph,Gp=Vp;var Yp=Wp;let Xp=()=>1;function Wp(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Xp);return Up(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Up(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)ir(e,t,n,o);for(;o=s.dequeue();)ir(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(ir(e,t,n,o,!0));break}}}return r}function ir(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,jr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,jr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{jr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function jr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new oa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=da(la(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),aa(e,"border",s,t)}function og(e,t=ca){const n=[];for(let r=0;rca){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function la(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function ua(e){var t=++ug;return e+(""+t)}function da(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Ur(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=Ee.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=Ee;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=Ee;var Yn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ve.Graph,On=Yn.slack,fa=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!On(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=On(t,s)),it.node(r).rank+=n)}var Rg=fa,Ks=Yn.slack,Ig=Yn.longestPath,Tg=Ve.alg.preorder,Og=Ve.alg.postorder,Lg=Ee.simplify,Dg=_t;_t.initLowLimValues=Kr;_t.initCutValues=qr;_t.calcCutValue=ha;_t.leaveEdge=pa;_t.enterEdge=ga;_t.exchangeEdges=ya;function _t(e){e=Lg(e),Ig(e);var t=Rg(e);Kr(t),qr(t,e);for(var n,r;n=pa(t);)r=ga(t,e,n),ya(t,e,n,r)}function qr(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ha(e,t,n)}function ha(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Kr(e,t){arguments.length<2&&(t=e.nodes()[0]),ma(e,{},1,t)}function ma(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ma(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function pa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ga(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===Zs(e,e.node(u.v),a)&&c!==Zs(e,e.node(u.w),a));return l.reduce((u,d)=>Ks(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function Zs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Yn,xa=Fg.longestPath,Vg=fa,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Qs(e);break;case"tight-tree":Wg(e);break;case"longest-path":Xg(e);break;case"none":break;default:Qs(e)}}var Xg=xa;function Wg(e){xa(e),Vg(e)}function Qs(e){Bg(e)}var Ug=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Ln=Ee;var Qg={run:Jg,cleanup:n0};function Jg(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=e0(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=t0(e)+1;e.children().forEach(a=>wa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function wa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{wa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,w=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,v=f!==w?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:v,nestingEdge:!0}),e.setEdge(w,l,{weight:y,minlen:v,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function e0(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function t0(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function n0(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let r0=Ee;var s0=i0;function i0(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iei(e.node(t))),e.edges().forEach(t=>ei(e.edge(t)))}function ei(e){let t=e.width;e.width=e.height,e.height=t}function l0(e){e.nodes().forEach(t=>or(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(or),Object.hasOwn(n,"y")&&or(n)})}function or(e){e.y=-e.y}function u0(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let ti=Ee;var d0=f0;function f0(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=ti.applyWithChunking(Math.max,r),i=ti.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let h0=Ee.zipObject;var m0=p0;function p0(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var y0=x0;function x0(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let w0=Ee;var b0=v0;function v0(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _0(r)}function _0(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&E0(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>w0.pick(s,["vs","i","barycenter","weight"]))}function E0(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let N0=Ee;var S0=k0;function k0(e,t){let n=N0.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(j0(!!t)),c=ni(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ni(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ni(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function j0(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let C0=y0,$0=b0,M0=S0;var A0=va;function va(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=C0(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=va(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&I0(m,f)}});let u=$0(l,n);R0(u,c);let d=M0(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function R0(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function I0(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let T0=Ve.Graph,O0=Ee;var L0=D0;function D0(e,t,n,r){r||(r=e.nodes());let s=P0(e),i=new T0({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function P0(e){for(var t;e.hasNode(t=O0.uniqueId("_root")););return t}var z0=H0;function H0(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let F0=d0,V0=m0,B0=A0,G0=L0,Y0=z0,X0=Ve.Graph,xn=Ee;var W0=_a;function _a(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,_a);return}let n=xn.maxRank(e),r=ri(e,xn.range(1,n+1),"inEdges"),s=ri(e,xn.range(n-1,-1,-1),"outEdges"),i=F0(e);if(si(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){U0(c%2?r:s,c%4>=2),i=xn.buildLayerMatrix(e);let u=V0(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return G0(e,i,n,r.get(i)||[])})}function U0(e,t){let n=new X0;e.forEach(function(r){let s=r.graph().root,i=B0(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Y0(r,n,i.vs)})}function si(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let q0=Ve.Graph,Qe=Ee;var K0={positionX:ay};function Z0(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=J0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(w=>{e.predecessors(w).forEach(y=>{let v=e.node(y),p=v.order;(p{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&Ea(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function J0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ea(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function ey(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function ty(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let w=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((w,y)=>Math.min(w,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function ry(e,t,n,r){let s=new q0,i=e.graph(),o=cy(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function sy(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=ly(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-Qe.applyWithChunking(Math.min,l);o!=="l"&&(u=s-Qe.applyWithChunking(Math.max,l)),u&&(e[a]=Qe.mapValues(c,d=>d+u))})})}function oy(e,t){return Qe.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function ay(e){let t=Qe.buildLayerMatrix(e),n=Object.assign(Z0(e,t),Q0(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=ty(e,s,n,c),u=ny(e,s,l.root,l.align,a==="r");a==="r"&&(u=Qe.mapValues(u,d=>-d)),r[o+a]=u})});let i=sy(e,r);return iy(r,i),oy(r,e.graph().align)}function cy(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function ly(e,t){return e.node(t).width}let Na=Ee,uy=K0.positionX;var dy=fy;function fy(e){e=Na.asNonCompoundGraph(e),hy(e),Object.entries(uy(e)).forEach(([t,n])=>e.node(t).x=n)}function hy(e){let t=Na.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ii=pg,oi=bg,my=Gg,py=Ee.normalizeRanks,gy=Ug,yy=Ee.removeEmptyRanks,ai=Qg,xy=s0,ci=o0,wy=W0,by=dy,De=Ee,vy=Ve.Graph;var _y=Ey;function Ey(e,t){let n=t&&t.debugTiming?De.time:De.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>Iy(e));n(" runLayout",()=>Ny(r,n,t)),n(" updateInputGraph",()=>Sy(e,r))})}function Ny(e,t,n){t(" makeSpaceForEdgeLabels",()=>Ty(e)),t(" removeSelfEdges",()=>By(e)),t(" acyclic",()=>ii.run(e)),t(" nestingGraph.run",()=>ai.run(e)),t(" rank",()=>my(De.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Oy(e)),t(" removeEmptyRanks",()=>yy(e)),t(" nestingGraph.cleanup",()=>ai.cleanup(e)),t(" normalizeRanks",()=>py(e)),t(" assignRankMinMax",()=>Ly(e)),t(" removeEdgeLabelProxies",()=>Dy(e)),t(" normalize.run",()=>oi.run(e)),t(" parentDummyChains",()=>gy(e)),t(" addBorderSegments",()=>xy(e)),t(" order",()=>wy(e,n)),t(" insertSelfEdges",()=>Gy(e)),t(" adjustCoordinateSystem",()=>ci.adjust(e)),t(" position",()=>by(e)),t(" positionSelfEdges",()=>Yy(e)),t(" removeBorderNodes",()=>Vy(e)),t(" normalize.undo",()=>oi.undo(e)),t(" fixupEdgeLabelCoords",()=>Hy(e)),t(" undoCoordinateSystem",()=>ci.undo(e)),t(" translateGraph",()=>Py(e)),t(" assignNodeIntersects",()=>zy(e)),t(" reversePoints",()=>Fy(e)),t(" acyclic.undo",()=>ii.undo(e))}function Sy(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let ky=["nodesep","edgesep","ranksep","marginx","marginy"],jy={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Cy=["acyclicer","ranker","rankdir","align"],$y=["width","height","rank"],li={width:0,height:0},My=["minlen","weight","width","height","labeloffset"],Ay={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ry=["labelpos"];function Iy(e){let t=new vy({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},jy,cr(n,ky),De.pick(n,Cy))),e.nodes().forEach(r=>{let s=lr(e.node(r));const i=cr(s,$y);Object.keys(li).forEach(o=>{i[o]===void 0&&(i[o]=li[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},Ay,cr(s,My),De.pick(s,Ry)))}),t}function Ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Oy(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};De.addDummyNode(e,"edge-proxy",i,"_ep")}})}function Ly(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Dy(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Py(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function zy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(De.intersectRect(r,i)),n.points.push(De.intersectRect(s,o))})}function Hy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Fy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Vy(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function By(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Gy(e){var t=De.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{De.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Yy(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return De.mapValues(De.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Xy=Ee,Wy=Ve.Graph;var Uy={debugOrdering:qy};function qy(e){let t=Xy.buildLayerMatrix(e),n=new Wy({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var Ky="1.1.8",Zy={graphlib:Ve,layout:_y,debug:Uy,util:{time:Ee.time,notime:Ee.notime},version:Ky};const ui=vi(Zy),Xe=264,Qy=44,Jy=26,ex=14;function wt(e){const t=Math.max(e.attributes.length,1);return Qy+t*Jy+ex}const tx=40;function ur(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?mi(e,n,o):r==="clustered"?hi(e,t,n,o,i):r==="hierarchical"||e.length<=tx?di(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?hi(e,t,n,o,i):mi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Sa(e,t,n,r=!1,s="LR"){const i=new ui.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Xe,height:d?wt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ui.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?wt(m):120,w=d.x-Xe/2,y=d.y-f/2;return a=Math.max(a,w+Xe),c=Math.max(c,y+f),{...u,position:{x:w,y}}}),width:a,height:c}}function di(e,t,n,r="LR"){return Sa(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?wt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Xe+ka);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Xe)}),i+=Math.max(...c.map(l=>n(l.id)))+ja}return{nodes:s,width:o,height:i}}const fi=120;function hi(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),w=new Set(f.map(E=>E.id));let y=0;for(const E of t)w.has(E.source)&&w.has(E.target)&&y++;const p=f.length<=8&&y>=f.length-1?Sa(f,t,n,!0,s):rx(f,n);return{name:m,...p}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const ka=40,ja=40;function mi(e,t,n){const r=l=>{const u=t.get(l);return u?wt(u):120},s=[...e].sort((l,u)=>{var y,v;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,w=((v=t.get(u.id))==null?void 0:v.name)??u.id;return f.localeCompare(w)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Xe+ka)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ja}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function cn({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ca=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var b,M;const[r,s]=x.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[i,o]=x.useState([]),[a,c]=x.useState(null),[l,u]=x.useState(null),[d,m]=x.useState("skos:exactMatch"),[f,w]=x.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,v]=x.useState([]),[p,E]=x.useState("");x.useEffect(()=>{Qo().then(N=>v(N.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const N=setTimeout(()=>{if(!r.trim())return o([]);Zo(r,p||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(N)},[r,p]);const $=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(cn,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(p===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(N=>h.jsx("button",{className:"src-chip"+(p===N.id?" active":""),title:N.count!=null?`${N.count} terms`:"live resolver",onClick:()=>E(N.id),children:N.name},N.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:p?`Search within ${p}…`:"Search vocabulary terms…",value:r,onChange:N=>s(N.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(N=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===N.iri?" picked":""),onClick:()=>u(N),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:N.label}),h.jsxs("span",{className:"term-source",children:[N.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),N.source]})]}),h.jsx("code",{className:"term-iri",children:N.prefixed}),N.definition&&h.jsx("p",{className:"term-def",children:N.definition})]},N.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:N=>m(N.target.value),children:sx.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:N=>w(N.target.value),children:Ca.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:$,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var b,M,N;const[s,i]=x.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[o,a]=x.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},w=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${w}:`,v=(N=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:N.members.map(_=>{var R;return(R=e.attributes.find(k=>k.id===_))==null?void 0:R.name}).filter(Boolean),p=v&&v.length?`${y}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,$=s.trim()||p;return h.jsxs(cn,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",$]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=x.useState(""),[o,a]=x.useState(""),[c,l]=x.useState(""),[u,d]=x.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const w=f==null?void 0:f.created_id;n(),w&&r(w)})};return h.jsxs(cn,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ca.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const $a=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=x.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=x.useState(r??""),[m,f]=x.useState(s??(l==null?void 0:l.id)??""),[w,y]=x.useState("many_to_one"),[v,p]=x.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",$=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:w,optionality:v}).then(o);return h.jsxs(cn,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:w,onChange:b=>y(b.target.value),children:$a.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>p(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:$,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=p=>{var E;return((E=t.entities.find($=>$.id===p))==null?void 0:E.name)??"?"},[i,o]=x.useState(e.name),[a,c]=x.useState(e.cardinality),[l,u]=x.useState(e.optionality),[d,m]=x.useState(e.identifying),[f,w]=x.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(cn,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:p=>o(p.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:p=>c(p.target.value),children:$a.map(p=>h.jsx("option",{children:p},p))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:p=>u(p.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:p=>m(p.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>w(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const pi=10,ux=6,Ge=24;function dx(e,t){return t?e:Math.round(e/pi)*pi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-Ge,o.right+Ge);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eF.transform[2]),[m,f]=x.useState(null),w=x.useRef(!1),y=x.useRef(0),v=c==null?void 0:c.onRouteChange,p=!!v,E=m??(c==null?void 0:c.routeX),[$,b,M]=Rn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),N=c==null?void 0:c.relationship,_=(c==null?void 0:c.dimmed)??!1,R=(N==null?void 0:N.cardinality)??"many_to_one",k=(N==null?void 0:N.optionality)==="optional",O=(N==null?void 0:N.identifying)??!1,D=R==="many_to_one"||R==="many_to_many",B=R==="one_to_many"||R==="many_to_many",H="rel-edge"+(l?" selected":"")+(_?" dimmed":""),g=((c==null?void 0:c.memberCount)??0)>1,C=c==null?void 0:c.onHoverEdge,S=E??b,I=M,L=S,j=I,T=x.useCallback(F=>v&&N&&v(N.id,F),[v,N]),P=x.useCallback(F=>{var pe,ce;if(!p||F.button!==0)return;F.stopPropagation(),(ce=(pe=F.target).setPointerCapture)==null||ce.call(pe,F.pointerId),w.current=!0,y.current=0;const J=u({x:F.clientX,y:F.clientY}).x;let te=0,oe=E??S;const ne=ue=>{const ye=u({x:ue.clientX,y:ue.clientY});y.current=Math.max(y.current,Math.abs(ye.x-J)),oe=mx(ye.x,{shift:ue.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),te||(te=requestAnimationFrame(()=>{te=0,f(oe)}))},re=()=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",re),te&&cancelAnimationFrame(te),w.current=!1,f(null),y.current>=gi&&T(oe)};window.addEventListener("pointermove",ne),window.addEventListener("pointerup",re)},[p,u,E,S,c,n,s,T]),z=x.useCallback(F=>{y.current>=gi&&(F.stopPropagation(),y.current=0)},[]),X=x.useCallback(F=>{p&&(F.stopPropagation(),T(null))},[p,T]);return h.jsxs("g",{className:H,onMouseEnter:C?()=>C(N.id):void 0,onMouseLeave:C?()=>C(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:$,fill:"none",strokeDasharray:O?void 0:"6 4"}),h.jsx("path",{d:$,fill:"none",strokeWidth:16/d,stroke:"transparent"}),h.jsx(yi,{x:n,y:r,side:o,many:D,optional:k}),h.jsx(yi,{x:s,y:i,side:a,many:B,optional:!1}),p&&((c==null?void 0:c.hovered)||l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:P,onClickCapture:z,onDoubleClick:X,children:[h.jsx("rect",{x:S-11/d,y:I-16/d,width:22/d,height:32/d,fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:S-4.5/d,y:I-9/d,width:9/d,height:18/d,rx:4/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I-3/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I+3/d,r:1.1/d})]}),(l||g)&&N&&h.jsxs("text",{className:"rel-label",x:L,y:j-8,children:[l?N.verb_phrase||N.name:"",g?`${l?" ":""}(${c.memberCount})`:""]})]})});function yi({x:e,y:t,side:n,many:r,optional:s}){const i=n===q.Left?-1:1,o=7,a=12,c=[];return r?c.push(h.jsx("path",{className:"rel-glyph",d:`M ${e+i*a} ${t} L ${e} ${t-o} M ${e+i*a} ${t} L ${e} ${t} M ${e+i*a} ${t} L ${e} ${t+o}`,fill:"none"},"foot")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a-3),y1:t-o,x2:e+i*(a-3),y2:t+o},"one")),s?c.push(h.jsx("circle",{className:"rel-glyph ring",cx:e+i*(a+6),cy:t,r:4},"opt")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a+5),y1:t-o,x2:e+i*(a+5),y2:t+o},"mand")),h.jsx(h.Fragment,{children:c})}const gx={entity:Pm},yx={relationship:px},xi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],wi="#8a7d6a";function xx(e,t,n){const s=Xe;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function wx(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Yr,targetHandle:n(e.to.entity,s)?s:Xr}}function qx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:w,fitBounds:y,getNodes:v}=an(),[p,E]=x.useState([]),[$,b]=x.useState([]),M=x.useRef(!1),N=x.useMemo(()=>{const V=u&&u.size>0?[...u].sort():null;return V?"sa:"+V.join("+"):"__all__"},[u]),_=x.useRef(null),[R,k]=x.useState(0),O=x.useRef(new Map),D=x.useRef(null);x.useEffect(()=>{if(!f){_.current=null;return}const V=O.current.get(N);if(V){_.current=V,M.current=!1,k(G=>G+1);return}let Y=!1;return f.load(N).then(G=>{Y||(O.current.set(N,G),_.current=G,M.current=!1,k(Q=>Q+1))}),()=>{Y=!0}},[f,N]);const[B,H]=x.useState(null),[g,C]=x.useState(null),[S,I]=x.useState(!1),[L,j]=x.useState(null),[T,P]=x.useState(null),[z,X]=x.useState(null),[F,Z]=x.useState(null),J=x.useRef({}),te=!t.canEdit,oe=x.useRef(null),ne=x.useCallback(()=>{f&&(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{const V={};for(const Q of v())Q.hidden||(V[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,U]of Object.entries(J.current))Y[Q]={routeX:Math.round(U)};const G={nodes:V,edges:Y};O.current.set(N,G),_.current=G,f.save(N,G)},800))},[f,v,N]),re=x.useCallback((V,Y)=>{Y==null?delete J.current[V]:J.current[V]=Y,b(G=>G.map(Q=>Q.id===V?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),ne()},[ne]),pe=x.useMemo(()=>{const V=new Map;return e.subject_areas.forEach((Y,G)=>V.set(Y.id,xi[G%xi.length])),V},[e]),ce=x.useMemo(()=>{const V=new Map;return e.entities.forEach(Y=>V.set(Y.id,Y)),V},[e]),ue=x.useMemo(()=>{const V=new Map,Y=new Map;return e.subject_areas.forEach(G=>{(G.members??[]).forEach(Q=>Y.set(Q,{id:G.id,name:G.name}))}),e.entities.forEach(G=>{var se,me;const Q=(se=G.conceptual)!=null&&se.id?Y.get(G.conceptual.id):void 0,U=(me=G.conceptual)==null?void 0:me.subject_area,ee=Q??(U?{id:U.id,name:U.name??U.id}:void 0);ee&&V.set(G.id,ee)}),V},[e]),ye=x.useCallback(V=>{var G;if(!u||u.size===0)return!1;const Y=(G=ue.get(V))==null?void 0:G.id;return!(Y&&u.has(Y))},[u,ue]),he=x.useMemo(()=>{const V=new Map,Y=(G,Q)=>{if(!Q.length)return;const U=V.get(G)??new Set;Q.forEach(ee=>U.add(ee)),V.set(G,U)};for(const G of e.relationships)Y(G.from.entity,G.from.attributes),Y(G.to.entity,G.to.attributes);return V},[e]);x.useEffect(()=>{var $e;const V=i.trim().toLowerCase(),Y=new Set;if(V)for(const W of e.entities)(W.name.toLowerCase()+" "+((($e=W.conceptual)==null?void 0:$e.name.toLowerCase())??"")+" "+W.attributes.map(ge=>ge.name.toLowerCase()).join(" ")).includes(V)&&Y.add(W.id);const G=new Set;if(r){G.add(r);for(const W of e.relationships)W.from.entity===r&&G.add(W.to.entity),W.to.entity===r&&G.add(W.from.entity)}const Q=e.entities.map(W=>{const fe=V!==""&&!Y.has(W.id),ge=r!==null&&!G.has(W.id);return{id:W.id,type:"entity",position:{x:0,y:0},hidden:ye(W.id),data:{entity:W,color:(()=>{const ve=ue.get(W.id);return ve?pe.get(ve.id)??wi:wi})(),dimmed:fe||ge,highlighted:V!==""&&Y.has(W.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(W.id))??!1,onToggleExpand:l,endpointAttrs:he.get(W.id),highlightAttrs:void 0,onHoverAttr:X}}}),U=e.relationships.filter(W=>ce.has(W.from.entity)&&ce.has(W.to.entity)).map(W=>{const{sourceHandle:fe,targetHandle:ge}=wx(W,ce),ve=r!==null&&W.from.entity!==r&&W.to.entity!==r;return{id:W.id,source:W.from.entity,target:W.to.entity,sourceHandle:fe,targetHandle:ge,type:"relationship",data:{relationship:W,dimmed:ve,memberCount:Math.max(W.from.attributes.length,W.to.attributes.length),onHoverEdge:Z}}}),ee=_.current;if(J.current={},ee)for(const[W,fe]of Object.entries(ee.edges))J.current[W]=fe.routeX;let se=Q;E(W=>{const fe=new Map(W.map(ae=>[ae.id,ae.position])),ge=Q.every(ae=>fe.has(ae.id)),ve=((u==null?void 0:u.size)??0)>0;if(M.current&&ge&&W.length>=Q.length&&!ve){const ae=Q.map(qe=>({...qe,position:fe.get(qe.id)??qe.position}));return se=ae,ae}const Be=ve?Q.filter(ae=>!ae.hidden):Q,Ot=ur(Be,U,ce,"auto",ue),st=new Map(Ot.map(ae=>[ae.id,ae.position])),ft=(ee==null?void 0:ee.nodes)??{},Lt=Object.keys(ft).length>0,Pe=[],Dt=Q.map(ae=>{const qe=ft[ae.id];if(qe){const Pt={x:qe.x,y:qe.y};return Pe.push({x:Pt.x,y:Pt.y,w:Xe,h:wt(ae.data.entity)}),{...ae,position:Pt}}return st.has(ae.id)?{...ae,position:st.get(ae.id)}:fe.has(ae.id)&&M.current?{...ae,position:fe.get(ae.id)}:ae});if(Lt)for(const ae of Dt)ft[ae.id]||ae.hidden||(ae.position=xx(ae.position,wt(ae.data.entity),Pe),Pe.push({x:ae.position.x,y:ae.position.y,w:Xe,h:wt(ae.data.entity)}));return M.current=!0,Lt||requestAnimationFrame(()=>w({padding:.15,duration:300})),se=Dt,Dt});const me=new Map;for(const W of se)me.set(W.id,{left:W.position.x,right:W.position.x+Xe});b(U.map(W=>({...W,data:{...W.data,routeX:J.current[W.id],onRouteChange:f?re:void 0,sourceCard:me.get(W.source),targetCard:me.get(W.target)}})))},[e,i,r,o,a,c,l,pe,ce,ue,ye,u,he,w,f,re,R]);const xe=x.useMemo(()=>{const V=new Set,Y=new Set,G=new Map,Q=(U,ee)=>{if(!ee.length)return;const se=G.get(U)??new Set;ee.forEach(me=>se.add(me)),G.set(U,se)};if(z)for(const U of e.relationships)(U.from.attributes.includes(z)||U.to.attributes.includes(z))&&(V.add(U.id),Y.add(U.from.entity),Y.add(U.to.entity),Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes));if(F){const U=e.relationships.find(ee=>ee.id===F);U&&(Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes))}return{active:z!==null,relsForAttr:V,entsForAttr:Y,hitAttrsByEntity:G}},[e,z,F]);x.useEffect(()=>{var Q;const V=i.trim().toLowerCase(),Y=new Set;if(V)for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(V)&&Y.add(U.id);const G=new Set;if(r){G.add(r);for(const U of e.relationships)U.from.entity===r&&G.add(U.to.entity),U.to.entity===r&&G.add(U.from.entity)}E(U=>U.map(ee=>{const se=V!==""&&!Y.has(ee.id),me=r!==null&&!G.has(ee.id),$e=xe.active&&!xe.entsForAttr.has(ee.id),W=se||me||$e,fe=V!==""&&Y.has(ee.id)||xe.active&&xe.entsForAttr.has(ee.id),ge=xe.hitAttrsByEntity.get(ee.id);return ee.data.dimmed===W&&ee.data.highlighted===fe&&ee.data.highlightAttrs===ge?ee:{...ee,data:{...ee.data,dimmed:W,highlighted:fe,highlightAttrs:ge}}})),b(U=>U.map(ee=>{var ge,ve,Be;const se=(ge=ee.data)==null?void 0:ge.relationship,me=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,$e=xe.active&&!xe.relsForAttr.has(ee.id),W=me||$e,fe=F===ee.id;return((ve=ee.data)==null?void 0:ve.dimmed)===W&&((Be=ee.data)==null?void 0:Be.hovered)===fe?ee:{...ee,data:{...ee.data,dimmed:W,hovered:fe}}}))},[xe,F,i,r,e]),x.useEffect(()=>{var Q;const V=i.trim().toLowerCase();if(!V)return;const Y=new Set;for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(V)&&Y.add(U.id);if(!Y.size)return;const G=requestAnimationFrame(()=>{const U=v().filter(se=>Y.has(se.id));if(!U.length)return;const ee=Mf(U);y(ee,{padding:.35,duration:400})});return()=>cancelAnimationFrame(G)},[i,e,v,y]);const le=x.useCallback((V="auto",Y="LR")=>{D.current=Object.fromEntries(v().map(G=>[G.id,{x:G.position.x,y:G.position.y}])),E(G=>ur(G,$,ce,V,ue,Y)),requestAnimationFrame(()=>w({padding:.15,duration:300})),ne()},[$,ce,ue,w,v,ne]),K=x.useCallback(()=>{const V=D.current;V&&(E(Y=>Y.map(G=>V[G.id]?{...G,position:V[G.id]}:G)),D.current=null,ne())},[ne]),Se=x.useCallback(()=>{f==null||f.reset(N),O.current.delete(N),_.current=null,J.current={},M.current=!1,b(V=>V.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(V=>{const Y=ur(V,$,ce,"auto",ue);return requestAnimationFrame(()=>w({padding:.15,duration:300})),Y})},[f,N,$,ce,ue,w]),Ce=x.useCallback(V=>{s(V),E(Y=>(Y.find(Q=>Q.id===V)&&requestAnimationFrame(()=>w({nodes:[{id:V}],padding:.4,duration:400})),Y))},[w,s]);x.useImperativeHandle(m,()=>({relayout:le,fitView:()=>w({padding:.15,duration:300}),focusEntity:Ce,newEntity:()=>I(!0),resetLayout:Se,undoRelayout:K}),[le,w,Ce,Se,K]);const dt=x.useCallback(V=>{if(te||!V.source||!V.target||V.source===V.target)return;const Y=V.sourceHandle&&V.sourceHandle!==Yr?V.sourceHandle:void 0,G=V.targetHandle&&V.targetHandle!==Xr?V.targetHandle:void 0;j({from:V.source,to:V.target,fromAttr:Y,toAttr:G})},[te]),Ae=x.useCallback(async(V,Y)=>{try{return await n(V,Y)}catch(G){throw d==null||d(G instanceof Error?G.message:String(G)),G}},[n,d]),Ue=r?ce.get(r)??null:null,Ie=e.relationships.find(V=>V.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Yo,{nodes:p,edges:$,nodeTypes:gx,edgeTypes:yx,onNodeClick:(V,Y)=>s(Y.id),onEdgeDoubleClick:(V,Y)=>!te&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(V,Y)=>{E(G=>G.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),ne()},onConnect:dt,nodesConnectable:!te,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:Le.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:V=>{var Y;return((Y=V.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),Ue&&h.jsx(Hm,{entity:Ue,doc:e,caps:t,exec:Ae,onClose:()=>s(null),onFocusEntity:Ce,onAlign:H,onEditMapping:C}),B&&h.jsx(ix,{entity:B,exec:Ae,onClose:()=>H(null)}),g&&h.jsx(ox,{entity:g,doc:e,exec:Ae,onClose:()=>C(null)}),S&&h.jsx(ax,{doc:e,exec:Ae,onClose:()=>I(!1),onCreated:Ce}),L&&h.jsx(cx,{doc:e,fromId:L.from,toId:L.to,initialFromAttr:L.fromAttr,initialToAttr:L.toAttr,exec:Ae,onClose:()=>j(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:Ae,onClose:()=>P(null)})]})}function Kx({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(bx,{}),e==="layers"&&h.jsx(_x,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(Ex,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Nx,{readOnly:n})]})}function bx(){const[e,t]=x.useState(""),[n,r]=x.useState([]),[s,i]=x.useState({loaded:0,vocabs:[]}),[o,a]=x.useState(null),[c,l]=x.useState([]),[u,d]=x.useState("");x.useEffect(()=>{Qo().then(f=>l(f.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const f=setTimeout(()=>{Zo(e||"a",u||void 0).then(w=>{r(e?w.results:[]),i({loaded:w.loaded_terms,vocabs:w.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=x.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const vx=["industry","core","domain","specialised"];function _x({refreshKey:e,onFocusEntity:t}){const[n,r]=x.useState(null),[s,i]=x.useState(null);if(x.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),vx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Ex({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=x.useState(null),[i,o]=x.useState(""),[a,c]=x.useState(""),[l,u]=x.useState(!1),d=x.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` `))).catch(()=>o(""))},[]);return x.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:i.split(` `).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index 44998c6..0232928 100644 --- a/packages/server/src/mdl_server/static/index.html +++ b/packages/server/src/mdl_server/static/index.html @@ -4,9 +4,9 @@ Modelith - + - + diff --git a/packages/server/src/mdl_server/static/sme.html b/packages/server/src/mdl_server/static/sme.html index 132f89f..87d79fe 100644 --- a/packages/server/src/mdl_server/static/sme.html +++ b/packages/server/src/mdl_server/static/sme.html @@ -4,9 +4,9 @@ Modelith Glossary - + - + From b35b8c589e264420b631f3d38adf4ee519493c9e Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Mon, 12 Oct 2026 16:55:07 +1100 Subject: [PATCH 06/14] canvas: edge handle grab-anywhere, elevate hovered/selected edge above cards Polish from real use, against standard diagram-editor UX patterns: 1. Grab zone (was: had to aim at the exact grip). The drag target now spans the WHOLE vertical segment (~40px wide on screen, full segment height) per React Flow's generous edge-interaction guidance, so you can grab the line anywhere along its run. Grip is a clearer 3-dot pill. 2. Occlusion (was: route/crow's-foot hidden behind a card). The hovered or selected edge is lifted above the node cards (zIndex 1000 vs nodes' 0) so its route and endpoint markers stay visible while you work it; other edges stay behind cards for a clean diagram. 3. Routing: the existing snap/magnetise/clamp keeps the segment out of its endpoint cards (so it can't be dropped behind the target), which with the elevation keeps the line readable during a drag. Verified live: grab zone 40x217px, hovered edge layer z=1000 over nodes z=0, glyphs stay rendered when the route nears a card, drag commits + persists. --- canvas/src/ModelCanvas.tsx | 11 +++++-- canvas/src/RelationshipEdge.tsx | 32 +++++++++++-------- ...m-BGW002_3.js => ModelDiagram-14z6V1AZ.js} | 2 +- .../{main-DzNDPWHD.js => main-DtmhCCsm.js} | 2 +- .../{sme-BFfrsm0Q.js => sme-KzTYm7pE.js} | 4 +-- ...{styles-DdybXVuP.js => styles-BeQbzs5X.js} | 8 ++--- .../server/src/mdl_server/static/index.html | 4 +-- .../server/src/mdl_server/static/sme.html | 4 +-- 8 files changed, 39 insertions(+), 28 deletions(-) rename packages/server/src/mdl_server/static/assets/{ModelDiagram-BGW002_3.js => ModelDiagram-14z6V1AZ.js} (97%) rename packages/server/src/mdl_server/static/assets/{main-DzNDPWHD.js => main-DtmhCCsm.js} (99%) rename packages/server/src/mdl_server/static/assets/{sme-BFfrsm0Q.js => sme-KzTYm7pE.js} (99%) rename packages/server/src/mdl_server/static/assets/{styles-DdybXVuP.js => styles-BeQbzs5X.js} (83%) diff --git a/canvas/src/ModelCanvas.tsx b/canvas/src/ModelCanvas.tsx index f26a52c..164a709 100644 --- a/canvas/src/ModelCanvas.tsx +++ b/canvas/src/ModelCanvas.tsx @@ -584,8 +584,15 @@ export function ModelCanvas({ // the hovered edge shows its drag handle (so it is grabbable without a click, // which now double-clicks to open the editor) const hovered = hoveredEdge === r.id; - if (r.data?.dimmed === dimmed && r.data?.hovered === hovered) return r; - return { ...r, data: { ...r.data!, dimmed, hovered } }; + const selected = selectedId !== null && rel !== undefined && + (rel.from.entity === selectedId || rel.to.entity === selectedId); + // Lift the hovered/selected edge ABOVE the node cards (default edges render + // behind them) so its route and crow's-foot markers are never hidden while + // you work it. Other edges stay behind the cards for a clean diagram. + const zIndex = hovered || selected ? 1000 : 0; + if (r.data?.dimmed === dimmed && r.data?.hovered === hovered && r.zIndex === zIndex) + return r; + return { ...r, zIndex, data: { ...r.data!, dimmed, hovered } }; }), ); }, [hover, hoveredEdge, query, selectedId, doc]); diff --git a/canvas/src/RelationshipEdge.tsx b/canvas/src/RelationshipEdge.tsx index a13d4b1..2804eb2 100644 --- a/canvas/src/RelationshipEdge.tsx +++ b/canvas/src/RelationshipEdge.tsx @@ -206,27 +206,31 @@ export const RelationshipEdge = memo(function RelationshipEdge({ onClickCapture={onClickCapture} onDoubleClick={onDoubleClick} > - {/* a fat transparent target (~22px on screen) around the grip for easy grabbing */} + {/* Grab target spanning the WHOLE vertical segment (not just a window at the + midpoint), ~40px wide on screen, so you can grab the line anywhere along its + run — you no longer have to aim at the grip itself. React Flow edge-interaction + guidance: a generous (20-75px) hit area. */} - {/* the visible grip: a rounded pill (~9x18px on screen) */} + {/* the visible grip: a rounded pill (~11x22px on screen) */} - {/* two dots to read as a drag affordance */} - - + {/* three dots to read as a drag affordance */} + + + )} {(selected || composite) && rel && ( diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-BGW002_3.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-14z6V1AZ.js similarity index 97% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-BGW002_3.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-14z6V1AZ.js index cd52bec..bd79f2d 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-BGW002_3.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-14z6V1AZ.js @@ -1 +1 @@ -import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-DdybXVuP.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; +import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-BeQbzs5X.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; diff --git a/packages/server/src/mdl_server/static/assets/main-DzNDPWHD.js b/packages/server/src/mdl_server/static/assets/main-DtmhCCsm.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-DzNDPWHD.js rename to packages/server/src/mdl_server/static/assets/main-DtmhCCsm.js index a9b403a..057253e 100644 --- a/packages/server/src/mdl_server/static/assets/main-DzNDPWHD.js +++ b/packages/server/src/mdl_server/static/assets/main-DtmhCCsm.js @@ -1,2 +1,2 @@ -import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-DdybXVuP.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` +import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-BeQbzs5X.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` `)||"model valid",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),M]}):F?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14}),F]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!u&&e.jsxs("button",{className:"tool-btn primary",onClick:A,title:"New entity (n)",children:[e.jsx(ye,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),E("ontology",e.jsx(be,{size:15}),"Ontology","Ontology browser"),E("layers",e.jsx(we,{size:15}),"Layers","Four-layer stack & coverage"),E("changes",e.jsx(ve,{size:15}),"Changes",k?"Uncommitted changes":"Changes",k),E("decisions",e.jsx(Me,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(w?" active":""),onClick:g,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(m?" active":""),onClick:p,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Ne,{size:15})}),e.jsx(Ke,{onRelayout:f,onReset:v}),e.jsx("button",{className:"grp-btn icon-only",onClick:y,title:"Fit view","aria-label":"Fit view",children:e.jsx(ke,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:r,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Se,{size:15})}),e.jsx(de,{exec:S,canEdit:!u,onImported:I,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:_,openImport:$})]})]})]})}const U=["LR","TB","RL","BT"],$e={LR:0,TB:90,RL:180,BT:270},se={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function Ke({onRelayout:s,onReset:l}){const[j,h]=a.useState(!1),[x,w]=a.useState("LR"),[g,m]=a.useState("auto"),p=a.useRef(null);a.useEffect(()=>{if(!j)return;const r=u=>{p.current&&!p.current.contains(u.target)&&h(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[j]);const y=r=>{m(r),s(r,x)},f=r=>{y(r),h(!1)},v=()=>{const r=U[(U.indexOf(x)+1)%U.length];w(r),s(g,r)};return e.jsxs("div",{className:"layout-picker",ref:p,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>y("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ee,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(j?" active":""),onClick:()=>h(r=>!r),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:v,title:`Flow direction: ${se[x]} (click to rotate)`,"aria-label":`Flow direction: ${se[x]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${$e[x]}deg)`},children:e.jsx(Pe,{size:15})})}),j&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>f("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>f("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>f("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>f("grid"),children:"Grid"}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"layout-menu-sep",role:"separator"}),e.jsx("button",{onClick:()=>{l(),h(!1)},title:"Clear saved positions and routes for this view",children:"Reset layout"})]})]})]})}function He(){const[s,l]=a.useState(null),[j,h]=a.useState(null),[x,w]=a.useState(null),[g,m]=a.useState(null),[p,y]=a.useState(""),[f,v]=a.useState(!0),[r,u]=a.useState(!1),[k,b]=a.useState(()=>new Set),[q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[z,D]=a.useState(()=>new Set),[K,M]=a.useState(!1),[F,E]=a.useState(0),o=a.useRef(null),L=a.useRef(""),B=a.useRef(!1),O=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((c,n)=>t.set(c.id,Y[n%Y.length])),t},[s]),H=a.useMemo(()=>{const t=new Map;if(!s)return t;const c=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(d=>c.set(d,n.id))}),s.entities.forEach(n=>{var N,Q,X;const P=((N=n.conceptual)!=null&&N.id?c.get(n.conceptual.id):void 0)??((X=(Q=n.conceptual)==null?void 0:Q.subject_area)==null?void 0:X.id)??"";t.set(n.id,P)}),t},[s]),te=a.useMemo(()=>{const t=new Map;return H.forEach(c=>t.set(c,(t.get(c)??0)+1)),t},[H]),R=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>ge(R),[R]),ae=a.useMemo(()=>ue(),[]),V=a.useMemo(()=>new URLSearchParams(window.location.search),[]),T=V.get("minimal")==="1";a.useEffect(()=>{T&&u(!0)},[T]);const re=a.useCallback(t=>{b(c=>{const n=new Set(c);return n.has(t)?n.delete(t):n.add(t),n})},[]),ce=V.get("import")==="1",W=a.useRef(!1),C=a.useCallback(()=>{J().then(l).catch(t=>w(String(t))),Z().then(h).catch(()=>h(null)),ee().then(t=>M(!!(t.git&&!t.clean))).catch(()=>M(!1)),E(t=>t+1)},[]);a.useEffect(C,[C]),a.useEffect(()=>{const t=setInterval(()=>{J().then(c=>{l(n=>n&&c.fingerprint===n.fingerprint?n:(B.current||(L.current=c.fingerprint),T||(Z().then(h).catch(()=>h(null)),ee().then(d=>M(!!(d.git&&!d.clean))).catch(()=>M(!1))),E(d=>d+1),c))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[T]),a.useEffect(()=>{s!=null&&s.fingerprint&&(L.current=s.fingerprint)},[s]);const G=a.useCallback(async(t,c)=>{if(s){B.current=!0;try{const n=await xe(t,c,L.current||s.fingerprint);return n!=null&&n.fingerprint&&(L.current=n.fingerprint),C(),n}catch(n){throw n instanceof pe&&n.status===409?(m("Model changed on disk — view refreshed, please retry."),C()):m(n instanceof Error?n.message:String(n)),n}finally{B.current=!1}}},[s,C]);a.useEffect(()=>{if(!g)return;const t=setTimeout(()=>m(null),5e3);return()=>clearTimeout(t)},[g]),a.useEffect(()=>{if(!s||W.current)return;const t=V.get("focus");if(!t)return;const c=s.entities.find(n=>{var d;return n.name===t||((d=n.conceptual)==null?void 0:d.name)===t});c&&(W.current=!0,requestAnimationFrame(()=>{var n;return(n=o.current)==null?void 0:n.focusEntity(c.id)}))},[s,V]);const oe=a.useCallback(()=>{var n;if(!s)return;const t=p.trim().toLowerCase();if(!t)return;const c=s.entities.find(d=>{var N;return(d.name.toLowerCase()+" "+(((N=d.conceptual)==null?void 0:N.name.toLowerCase())??"")+" "+d.attributes.map(Q=>Q.name.toLowerCase()).join(" ")).includes(t)});c&&((n=o.current)==null||n.focusEntity(c.id))},[s,p]);return a.useEffect(()=>{const t=c=>{var d,P,N;const n=(d=document.activeElement)==null?void 0:d.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(c.key==="/"&&(c.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),c.key==="n"&&!R&&((N=o.current)==null||N.newEntity()),c.key==="Escape"&&(A(null),y(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[R]),x?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:x}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!T&&e.jsx(_e,{doc:s,diagnostics:j,query:p,onQuery:y,onSubmitQuery:oe,showTypes:f,onToggleTypes:()=>v(t=>!t),collapseDetail:r,onToggleCollapse:()=>u(t=>!t),onFitView:()=>{var t;return(t=o.current)==null?void 0:t.fitView()},onRelayout:(t,c)=>{var n;return(n=o.current)==null?void 0:n.relayout(t,c)},onResetLayout:()=>{var t;return(t=o.current)==null?void 0:t.resetLayout()},onRefresh:C,readOnly:R,dirty:K,panelTab:S,onPanelTab:t=>I(c=>c===t?null:t),onNewEntity:()=>{var t;return(t=o.current)==null?void 0:t.newEntity()},exec:G,onImported:C,onImportBatch:je,openImport:ce,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:z.size}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(me,{doc:s,caps:ne,exec:G,selectedId:S?null:q,onSelect:A,query:p,showTypes:f,collapseDetail:r,expandedEntities:k,onToggleExpand:re,activeAreas:z,onError:m,handleRef:o,layoutStore:ae}),!T&&e.jsx(Ae,{doc:s,saColors:O,countByArea:te,activeAreas:z,onSetActive:D,open:_,onClose:()=>$(!1)}),S&&e.jsx(fe,{tab:S,onClose:()=>I(null),readOnly:R,refreshKey:F,onModelChanged:C,onFocusEntity:t=>{var c;I(null),(c=o.current)==null||c.focusEntity(t)}}),g&&e.jsx("div",{className:"toast",children:g})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ve(){return e.jsx(he,{children:e.jsx(He,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(le.StrictMode,{children:e.jsx(Ve,{})})); diff --git a/packages/server/src/mdl_server/static/assets/sme-BFfrsm0Q.js b/packages/server/src/mdl_server/static/assets/sme-KzTYm7pE.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-BFfrsm0Q.js rename to packages/server/src/mdl_server/static/assets/sme-KzTYm7pE.js index 1956c24..29a8779 100644 --- a/packages/server/src/mdl_server/static/assets/sme-BFfrsm0Q.js +++ b/packages/server/src/mdl_server/static/assets/sme-KzTYm7pE.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-BGW002_3.js","assets/client-DOmNpTln.js","assets/styles-DdybXVuP.js","assets/styles-BpoQ4C-h.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-DdybXVuP.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-BGW002_3.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-14z6V1AZ.js","assets/client-DOmNpTln.js","assets/styles-BeQbzs5X.js","assets/styles-BpoQ4C-h.css"])))=>i.map(i=>d[i]); +import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-BeQbzs5X.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-14z6V1AZ.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); diff --git a/packages/server/src/mdl_server/static/assets/styles-DdybXVuP.js b/packages/server/src/mdl_server/static/assets/styles-BeQbzs5X.js similarity index 83% rename from packages/server/src/mdl_server/static/assets/styles-DdybXVuP.js rename to packages/server/src/mdl_server/static/assets/styles-BeQbzs5X.js index 02cd638..50bcf0b 100644 --- a/packages/server/src/mdl_server/static/assets/styles-DdybXVuP.js +++ b/packages/server/src/mdl_server/static/assets/styles-BeQbzs5X.js @@ -6,7 +6,7 @@ var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var At=x;function ac(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var cc=typeof Object.is=="function"?Object.is:ac,lc=At.useState,uc=At.useEffect,dc=At.useLayoutEffect,fc=At.useDebugValue;function hc(e,t){var n=t(),r=lc({inst:{value:n,getSnapshot:t}}),s=r[0].inst,i=r[1];return dc(function(){s.value=n,s.getSnapshot=t,Wn(s)&&i({inst:s})},[e,n,t]),uc(function(){return Wn(s)&&i({inst:s}),e(function(){Wn(s)&&i({inst:s})})},[e]),fc(n),n}function Wn(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!cc(e,n)}catch{return!0}}function mc(e,t){return t()}var pc=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?mc:hc;Si.useSyncExternalStore=At.useSyncExternalStore!==void 0?At.useSyncExternalStore:pc;Ni.exports=Si;var gc=Ni.exports;/** + */var Rt=x;function ac(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var cc=typeof Object.is=="function"?Object.is:ac,lc=Rt.useState,uc=Rt.useEffect,dc=Rt.useLayoutEffect,fc=Rt.useDebugValue;function hc(e,t){var n=t(),r=lc({inst:{value:n,getSnapshot:t}}),s=r[0].inst,i=r[1];return dc(function(){s.value=n,s.getSnapshot=t,Wn(s)&&i({inst:s})},[e,n,t]),uc(function(){return Wn(s)&&i({inst:s}),e(function(){Wn(s)&&i({inst:s})})},[e]),fc(n),n}function Wn(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!cc(e,n)}catch{return!0}}function mc(e,t){return t()}var pc=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?mc:hc;Si.useSyncExternalStore=Rt.useSyncExternalStore!==void 0?Rt.useSyncExternalStore:pc;Ni.exports=Si;var gc=Ni.exports;/** * @license React * use-sync-external-store-shim/with-selector.production.js * @@ -14,9 +14,9 @@ var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Dn=x,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=Dn.useRef,_c=Dn.useEffect,Ec=Dn.useMemo,Nc=Dn.useDebugValue;Ei.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var w=o.value;if(s(w,f))return d=w}return d=f}if(w=d,wc(u,f))return w;var y=r(f);return s!==void 0&&s(w,y)?(u=f,w):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};_i.exports=Ei;var Sc=_i.exports;const kc=vi(Sc),jc={},es=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(w=>w(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?es(e):es,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function ki(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const ts=(e,t)=>{const n=Cc(e),r=(s,i=t)=>ki(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?ts(e,t):ts;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rs.hasOwnProperty(t)?{space:rs[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===dr&&t.documentElement.namespaceURI===dr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ji(e){var t=zn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function Cr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=Cr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=$&&($=E+1);!(M=v[$])&&++$=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Rt(this.node(),e)}function Rt(e,t){return e.style.getPropertyValue(t)||Ri(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ii(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Ti(e)}function Ti(e){this._node=e,this._names=Ii(e.getAttribute("class")||"")}Ti.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Oi(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function fr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}fr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Pn("start","drag","end"),o=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",p,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,M){if(!(u||!e.call(this,b,M))){var N=$(this,t.call(this,b,M),b,M,"mouse");N&&(Te(b.view).on("mousemove.drag",w,Ut).on("mouseup.drag",y,Ut),zi(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,N("start",b))}}function w(b){if(Ct(b),!l){var M=b.clientX-a,N=b.clientY-c;l=M*M+N*N>d}s.mouse("drag",b)}function y(b){Te(b.view).on("mousemove.drag mouseup.drag",null),Hi(b.view,l),Ct(b),s.mouse("end",b)}function v(b,M){if(e.call(this,b,M)){var N=b.changedTouches,_=t.call(this,b,M),R=N.length,k,O;for(k=0;k>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?un(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?un(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Me(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Me(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?un(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?un(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?us(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?us(t[1],t[2]/100,t[3]/100,t[4]):ss.hasOwnProperty(e)?as(ss[e]):e==="transparent"?new Me(NaN,NaN,NaN,0):null}function as(e){return new Me(e>>16&255,e>>8&255,e&255,1)}function un(e,t,n,r){return r<=0&&(e=t=n=NaN),new Me(e,t,n,r)}function Mu(e){return e instanceof rn||(e=Zt(e)),e?(e=e.rgb(),new Me(e.r,e.g,e.b,e.opacity)):new Me}function hr(e,t,n,r){return arguments.length===1?Mu(e):new Me(e,t,n,r??1)}function Me(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Mr(Me,hr,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Me(yt(this.r),yt(this.g),yt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:cs,formatHex:cs,formatHex8:Au,formatRgb:ls,toString:ls}));function cs(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function ls(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function us(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new He(e,t,n,r)}function Vi(e){if(e instanceof He)return new He(e.h,e.s,e.l,e.opacity);if(e instanceof rn||(e=Zt(e)),!e)return new He;if(e instanceof He)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new He(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Vi(e):new He(e,t,n,r??1)}function He(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Mr(He,Ru,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new He(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new He(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Me(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new He(ds(this.h),dn(this.s),dn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${ds(this.h)}, ${dn(this.s)*100}%, ${dn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ds(e){return e=(e||0)%360,e<0?e+360:e}function dn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Bi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Gi:function(t,n){return n-t?Tu(t,n,e):Bi(isNaN(t)?n:t)}}function Gi(e,t){var n=t-e;return n?Iu(e,n):Bi(isNaN(e)?t:e)}const fs=function e(t){var n=Ou(t);function r(s,i){var o=n((s=hr(s)).r,(i=hr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Gi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function ot(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var mr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(mr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=mr.lastIndex=Kn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=mr.exec(e))&&(s=Kn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:ot(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:ot(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:ot(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,w){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");w.push({i:y-4,x:ot(l,d)},{i:y-2,x:ot(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var w=-1,y=m.length,v;++w=0&&e._call.call(void 0,t),e=e._next;--It}function ps(){bt=(Cn=Qt.now())+Hn,It=Gt=0;try{Uu()}finally{It=0,Ku(),bt=0}}function qu(){var e=Qt.now(),t=e-Cn;t>Wi&&(Hn-=t,Cn=e)}function Ku(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Yt=e,gr(r)}function gr(e){if(!It){Gt&&(Gt=clearTimeout(Gt));var t=e-bt;t>24?(e<1/0&&(Gt=setTimeout(ps,e-Qt.now()-Hn)),zt&&(zt=clearInterval(zt))):(zt||(Cn=Qt.now(),zt=setInterval(qu,Wi)),It=1,Ui(ps))}}function gs(e,t,n){var r=new $n;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Pn("start","end","cancel","interrupt"),Qu=[],Ki=0,ys=1,yr=2,vn=3,xs=4,xr=5,_n=6;function Fn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Ki})}function Rr(e,t){var n=Fe(e,t);if(n.state>Ki)throw new Error("too late; already scheduled");return n}function We(e,t){var n=Fe(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Fe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=qi(i,0,n.time);function i(l){n.state=ys,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ys)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return gs(o);f.state===xs?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uyr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Rr:We;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Fe(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Cr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Je(e,t,n){this.k=e,this.x=t,this.y=n}Je.prototype={constructor:Je,scale:function(e){return e===1?this:new Je(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Je(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var et=new Je(1,0,0);Je.prototype;function Zn(e){e.stopImmediatePropagation()}function Ht(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ws(){return this.__zoom||et}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function eo(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Xu,l=Pn("start","zoom","end"),u,d,m,f=500,w=150,y=0,v=10;function p(g){g.property("__zoom",ws).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",D).on("touchmove.zoom",B).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}p.transform=function(g,C,S,I){var L=g.selection?g.selection():g;L.property("__zoom",ws),g!==L?M(g,C,S,I):L.interrupt().each(function(){N(this,arguments).event(I).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},p.scaleBy=function(g,C,S,I){p.scaleTo(g,function(){var L=this.__zoom.k,j=typeof C=="function"?C.apply(this,arguments):C;return L*j},S,I)},p.scaleTo=function(g,C,S,I){p.transform(g,function(){var L=t.apply(this,arguments),j=this.__zoom,T=S==null?b(L):typeof S=="function"?S.apply(this,arguments):S,P=j.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n($(E(j,z),T,P),L,o)},S,I)},p.translateBy=function(g,C,S,I){p.transform(g,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,I)},p.translateTo=function(g,C,S,I,L){p.transform(g,function(){var j=t.apply(this,arguments),T=this.__zoom,P=I==null?b(j):typeof I=="function"?I.apply(this,arguments):I;return n(et.translate(P[0],P[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof S=="function"?-S.apply(this,arguments):-S),j,o)},I,L)};function E(g,C){return C=Math.max(i[0],Math.min(i[1],C)),C===g.k?g:new Je(C,g.x,g.y)}function $(g,C,S){var I=C[0]-S[0]*g.k,L=C[1]-S[1]*g.k;return I===g.x&&L===g.y?g:new Je(g.k,I,L)}function b(g){return[(+g[0][0]+ +g[1][0])/2,(+g[0][1]+ +g[1][1])/2]}function M(g,C,S,I){g.on("start.zoom",function(){N(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(I).end()}).tween("zoom",function(){var L=this,j=arguments,T=N(L,j).event(I),P=t.apply(L,j),z=S==null?b(P):typeof S=="function"?S.apply(L,j):S,X=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),F=L.__zoom,Z=typeof C=="function"?C.apply(L,j):C,J=c(F.invert(z).concat(X/F.k),Z.invert(z).concat(X/Z.k));return function(te){if(te===1)te=Z;else{var oe=J(te),ne=X/oe[2];te=new Je(ne,z[0]-oe[0]*ne,z[1]-oe[1]*ne)}T.zoom(null,te)}})}function N(g,C,S){return!S&&g.__zooming||new _(g,C)}function _(g,C){this.that=g,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(g,C),this.taps=0}_.prototype={event:function(g){return g&&(this.sourceEvent=g),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(g,C){return this.mouse&&g!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&g!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&g!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(g){var C=Te(this.that).datum();l.call(g,this.that,new sf(g,{sourceEvent:this.sourceEvent,target:p,transform:this.that.__zoom,dispatch:l}),C)}};function R(g,...C){if(!e.apply(this,arguments))return;var S=N(this,C).event(g),I=this.__zoom,L=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,r.apply(this,arguments)))),j=ze(g);if(S.wheel)(S.mouse[0][0]!==j[0]||S.mouse[0][1]!==j[1])&&(S.mouse[1]=I.invert(S.mouse[0]=j)),clearTimeout(S.wheel);else{if(I.k===L)return;S.mouse=[j,I.invert(j)],En(this),S.start()}Ht(g),S.wheel=setTimeout(T,w),S.zoom("mouse",n($(E(I,L),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function k(g,...C){if(m||!e.apply(this,arguments))return;var S=g.currentTarget,I=N(this,C,!0).event(g),L=Te(g.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",X,!0),j=ze(g,S),T=g.clientX,P=g.clientY;zi(g.view),Zn(g),I.mouse=[j,this.__zoom.invert(j)],En(this),I.start();function z(F){if(Ht(F),!I.moved){var Z=F.clientX-T,J=F.clientY-P;I.moved=Z*Z+J*J>y}I.event(F).zoom("mouse",n($(I.that.__zoom,I.mouse[0]=ze(F,S),I.mouse[1]),I.extent,o))}function X(F){L.on("mousemove.zoom mouseup.zoom",null),Hi(F.view,I.moved),Ht(F),I.event(F).end()}}function O(g,...C){if(e.apply(this,arguments)){var S=this.__zoom,I=ze(g.changedTouches?g.changedTouches[0]:g,this),L=S.invert(I),j=S.k*(g.shiftKey?.5:2),T=n($(E(S,j),I,L),t.apply(this,C),o);Ht(g),a>0?Te(this).transition().duration(a).call(M,T,I,g):Te(this).call(p.transform,T,I,g)}}function D(g,...C){if(e.apply(this,arguments)){var S=g.touches,I=S.length,L=N(this,C,g.changedTouches.length===I).event(g),j,T,P,z;for(Zn(g),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},to=nt.error001();function de(e,t){const n=x.useContext(Vn);if(n===null)throw new Error(to);return ki(n,e,t)}const Ne=()=>{const e=x.useContext(Vn);if(e===null)throw new Error(to);return x.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Tr({position:e,children:t,className:n,style:r,...s}){const i=de(ff),o=`${e}`.split("-");return A.createElement("div",{className:je(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Tr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=x.useRef(null),[m,f]=x.useState({x:0,y:0,width:0,height:0}),w=je(["react-flow__edge-textwrapper",l]);return x.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:w,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=x.memo(mf);const Or=e=>({width:e.offsetWidth,height:e.offsetHeight}),Tt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Lr=(e={x:0,y:0},t)=>({x:Tt(e.x,t[0][0],t[1][0]),y:Tt(e.y,t[0][1],t[1][1])}),bs=(e,t,n)=>en?-Tt(Math.abs(e-n),1,50)/50:0,no=(e,t)=>{const n=bs(e.x,35,t.width-35)*20,r=bs(e.y,35,t.height-35)*20;return[n,r]},ro=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},so=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Jt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),io=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),vs=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>io(so(Jt(e),Jt(t))),wr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Oe(e.width)&&Oe(e.height)&&Oe(e.x)&&Oe(e.y),Oe=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),oo=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function br(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const ao=e=>"clientX"in e,ut=(e,t)=>{var i,o;const n=ao(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Mn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},sn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Oe(n)&&Oe(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);sn.displayName="BaseEdge";function Ft(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function co({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[v,p,E]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(sn,{path:v,labelX:p,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:y})});Dr.displayName="SimpleBezierEdge";const Es={[q.Left]:{x:-1,y:0},[q.Right]:{x:1,y:0},[q.Top]:{x:0,y:-1},[q.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=q.Bottom,target:n})=>t===q.Left||t===q.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=q.Bottom,target:n,targetPosition:r=q.Top,center:s,offset:i}){const o=Es[t],a=Es[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],w,y;const v={x:0,y:0},p={x:0,y:0},[E,$,b,M]=co({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){w=s.x??E,y=s.y??$;const _=[{x:w,y:c.y},{x:w,y:l.y}],R=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?R:_:f=o.y===m?_:R,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const g=Math.min(i-1,i-H);o[d]===m?v[d]=(c[d]>e[d]?-1:1)*g:p[d]=(l[d]>n[d]?-1:1)*g}}if(t!==r){const H=d==="x"?"y":"x",g=o[d]===a[H],C=c[H]>l[H],S=c[H]=B?(w=(k.x+O.x)/2,y=f[0].y):(w=f[0].x,y=(k.y+O.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:l.x+p.x,y:l.y+p.y},n],w,y,b,M]}function _f(e,t,n,r){const s=Math.min(Ns(e,t)/2,Ns(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let $="";return E>0&&E{const[p,E,$]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:w,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const Pr=x.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:x.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Pr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=co({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const zr=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[w,y,v]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(sn,{path:w,labelX:y,labelY:v,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});zr.displayName="StraightEdge";function mn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Ss({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case q.Left:return[t-mn(t-r,i),n];case q.Right:return[t+mn(r-t,i),n];case q.Top:return[t,n-mn(n-s,i)];case q.Bottom:return[t,n+mn(s-n,i)]}}function fo({sourceX:e,sourceY:t,sourcePosition:n=q.Bottom,targetX:r,targetY:s,targetPosition:i=q.Top,curvature:o=.25}){const[a,c]=Ss({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Ss({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,w]=lo({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,w]}const In=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=q.Bottom,targetPosition:i=q.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,pathOptions:y,interactionWidth:v})=>{const[p,E,$]=fo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:v})});In.displayName="BezierEdge";const Hr=x.createContext(null),Nf=Hr.Provider;Hr.Consumer;const Sf=()=>x.useContext(Hr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,vr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},_r=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},ho=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},on=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return so(r,Jt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return io(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),on(e,t)),mo=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:w=!1}=u;if(o&&!f||w)return!1;const{positionAbsolute:y}=xt(u,a),v={x:y.x,y:y.y,width:d||0,height:m||0},p=wr(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,$=i&&p>0,b=(d||0)*(m||0);(E||$||p>=b||u.dragging)&&l.push(u)}),l},po=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},go=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Tt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function ks(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=ut(e),l=t.elementsFromPoint(o,a).find(w=>w.classList.contains("react-flow__handle"));if(l){const w=l.getAttribute("data-nodeid");if(w){const y=Fr(void 0,l),v=l.getAttribute("data-handleid"),p=i({nodeId:w,id:v,type:y});if(p){const E=s.find($=>$.nodeId===w&&$.type===y&&$.id===v);return{handle:{id:v,type:y,nodeId:w,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:p}}}}let u=[],d=1/0;if(s.forEach(w=>{const y=Math.sqrt((w.x-n.x)**2+(w.y-n.y)**2);if(y<=r){const v=i(w);y<=d&&(yw.isValid),f=u.some(({handle:w})=>w.type==="target");return u.find(({handle:w,validHandleResult:y})=>f?w.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},yo=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function xo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...yo(),handleDomNode:c};if(c){const u=Fr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),w=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&w&&(t===vt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=ks(i,o,"source",`${t}-${n}-${r}`),c=ks(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Fr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function wo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ro(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:w,onConnectStart:y,panBy:v,getNodes:p,cancelConnection:E}=i();let $=0,b;const{x:M,y:N}=ut(e),_=u==null?void 0:u.elementFromPoint(M,N),R=Fr(c,_),k=m==null?void 0:m.getBoundingClientRect();if(!k||!R)return;let O,D=ut(e,k),B=!1,H=null,g=!1,C=null;const S=If({nodes:p(),nodeId:n,handleId:t,handleType:R}),I=()=>{if(!f)return;const[T,P]=no(D,k);v({x:T,y:P}),$=requestAnimationFrame(I)};o({connectionPosition:D,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:R});function L(T){const{transform:P}=i();D=ut(T,k);const{handle:z,validHandleResult:X}=Af(T,u,_r(D,P,!1,[1,1]),w,S,F=>xo(F,d,n,t,s?"target":"source",a,u));if(b=z,B||(I(),B=!0),C=X.handleDomNode,H=X.connection,g=X.isValid,o({connectionPosition:b&&g?ho({x:b.x,y:b.y},P):D,connectionStatus:Tf(!!b,g),connectionEndHandle:X.endHandle}),!b&&!g&&!C)return Qn(O);H.source!==H.target&&C&&(Qn(O),O=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",g),C.classList.toggle("react-flow__handle-valid",g))}function j(T){var P,z;(b||C)&&H&&g&&(r==null||r(H)),(z=(P=i()).onConnectEnd)==null||z.call(P,T),c&&(l==null||l(T)),Qn(O),E(),cancelAnimationFrame($),B=!1,g=!1,H=null,C=null,u.removeEventListener("mousemove",L),u.removeEventListener("mouseup",j),u.removeEventListener("touchmove",L),u.removeEventListener("touchend",j)}u.addEventListener("mousemove",L),u.addEventListener("mouseup",j),u.addEventListener("touchmove",L),u.addEventListener("touchend",j)}const js=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},bo=x.forwardRef(({type:e="source",position:t=q.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var k,O;const w=o||null,y=e==="target",v=Ne(),p=Sf(),{connectOnClick:E,noPanClassName:$}=de(Of,ke),{connecting:b,clickConnecting:M}=de(Lf(p,w,e),ke);p||(O=(k=v.getState()).onError)==null||O.call(k,"010",nt.error010());const N=D=>{const{defaultEdgeOptions:B,onConnect:H,hasDefaultEdges:g}=v.getState(),C={...B,...D};if(g){const{edges:S,setEdges:I}=v.getState();I($f(C,S))}H==null||H(C),a==null||a(C)},_=D=>{if(!p)return;const B=ao(D);s&&(B&&D.button===0||!B)&&wo({event:D,handleId:w,nodeId:p,onConnect:N,isTarget:y,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||js}),B?u==null||u(D):d==null||d(D)},R=D=>{const{onClickConnectStart:B,onClickConnectEnd:H,connectionClickStartHandle:g,connectionMode:C,isValidConnection:S}=v.getState();if(!p||!g&&!s)return;if(!g){B==null||B(D,{nodeId:p,handleId:w,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:p,type:e,handleId:w}});return}const I=ro(D.target),L=n||S||js,{connection:j,isValid:T}=xo({nodeId:p,id:w,type:e},C,g.nodeId,g.handleId||null,g.type,L,I);T&&N(j),H==null||H(D),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":w,"data-nodeid":p,"data-handlepos":t,"data-id":`${p}-${w}-${e}`,className:je(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",$,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!b||i&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});bo.displayName="Handle";var lt=x.memo(bo);const vo=({data:e,isConnectable:t,targetPosition:n=q.Top,sourcePosition:r=q.Bottom})=>A.createElement(A.Fragment,null,A.createElement(lt,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(lt,{type:"source",position:r,isConnectable:t}));vo.displayName="DefaultNode";var Er=x.memo(vo);const _o=({data:e,isConnectable:t,sourcePosition:n=q.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(lt,{type:"source",position:n,isConnectable:t}));_o.displayName="InputNode";var Eo=x.memo(_o);const No=({data:e,isConnectable:t,targetPosition:n=q.Top})=>A.createElement(A.Fragment,null,A.createElement(lt,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);No.displayName="OutputNode";var So=x.memo(No);const Vr=()=>null;Vr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),pn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(pn),t.selectedNodes.map(pn))&&ke(e.selectedEdges.map(pn),t.selectedEdges.map(pn))}const ko=x.memo(({onSelectionChange:e})=>{const t=Ne(),{selectedNodes:n,selectedEdges:r}=de(Df,Pf);return x.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});ko.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=de(zf);return e||t?A.createElement(ko,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Et(e,t){x.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ie(e,t,n){x.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:w,minZoom:y,maxZoom:v,nodeExtent:p,onNodesChange:E,onEdgesChange:$,elementsSelectable:b,connectionMode:M,snapGrid:N,snapToGrid:_,translateExtent:R,connectOnClick:k,defaultEdgeOptions:O,fitView:D,fitViewOptions:B,onNodesDelete:H,onEdgesDelete:g,onNodeDrag:C,onNodeDragStart:S,onNodeDragStop:I,onSelectionDrag:L,onSelectionDragStart:j,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:X,autoPanOnConnect:F,autoPanOnNodeDrag:Z,onError:J,connectionRadius:te,isValidConnection:oe,nodeDragThreshold:ne})=>{const{setNodes:re,setEdges:pe,setDefaultNodesAndEdges:ce,setMinZoom:ue,setMaxZoom:ye,setTranslateExtent:he,setNodeExtent:xe,reset:le}=de(Ff,ke),K=Ne();return x.useEffect(()=>{const Se=r==null?void 0:r.map(Ce=>({...Ce,...O}));return ce(n,Se),()=>{le()}},[]),ie("defaultEdgeOptions",O,K.setState),ie("connectionMode",M,K.setState),ie("onConnect",s,K.setState),ie("onConnectStart",i,K.setState),ie("onConnectEnd",o,K.setState),ie("onClickConnectStart",a,K.setState),ie("onClickConnectEnd",c,K.setState),ie("nodesDraggable",l,K.setState),ie("nodesConnectable",u,K.setState),ie("nodesFocusable",d,K.setState),ie("edgesFocusable",m,K.setState),ie("edgesUpdatable",f,K.setState),ie("elementsSelectable",b,K.setState),ie("elevateNodesOnSelect",w,K.setState),ie("snapToGrid",_,K.setState),ie("snapGrid",N,K.setState),ie("onNodesChange",E,K.setState),ie("onEdgesChange",$,K.setState),ie("connectOnClick",k,K.setState),ie("fitViewOnInit",D,K.setState),ie("fitViewOnInitOptions",B,K.setState),ie("onNodesDelete",H,K.setState),ie("onEdgesDelete",g,K.setState),ie("onNodeDrag",C,K.setState),ie("onNodeDragStart",S,K.setState),ie("onNodeDragStop",I,K.setState),ie("onSelectionDrag",L,K.setState),ie("onSelectionDragStart",j,K.setState),ie("onSelectionDragStop",T,K.setState),ie("noPanClassName",P,K.setState),ie("nodeOrigin",z,K.setState),ie("rfId",X,K.setState),ie("autoPanOnConnect",F,K.setState),ie("autoPanOnNodeDrag",Z,K.setState),ie("onError",J,K.setState),ie("connectionRadius",te,K.setState),ie("isValidConnection",oe,K.setState),ie("nodeDragThreshold",ne,K.setState),Et(e,re),Et(t,pe),Et(y,ue),Et(v,ye),Et(R,he),Et(p,xe),null},Cs={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},jo="react-flow__node-desc",Co="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Xf({rfId:e}){const t=de(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Wf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${jo}-${e}`,style:Cs},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Co}-${e}`,style:Cs},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Xf,{rfId:e}))}var tn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=x.useState(!1),s=x.useRef(!1),i=x.useRef(new Set([])),[o,a]=x.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return x.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);i.current.add(f[y]),$s(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);$s(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Ms(e,t){return t.includes(e)?"code":"key"}function $o(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return $o(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function Mo(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=$o(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Oe(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Mo(s,n,i),s}function Ao(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const w=n().filter(v=>{var E;const p=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?p&&t.nodes.some($=>$.id===v.id):p}),y=w.every(v=>v.width&&v.height);if(w.length>0&&y){const v=on(w,d),{x:p,y:E,zoom:$}=go(v,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),b=et.translate(p,E).scale($);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Uf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function gn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Uf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const Nt=()=>{},Kf={zoomIn:Nt,zoomOut:Nt,zoomTo:Nt,getZoom:()=>1,setViewport:Nt,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:Nt,fitBounds:Nt,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Ne(),{d3Zoom:t,d3Selection:n}=de(Zf,ke);return x.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=et.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Ao(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=et.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=go(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=et.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),_r(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return _r(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=ho(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function an(){const e=Qf(),t=Ne(),n=x.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=x.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=x.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(v=>({...v}))},[]),i=x.useCallback(y=>{const{edges:v=[]}=t.getState();return v.find(p=>p.id===y)},[]),o=x.useCallback(y=>{const{getNodes:v,setNodes:p,hasDefaultNodes:E,onNodesChange:$}=t.getState(),b=v(),M=typeof y=="function"?y(b):y;if(E)p(M);else if($){const N=M.length===0?b.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));$(N)}},[]),a=x.useCallback(y=>{const{edges:v=[],setEdges:p,hasDefaultEdges:E,onEdgesChange:$}=t.getState(),b=typeof y=="function"?y(v):y;if(E)p(b);else if($){const M=b.length===0?v.map(N=>({type:"remove",id:N.id})):b.map(N=>({item:N,type:"reset"}));$(M)}},[]),c=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{getNodes:p,setNodes:E,hasDefaultNodes:$,onNodesChange:b}=t.getState();if($){const N=[...p(),...v];E(N)}else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),l=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{edges:p=[],setEdges:E,hasDefaultEdges:$,onEdgesChange:b}=t.getState();if($)E([...p,...v]);else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),u=x.useCallback(()=>{const{getNodes:y,edges:v=[],transform:p}=t.getState(),[E,$,b]=p;return{nodes:y().map(M=>({...M})),edges:v.map(M=>({...M})),viewport:{x:E,y:$,zoom:b}}},[]),d=x.useCallback(({nodes:y,edges:v})=>{const{nodeInternals:p,getNodes:E,edges:$,hasDefaultNodes:b,hasDefaultEdges:M,onNodesDelete:N,onEdgesDelete:_,onNodesChange:R,onEdgesChange:k}=t.getState(),O=(y||[]).map(C=>C.id),D=(v||[]).map(C=>C.id),B=E().reduce((C,S)=>{const I=S.parentNode||S.parentId,L=!O.includes(S.id)&&I&&C.find(T=>T.id===I);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(O.includes(S.id)||L)&&C.push(S),C},[]),H=$.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),g=H.filter(C=>D.includes(C.id));if(B||g){const C=po(B,H),S=[...g,...C],I=S.reduce((L,j)=>(L.includes(j.id)||L.push(j.id),L),[]);if((M||b)&&(M&&t.setState({edges:$.filter(L=>!I.includes(L.id))}),b&&(B.forEach(L=>{p.delete(L.id)}),t.setState({nodeInternals:new Map(p)}))),I.length>0&&(_==null||_(S),k&&k(I.map(L=>({id:L,type:"remove"})))),B.length>0&&(N==null||N(B),R)){const L=B.map(j=>({id:j.id,type:"remove"}));R(L)}}},[]),m=x.useCallback(y=>{const v=yf(y),p=v?null:t.getState().nodeInternals.get(y.id);return!v&&!p?[null,null,v]:[v?y:vs(p),p,v]},[]),f=x.useCallback((y,v=!0,p)=>{const[E,$,b]=m(y);return E?(p||t.getState().getNodes()).filter(M=>{if(!b&&(M.id===$.id||!M.positionAbsolute))return!1;const N=vs(M),_=wr(N,E);return v&&_>0||_>=E.width*E.height}):[]},[]),w=x.useCallback((y,v,p=!0)=>{const[E]=m(y);if(!E)return!1;const $=wr(E,v);return p&&$>0||$>=E.width*E.height},[]);return x.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:w}),[e,n,r,s,i,o,a,c,l,u,d,f,w])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ne(),{deleteElements:r}=an(),s=tn(e,Jf),i=tn(t);x.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),x.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Ne();x.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Or(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",nt.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Br={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,yn=e=>({x:e.x,y:e.y,zoom:e.k}),St=(e,t)=>e.target.closest(`.${t}`),As=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rs=e=>{const t=e.ctrlKey&&Mn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:w,maxZoom:y,zoomActivationKeyCode:v,preventScrolling:p=!0,children:E,noWheelClassName:$,noPanClassName:b})=>{const M=x.useRef(),N=Ne(),_=x.useRef(!1),R=x.useRef(!1),k=x.useRef(null),O=x.useRef({x:0,y:0,zoom:0}),{d3Zoom:D,d3Selection:B,d3ZoomHandler:H,userSelectionActive:g}=de(rh,ke),C=tn(v),S=x.useRef(0),I=x.useRef(!1),L=x.useRef();return th(k),x.useEffect(()=>{if(k.current){const j=k.current.getBoundingClientRect(),T=eo().scaleExtent([w,y]).translateExtent(f),P=Te(k.current).call(T),z=et.translate(m.x,m.y).scale(Tt(m.zoom,w,y)),X=[[0,0],[j.width,j.height]],F=T.constrain()(z,X,f);T.transform(P,F),T.wheelDelta(Rs),N.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[F.x,F.y,F.k],domNode:k.current.closest(".react-flow")})}},[]),x.useEffect(()=>{B&&D&&(o&&!C&&!g?B.on("wheel.zoom",j=>{if(St(j,$))return!1;j.preventDefault(),j.stopImmediatePropagation();const T=B.property("__zoom").k||1;if(j.ctrlKey&&i){const oe=ze(j),ne=Rs(j),re=T*Math.pow(2,ne);D.scaleTo(B,re,oe,j);return}const P=j.deltaMode===1?20:1;let z=c===gt.Vertical?0:j.deltaX*P,X=c===gt.Horizontal?0:j.deltaY*P;!Mn()&&j.shiftKey&&c!==gt.Vertical&&(z=j.deltaY*P,X=0),D.translateBy(B,-(z/T)*a,-(X/T)*a,{internal:!0});const F=yn(B.property("__zoom")),{onViewportChangeStart:Z,onViewportChange:J,onViewportChangeEnd:te}=N.getState();clearTimeout(L.current),I.current||(I.current=!0,t==null||t(j,F),Z==null||Z(F)),I.current&&(e==null||e(j,F),J==null||J(F),L.current=setTimeout(()=>{n==null||n(j,F),te==null||te(F),I.current=!1},150))},{passive:!1}):typeof H<"u"&&B.on("wheel.zoom",function(j,T){if(!p&&j.type==="wheel"&&!j.ctrlKey||St(j,$))return null;j.preventDefault(),H.call(this,j,T)},{passive:!1}))},[g,o,c,B,D,H,C,i,p,$,t,e,n]),x.useEffect(()=>{D&&D.on("start",j=>{var z,X;if(!j.sourceEvent||j.sourceEvent.internal)return null;S.current=(z=j.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=N.getState(),P=yn(j.transform);_.current=!0,O.current=P,((X=j.sourceEvent)==null?void 0:X.type)==="mousedown"&&N.setState({paneDragging:!0}),T==null||T(P),t==null||t(j.sourceEvent,P)})},[D,t]),x.useEffect(()=>{D&&(g&&!_.current?D.on("zoom",null):g||D.on("zoom",j=>{var P;const{onViewportChange:T}=N.getState();if(N.setState({transform:[j.transform.x,j.transform.y,j.transform.k]}),R.current=!!(r&&As(d,S.current??0)),(e||T)&&!((P=j.sourceEvent)!=null&&P.internal)){const z=yn(j.transform);T==null||T(z),e==null||e(j.sourceEvent,z)}}))},[g,D,e,d,r]),x.useEffect(()=>{D&&D.on("end",j=>{if(!j.sourceEvent||j.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=N.getState();if(_.current=!1,N.setState({paneDragging:!1}),r&&As(d,S.current??0)&&!R.current&&r(j.sourceEvent),R.current=!1,(n||T)&&nh(O.current,j.transform)){const P=yn(j.transform);O.current=P,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(P),n==null||n(j.sourceEvent,P)},o?150:0)}})},[D,o,d,n,r]),x.useEffect(()=>{D&&D.filter(j=>{const T=C||s,P=i&&j.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&j.button===1&&j.type==="mousedown"&&(St(j,"react-flow__node")||St(j,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||g||!l&&j.type==="dblclick"||St(j,$)&&j.type==="wheel"||St(j,b)&&(j.type!=="wheel"||o&&j.type==="wheel"&&!C)||!i&&j.ctrlKey&&j.type==="wheel"||!T&&!o&&!P&&j.type==="wheel"||!d&&(j.type==="mousedown"||j.type==="touchstart")||Array.isArray(d)&&!d.includes(j.button)&&j.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(j.button)||!j.button||j.button<=1;return(!j.ctrlKey||j.type==="wheel")&&z})},[g,D,s,i,o,l,d,u,C]),A.createElement("div",{className:"react-flow__renderer",ref:k,style:Br},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=de(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Is(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&Is(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&Is(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const at=(e,t)=>({id:e,type:"select",selected:t});function jt(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(at(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(at(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ro=x.memo(({isSelecting:e,selectionMode:t=en.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=x.useRef(null),f=Ne(),w=x.useRef(0),y=x.useRef(0),v=x.useRef(),{userSelectionActive:p,elementsSelectable:E,dragging:$}=de(lh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),w.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},N=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,R=H=>{const{resetSelectedElements:g,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!v.current)return;const{x:S,y:I}=ut(H,v.current);g(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:I,x:S,y:I}}),r==null||r(H)},k=H=>{const{userSelectionRect:g,nodeInternals:C,edges:S,transform:I,onNodesChange:L,onEdgesChange:j,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!g)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=ut(H,v.current),X=g.startX??0,F=g.startY??0,Z={...g,x:z.xre.id),ne=te.map(re=>re.id);if(w.current!==ne.length){w.current=ne.length;const re=jt(J,ne);re.length&&(L==null||L(re))}if(y.current!==oe.length){y.current=oe.length;const re=jt(S,oe);re.length&&(j==null||j(re))}f.setState({userSelectionRect:Z})},O=H=>{if(H.button!==0)return;const{userSelectionRect:g}=f.getState();!p&&g&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:w.current>0}),b(),s==null||s(H)},D=H=>{p&&(f.setState({nodesSelectionActive:w.current>0}),s==null||s(H)),b()},B=E&&(e||p);return A.createElement("div",{className:je(["react-flow__pane",{dragging:$,selection:e}]),onClick:B?void 0:er(M,m),onContextMenu:er(N,m),onWheel:er(_,m),onMouseEnter:B?void 0:c,onMouseDown:B?R:void 0,onMouseMove:B?k:l,onMouseUp:B?O:void 0,onMouseLeave:B?D:u,ref:m,style:Br},d,A.createElement(oh,null))});Ro.displayName="Pane";function Io(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Io(r,t):!1}function Ts(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Io(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function To(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Oe(m)&&Oe(f)&&Oe(d.width)&&Oe(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",nt.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Lr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Os=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Or(c)}})};function Vt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Nr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",nt.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Ne();return x.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Oo({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Ne(),[c,l]=x.useState(!1),u=x.useRef([]),d=x.useRef({x:null,y:null}),m=x.useRef(0),f=x.useRef(null),w=x.useRef({x:0,y:0}),y=x.useRef(null),v=x.useRef(!1),p=x.useRef(!1),E=x.useRef(!1),$=fh();return x.useEffect(()=>{if(e!=null&&e.current){const b=Te(e.current),M=({x:R,y:k})=>{const{nodeInternals:O,onNodeDrag:D,onSelectionDrag:B,updateNodePositions:H,nodeExtent:g,snapGrid:C,snapToGrid:S,nodeOrigin:I,onError:L}=a.getState();d.current={x:R,y:k};let j=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&g){const z=on(u.current,I);T=Jt(z)}if(u.current=u.current.map(z=>{const X={x:R-z.distance.x,y:k-z.distance.y};S&&(X.x=C[0]*Math.round(X.x/C[0]),X.y=C[1]*Math.round(X.y/C[1]));const F=[[g[0][0],g[0][1]],[g[1][0],g[1][1]]];u.current.length>1&&g&&!z.extent&&(F[0][0]=z.positionAbsolute.x-T.x+g[0][0],F[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+g[1][0],F[0][1]=z.positionAbsolute.y-T.y+g[0][1],F[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+g[1][1]);const Z=To(z,X,O,F,I,L);return j=j||z.position.x!==Z.position.x||z.position.y!==Z.position.y,z.position=Z.position,z.positionAbsolute=Z.positionAbsolute,z}),!j)return;H(u.current,!0,!0),l(!0);const P=s?D:nr(B);if(P&&y.current){const[z,X]=tr({nodeId:s,dragItems:u.current,nodeInternals:O});P(y.current,z,X)}},N=()=>{if(!f.current)return;const[R,k]=no(w.current,f.current);if(R!==0||k!==0){const{transform:O,panBy:D}=a.getState();d.current.x=(d.current.x??0)-R/O[2],d.current.y=(d.current.y??0)-k/O[2],D({x:R,y:k})&&M(d.current)}m.current=requestAnimationFrame(N)},_=R=>{var I;const{nodeInternals:k,multiSelectionActive:O,nodesDraggable:D,unselectNodesAndEdges:B,onNodeDragStart:H,onSelectionDragStart:g}=a.getState();p.current=!0;const C=s?H:nr(g);(!o||!i)&&!O&&s&&((I=k.get(s))!=null&&I.selected||B()),s&&i&&o&&Nr({id:s,store:a,nodeRef:e});const S=$(R);if(d.current=S,u.current=uh(k,D,S,s),C&&u.current){const[L,j]=tr({nodeId:s,dragItems:u.current,nodeInternals:k});C(R.sourceEvent,L,j)}};if(t)b.on(".drag",null);else{const R=bu().on("start",k=>{const{domNode:O,nodeDragThreshold:D}=a.getState();D===0&&_(k),E.current=!1;const B=$(k);d.current=B,f.current=(O==null?void 0:O.getBoundingClientRect())||null,w.current=ut(k.sourceEvent,f.current)}).on("drag",k=>{var H,g;const O=$(k),{autoPanOnNodeDrag:D,nodeDragThreshold:B}=a.getState();if(k.sourceEvent.type==="touchmove"&&k.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&p.current&&D&&(v.current=!0,N()),!p.current){const C=O.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=O.ySnapped-(((g=d==null?void 0:d.current)==null?void 0:g.y)??0);Math.sqrt(C*C+S*S)>B&&_(k)}(d.current.x!==O.xSnapped||d.current.y!==O.ySnapped)&&u.current&&p.current&&(y.current=k.sourceEvent,w.current=ut(k.sourceEvent,f.current),M(O))}}).on("end",k=>{if(!(!p.current||E.current)&&(l(!1),v.current=!1,p.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:O,nodeInternals:D,onNodeDragStop:B,onSelectionDragStop:H}=a.getState(),g=s?B:nr(H);if(O(u.current,!1,!1),g){const[C,S]=tr({nodeId:s,dragItems:u.current,nodeInternals:D});g(k.sourceEvent,C,S)}}}).filter(k=>{const O=k.target;return!k.button&&(!n||!Ts(O,`.${n}`,e))&&(!r||Ts(O,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,$]),c}function Lo(){const e=Ne();return x.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,w=n.isShiftPressed?4:1,y=n.x*m*w,v=n.y*f*w,p=d.map(E=>{if(E.positionAbsolute){const $={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+v};a&&($.x=c[0]*Math.round($.x/c[0]),$.y=c[1]*Math.round($.y/c[1]));const{positionAbsolute:b,position:M}=To(E,$,r,s,void 0,l);E.position=M,E.positionAbsolute=b}return E});i(p,!0,!1)},[])}const Mt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Bt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:w,onDoubleClick:y,style:v,className:p,isDraggable:E,isSelectable:$,isConnectable:b,isFocusable:M,selectNodesOnDrag:N,sourcePosition:_,targetPosition:R,hidden:k,resizeObserver:O,dragHandle:D,zIndex:B,isParent:H,noDragClassName:g,noPanClassName:C,initialized:S,disableKeyboardA11y:I,ariaLabel:L,rfId:j,hasHandleBounds:T})=>{const P=Ne(),z=x.useRef(null),X=x.useRef(null),F=x.useRef(_),Z=x.useRef(R),J=x.useRef(r),te=$||E||u||d||m||f,oe=Lo(),ne=Vt(n,P.getState,d),re=Vt(n,P.getState,m),pe=Vt(n,P.getState,f),ce=Vt(n,P.getState,w),ue=Vt(n,P.getState,y),ye=le=>{const{nodeDragThreshold:K}=P.getState();if($&&(!N||!E||K>0)&&Nr({id:n,store:P,nodeRef:z}),u){const Se=P.getState().nodeInternals.get(n);Se&&u(le,{...Se})}},he=le=>{if(!br(le)&&!I)if(oo.includes(le.key)&&$){const K=le.key==="Escape";Nr({id:n,store:P,unselect:K,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Mt,le.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),oe({x:Mt[le.key].x,y:Mt[le.key].y,isShiftPressed:le.shiftKey}))};x.useEffect(()=>()=>{X.current&&(O==null||O.unobserve(X.current),X.current=null)},[]),x.useEffect(()=>{if(z.current&&!k){const le=z.current;(!S||!T||X.current!==le)&&(X.current&&(O==null||O.unobserve(X.current)),O==null||O.observe(le),X.current=le)}},[k,S,T]),x.useEffect(()=>{const le=J.current!==r,K=F.current!==_,Se=Z.current!==R;z.current&&(le||K||Se)&&(le&&(J.current=r),K&&(F.current=_),Se&&(Z.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const xe=Oo({nodeRef:z,disabled:k||!E,noDragClassName:g,handleSelector:D,nodeId:n,isSelectable:$,selectNodesOnDrag:N});return k?null:A.createElement("div",{className:je(["react-flow__node",`react-flow__node-${r}`,{[C]:E},p,{selected:l,selectable:$,parent:H,dragging:xe}]),ref:z,style:{zIndex:B,transform:`translate(${a}px,${c}px)`,pointerEvents:te?"all":"none",visibility:S?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:re,onMouseLeave:pe,onContextMenu:ce,onClick:ye,onDoubleClick:ue,onKeyDown:M?he:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":I?void 0:`${jo}-${j}`,"aria-label":L},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:xe,dragHandle:D,zIndex:B})))};return t.displayName="NodeWrapper",x.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...on(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ne(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=de(hh,ke),u=Lo(),d=x.useRef(null);if(x.useEffect(()=>{var w;n||(w=d.current)==null||w.focus({preventScroll:!0})},[n]),Oo({nodeRef:d}),l||!s||!i)return null;const m=e?w=>{const y=r.getState().getNodes().filter(v=>v.selected);e(w,y)}:void 0,f=w=>{Object.prototype.hasOwnProperty.call(Mt,w.key)&&u({x:Mt[w.key].x,y:Mt[w.key].y,isShiftPressed:w.shiftKey})};return A.createElement("div",{className:je(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=x.memo(mh);const gh=e=>e.nodesSelectionActive,Do=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:w,onSelectionEnd:y,multiSelectionKeyCode:v,panActivationKeyCode:p,zoomActivationKeyCode:E,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:N,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:O,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,preventScrolling:C,onSelectionContextMenu:S,noWheelClassName:I,noPanClassName:L,disableKeyboardA11y:j})=>{const T=de(gh),P=tn(d),z=tn(p),X=z||O,F=z||N,Z=P||m&&X!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:F,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:!P&&X,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:I,noPanClassName:L},A.createElement(Ro,{onSelectionStart:w,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:X,isSelecting:!!Z,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:L,disableKeyboardA11y:j})))};Do.displayName="FlowRenderer";var yh=x.memo(Do);function xh(e){return de(x.useCallback(n=>e?mo(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Bt(e.input||Eo),default:Bt(e.default||Er),output:Bt(e.output||So),group:Bt(e.group||Vr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Bt(e[i]||Er),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Po=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=de(vh,ke),a=xh(e.onlyRenderVisibleElements),c=x.useRef(),l=x.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return x.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Br},a.map(u=>{var M,N,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",nt.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),w=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),v=!!(u.focusable||r&&typeof u.focusable>"u"),p=e.nodeExtent?Lr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(p==null?void 0:p.x)??0,$=(p==null?void 0:p.y)??0,b=bh({x:E,y:$,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||q.Bottom,targetPosition:u.targetPosition||q.Top,hidden:u.hidden,xPos:E,yPos:$,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:w,isConnectable:y,isFocusable:v,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((N=u[we])!=null&&N.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Po.displayName="NodeRenderer";var _h=x.memo(Po);const Eh=(e,t,n)=>n===q.Left?e-t:n===q.Right?e+t:e,Nh=(e,t,n)=>n===q.Top?e-t:n===q.Bottom?e+t:e,Ls="react-flow__edgeupdater",Ds=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:je([Ls,`${Ls}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var kt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,style:v,source:p,target:E,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,elementsSelectable:k,hidden:O,sourceHandleId:D,targetHandleId:B,onContextMenu:H,onMouseEnter:g,onMouseMove:C,onMouseLeave:S,reconnectRadius:I,onReconnect:L,onReconnectStart:j,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:X,ariaLabel:F,isFocusable:Z,isReconnectable:J,pathOptions:te,interactionWidth:oe,disableKeyboardA11y:ne})=>{const re=x.useRef(null),[pe,ce]=x.useState(!1),[ue,ye]=x.useState(!1),he=Ne(),xe=x.useMemo(()=>`url('#${vr(z,X)}')`,[z,X]),le=x.useMemo(()=>`url('#${vr(P,X)}')`,[P,X]);if(O)return null;const K=se=>{var ve;const{edges:me,addSelectedEdges:$e,unselectNodesAndEdges:W,multiSelectionActive:fe}=he.getState(),ge=me.find(Be=>Be.id===n);ge&&(k&&(he.setState({nodesSelectionActive:!1}),ge.selected&&fe?(W({nodes:[],edges:[ge]}),(ve=re.current)==null||ve.blur()):$e([n])),o&&o(se,ge))},Se=Ft(n,he.getState,a),Ce=Ft(n,he.getState,H),dt=Ft(n,he.getState,g),Ae=Ft(n,he.getState,C),Ue=Ft(n,he.getState,S),Ie=(se,me)=>{if(se.button!==0)return;const{edges:$e,isValidConnection:W}=he.getState(),fe=me?E:p,ge=(me?B:D)||null,ve=me?"target":"source",Be=W||Sh,Ot=me,st=$e.find(Pe=>Pe.id===n);ye(!0),j==null||j(se,st,ve);const ft=Pe=>{ye(!1),T==null||T(Pe,st,ve)};wo({event:se,handleId:ge,nodeId:fe,onConnect:Pe=>L==null?void 0:L(st,Pe),isTarget:Ot,getState:he.getState,setState:he.setState,isValidConnection:Be,edgeUpdaterType:ve,onReconnectEnd:ft})},V=se=>Ie(se,!0),Y=se=>Ie(se,!1),G=()=>ce(!0),Q=()=>ce(!1),U=!k&&!o,ee=se=>{var me;if(!ne&&oo.includes(se.key)&&k){const{unselectNodesAndEdges:$e,addSelectedEdges:W,edges:fe}=he.getState();se.key==="Escape"?((me=re.current)==null||me.blur(),$e({edges:[fe.find(ve=>ve.id===n)]})):W([n])}};return A.createElement("g",{className:je(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:pe}]),onClick:K,onDoubleClick:Se,onContextMenu:Ce,onMouseEnter:dt,onMouseMove:Ae,onMouseLeave:Ue,onKeyDown:Z?ee:void 0,tabIndex:Z?0:void 0,role:Z?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":F===null?void 0:F||`Edge from ${p} to ${E}`,"aria-describedby":Z?`${Co}-${X}`:void 0,ref:re},!ue&&A.createElement(e,{id:n,source:p,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,data:i,style:v,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,sourceHandleId:D,targetHandleId:B,markerStart:xe,markerEnd:le,pathOptions:te,interactionWidth:oe}),J&&A.createElement(A.Fragment,null,(J==="source"||J===!0)&&A.createElement(Ds,{position:_,centerX:$,centerY:b,radius:I,onMouseDown:V,onMouseEnter:G,onMouseOut:Q,type:"source"}),(J==="target"||J===!0)&&A.createElement(Ds,{position:R,centerX:M,centerY:N,radius:I,onMouseDown:Y,onMouseEnter:G,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",x.memo(t)};function kh(e){const t={default:kt(e.default||In),straight:kt(e.bezier||zr),step:kt(e.step||Pr),smoothstep:kt(e.step||Bn),simplebezier:kt(e.simplebezier||Dr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=kt(e[i]||In),s),n);return{...t,...r}}function Ps(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case q.Top:return{x:r+i/2,y:s};case q.Right:return{x:r+i,y:s+o/2};case q.Bottom:return{x:r+i/2,y:s+o};case q.Left:return{x:r,y:s+o/2}}}function zs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ps(n,e,t),a=Ps(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Jt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Hs(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Oe(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),w=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(w?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=de(x.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Fs={[An.Arrow]:Rh,[An.ArrowClosed]:Ih};function Th(e){const t=Ne();return x.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(Fs,e)?Fs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",nt.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=vr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},zo=({defaultColor:e,rfId:t})=>{const n=de(x.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};zo.displayName="MarkerDefinitions";var Dh=x.memo(zo);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ho=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,children:v,disableKeyboardA11y:p})=>{const{edgesFocusable:E,edgesUpdatable:$,elementsSelectable:b,width:M,height:N,connectionMode:_,nodeInternals:R,onError:k}=de(Ph,ke),O=Ah(t,R,n);return M?A.createElement(A.Fragment,null,O.map(({level:D,edges:B,isMaxLevel:H})=>A.createElement("svg",{key:D,style:{zIndex:D},width:M,height:N,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,B.map(g=>{const[C,S,I]=Hs(R.get(g.source)),[L,j,T]=Hs(R.get(g.target));if(!I||!T)return null;let P=g.type||"default";s[P]||(k==null||k("011",nt.error011(P)),P="default");const z=s[P]||s.default,X=_===vt.Strict?j.target:(j.target??[]).concat(j.source??[]),F=zs(S.source,g.sourceHandle),Z=zs(X,g.targetHandle),J=(F==null?void 0:F.position)||q.Bottom,te=(Z==null?void 0:Z.position)||q.Top,oe=!!(g.focusable||E&&typeof g.focusable>"u"),ne=g.reconnectable||g.updatable,re=typeof m<"u"&&(ne||$&&typeof ne>"u");if(!F||!Z)return k==null||k("008",nt.error008(F,g)),null;const{sourceX:pe,sourceY:ce,targetX:ue,targetY:ye}=jh(C,F,J,L,Z,te);return A.createElement(z,{key:g.id,id:g.id,className:je([g.className,i]),type:P,data:g.data,selected:!!g.selected,animated:!!g.animated,hidden:!!g.hidden,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,style:g.style,source:g.source,target:g.target,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerEnd:g.markerEnd,markerStart:g.markerStart,sourceX:pe,sourceY:ce,targetX:ue,targetY:ye,sourcePosition:J,targetPosition:te,elementsSelectable:b,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,rfId:r,ariaLabel:g.ariaLabel,isFocusable:oe,isReconnectable:re,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth,disableKeyboardA11y:p})})))),v):null};Ho.displayName="EdgeRenderer";var zh=x.memo(Ho);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=de(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=an(),n=x.useRef(!1);x.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[q.Left]:q.Right,[q.Right]:q.Left,[q.Top]:q.Bottom,[q.Bottom]:q.Top},Fo=({nodeId:e,handleType:t,style:n,type:r=ct.Bezier,CustomComponent:s,connectionStatus:i})=>{var N,_,R;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=de(x.useCallback(k=>({fromNode:k.nodeInternals.get(e),handleId:k.connectionHandleId,toX:(k.connectionPosition.x-k.transform[0])/k.transform[2],toY:(k.connectionPosition.y-k.transform[1])/k.transform[2],connectionMode:k.connectionMode}),[e]),ke),d=(N=o==null?void 0:o[we])==null?void 0:N.handleBounds;let m=d==null?void 0:d[t];if(u===vt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(k=>k.id===a):m[0],w=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,v=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+w,p=(((R=o.positionAbsolute)==null?void 0:R.y)??0)+y,E=f==null?void 0:f.position,$=E?Bh[E]:null;if(!E||!$)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:v,fromY:p,toX:c,toY:l,fromPosition:E,toPosition:$,connectionStatus:i});let b="";const M={sourceX:v,sourceY:p,sourcePosition:E,targetX:c,targetY:l,targetPosition:$};return r===ct.Bezier?[b]=fo(M):r===ct.Step?[b]=Rn({...M,borderRadius:0}):r===ct.SmoothStep?[b]=Rn(M):r===ct.SimpleBezier?[b]=uo(M):b=`M${v},${p} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Fo.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=de(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:je(["react-flow__connection",l])},A.createElement(Fo,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Vs(e,t){return x.useRef(null),Ne(),x.useMemo(()=>t(e),[e])}const Vo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:w,onSelectionStart:y,onSelectionEnd:v,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:$,connectionLineContainerStyle:b,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,deleteKeyCode:D,onlyRenderVisibleElements:B,elementsSelectable:H,selectNodesOnDrag:g,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,preventScrolling:j,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:X,panOnScrollSpeed:F,panOnScrollMode:Z,zoomOnDoubleClick:J,panOnDrag:te,onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneScroll:ce,onPaneContextMenu:ue,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Se,onReconnectEnd:Ce,reconnectRadius:dt,noDragClassName:Ae,noWheelClassName:Ue,noPanClassName:Ie,elevateEdgesOnSelect:V,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})=>{const ee=Vs(e,wh),se=Vs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:re,onPaneMouseLeave:pe,onPaneContextMenu:ue,onPaneScroll:ce,deleteKeyCode:D,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,onSelectionStart:y,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:J,panOnScroll:X,panOnScrollSpeed:F,panOnScrollMode:Z,panOnDrag:te,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,onSelectionContextMenu:w,preventScrolling:j,noDragClassName:Ae,noWheelClassName:Ue,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:B,onEdgeContextMenu:ye,onEdgeMouseEnter:he,onEdgeMouseMove:xe,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Se,onReconnectEnd:Ce,reconnectRadius:dt,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!V,disableKeyboardA11y:Y,rfId:U},A.createElement(Yh,{style:E,type:p,component:$,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:ee,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:g,onlyRenderVisibleElements:B,noPanClassName:Ie,noDragClassName:Ae,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})))};Vo.displayName="GraphView";var Xh=x.memo(Vo);const Sr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],it={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Sr,nodeExtent:Sr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:vt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Wh=()=>Rc((e,t)=>({...it,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Jn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,v)=>{const p=s.get(v.id);if(p!=null&&p.hidden)s.set(p.id,{...p,[we]:{...p[we],handleBounds:void 0}});else if(p){const E=Or(v.nodeElement);!!(E.width&&E.height&&(p.width!==E.width||p.height!==E.height||v.forceUpdate))&&(s.set(p.id,{...p,[we]:{...p[we],handleBounds:{source:Os(".source",v.nodeElement,m,l),target:Os(".target",v.nodeElement,m,l)}},...E}),y.push({id:p.id,type:"dimensions",dimensions:E}))}return y},[]);Mo(s,l);const w=o||i&&!o&&Ao(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:w}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Jn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>at(c,!0)):(o=jt(i(),n),a=jt(s,[])),gn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>at(c,!0)):(o=jt(s,n),a=jt(i(),[])),gn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,at(u.id,!1))),l=a.map(u=>at(u.id,!1));gn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>at(a.id,!1)),o=n.filter(a=>a.selected).map(a=>at(a.id,!1));gn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Lr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=et.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:it.connectionNodeId,connectionHandleId:it.connectionHandleId,connectionHandleType:it.connectionHandleType,connectionStatus:it.connectionStatus,connectionStartHandle:it.connectionStartHandle,connectionEndHandle:it.connectionEndHandle}),reset:()=>e({...it})}),Object.is),Bo=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Wh()),A.createElement(df,{value:t.current},e)};Bo.displayName="ReactFlowProvider";const Go=({children:e})=>x.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Bo,null,e);Go.displayName="ReactFlowWrapper";const Uh={input:Eo,default:Er,output:So,group:Vr},qh={default:In,straight:zr,step:Pr,smoothstep:Bn,simplebezier:Dr},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Yo=x.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Uh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onNodesDelete:O,onEdgesDelete:D,onSelectionChange:B,onSelectionDragStart:H,onSelectionDrag:g,onSelectionDragStop:C,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,connectionMode:j=vt.Strict,connectionLineType:T=ct.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,deleteKeyCode:F="Backspace",selectionKeyCode:Z="Shift",selectionOnDrag:J=!1,selectionMode:te=en.Full,panActivationKeyCode:oe="Space",multiSelectionKeyCode:ne=Mn()?"Meta":"Control",zoomActivationKeyCode:re=Mn()?"Meta":"Control",snapToGrid:pe=!1,snapGrid:ce=Zh,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:ye=!0,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,nodeOrigin:K=Kh,edgesFocusable:Se,edgesUpdatable:Ce,elementsSelectable:dt,defaultViewport:Ae=Qh,minZoom:Ue=.5,maxZoom:Ie=2,translateExtent:V=Sr,preventScrolling:Y=!0,nodeExtent:G,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:ee=!0,panOnScroll:se=!1,panOnScrollSpeed:me=.5,panOnScrollMode:$e=gt.Free,zoomOnDoubleClick:W=!0,panOnDrag:fe=!0,onPaneClick:ge,onPaneMouseEnter:ve,onPaneMouseMove:Be,onPaneMouseLeave:Ot,onPaneScroll:st,onPaneContextMenu:ft,children:Lt,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:qe,onEdgeMouseLeave:Pt,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:Zr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Xa,defaultEdgeOptions:Wa,elevateNodesOnSelect:Ua=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Qr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Jr,nodeDragThreshold:nc,...rc},sc)=>{const Xn=Jr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:je(["react-flow",s]),"data-testid":"rf__wrapper",id:Jr},A.createElement(Go,null,A.createElement(Xh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,selectionKeyCode:Z,selectionOnDrag:J,selectionMode:te,deleteKeyCode:F,multiSelectionKeyCode:ne,panActivationKeyCode:oe,zoomActivationKeyCode:re,onlyRenderVisibleElements:ue,selectNodesOnDrag:ye,defaultViewport:Ae,translateExtent:V,minZoom:Ue,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:U,zoomOnPinch:ee,zoomOnDoubleClick:W,panOnScroll:se,panOnScrollSpeed:me,panOnScrollMode:$e,panOnDrag:fe,onPaneClick:ge,onPaneMouseEnter:ve,onPaneMouseMove:Be,onPaneMouseLeave:Ot,onPaneScroll:st,onPaneContextMenu:ft,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,onEdgeContextMenu:Pe,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:qe,onEdgeMouseLeave:Pt,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:Zr,elevateEdgesOnSelect:qa,rfId:Xn,disableKeyboardA11y:Qr,nodeOrigin:K,nodeExtent:G}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,nodesDraggable:he,nodesConnectable:xe,nodesFocusable:le,edgesFocusable:Se,edgesUpdatable:Ce,elementsSelectable:dt,elevateNodesOnSelect:Ua,minZoom:Ue,maxZoom:Ie,nodeExtent:G,onNodesChange:Pa,onEdgesChange:za,snapToGrid:pe,snapGrid:ce,connectionMode:j,translateExtent:V,connectOnClick:Ga,defaultEdgeOptions:Wa,fitView:Va,fitViewOptions:Ba,onNodesDelete:O,onEdgesDelete:D,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onSelectionDrag:g,onSelectionDragStart:H,onSelectionDragStop:C,noPanClassName:Zr,nodeOrigin:K,rfId:Xn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:B}),Lt,A.createElement(hf,{proOptions:Xa,position:Ya}),A.createElement(Wf,{rfId:Xn,disableKeyboardA11y:Qr})))});Yo.displayName="ReactFlow";const Xo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:w,backgroundColor:y}=i||{},v=o||w||y;return A.createElement("rect",{className:je(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?p=>m(p,e):void 0})};Xo.displayName="MiniMapNode";var em=x.memo(Xo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=de(nm,ke),c=de(tm),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:w,y}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:w,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=x.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(on(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:w=!1,zoomable:y=!1,ariaLabel:v="React Flow mini map",inversePan:p=!1,zoomStep:E=10,offsetScale:$=5}){const b=Ne(),M=x.useRef(null),{boundingRect:N,viewBB:_,rfId:R}=de(am,ke),k=(e==null?void 0:e.width)??im,O=(e==null?void 0:e.height)??om,D=N.width/k,B=N.height/O,H=Math.max(D,B),g=H*k,C=H*O,S=$*H,I=N.x-(g-N.width)/2-S,L=N.y-(C-N.height)/2-S,j=g+S*2,T=C+S*2,P=`${cm}-${R}`,z=x.useRef(0);z.current=H,x.useEffect(()=>{if(M.current){const Z=Te(M.current),J=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce}=b.getState();if(ne.sourceEvent.type!=="wheel"||!pe||!ce)return;const ue=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,ye=re[2]*Math.pow(2,ue);ce.scaleTo(pe,ye)},te=ne=>{const{transform:re,d3Selection:pe,d3Zoom:ce,translateExtent:ue,width:ye,height:he}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!pe||!ce)return;const xe=z.current*Math.max(1,re[2])*(p?-1:1),le={x:re[0]-ne.sourceEvent.movementX*xe,y:re[1]-ne.sourceEvent.movementY*xe},K=[[0,0],[ye,he]],Se=et.translate(le.x,le.y).scale(re[2]),Ce=ce.constrain()(Se,K,ue);ce.transform(pe,Ce)},oe=eo().on("zoom",w?te:null).on("zoom.wheel",y?J:null);return Z.call(oe),()=>{Z.on("zoom",null)}}},[w,y,p,E]);const X=m?Z=>{const J=ze(Z);m(Z,{x:J[0],y:J[1]})}:void 0,F=f?(Z,J)=>{const te=b.getState().nodeInternals.get(J);f(Z,te)}:void 0;return A.createElement(Tr,{position:d,style:e,className:je(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:k,height:O,viewBox:`${I} ${L} ${j} ${T}`,role:"img","aria-labelledby":P,ref:M,onClick:X},v&&A.createElement("title",{id:P},v),A.createElement(sm,{onClick:F,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${I-S},${L-S}h${j+S*2}v${T+S*2}h${-j-S*2}z - M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Wo.displayName="MiniMap";var lm=x.memo(Wo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Xt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:je(["react-flow__controls-button",t]),...n},e);Xt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ne(),[f,w]=x.useState(!1),{isInteractive:y,minZoomReached:v,maxZoomReached:p}=de(pm,ke),{zoomIn:E,zoomOut:$,fitView:b}=an();if(x.useEffect(()=>{w(!0)},[]),!f)return null;const M=()=>{E(),i==null||i()},N=()=>{$(),o==null||o()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c==null||c(!y)};return A.createElement(Tr,{className:je(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Xt,{onClick:M,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:p},A.createElement(um,null)),A.createElement(Xt,{onClick:N,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(dm,null))),n&&A.createElement(Xt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Xt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},y?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=x.memo(Uo),Le;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Le||(Le={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[Le.Dots]:"#91919a",[Le.Lines]:"#eee",[Le.Cross]:"#e2e2e2"},bm={[Le.Dots]:1,[Le.Lines]:1,[Le.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function qo({id:e,variant:t=Le.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=x.useRef(null),{transform:u,patternId:d}=de(vm,ke),m=o||wm[t],f=r||bm[t],w=t===Le.Dots,y=t===Le.Cross,v=Array.isArray(n)?n:[n,n],p=[v[0]*u[2]||1,v[1]*u[2]||1],E=f*u[2],$=y?[E,E]:p,b=w?[E/i,E/i]:[$[0]/i,$[1]/i];return A.createElement("svg",{className:je(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%p[0],y:u[1]%p[1],width:p[0],height:p[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},w?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:$,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}qo.displayName="Background";var _m=x.memo(qo);const Gr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Gr+e}async function be(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function rt(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new Ko(r.error??`${e}: ${n.status}`,n.status);return r}class Ko extends Error{constructor(n,r){super(n);_e(this,"status");this.status=r}}const Cx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),$x=()=>be("/api/diagnostics"),Zo=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Qo=()=>be("/api/ontology/ontologies"),Em=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>be("/api/ontology/stack"),Sm=()=>be("/api/ontology/coverage"),km=(e,t,n)=>rt("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>be("/api/git/status"),Cm=()=>be("/api/git/diff"),$m=e=>rt("/api/git/commit",{message:e}),Mm=()=>rt("/api/git/discard",{}),Am=()=>be("/api/decisions"),Bs=(e,t)=>rt(`/api/decisions/${e}/verdict`,{verdict:t}),Mx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Ax=()=>be("/api/glossary/config"),Rx=e=>rt("/api/git/propose",e),Ix=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Tx=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),Ox=e=>rt("/api/git/classify",{changes:e}),Lx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Dx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Px=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>be("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Gr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>rt("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>rt("/api/import/preview",{format:e,content:t}),zx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Hx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Fx=(e,t,n)=>fetch(`${Gr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new Ko(await r.text(),r.status);return await r.json()}),Vx=()=>be("/api/glossary/subject-areas"),Bx=e=>be(`/api/glossary/subject-area/${e}`),Gx=(e,t)=>rt(`/api/glossary/subject-area/${e}/expand`,t);function Yx(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Yr="__entity_source",Xr="__entity_target",Pm=x.memo(function({data:t,selected:n}){var N;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:w}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>y(_.a)-y(R.a)||_.i-R.i).map(_=>_.a),p=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const $=!!c&&!l;let b=0;if($){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const M=(_,R)=>{const k="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:k,onMouseEnter:w?()=>w(_.id):void 0,onMouseLeave:w?()=>w(null):void 0,children:[h.jsx(lt,{id:_.id,type:"target",position:q.Left,className:"port attr-port"}),h.jsx(lt,{id:_.id,type:"source",position:q.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(lt,{id:Xr,type:"target",position:q.Left,className:"port"}),h.jsx(lt,{id:Yr,type:"source",position:q.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((N=r.conceptual)==null?void 0:N.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var k;const _=(((k=r.conceptual)==null?void 0:k.ontology_refs)??[]).filter(O=>O.uri);if(_.length===0)return null;const R=_.map(O=>O.uri).join(` -`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),p.length>0&&h.jsx("div",{className:"attr-section keys",children:p.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,w,y,v,p,E,$,b,M,N,_,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(k=>k.from.entity===e.id||k.to.entity===e.id),d=k=>{var O;return((O=t.entities.find(D=>D.id===k))==null?void 0:O.name)??k};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Ze,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,name:k})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Ze,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,physical_name:k})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Ze,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:k=>r("set_definition",{id:e.id,definition:k})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((w=l==null?void 0:l.ontology_refs)==null?void 0:w.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((p=e.term_map)==null?void 0:p.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),($=e.term_map)!=null&&$.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((N=e.term_map)==null?void 0:N.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Ze,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:k,steward:((O=l==null?void 0:l.stewardship)==null?void 0:O.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Ze,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:((O=l==null?void 0:l.stewardship)==null?void 0:O.owner)??null,steward:k})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(k=>h.jsx(Xm,{a:k,entity:e,doc:t,readOnly:c,exec:r},k.id))})}),!c&&h.jsx(Wm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(k=>{const O=k.members.map(D=>{var B;return((B=e.attributes.find(H=>H.id===D))==null?void 0:B.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+k.type,children:k.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:k.name}),h.jsx("span",{className:"key-cols",children:O})]},k.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([k,O])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:k}),h.jsx("td",{className:"udp-val",children:String(O)})]},k))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(k=>{const O=k.from.entity===e.id?k.to.entity:k.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(O),children:[h.jsx("span",{className:"rel-card",children:Um(k,e.id)}),d(O)]}),(k.verb_phrase||k.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Ze,{value:k.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,verb_phrase:D})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Ze,{value:k.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,inverse_verb_phrase:D})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${k.name}`,onClick:()=>r("delete_relationship",{id:k.id}),children:"✕"})]},k.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var k;return(k=navigator.clipboard)==null?void 0:k.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Ze({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=x.useState(e);x.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Xm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Ze,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Ze,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Wm({entity:e,exec:t}){const[n,r]=x.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Um(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Gs="";let Km=class{constructor(t){_e(this,"_isDirected",!0);_e(this,"_isMultigraph",!1);_e(this,"_isCompound",!1);_e(this,"_label");_e(this,"_defaultNodeLabelFn",()=>{});_e(this,"_defaultEdgeLabelFn",()=>{});_e(this,"_nodes",{});_e(this,"_in",{});_e(this,"_preds",{});_e(this,"_out",{});_e(this,"_sucs",{});_e(this,"_edgeObjs",{});_e(this,"_edgeLabels",{});_e(this,"_nodeCount",0);_e(this,"_edgeCount",0);_e(this,"_parent");_e(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Ys(this._preds[n],t),Ys(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Xs(this._preds[n],t),Xs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Ys(e,t){e[t]?e[t]++:e[t]=1}function Xs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Gs+i+Gs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function sr(e,t){return Wt(e,t.v,t.w,t.name)}var Wr=Km,Qm="2.2.4",Jm={Graph:Wr,version:Qm},ep=Wr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){_e(this,"_arr",[]);_e(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=ea,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ta=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ta,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),ia(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),ia(t(i),o=>s.push(o)))}}function ia(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=sa,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=sa,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Wr,Lp=Jo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:ea,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ta,topsort:ra},Us=Jm,Ve={Graph:Us.Graph,json:tp,alg:zp,version:Us.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return qs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&qs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function qs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ve.Graph,Gp=Vp;var Yp=Wp;let Xp=()=>1;function Wp(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Xp);return Up(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Up(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)ir(e,t,n,o);for(;o=s.dequeue();)ir(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(ir(e,t,n,o,!0));break}}}return r}function ir(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,jr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,jr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{jr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function jr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new oa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=da(la(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),aa(e,"border",s,t)}function og(e,t=ca){const n=[];for(let r=0;rca){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function la(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function ua(e){var t=++ug;return e+(""+t)}function da(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Ur(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=Ee.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=Ee;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=Ee;var Yn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ve.Graph,On=Yn.slack,fa=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!On(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=On(t,s)),it.node(r).rank+=n)}var Rg=fa,Ks=Yn.slack,Ig=Yn.longestPath,Tg=Ve.alg.preorder,Og=Ve.alg.postorder,Lg=Ee.simplify,Dg=_t;_t.initLowLimValues=Kr;_t.initCutValues=qr;_t.calcCutValue=ha;_t.leaveEdge=pa;_t.enterEdge=ga;_t.exchangeEdges=ya;function _t(e){e=Lg(e),Ig(e);var t=Rg(e);Kr(t),qr(t,e);for(var n,r;n=pa(t);)r=ga(t,e,n),ya(t,e,n,r)}function qr(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ha(e,t,n)}function ha(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Kr(e,t){arguments.length<2&&(t=e.nodes()[0]),ma(e,{},1,t)}function ma(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ma(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function pa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ga(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===Zs(e,e.node(u.v),a)&&c!==Zs(e,e.node(u.w),a));return l.reduce((u,d)=>Ks(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function Zs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Yn,xa=Fg.longestPath,Vg=fa,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Qs(e);break;case"tight-tree":Wg(e);break;case"longest-path":Xg(e);break;case"none":break;default:Qs(e)}}var Xg=xa;function Wg(e){xa(e),Vg(e)}function Qs(e){Bg(e)}var Ug=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Ln=Ee;var Qg={run:Jg,cleanup:n0};function Jg(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=e0(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=t0(e)+1;e.children().forEach(a=>wa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function wa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{wa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,w=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,v=f!==w?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:v,nestingEdge:!0}),e.setEdge(w,l,{weight:y,minlen:v,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function e0(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function t0(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function n0(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let r0=Ee;var s0=i0;function i0(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iei(e.node(t))),e.edges().forEach(t=>ei(e.edge(t)))}function ei(e){let t=e.width;e.width=e.height,e.height=t}function l0(e){e.nodes().forEach(t=>or(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(or),Object.hasOwn(n,"y")&&or(n)})}function or(e){e.y=-e.y}function u0(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let ti=Ee;var d0=f0;function f0(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=ti.applyWithChunking(Math.max,r),i=ti.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let h0=Ee.zipObject;var m0=p0;function p0(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var y0=x0;function x0(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let w0=Ee;var b0=v0;function v0(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _0(r)}function _0(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&E0(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>w0.pick(s,["vs","i","barycenter","weight"]))}function E0(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let N0=Ee;var S0=k0;function k0(e,t){let n=N0.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(j0(!!t)),c=ni(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ni(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ni(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function j0(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let C0=y0,$0=b0,M0=S0;var A0=va;function va(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=C0(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=va(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&I0(m,f)}});let u=$0(l,n);R0(u,c);let d=M0(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function R0(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function I0(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let T0=Ve.Graph,O0=Ee;var L0=D0;function D0(e,t,n,r){r||(r=e.nodes());let s=P0(e),i=new T0({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function P0(e){for(var t;e.hasNode(t=O0.uniqueId("_root")););return t}var z0=H0;function H0(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let F0=d0,V0=m0,B0=A0,G0=L0,Y0=z0,X0=Ve.Graph,xn=Ee;var W0=_a;function _a(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,_a);return}let n=xn.maxRank(e),r=ri(e,xn.range(1,n+1),"inEdges"),s=ri(e,xn.range(n-1,-1,-1),"outEdges"),i=F0(e);if(si(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){U0(c%2?r:s,c%4>=2),i=xn.buildLayerMatrix(e);let u=V0(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return G0(e,i,n,r.get(i)||[])})}function U0(e,t){let n=new X0;e.forEach(function(r){let s=r.graph().root,i=B0(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Y0(r,n,i.vs)})}function si(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let q0=Ve.Graph,Qe=Ee;var K0={positionX:ay};function Z0(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=J0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(w=>{e.predecessors(w).forEach(y=>{let v=e.node(y),p=v.order;(p{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&Ea(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function J0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ea(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function ey(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function ty(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let w=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((w,y)=>Math.min(w,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function ry(e,t,n,r){let s=new q0,i=e.graph(),o=cy(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function sy(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=ly(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-Qe.applyWithChunking(Math.min,l);o!=="l"&&(u=s-Qe.applyWithChunking(Math.max,l)),u&&(e[a]=Qe.mapValues(c,d=>d+u))})})}function oy(e,t){return Qe.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function ay(e){let t=Qe.buildLayerMatrix(e),n=Object.assign(Z0(e,t),Q0(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=ty(e,s,n,c),u=ny(e,s,l.root,l.align,a==="r");a==="r"&&(u=Qe.mapValues(u,d=>-d)),r[o+a]=u})});let i=sy(e,r);return iy(r,i),oy(r,e.graph().align)}function cy(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function ly(e,t){return e.node(t).width}let Na=Ee,uy=K0.positionX;var dy=fy;function fy(e){e=Na.asNonCompoundGraph(e),hy(e),Object.entries(uy(e)).forEach(([t,n])=>e.node(t).x=n)}function hy(e){let t=Na.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ii=pg,oi=bg,my=Gg,py=Ee.normalizeRanks,gy=Ug,yy=Ee.removeEmptyRanks,ai=Qg,xy=s0,ci=o0,wy=W0,by=dy,De=Ee,vy=Ve.Graph;var _y=Ey;function Ey(e,t){let n=t&&t.debugTiming?De.time:De.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>Iy(e));n(" runLayout",()=>Ny(r,n,t)),n(" updateInputGraph",()=>Sy(e,r))})}function Ny(e,t,n){t(" makeSpaceForEdgeLabels",()=>Ty(e)),t(" removeSelfEdges",()=>By(e)),t(" acyclic",()=>ii.run(e)),t(" nestingGraph.run",()=>ai.run(e)),t(" rank",()=>my(De.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Oy(e)),t(" removeEmptyRanks",()=>yy(e)),t(" nestingGraph.cleanup",()=>ai.cleanup(e)),t(" normalizeRanks",()=>py(e)),t(" assignRankMinMax",()=>Ly(e)),t(" removeEdgeLabelProxies",()=>Dy(e)),t(" normalize.run",()=>oi.run(e)),t(" parentDummyChains",()=>gy(e)),t(" addBorderSegments",()=>xy(e)),t(" order",()=>wy(e,n)),t(" insertSelfEdges",()=>Gy(e)),t(" adjustCoordinateSystem",()=>ci.adjust(e)),t(" position",()=>by(e)),t(" positionSelfEdges",()=>Yy(e)),t(" removeBorderNodes",()=>Vy(e)),t(" normalize.undo",()=>oi.undo(e)),t(" fixupEdgeLabelCoords",()=>Hy(e)),t(" undoCoordinateSystem",()=>ci.undo(e)),t(" translateGraph",()=>Py(e)),t(" assignNodeIntersects",()=>zy(e)),t(" reversePoints",()=>Fy(e)),t(" acyclic.undo",()=>ii.undo(e))}function Sy(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let ky=["nodesep","edgesep","ranksep","marginx","marginy"],jy={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Cy=["acyclicer","ranker","rankdir","align"],$y=["width","height","rank"],li={width:0,height:0},My=["minlen","weight","width","height","labeloffset"],Ay={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ry=["labelpos"];function Iy(e){let t=new vy({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},jy,cr(n,ky),De.pick(n,Cy))),e.nodes().forEach(r=>{let s=lr(e.node(r));const i=cr(s,$y);Object.keys(li).forEach(o=>{i[o]===void 0&&(i[o]=li[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},Ay,cr(s,My),De.pick(s,Ry)))}),t}function Ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Oy(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};De.addDummyNode(e,"edge-proxy",i,"_ep")}})}function Ly(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Dy(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Py(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function zy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(De.intersectRect(r,i)),n.points.push(De.intersectRect(s,o))})}function Hy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Fy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Vy(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function By(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Gy(e){var t=De.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{De.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Yy(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return De.mapValues(De.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Xy=Ee,Wy=Ve.Graph;var Uy={debugOrdering:qy};function qy(e){let t=Xy.buildLayerMatrix(e),n=new Wy({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var Ky="1.1.8",Zy={graphlib:Ve,layout:_y,debug:Uy,util:{time:Ee.time,notime:Ee.notime},version:Ky};const ui=vi(Zy),Xe=264,Qy=44,Jy=26,ex=14;function wt(e){const t=Math.max(e.attributes.length,1);return Qy+t*Jy+ex}const tx=40;function ur(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?mi(e,n,o):r==="clustered"?hi(e,t,n,o,i):r==="hierarchical"||e.length<=tx?di(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?hi(e,t,n,o,i):mi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Sa(e,t,n,r=!1,s="LR"){const i=new ui.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Xe,height:d?wt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ui.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?wt(m):120,w=d.x-Xe/2,y=d.y-f/2;return a=Math.max(a,w+Xe),c=Math.max(c,y+f),{...u,position:{x:w,y}}}),width:a,height:c}}function di(e,t,n,r="LR"){return Sa(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?wt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Xe+ka);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Xe)}),i+=Math.max(...c.map(l=>n(l.id)))+ja}return{nodes:s,width:o,height:i}}const fi=120;function hi(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),w=new Set(f.map(E=>E.id));let y=0;for(const E of t)w.has(E.source)&&w.has(E.target)&&y++;const p=f.length<=8&&y>=f.length-1?Sa(f,t,n,!0,s):rx(f,n);return{name:m,...p}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const ka=40,ja=40;function mi(e,t,n){const r=l=>{const u=t.get(l);return u?wt(u):120},s=[...e].sort((l,u)=>{var y,v;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,w=((v=t.get(u.id))==null?void 0:v.name)??u.id;return f.localeCompare(w)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Xe+ka)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ja}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function cn({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ca=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var b,M;const[r,s]=x.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[i,o]=x.useState([]),[a,c]=x.useState(null),[l,u]=x.useState(null),[d,m]=x.useState("skos:exactMatch"),[f,w]=x.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,v]=x.useState([]),[p,E]=x.useState("");x.useEffect(()=>{Qo().then(N=>v(N.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const N=setTimeout(()=>{if(!r.trim())return o([]);Zo(r,p||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(N)},[r,p]);const $=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(cn,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(p===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(N=>h.jsx("button",{className:"src-chip"+(p===N.id?" active":""),title:N.count!=null?`${N.count} terms`:"live resolver",onClick:()=>E(N.id),children:N.name},N.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:p?`Search within ${p}…`:"Search vocabulary terms…",value:r,onChange:N=>s(N.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(N=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===N.iri?" picked":""),onClick:()=>u(N),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:N.label}),h.jsxs("span",{className:"term-source",children:[N.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),N.source]})]}),h.jsx("code",{className:"term-iri",children:N.prefixed}),N.definition&&h.jsx("p",{className:"term-def",children:N.definition})]},N.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:N=>m(N.target.value),children:sx.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:N=>w(N.target.value),children:Ca.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:$,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var b,M,N;const[s,i]=x.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[o,a]=x.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},w=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${w}:`,v=(N=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:N.members.map(_=>{var R;return(R=e.attributes.find(k=>k.id===_))==null?void 0:R.name}).filter(Boolean),p=v&&v.length?`${y}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,$=s.trim()||p;return h.jsxs(cn,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",$]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=x.useState(""),[o,a]=x.useState(""),[c,l]=x.useState(""),[u,d]=x.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const w=f==null?void 0:f.created_id;n(),w&&r(w)})};return h.jsxs(cn,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ca.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const $a=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=x.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=x.useState(r??""),[m,f]=x.useState(s??(l==null?void 0:l.id)??""),[w,y]=x.useState("many_to_one"),[v,p]=x.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",$=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:w,optionality:v}).then(o);return h.jsxs(cn,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:w,onChange:b=>y(b.target.value),children:$a.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>p(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:$,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=p=>{var E;return((E=t.entities.find($=>$.id===p))==null?void 0:E.name)??"?"},[i,o]=x.useState(e.name),[a,c]=x.useState(e.cardinality),[l,u]=x.useState(e.optionality),[d,m]=x.useState(e.identifying),[f,w]=x.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(cn,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:p=>o(p.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:p=>c(p.target.value),children:$a.map(p=>h.jsx("option",{children:p},p))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:p=>u(p.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:p=>m(p.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>w(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const pi=10,ux=6,Ge=24;function dx(e,t){return t?e:Math.round(e/pi)*pi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-Ge,o.right+Ge);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eF.transform[2]),[m,f]=x.useState(null),w=x.useRef(!1),y=x.useRef(0),v=c==null?void 0:c.onRouteChange,p=!!v,E=m??(c==null?void 0:c.routeX),[$,b,M]=Rn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),N=c==null?void 0:c.relationship,_=(c==null?void 0:c.dimmed)??!1,R=(N==null?void 0:N.cardinality)??"many_to_one",k=(N==null?void 0:N.optionality)==="optional",O=(N==null?void 0:N.identifying)??!1,D=R==="many_to_one"||R==="many_to_many",B=R==="one_to_many"||R==="many_to_many",H="rel-edge"+(l?" selected":"")+(_?" dimmed":""),g=((c==null?void 0:c.memberCount)??0)>1,C=c==null?void 0:c.onHoverEdge,S=E??b,I=M,L=S,j=I,T=x.useCallback(F=>v&&N&&v(N.id,F),[v,N]),P=x.useCallback(F=>{var pe,ce;if(!p||F.button!==0)return;F.stopPropagation(),(ce=(pe=F.target).setPointerCapture)==null||ce.call(pe,F.pointerId),w.current=!0,y.current=0;const J=u({x:F.clientX,y:F.clientY}).x;let te=0,oe=E??S;const ne=ue=>{const ye=u({x:ue.clientX,y:ue.clientY});y.current=Math.max(y.current,Math.abs(ye.x-J)),oe=mx(ye.x,{shift:ue.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),te||(te=requestAnimationFrame(()=>{te=0,f(oe)}))},re=()=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",re),te&&cancelAnimationFrame(te),w.current=!1,f(null),y.current>=gi&&T(oe)};window.addEventListener("pointermove",ne),window.addEventListener("pointerup",re)},[p,u,E,S,c,n,s,T]),z=x.useCallback(F=>{y.current>=gi&&(F.stopPropagation(),y.current=0)},[]),X=x.useCallback(F=>{p&&(F.stopPropagation(),T(null))},[p,T]);return h.jsxs("g",{className:H,onMouseEnter:C?()=>C(N.id):void 0,onMouseLeave:C?()=>C(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:$,fill:"none",strokeDasharray:O?void 0:"6 4"}),h.jsx("path",{d:$,fill:"none",strokeWidth:16/d,stroke:"transparent"}),h.jsx(yi,{x:n,y:r,side:o,many:D,optional:k}),h.jsx(yi,{x:s,y:i,side:a,many:B,optional:!1}),p&&((c==null?void 0:c.hovered)||l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:P,onClickCapture:z,onDoubleClick:X,children:[h.jsx("rect",{x:S-11/d,y:I-16/d,width:22/d,height:32/d,fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:S-4.5/d,y:I-9/d,width:9/d,height:18/d,rx:4/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I-3/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I+3/d,r:1.1/d})]}),(l||g)&&N&&h.jsxs("text",{className:"rel-label",x:L,y:j-8,children:[l?N.verb_phrase||N.name:"",g?`${l?" ":""}(${c.memberCount})`:""]})]})});function yi({x:e,y:t,side:n,many:r,optional:s}){const i=n===q.Left?-1:1,o=7,a=12,c=[];return r?c.push(h.jsx("path",{className:"rel-glyph",d:`M ${e+i*a} ${t} L ${e} ${t-o} M ${e+i*a} ${t} L ${e} ${t} M ${e+i*a} ${t} L ${e} ${t+o}`,fill:"none"},"foot")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a-3),y1:t-o,x2:e+i*(a-3),y2:t+o},"one")),s?c.push(h.jsx("circle",{className:"rel-glyph ring",cx:e+i*(a+6),cy:t,r:4},"opt")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a+5),y1:t-o,x2:e+i*(a+5),y2:t+o},"mand")),h.jsx(h.Fragment,{children:c})}const gx={entity:Pm},yx={relationship:px},xi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],wi="#8a7d6a";function xx(e,t,n){const s=Xe;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function wx(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Yr,targetHandle:n(e.to.entity,s)?s:Xr}}function qx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:w,fitBounds:y,getNodes:v}=an(),[p,E]=x.useState([]),[$,b]=x.useState([]),M=x.useRef(!1),N=x.useMemo(()=>{const V=u&&u.size>0?[...u].sort():null;return V?"sa:"+V.join("+"):"__all__"},[u]),_=x.useRef(null),[R,k]=x.useState(0),O=x.useRef(new Map),D=x.useRef(null);x.useEffect(()=>{if(!f){_.current=null;return}const V=O.current.get(N);if(V){_.current=V,M.current=!1,k(G=>G+1);return}let Y=!1;return f.load(N).then(G=>{Y||(O.current.set(N,G),_.current=G,M.current=!1,k(Q=>Q+1))}),()=>{Y=!0}},[f,N]);const[B,H]=x.useState(null),[g,C]=x.useState(null),[S,I]=x.useState(!1),[L,j]=x.useState(null),[T,P]=x.useState(null),[z,X]=x.useState(null),[F,Z]=x.useState(null),J=x.useRef({}),te=!t.canEdit,oe=x.useRef(null),ne=x.useCallback(()=>{f&&(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{const V={};for(const Q of v())Q.hidden||(V[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,U]of Object.entries(J.current))Y[Q]={routeX:Math.round(U)};const G={nodes:V,edges:Y};O.current.set(N,G),_.current=G,f.save(N,G)},800))},[f,v,N]),re=x.useCallback((V,Y)=>{Y==null?delete J.current[V]:J.current[V]=Y,b(G=>G.map(Q=>Q.id===V?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),ne()},[ne]),pe=x.useMemo(()=>{const V=new Map;return e.subject_areas.forEach((Y,G)=>V.set(Y.id,xi[G%xi.length])),V},[e]),ce=x.useMemo(()=>{const V=new Map;return e.entities.forEach(Y=>V.set(Y.id,Y)),V},[e]),ue=x.useMemo(()=>{const V=new Map,Y=new Map;return e.subject_areas.forEach(G=>{(G.members??[]).forEach(Q=>Y.set(Q,{id:G.id,name:G.name}))}),e.entities.forEach(G=>{var se,me;const Q=(se=G.conceptual)!=null&&se.id?Y.get(G.conceptual.id):void 0,U=(me=G.conceptual)==null?void 0:me.subject_area,ee=Q??(U?{id:U.id,name:U.name??U.id}:void 0);ee&&V.set(G.id,ee)}),V},[e]),ye=x.useCallback(V=>{var G;if(!u||u.size===0)return!1;const Y=(G=ue.get(V))==null?void 0:G.id;return!(Y&&u.has(Y))},[u,ue]),he=x.useMemo(()=>{const V=new Map,Y=(G,Q)=>{if(!Q.length)return;const U=V.get(G)??new Set;Q.forEach(ee=>U.add(ee)),V.set(G,U)};for(const G of e.relationships)Y(G.from.entity,G.from.attributes),Y(G.to.entity,G.to.attributes);return V},[e]);x.useEffect(()=>{var $e;const V=i.trim().toLowerCase(),Y=new Set;if(V)for(const W of e.entities)(W.name.toLowerCase()+" "+((($e=W.conceptual)==null?void 0:$e.name.toLowerCase())??"")+" "+W.attributes.map(ge=>ge.name.toLowerCase()).join(" ")).includes(V)&&Y.add(W.id);const G=new Set;if(r){G.add(r);for(const W of e.relationships)W.from.entity===r&&G.add(W.to.entity),W.to.entity===r&&G.add(W.from.entity)}const Q=e.entities.map(W=>{const fe=V!==""&&!Y.has(W.id),ge=r!==null&&!G.has(W.id);return{id:W.id,type:"entity",position:{x:0,y:0},hidden:ye(W.id),data:{entity:W,color:(()=>{const ve=ue.get(W.id);return ve?pe.get(ve.id)??wi:wi})(),dimmed:fe||ge,highlighted:V!==""&&Y.has(W.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(W.id))??!1,onToggleExpand:l,endpointAttrs:he.get(W.id),highlightAttrs:void 0,onHoverAttr:X}}}),U=e.relationships.filter(W=>ce.has(W.from.entity)&&ce.has(W.to.entity)).map(W=>{const{sourceHandle:fe,targetHandle:ge}=wx(W,ce),ve=r!==null&&W.from.entity!==r&&W.to.entity!==r;return{id:W.id,source:W.from.entity,target:W.to.entity,sourceHandle:fe,targetHandle:ge,type:"relationship",data:{relationship:W,dimmed:ve,memberCount:Math.max(W.from.attributes.length,W.to.attributes.length),onHoverEdge:Z}}}),ee=_.current;if(J.current={},ee)for(const[W,fe]of Object.entries(ee.edges))J.current[W]=fe.routeX;let se=Q;E(W=>{const fe=new Map(W.map(ae=>[ae.id,ae.position])),ge=Q.every(ae=>fe.has(ae.id)),ve=((u==null?void 0:u.size)??0)>0;if(M.current&&ge&&W.length>=Q.length&&!ve){const ae=Q.map(qe=>({...qe,position:fe.get(qe.id)??qe.position}));return se=ae,ae}const Be=ve?Q.filter(ae=>!ae.hidden):Q,Ot=ur(Be,U,ce,"auto",ue),st=new Map(Ot.map(ae=>[ae.id,ae.position])),ft=(ee==null?void 0:ee.nodes)??{},Lt=Object.keys(ft).length>0,Pe=[],Dt=Q.map(ae=>{const qe=ft[ae.id];if(qe){const Pt={x:qe.x,y:qe.y};return Pe.push({x:Pt.x,y:Pt.y,w:Xe,h:wt(ae.data.entity)}),{...ae,position:Pt}}return st.has(ae.id)?{...ae,position:st.get(ae.id)}:fe.has(ae.id)&&M.current?{...ae,position:fe.get(ae.id)}:ae});if(Lt)for(const ae of Dt)ft[ae.id]||ae.hidden||(ae.position=xx(ae.position,wt(ae.data.entity),Pe),Pe.push({x:ae.position.x,y:ae.position.y,w:Xe,h:wt(ae.data.entity)}));return M.current=!0,Lt||requestAnimationFrame(()=>w({padding:.15,duration:300})),se=Dt,Dt});const me=new Map;for(const W of se)me.set(W.id,{left:W.position.x,right:W.position.x+Xe});b(U.map(W=>({...W,data:{...W.data,routeX:J.current[W.id],onRouteChange:f?re:void 0,sourceCard:me.get(W.source),targetCard:me.get(W.target)}})))},[e,i,r,o,a,c,l,pe,ce,ue,ye,u,he,w,f,re,R]);const xe=x.useMemo(()=>{const V=new Set,Y=new Set,G=new Map,Q=(U,ee)=>{if(!ee.length)return;const se=G.get(U)??new Set;ee.forEach(me=>se.add(me)),G.set(U,se)};if(z)for(const U of e.relationships)(U.from.attributes.includes(z)||U.to.attributes.includes(z))&&(V.add(U.id),Y.add(U.from.entity),Y.add(U.to.entity),Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes));if(F){const U=e.relationships.find(ee=>ee.id===F);U&&(Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes))}return{active:z!==null,relsForAttr:V,entsForAttr:Y,hitAttrsByEntity:G}},[e,z,F]);x.useEffect(()=>{var Q;const V=i.trim().toLowerCase(),Y=new Set;if(V)for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(V)&&Y.add(U.id);const G=new Set;if(r){G.add(r);for(const U of e.relationships)U.from.entity===r&&G.add(U.to.entity),U.to.entity===r&&G.add(U.from.entity)}E(U=>U.map(ee=>{const se=V!==""&&!Y.has(ee.id),me=r!==null&&!G.has(ee.id),$e=xe.active&&!xe.entsForAttr.has(ee.id),W=se||me||$e,fe=V!==""&&Y.has(ee.id)||xe.active&&xe.entsForAttr.has(ee.id),ge=xe.hitAttrsByEntity.get(ee.id);return ee.data.dimmed===W&&ee.data.highlighted===fe&&ee.data.highlightAttrs===ge?ee:{...ee,data:{...ee.data,dimmed:W,highlighted:fe,highlightAttrs:ge}}})),b(U=>U.map(ee=>{var ge,ve,Be;const se=(ge=ee.data)==null?void 0:ge.relationship,me=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,$e=xe.active&&!xe.relsForAttr.has(ee.id),W=me||$e,fe=F===ee.id;return((ve=ee.data)==null?void 0:ve.dimmed)===W&&((Be=ee.data)==null?void 0:Be.hovered)===fe?ee:{...ee,data:{...ee.data,dimmed:W,hovered:fe}}}))},[xe,F,i,r,e]),x.useEffect(()=>{var Q;const V=i.trim().toLowerCase();if(!V)return;const Y=new Set;for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(V)&&Y.add(U.id);if(!Y.size)return;const G=requestAnimationFrame(()=>{const U=v().filter(se=>Y.has(se.id));if(!U.length)return;const ee=Mf(U);y(ee,{padding:.35,duration:400})});return()=>cancelAnimationFrame(G)},[i,e,v,y]);const le=x.useCallback((V="auto",Y="LR")=>{D.current=Object.fromEntries(v().map(G=>[G.id,{x:G.position.x,y:G.position.y}])),E(G=>ur(G,$,ce,V,ue,Y)),requestAnimationFrame(()=>w({padding:.15,duration:300})),ne()},[$,ce,ue,w,v,ne]),K=x.useCallback(()=>{const V=D.current;V&&(E(Y=>Y.map(G=>V[G.id]?{...G,position:V[G.id]}:G)),D.current=null,ne())},[ne]),Se=x.useCallback(()=>{f==null||f.reset(N),O.current.delete(N),_.current=null,J.current={},M.current=!1,b(V=>V.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(V=>{const Y=ur(V,$,ce,"auto",ue);return requestAnimationFrame(()=>w({padding:.15,duration:300})),Y})},[f,N,$,ce,ue,w]),Ce=x.useCallback(V=>{s(V),E(Y=>(Y.find(Q=>Q.id===V)&&requestAnimationFrame(()=>w({nodes:[{id:V}],padding:.4,duration:400})),Y))},[w,s]);x.useImperativeHandle(m,()=>({relayout:le,fitView:()=>w({padding:.15,duration:300}),focusEntity:Ce,newEntity:()=>I(!0),resetLayout:Se,undoRelayout:K}),[le,w,Ce,Se,K]);const dt=x.useCallback(V=>{if(te||!V.source||!V.target||V.source===V.target)return;const Y=V.sourceHandle&&V.sourceHandle!==Yr?V.sourceHandle:void 0,G=V.targetHandle&&V.targetHandle!==Xr?V.targetHandle:void 0;j({from:V.source,to:V.target,fromAttr:Y,toAttr:G})},[te]),Ae=x.useCallback(async(V,Y)=>{try{return await n(V,Y)}catch(G){throw d==null||d(G instanceof Error?G.message:String(G)),G}},[n,d]),Ue=r?ce.get(r)??null:null,Ie=e.relationships.find(V=>V.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Yo,{nodes:p,edges:$,nodeTypes:gx,edgeTypes:yx,onNodeClick:(V,Y)=>s(Y.id),onEdgeDoubleClick:(V,Y)=>!te&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(V,Y)=>{E(G=>G.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),ne()},onConnect:dt,nodesConnectable:!te,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:Le.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:V=>{var Y;return((Y=V.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),Ue&&h.jsx(Hm,{entity:Ue,doc:e,caps:t,exec:Ae,onClose:()=>s(null),onFocusEntity:Ce,onAlign:H,onEditMapping:C}),B&&h.jsx(ix,{entity:B,exec:Ae,onClose:()=>H(null)}),g&&h.jsx(ox,{entity:g,doc:e,exec:Ae,onClose:()=>C(null)}),S&&h.jsx(ax,{doc:e,exec:Ae,onClose:()=>I(!1),onCreated:Ce}),L&&h.jsx(cx,{doc:e,fromId:L.from,toId:L.to,initialFromAttr:L.fromAttr,initialToAttr:L.toAttr,exec:Ae,onClose:()=>j(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:Ae,onClose:()=>P(null)})]})}function Kx({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(bx,{}),e==="layers"&&h.jsx(_x,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(Ex,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Nx,{readOnly:n})]})}function bx(){const[e,t]=x.useState(""),[n,r]=x.useState([]),[s,i]=x.useState({loaded:0,vocabs:[]}),[o,a]=x.useState(null),[c,l]=x.useState([]),[u,d]=x.useState("");x.useEffect(()=>{Qo().then(f=>l(f.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const f=setTimeout(()=>{Zo(e||"a",u||void 0).then(w=>{r(e?w.results:[]),i({loaded:w.loaded_terms,vocabs:w.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=x.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const vx=["industry","core","domain","specialised"];function _x({refreshKey:e,onFocusEntity:t}){const[n,r]=x.useState(null),[s,i]=x.useState(null);if(x.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),vx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Ex({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=x.useState(null),[i,o]=x.useState(""),[a,c]=x.useState(""),[l,u]=x.useState(!1),d=x.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` + */var Dn=x,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=Dn.useRef,_c=Dn.useEffect,Ec=Dn.useMemo,Nc=Dn.useDebugValue;Ei.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var w=o.value;if(s(w,f))return d=w}return d=f}if(w=d,wc(u,f))return w;var y=r(f);return s!==void 0&&s(w,y)?(u=f,w):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};_i.exports=Ei;var Sc=_i.exports;const kc=vi(Sc),jc={},es=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(w=>w(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?es(e):es,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function ki(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const ts=(e,t)=>{const n=Cc(e),r=(s,i=t)=>ki(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?ts(e,t):ts;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rs.hasOwnProperty(t)?{space:rs[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===dr&&t.documentElement.namespaceURI===dr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ji(e){var t=zn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function Cr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=Cr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=$&&($=E+1);!(M=v[$])&&++$=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):It(this.node(),e)}function It(e,t){return e.style.getPropertyValue(t)||Ri(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ii(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Ti(e)}function Ti(e){this._node=e,this._names=Ii(e.getAttribute("class")||"")}Ti.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Oi(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function fr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}fr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Pn("start","drag","end"),o=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",p,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,M){if(!(u||!e.call(this,b,M))){var N=$(this,t.call(this,b,M),b,M,"mouse");N&&(Te(b.view).on("mousemove.drag",w,Ut).on("mouseup.drag",y,Ut),zi(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,N("start",b))}}function w(b){if($t(b),!l){var M=b.clientX-a,N=b.clientY-c;l=M*M+N*N>d}s.mouse("drag",b)}function y(b){Te(b.view).on("mousemove.drag mouseup.drag",null),Hi(b.view,l),$t(b),s.mouse("end",b)}function v(b,M){if(e.call(this,b,M)){var N=b.changedTouches,_=t.call(this,b,M),R=N.length,k,O;for(k=0;k>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?un(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?un(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Me(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Me(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?un(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?un(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?us(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?us(t[1],t[2]/100,t[3]/100,t[4]):ss.hasOwnProperty(e)?as(ss[e]):e==="transparent"?new Me(NaN,NaN,NaN,0):null}function as(e){return new Me(e>>16&255,e>>8&255,e&255,1)}function un(e,t,n,r){return r<=0&&(e=t=n=NaN),new Me(e,t,n,r)}function Mu(e){return e instanceof rn||(e=Zt(e)),e?(e=e.rgb(),new Me(e.r,e.g,e.b,e.opacity)):new Me}function hr(e,t,n,r){return arguments.length===1?Mu(e):new Me(e,t,n,r??1)}function Me(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Mr(Me,hr,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Me(xt(this.r),xt(this.g),xt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:cs,formatHex:cs,formatHex8:Au,formatRgb:ls,toString:ls}));function cs(){return`#${gt(this.r)}${gt(this.g)}${gt(this.b)}`}function Au(){return`#${gt(this.r)}${gt(this.g)}${gt(this.b)}${gt((isNaN(this.opacity)?1:this.opacity)*255)}`}function ls(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${xt(this.r)}, ${xt(this.g)}, ${xt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function xt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function gt(e){return e=xt(e),(e<16?"0":"")+e.toString(16)}function us(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Fe(e,t,n,r)}function Vi(e){if(e instanceof Fe)return new Fe(e.h,e.s,e.l,e.opacity);if(e instanceof rn||(e=Zt(e)),!e)return new Fe;if(e instanceof Fe)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new Fe(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Vi(e):new Fe(e,t,n,r??1)}function Fe(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Mr(Fe,Ru,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Fe(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Fe(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Me(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Fe(ds(this.h),dn(this.s),dn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${ds(this.h)}, ${dn(this.s)*100}%, ${dn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ds(e){return e=(e||0)%360,e<0?e+360:e}function dn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Bi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Gi:function(t,n){return n-t?Tu(t,n,e):Bi(isNaN(t)?n:t)}}function Gi(e,t){var n=t-e;return n?Iu(e,n):Bi(isNaN(e)?t:e)}const fs=function e(t){var n=Ou(t);function r(s,i){var o=n((s=hr(s)).r,(i=hr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Gi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function at(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var mr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(mr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=mr.lastIndex=Kn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=mr.exec(e))&&(s=Kn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:at(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:at(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:at(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,w){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");w.push({i:y-4,x:at(l,d)},{i:y-2,x:at(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var w=-1,y=m.length,v;++w=0&&e._call.call(void 0,t),e=e._next;--Tt}function ps(){vt=(Cn=Qt.now())+Hn,Tt=Gt=0;try{Uu()}finally{Tt=0,Ku(),vt=0}}function qu(){var e=Qt.now(),t=e-Cn;t>Wi&&(Hn-=t,Cn=e)}function Ku(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Yt=e,gr(r)}function gr(e){if(!Tt){Gt&&(Gt=clearTimeout(Gt));var t=e-vt;t>24?(e<1/0&&(Gt=setTimeout(ps,e-Qt.now()-Hn)),zt&&(zt=clearInterval(zt))):(zt||(Cn=Qt.now(),zt=setInterval(qu,Wi)),Tt=1,Ui(ps))}}function gs(e,t,n){var r=new $n;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Pn("start","end","cancel","interrupt"),Qu=[],Ki=0,ys=1,yr=2,vn=3,xs=4,xr=5,_n=6;function Fn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Ki})}function Rr(e,t){var n=Ve(e,t);if(n.state>Ki)throw new Error("too late; already scheduled");return n}function Ue(e,t){var n=Ve(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Ve(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=qi(i,0,n.time);function i(l){n.state=ys,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ys)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return gs(o);f.state===xs?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uyr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Rr:Ue;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Ve(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Cr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function et(e,t,n){this.k=e,this.x=t,this.y=n}et.prototype={constructor:et,scale:function(e){return e===1?this:new et(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new et(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var tt=new et(1,0,0);et.prototype;function Zn(e){e.stopImmediatePropagation()}function Ht(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ws(){return this.__zoom||tt}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function eo(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Xu,l=Pn("start","zoom","end"),u,d,m,f=500,w=150,y=0,v=10;function p(g){g.property("__zoom",ws).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",D).on("touchmove.zoom",B).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}p.transform=function(g,C,S,I){var L=g.selection?g.selection():g;L.property("__zoom",ws),g!==L?M(g,C,S,I):L.interrupt().each(function(){N(this,arguments).event(I).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},p.scaleBy=function(g,C,S,I){p.scaleTo(g,function(){var L=this.__zoom.k,j=typeof C=="function"?C.apply(this,arguments):C;return L*j},S,I)},p.scaleTo=function(g,C,S,I){p.transform(g,function(){var L=t.apply(this,arguments),j=this.__zoom,T=S==null?b(L):typeof S=="function"?S.apply(this,arguments):S,P=j.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n($(E(j,z),T,P),L,o)},S,I)},p.translateBy=function(g,C,S,I){p.transform(g,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,I)},p.translateTo=function(g,C,S,I,L){p.transform(g,function(){var j=t.apply(this,arguments),T=this.__zoom,P=I==null?b(j):typeof I=="function"?I.apply(this,arguments):I;return n(tt.translate(P[0],P[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof S=="function"?-S.apply(this,arguments):-S),j,o)},I,L)};function E(g,C){return C=Math.max(i[0],Math.min(i[1],C)),C===g.k?g:new et(C,g.x,g.y)}function $(g,C,S){var I=C[0]-S[0]*g.k,L=C[1]-S[1]*g.k;return I===g.x&&L===g.y?g:new et(g.k,I,L)}function b(g){return[(+g[0][0]+ +g[1][0])/2,(+g[0][1]+ +g[1][1])/2]}function M(g,C,S,I){g.on("start.zoom",function(){N(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(I).end()}).tween("zoom",function(){var L=this,j=arguments,T=N(L,j).event(I),P=t.apply(L,j),z=S==null?b(P):typeof S=="function"?S.apply(L,j):S,X=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),F=L.__zoom,Z=typeof C=="function"?C.apply(L,j):C,J=c(F.invert(z).concat(X/F.k),Z.invert(z).concat(X/Z.k));return function(te){if(te===1)te=Z;else{var oe=J(te),ne=X/oe[2];te=new et(ne,z[0]-oe[0]*ne,z[1]-oe[1]*ne)}T.zoom(null,te)}})}function N(g,C,S){return!S&&g.__zooming||new _(g,C)}function _(g,C){this.that=g,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(g,C),this.taps=0}_.prototype={event:function(g){return g&&(this.sourceEvent=g),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(g,C){return this.mouse&&g!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&g!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&g!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(g){var C=Te(this.that).datum();l.call(g,this.that,new sf(g,{sourceEvent:this.sourceEvent,target:p,transform:this.that.__zoom,dispatch:l}),C)}};function R(g,...C){if(!e.apply(this,arguments))return;var S=N(this,C).event(g),I=this.__zoom,L=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,r.apply(this,arguments)))),j=He(g);if(S.wheel)(S.mouse[0][0]!==j[0]||S.mouse[0][1]!==j[1])&&(S.mouse[1]=I.invert(S.mouse[0]=j)),clearTimeout(S.wheel);else{if(I.k===L)return;S.mouse=[j,I.invert(j)],En(this),S.start()}Ht(g),S.wheel=setTimeout(T,w),S.zoom("mouse",n($(E(I,L),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function k(g,...C){if(m||!e.apply(this,arguments))return;var S=g.currentTarget,I=N(this,C,!0).event(g),L=Te(g.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",X,!0),j=He(g,S),T=g.clientX,P=g.clientY;zi(g.view),Zn(g),I.mouse=[j,this.__zoom.invert(j)],En(this),I.start();function z(F){if(Ht(F),!I.moved){var Z=F.clientX-T,J=F.clientY-P;I.moved=Z*Z+J*J>y}I.event(F).zoom("mouse",n($(I.that.__zoom,I.mouse[0]=He(F,S),I.mouse[1]),I.extent,o))}function X(F){L.on("mousemove.zoom mouseup.zoom",null),Hi(F.view,I.moved),Ht(F),I.event(F).end()}}function O(g,...C){if(e.apply(this,arguments)){var S=this.__zoom,I=He(g.changedTouches?g.changedTouches[0]:g,this),L=S.invert(I),j=S.k*(g.shiftKey?.5:2),T=n($(E(S,j),I,L),t.apply(this,C),o);Ht(g),a>0?Te(this).transition().duration(a).call(M,T,I,g):Te(this).call(p.transform,T,I,g)}}function D(g,...C){if(e.apply(this,arguments)){var S=g.touches,I=S.length,L=N(this,C,g.changedTouches.length===I).event(g),j,T,P,z;for(Zn(g),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},to=rt.error001();function de(e,t){const n=x.useContext(Vn);if(n===null)throw new Error(to);return ki(n,e,t)}const Ne=()=>{const e=x.useContext(Vn);if(e===null)throw new Error(to);return x.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Tr({position:e,children:t,className:n,style:r,...s}){const i=de(ff),o=`${e}`.split("-");return A.createElement("div",{className:je(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Tr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=x.useRef(null),[m,f]=x.useState({x:0,y:0,width:0,height:0}),w=je(["react-flow__edge-textwrapper",l]);return x.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:w,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=x.memo(mf);const Or=e=>({width:e.offsetWidth,height:e.offsetHeight}),Ot=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Lr=(e={x:0,y:0},t)=>({x:Ot(e.x,t[0][0],t[1][0]),y:Ot(e.y,t[0][1],t[1][1])}),bs=(e,t,n)=>en?-Ot(Math.abs(e-n),1,50)/50:0,no=(e,t)=>{const n=bs(e.x,35,t.width-35)*20,r=bs(e.y,35,t.height-35)*20;return[n,r]},ro=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},so=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Jt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),io=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),vs=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>io(so(Jt(e),Jt(t))),wr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Oe(e.width)&&Oe(e.height)&&Oe(e.x)&&Oe(e.y),Oe=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),oo=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function br(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const ao=e=>"clientX"in e,dt=(e,t)=>{var i,o;const n=ao(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Mn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},sn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Oe(n)&&Oe(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);sn.displayName="BaseEdge";function Ft(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function co({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[v,p,E]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(sn,{path:v,labelX:p,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:y})});Dr.displayName="SimpleBezierEdge";const Es={[q.Left]:{x:-1,y:0},[q.Right]:{x:1,y:0},[q.Top]:{x:0,y:-1},[q.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=q.Bottom,target:n})=>t===q.Left||t===q.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=q.Bottom,target:n,targetPosition:r=q.Top,center:s,offset:i}){const o=Es[t],a=Es[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],w,y;const v={x:0,y:0},p={x:0,y:0},[E,$,b,M]=co({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){w=s.x??E,y=s.y??$;const _=[{x:w,y:c.y},{x:w,y:l.y}],R=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?R:_:f=o.y===m?_:R,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const g=Math.min(i-1,i-H);o[d]===m?v[d]=(c[d]>e[d]?-1:1)*g:p[d]=(l[d]>n[d]?-1:1)*g}}if(t!==r){const H=d==="x"?"y":"x",g=o[d]===a[H],C=c[H]>l[H],S=c[H]=B?(w=(k.x+O.x)/2,y=f[0].y):(w=f[0].x,y=(k.y+O.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:l.x+p.x,y:l.y+p.y},n],w,y,b,M]}function _f(e,t,n,r){const s=Math.min(Ns(e,t)/2,Ns(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let $="";return E>0&&E{const[p,E,$]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:w,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const Pr=x.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:x.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Pr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=co({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const zr=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[w,y,v]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(sn,{path:w,labelX:y,labelY:v,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});zr.displayName="StraightEdge";function mn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Ss({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case q.Left:return[t-mn(t-r,i),n];case q.Right:return[t+mn(r-t,i),n];case q.Top:return[t,n-mn(n-s,i)];case q.Bottom:return[t,n+mn(s-n,i)]}}function fo({sourceX:e,sourceY:t,sourcePosition:n=q.Bottom,targetX:r,targetY:s,targetPosition:i=q.Top,curvature:o=.25}){const[a,c]=Ss({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Ss({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,w]=lo({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,w]}const In=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=q.Bottom,targetPosition:i=q.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,pathOptions:y,interactionWidth:v})=>{const[p,E,$]=fo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:v})});In.displayName="BezierEdge";const Hr=x.createContext(null),Nf=Hr.Provider;Hr.Consumer;const Sf=()=>x.useContext(Hr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,vr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},_r=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},ho=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),wt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},on=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=wt(s,t).positionAbsolute;return so(r,Jt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return io(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),on(e,t)),mo=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:w=!1}=u;if(o&&!f||w)return!1;const{positionAbsolute:y}=wt(u,a),v={x:y.x,y:y.y,width:d||0,height:m||0},p=wr(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,$=i&&p>0,b=(d||0)*(m||0);(E||$||p>=b||u.dragging)&&l.push(u)}),l},po=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},go=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Ot(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},pt=(e,t=0)=>e.transition().duration(t);function ks(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=dt(e),l=t.elementsFromPoint(o,a).find(w=>w.classList.contains("react-flow__handle"));if(l){const w=l.getAttribute("data-nodeid");if(w){const y=Fr(void 0,l),v=l.getAttribute("data-handleid"),p=i({nodeId:w,id:v,type:y});if(p){const E=s.find($=>$.nodeId===w&&$.type===y&&$.id===v);return{handle:{id:v,type:y,nodeId:w,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:p}}}}let u=[],d=1/0;if(s.forEach(w=>{const y=Math.sqrt((w.x-n.x)**2+(w.y-n.y)**2);if(y<=r){const v=i(w);y<=d&&(yw.isValid),f=u.some(({handle:w})=>w.type==="target");return u.find(({handle:w,validHandleResult:y})=>f?w.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},yo=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function xo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...yo(),handleDomNode:c};if(c){const u=Fr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),w=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&w&&(t===_t.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=ks(i,o,"source",`${t}-${n}-${r}`),c=ks(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Fr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function wo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ro(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:w,onConnectStart:y,panBy:v,getNodes:p,cancelConnection:E}=i();let $=0,b;const{x:M,y:N}=dt(e),_=u==null?void 0:u.elementFromPoint(M,N),R=Fr(c,_),k=m==null?void 0:m.getBoundingClientRect();if(!k||!R)return;let O,D=dt(e,k),B=!1,H=null,g=!1,C=null;const S=If({nodes:p(),nodeId:n,handleId:t,handleType:R}),I=()=>{if(!f)return;const[T,P]=no(D,k);v({x:T,y:P}),$=requestAnimationFrame(I)};o({connectionPosition:D,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:R});function L(T){const{transform:P}=i();D=dt(T,k);const{handle:z,validHandleResult:X}=Af(T,u,_r(D,P,!1,[1,1]),w,S,F=>xo(F,d,n,t,s?"target":"source",a,u));if(b=z,B||(I(),B=!0),C=X.handleDomNode,H=X.connection,g=X.isValid,o({connectionPosition:b&&g?ho({x:b.x,y:b.y},P):D,connectionStatus:Tf(!!b,g),connectionEndHandle:X.endHandle}),!b&&!g&&!C)return Qn(O);H.source!==H.target&&C&&(Qn(O),O=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",g),C.classList.toggle("react-flow__handle-valid",g))}function j(T){var P,z;(b||C)&&H&&g&&(r==null||r(H)),(z=(P=i()).onConnectEnd)==null||z.call(P,T),c&&(l==null||l(T)),Qn(O),E(),cancelAnimationFrame($),B=!1,g=!1,H=null,C=null,u.removeEventListener("mousemove",L),u.removeEventListener("mouseup",j),u.removeEventListener("touchmove",L),u.removeEventListener("touchend",j)}u.addEventListener("mousemove",L),u.addEventListener("mouseup",j),u.addEventListener("touchmove",L),u.addEventListener("touchend",j)}const js=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},bo=x.forwardRef(({type:e="source",position:t=q.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var k,O;const w=o||null,y=e==="target",v=Ne(),p=Sf(),{connectOnClick:E,noPanClassName:$}=de(Of,ke),{connecting:b,clickConnecting:M}=de(Lf(p,w,e),ke);p||(O=(k=v.getState()).onError)==null||O.call(k,"010",rt.error010());const N=D=>{const{defaultEdgeOptions:B,onConnect:H,hasDefaultEdges:g}=v.getState(),C={...B,...D};if(g){const{edges:S,setEdges:I}=v.getState();I($f(C,S))}H==null||H(C),a==null||a(C)},_=D=>{if(!p)return;const B=ao(D);s&&(B&&D.button===0||!B)&&wo({event:D,handleId:w,nodeId:p,onConnect:N,isTarget:y,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||js}),B?u==null||u(D):d==null||d(D)},R=D=>{const{onClickConnectStart:B,onClickConnectEnd:H,connectionClickStartHandle:g,connectionMode:C,isValidConnection:S}=v.getState();if(!p||!g&&!s)return;if(!g){B==null||B(D,{nodeId:p,handleId:w,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:p,type:e,handleId:w}});return}const I=ro(D.target),L=n||S||js,{connection:j,isValid:T}=xo({nodeId:p,id:w,type:e},C,g.nodeId,g.handleId||null,g.type,L,I);T&&N(j),H==null||H(D),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":w,"data-nodeid":p,"data-handlepos":t,"data-id":`${p}-${w}-${e}`,className:je(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",$,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!b||i&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});bo.displayName="Handle";var ut=x.memo(bo);const vo=({data:e,isConnectable:t,targetPosition:n=q.Top,sourcePosition:r=q.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ut,{type:"source",position:r,isConnectable:t}));vo.displayName="DefaultNode";var Er=x.memo(vo);const _o=({data:e,isConnectable:t,sourcePosition:n=q.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ut,{type:"source",position:n,isConnectable:t}));_o.displayName="InputNode";var Eo=x.memo(_o);const No=({data:e,isConnectable:t,targetPosition:n=q.Top})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);No.displayName="OutputNode";var So=x.memo(No);const Vr=()=>null;Vr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),pn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(pn),t.selectedNodes.map(pn))&&ke(e.selectedEdges.map(pn),t.selectedEdges.map(pn))}const ko=x.memo(({onSelectionChange:e})=>{const t=Ne(),{selectedNodes:n,selectedEdges:r}=de(Df,Pf);return x.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});ko.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=de(zf);return e||t?A.createElement(ko,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Nt(e,t){x.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ie(e,t,n){x.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:w,minZoom:y,maxZoom:v,nodeExtent:p,onNodesChange:E,onEdgesChange:$,elementsSelectable:b,connectionMode:M,snapGrid:N,snapToGrid:_,translateExtent:R,connectOnClick:k,defaultEdgeOptions:O,fitView:D,fitViewOptions:B,onNodesDelete:H,onEdgesDelete:g,onNodeDrag:C,onNodeDragStart:S,onNodeDragStop:I,onSelectionDrag:L,onSelectionDragStart:j,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:X,autoPanOnConnect:F,autoPanOnNodeDrag:Z,onError:J,connectionRadius:te,isValidConnection:oe,nodeDragThreshold:ne})=>{const{setNodes:se,setEdges:pe,setDefaultNodesAndEdges:ce,setMinZoom:ue,setMaxZoom:ge,setTranslateExtent:he,setNodeExtent:ye,reset:le}=de(Ff,ke),K=Ne();return x.useEffect(()=>{const Se=r==null?void 0:r.map(Ce=>({...Ce,...O}));return ce(n,Se),()=>{le()}},[]),ie("defaultEdgeOptions",O,K.setState),ie("connectionMode",M,K.setState),ie("onConnect",s,K.setState),ie("onConnectStart",i,K.setState),ie("onConnectEnd",o,K.setState),ie("onClickConnectStart",a,K.setState),ie("onClickConnectEnd",c,K.setState),ie("nodesDraggable",l,K.setState),ie("nodesConnectable",u,K.setState),ie("nodesFocusable",d,K.setState),ie("edgesFocusable",m,K.setState),ie("edgesUpdatable",f,K.setState),ie("elementsSelectable",b,K.setState),ie("elevateNodesOnSelect",w,K.setState),ie("snapToGrid",_,K.setState),ie("snapGrid",N,K.setState),ie("onNodesChange",E,K.setState),ie("onEdgesChange",$,K.setState),ie("connectOnClick",k,K.setState),ie("fitViewOnInit",D,K.setState),ie("fitViewOnInitOptions",B,K.setState),ie("onNodesDelete",H,K.setState),ie("onEdgesDelete",g,K.setState),ie("onNodeDrag",C,K.setState),ie("onNodeDragStart",S,K.setState),ie("onNodeDragStop",I,K.setState),ie("onSelectionDrag",L,K.setState),ie("onSelectionDragStart",j,K.setState),ie("onSelectionDragStop",T,K.setState),ie("noPanClassName",P,K.setState),ie("nodeOrigin",z,K.setState),ie("rfId",X,K.setState),ie("autoPanOnConnect",F,K.setState),ie("autoPanOnNodeDrag",Z,K.setState),ie("onError",J,K.setState),ie("connectionRadius",te,K.setState),ie("isValidConnection",oe,K.setState),ie("nodeDragThreshold",ne,K.setState),Nt(e,se),Nt(t,pe),Nt(y,ue),Nt(v,ge),Nt(R,he),Nt(p,ye),null},Cs={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},jo="react-flow__node-desc",Co="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Xf({rfId:e}){const t=de(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Wf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${jo}-${e}`,style:Cs},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Co}-${e}`,style:Cs},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Xf,{rfId:e}))}var tn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=x.useState(!1),s=x.useRef(!1),i=x.useRef(new Set([])),[o,a]=x.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return x.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);i.current.add(f[y]),$s(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);$s(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Ms(e,t){return t.includes(e)?"code":"key"}function $o(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=wt(i,r);return $o(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function Mo(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=$o(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Oe(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Mo(s,n,i),s}function Ao(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const w=n().filter(v=>{var E;const p=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?p&&t.nodes.some($=>$.id===v.id):p}),y=w.every(v=>v.width&&v.height);if(w.length>0&&y){const v=on(w,d),{x:p,y:E,zoom:$}=go(v,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),b=tt.translate(p,E).scale($);return typeof t.duration=="number"&&t.duration>0?a.transform(pt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Uf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function gn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Uf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const St=()=>{},Kf={zoomIn:St,zoomOut:St,zoomTo:St,getZoom:()=>1,setViewport:St,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:St,fitBounds:St,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Ne(),{d3Zoom:t,d3Selection:n}=de(Zf,ke);return x.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(pt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(pt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(pt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=tt.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(pt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Ao(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=tt.translate(d,m).scale(u);t.transform(pt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=go(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=tt.translate(u,d).scale(m);t.transform(pt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),_r(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return _r(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=ho(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function an(){const e=Qf(),t=Ne(),n=x.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=x.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=x.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(v=>({...v}))},[]),i=x.useCallback(y=>{const{edges:v=[]}=t.getState();return v.find(p=>p.id===y)},[]),o=x.useCallback(y=>{const{getNodes:v,setNodes:p,hasDefaultNodes:E,onNodesChange:$}=t.getState(),b=v(),M=typeof y=="function"?y(b):y;if(E)p(M);else if($){const N=M.length===0?b.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));$(N)}},[]),a=x.useCallback(y=>{const{edges:v=[],setEdges:p,hasDefaultEdges:E,onEdgesChange:$}=t.getState(),b=typeof y=="function"?y(v):y;if(E)p(b);else if($){const M=b.length===0?v.map(N=>({type:"remove",id:N.id})):b.map(N=>({item:N,type:"reset"}));$(M)}},[]),c=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{getNodes:p,setNodes:E,hasDefaultNodes:$,onNodesChange:b}=t.getState();if($){const N=[...p(),...v];E(N)}else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),l=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{edges:p=[],setEdges:E,hasDefaultEdges:$,onEdgesChange:b}=t.getState();if($)E([...p,...v]);else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),u=x.useCallback(()=>{const{getNodes:y,edges:v=[],transform:p}=t.getState(),[E,$,b]=p;return{nodes:y().map(M=>({...M})),edges:v.map(M=>({...M})),viewport:{x:E,y:$,zoom:b}}},[]),d=x.useCallback(({nodes:y,edges:v})=>{const{nodeInternals:p,getNodes:E,edges:$,hasDefaultNodes:b,hasDefaultEdges:M,onNodesDelete:N,onEdgesDelete:_,onNodesChange:R,onEdgesChange:k}=t.getState(),O=(y||[]).map(C=>C.id),D=(v||[]).map(C=>C.id),B=E().reduce((C,S)=>{const I=S.parentNode||S.parentId,L=!O.includes(S.id)&&I&&C.find(T=>T.id===I);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(O.includes(S.id)||L)&&C.push(S),C},[]),H=$.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),g=H.filter(C=>D.includes(C.id));if(B||g){const C=po(B,H),S=[...g,...C],I=S.reduce((L,j)=>(L.includes(j.id)||L.push(j.id),L),[]);if((M||b)&&(M&&t.setState({edges:$.filter(L=>!I.includes(L.id))}),b&&(B.forEach(L=>{p.delete(L.id)}),t.setState({nodeInternals:new Map(p)}))),I.length>0&&(_==null||_(S),k&&k(I.map(L=>({id:L,type:"remove"})))),B.length>0&&(N==null||N(B),R)){const L=B.map(j=>({id:j.id,type:"remove"}));R(L)}}},[]),m=x.useCallback(y=>{const v=yf(y),p=v?null:t.getState().nodeInternals.get(y.id);return!v&&!p?[null,null,v]:[v?y:vs(p),p,v]},[]),f=x.useCallback((y,v=!0,p)=>{const[E,$,b]=m(y);return E?(p||t.getState().getNodes()).filter(M=>{if(!b&&(M.id===$.id||!M.positionAbsolute))return!1;const N=vs(M),_=wr(N,E);return v&&_>0||_>=E.width*E.height}):[]},[]),w=x.useCallback((y,v,p=!0)=>{const[E]=m(y);if(!E)return!1;const $=wr(E,v);return p&&$>0||$>=E.width*E.height},[]);return x.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:w}),[e,n,r,s,i,o,a,c,l,u,d,f,w])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ne(),{deleteElements:r}=an(),s=tn(e,Jf),i=tn(t);x.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),x.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Ne();x.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Or(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",rt.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Br={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,yn=e=>({x:e.x,y:e.y,zoom:e.k}),kt=(e,t)=>e.target.closest(`.${t}`),As=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rs=e=>{const t=e.ctrlKey&&Mn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=yt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:w,maxZoom:y,zoomActivationKeyCode:v,preventScrolling:p=!0,children:E,noWheelClassName:$,noPanClassName:b})=>{const M=x.useRef(),N=Ne(),_=x.useRef(!1),R=x.useRef(!1),k=x.useRef(null),O=x.useRef({x:0,y:0,zoom:0}),{d3Zoom:D,d3Selection:B,d3ZoomHandler:H,userSelectionActive:g}=de(rh,ke),C=tn(v),S=x.useRef(0),I=x.useRef(!1),L=x.useRef();return th(k),x.useEffect(()=>{if(k.current){const j=k.current.getBoundingClientRect(),T=eo().scaleExtent([w,y]).translateExtent(f),P=Te(k.current).call(T),z=tt.translate(m.x,m.y).scale(Ot(m.zoom,w,y)),X=[[0,0],[j.width,j.height]],F=T.constrain()(z,X,f);T.transform(P,F),T.wheelDelta(Rs),N.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[F.x,F.y,F.k],domNode:k.current.closest(".react-flow")})}},[]),x.useEffect(()=>{B&&D&&(o&&!C&&!g?B.on("wheel.zoom",j=>{if(kt(j,$))return!1;j.preventDefault(),j.stopImmediatePropagation();const T=B.property("__zoom").k||1;if(j.ctrlKey&&i){const oe=He(j),ne=Rs(j),se=T*Math.pow(2,ne);D.scaleTo(B,se,oe,j);return}const P=j.deltaMode===1?20:1;let z=c===yt.Vertical?0:j.deltaX*P,X=c===yt.Horizontal?0:j.deltaY*P;!Mn()&&j.shiftKey&&c!==yt.Vertical&&(z=j.deltaY*P,X=0),D.translateBy(B,-(z/T)*a,-(X/T)*a,{internal:!0});const F=yn(B.property("__zoom")),{onViewportChangeStart:Z,onViewportChange:J,onViewportChangeEnd:te}=N.getState();clearTimeout(L.current),I.current||(I.current=!0,t==null||t(j,F),Z==null||Z(F)),I.current&&(e==null||e(j,F),J==null||J(F),L.current=setTimeout(()=>{n==null||n(j,F),te==null||te(F),I.current=!1},150))},{passive:!1}):typeof H<"u"&&B.on("wheel.zoom",function(j,T){if(!p&&j.type==="wheel"&&!j.ctrlKey||kt(j,$))return null;j.preventDefault(),H.call(this,j,T)},{passive:!1}))},[g,o,c,B,D,H,C,i,p,$,t,e,n]),x.useEffect(()=>{D&&D.on("start",j=>{var z,X;if(!j.sourceEvent||j.sourceEvent.internal)return null;S.current=(z=j.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=N.getState(),P=yn(j.transform);_.current=!0,O.current=P,((X=j.sourceEvent)==null?void 0:X.type)==="mousedown"&&N.setState({paneDragging:!0}),T==null||T(P),t==null||t(j.sourceEvent,P)})},[D,t]),x.useEffect(()=>{D&&(g&&!_.current?D.on("zoom",null):g||D.on("zoom",j=>{var P;const{onViewportChange:T}=N.getState();if(N.setState({transform:[j.transform.x,j.transform.y,j.transform.k]}),R.current=!!(r&&As(d,S.current??0)),(e||T)&&!((P=j.sourceEvent)!=null&&P.internal)){const z=yn(j.transform);T==null||T(z),e==null||e(j.sourceEvent,z)}}))},[g,D,e,d,r]),x.useEffect(()=>{D&&D.on("end",j=>{if(!j.sourceEvent||j.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=N.getState();if(_.current=!1,N.setState({paneDragging:!1}),r&&As(d,S.current??0)&&!R.current&&r(j.sourceEvent),R.current=!1,(n||T)&&nh(O.current,j.transform)){const P=yn(j.transform);O.current=P,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(P),n==null||n(j.sourceEvent,P)},o?150:0)}})},[D,o,d,n,r]),x.useEffect(()=>{D&&D.filter(j=>{const T=C||s,P=i&&j.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&j.button===1&&j.type==="mousedown"&&(kt(j,"react-flow__node")||kt(j,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||g||!l&&j.type==="dblclick"||kt(j,$)&&j.type==="wheel"||kt(j,b)&&(j.type!=="wheel"||o&&j.type==="wheel"&&!C)||!i&&j.ctrlKey&&j.type==="wheel"||!T&&!o&&!P&&j.type==="wheel"||!d&&(j.type==="mousedown"||j.type==="touchstart")||Array.isArray(d)&&!d.includes(j.button)&&j.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(j.button)||!j.button||j.button<=1;return(!j.ctrlKey||j.type==="wheel")&&z})},[g,D,s,i,o,l,d,u,C]),A.createElement("div",{className:"react-flow__renderer",ref:k,style:Br},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=de(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Is(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&Is(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&Is(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ct=(e,t)=>({id:e,type:"select",selected:t});function Ct(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ct(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ct(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ro=x.memo(({isSelecting:e,selectionMode:t=en.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=x.useRef(null),f=Ne(),w=x.useRef(0),y=x.useRef(0),v=x.useRef(),{userSelectionActive:p,elementsSelectable:E,dragging:$}=de(lh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),w.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},N=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,R=H=>{const{resetSelectedElements:g,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!v.current)return;const{x:S,y:I}=dt(H,v.current);g(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:I,x:S,y:I}}),r==null||r(H)},k=H=>{const{userSelectionRect:g,nodeInternals:C,edges:S,transform:I,onNodesChange:L,onEdgesChange:j,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!g)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=dt(H,v.current),X=g.startX??0,F=g.startY??0,Z={...g,x:z.xse.id),ne=te.map(se=>se.id);if(w.current!==ne.length){w.current=ne.length;const se=Ct(J,ne);se.length&&(L==null||L(se))}if(y.current!==oe.length){y.current=oe.length;const se=Ct(S,oe);se.length&&(j==null||j(se))}f.setState({userSelectionRect:Z})},O=H=>{if(H.button!==0)return;const{userSelectionRect:g}=f.getState();!p&&g&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:w.current>0}),b(),s==null||s(H)},D=H=>{p&&(f.setState({nodesSelectionActive:w.current>0}),s==null||s(H)),b()},B=E&&(e||p);return A.createElement("div",{className:je(["react-flow__pane",{dragging:$,selection:e}]),onClick:B?void 0:er(M,m),onContextMenu:er(N,m),onWheel:er(_,m),onMouseEnter:B?void 0:c,onMouseDown:B?R:void 0,onMouseMove:B?k:l,onMouseUp:B?O:void 0,onMouseLeave:B?D:u,ref:m,style:Br},d,A.createElement(oh,null))});Ro.displayName="Pane";function Io(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Io(r,t):!1}function Ts(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Io(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function To(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=wt(d,s).positionAbsolute;a=d&&Oe(m)&&Oe(f)&&Oe(d.width)&&Oe(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",rt.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=wt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=wt(d,s).positionAbsolute}const u=a&&a!=="parent"?Lr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Os=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Or(c)}})};function Vt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Nr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",rt.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Ne();return x.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Oo({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Ne(),[c,l]=x.useState(!1),u=x.useRef([]),d=x.useRef({x:null,y:null}),m=x.useRef(0),f=x.useRef(null),w=x.useRef({x:0,y:0}),y=x.useRef(null),v=x.useRef(!1),p=x.useRef(!1),E=x.useRef(!1),$=fh();return x.useEffect(()=>{if(e!=null&&e.current){const b=Te(e.current),M=({x:R,y:k})=>{const{nodeInternals:O,onNodeDrag:D,onSelectionDrag:B,updateNodePositions:H,nodeExtent:g,snapGrid:C,snapToGrid:S,nodeOrigin:I,onError:L}=a.getState();d.current={x:R,y:k};let j=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&g){const z=on(u.current,I);T=Jt(z)}if(u.current=u.current.map(z=>{const X={x:R-z.distance.x,y:k-z.distance.y};S&&(X.x=C[0]*Math.round(X.x/C[0]),X.y=C[1]*Math.round(X.y/C[1]));const F=[[g[0][0],g[0][1]],[g[1][0],g[1][1]]];u.current.length>1&&g&&!z.extent&&(F[0][0]=z.positionAbsolute.x-T.x+g[0][0],F[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+g[1][0],F[0][1]=z.positionAbsolute.y-T.y+g[0][1],F[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+g[1][1]);const Z=To(z,X,O,F,I,L);return j=j||z.position.x!==Z.position.x||z.position.y!==Z.position.y,z.position=Z.position,z.positionAbsolute=Z.positionAbsolute,z}),!j)return;H(u.current,!0,!0),l(!0);const P=s?D:nr(B);if(P&&y.current){const[z,X]=tr({nodeId:s,dragItems:u.current,nodeInternals:O});P(y.current,z,X)}},N=()=>{if(!f.current)return;const[R,k]=no(w.current,f.current);if(R!==0||k!==0){const{transform:O,panBy:D}=a.getState();d.current.x=(d.current.x??0)-R/O[2],d.current.y=(d.current.y??0)-k/O[2],D({x:R,y:k})&&M(d.current)}m.current=requestAnimationFrame(N)},_=R=>{var I;const{nodeInternals:k,multiSelectionActive:O,nodesDraggable:D,unselectNodesAndEdges:B,onNodeDragStart:H,onSelectionDragStart:g}=a.getState();p.current=!0;const C=s?H:nr(g);(!o||!i)&&!O&&s&&((I=k.get(s))!=null&&I.selected||B()),s&&i&&o&&Nr({id:s,store:a,nodeRef:e});const S=$(R);if(d.current=S,u.current=uh(k,D,S,s),C&&u.current){const[L,j]=tr({nodeId:s,dragItems:u.current,nodeInternals:k});C(R.sourceEvent,L,j)}};if(t)b.on(".drag",null);else{const R=bu().on("start",k=>{const{domNode:O,nodeDragThreshold:D}=a.getState();D===0&&_(k),E.current=!1;const B=$(k);d.current=B,f.current=(O==null?void 0:O.getBoundingClientRect())||null,w.current=dt(k.sourceEvent,f.current)}).on("drag",k=>{var H,g;const O=$(k),{autoPanOnNodeDrag:D,nodeDragThreshold:B}=a.getState();if(k.sourceEvent.type==="touchmove"&&k.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&p.current&&D&&(v.current=!0,N()),!p.current){const C=O.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=O.ySnapped-(((g=d==null?void 0:d.current)==null?void 0:g.y)??0);Math.sqrt(C*C+S*S)>B&&_(k)}(d.current.x!==O.xSnapped||d.current.y!==O.ySnapped)&&u.current&&p.current&&(y.current=k.sourceEvent,w.current=dt(k.sourceEvent,f.current),M(O))}}).on("end",k=>{if(!(!p.current||E.current)&&(l(!1),v.current=!1,p.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:O,nodeInternals:D,onNodeDragStop:B,onSelectionDragStop:H}=a.getState(),g=s?B:nr(H);if(O(u.current,!1,!1),g){const[C,S]=tr({nodeId:s,dragItems:u.current,nodeInternals:D});g(k.sourceEvent,C,S)}}}).filter(k=>{const O=k.target;return!k.button&&(!n||!Ts(O,`.${n}`,e))&&(!r||Ts(O,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,$]),c}function Lo(){const e=Ne();return x.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,w=n.isShiftPressed?4:1,y=n.x*m*w,v=n.y*f*w,p=d.map(E=>{if(E.positionAbsolute){const $={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+v};a&&($.x=c[0]*Math.round($.x/c[0]),$.y=c[1]*Math.round($.y/c[1]));const{positionAbsolute:b,position:M}=To(E,$,r,s,void 0,l);E.position=M,E.positionAbsolute=b}return E});i(p,!0,!1)},[])}const At={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Bt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:w,onDoubleClick:y,style:v,className:p,isDraggable:E,isSelectable:$,isConnectable:b,isFocusable:M,selectNodesOnDrag:N,sourcePosition:_,targetPosition:R,hidden:k,resizeObserver:O,dragHandle:D,zIndex:B,isParent:H,noDragClassName:g,noPanClassName:C,initialized:S,disableKeyboardA11y:I,ariaLabel:L,rfId:j,hasHandleBounds:T})=>{const P=Ne(),z=x.useRef(null),X=x.useRef(null),F=x.useRef(_),Z=x.useRef(R),J=x.useRef(r),te=$||E||u||d||m||f,oe=Lo(),ne=Vt(n,P.getState,d),se=Vt(n,P.getState,m),pe=Vt(n,P.getState,f),ce=Vt(n,P.getState,w),ue=Vt(n,P.getState,y),ge=le=>{const{nodeDragThreshold:K}=P.getState();if($&&(!N||!E||K>0)&&Nr({id:n,store:P,nodeRef:z}),u){const Se=P.getState().nodeInternals.get(n);Se&&u(le,{...Se})}},he=le=>{if(!br(le)&&!I)if(oo.includes(le.key)&&$){const K=le.key==="Escape";Nr({id:n,store:P,unselect:K,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(At,le.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),oe({x:At[le.key].x,y:At[le.key].y,isShiftPressed:le.shiftKey}))};x.useEffect(()=>()=>{X.current&&(O==null||O.unobserve(X.current),X.current=null)},[]),x.useEffect(()=>{if(z.current&&!k){const le=z.current;(!S||!T||X.current!==le)&&(X.current&&(O==null||O.unobserve(X.current)),O==null||O.observe(le),X.current=le)}},[k,S,T]),x.useEffect(()=>{const le=J.current!==r,K=F.current!==_,Se=Z.current!==R;z.current&&(le||K||Se)&&(le&&(J.current=r),K&&(F.current=_),Se&&(Z.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const ye=Oo({nodeRef:z,disabled:k||!E,noDragClassName:g,handleSelector:D,nodeId:n,isSelectable:$,selectNodesOnDrag:N});return k?null:A.createElement("div",{className:je(["react-flow__node",`react-flow__node-${r}`,{[C]:E},p,{selected:l,selectable:$,parent:H,dragging:ye}]),ref:z,style:{zIndex:B,transform:`translate(${a}px,${c}px)`,pointerEvents:te?"all":"none",visibility:S?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:se,onMouseLeave:pe,onContextMenu:ce,onClick:ge,onDoubleClick:ue,onKeyDown:M?he:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":I?void 0:`${jo}-${j}`,"aria-label":L},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:ye,dragHandle:D,zIndex:B})))};return t.displayName="NodeWrapper",x.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...on(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ne(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=de(hh,ke),u=Lo(),d=x.useRef(null);if(x.useEffect(()=>{var w;n||(w=d.current)==null||w.focus({preventScroll:!0})},[n]),Oo({nodeRef:d}),l||!s||!i)return null;const m=e?w=>{const y=r.getState().getNodes().filter(v=>v.selected);e(w,y)}:void 0,f=w=>{Object.prototype.hasOwnProperty.call(At,w.key)&&u({x:At[w.key].x,y:At[w.key].y,isShiftPressed:w.shiftKey})};return A.createElement("div",{className:je(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=x.memo(mh);const gh=e=>e.nodesSelectionActive,Do=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:w,onSelectionEnd:y,multiSelectionKeyCode:v,panActivationKeyCode:p,zoomActivationKeyCode:E,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:N,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:O,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,preventScrolling:C,onSelectionContextMenu:S,noWheelClassName:I,noPanClassName:L,disableKeyboardA11y:j})=>{const T=de(gh),P=tn(d),z=tn(p),X=z||O,F=z||N,Z=P||m&&X!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:F,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:!P&&X,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:I,noPanClassName:L},A.createElement(Ro,{onSelectionStart:w,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:X,isSelecting:!!Z,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:L,disableKeyboardA11y:j})))};Do.displayName="FlowRenderer";var yh=x.memo(Do);function xh(e){return de(x.useCallback(n=>e?mo(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Bt(e.input||Eo),default:Bt(e.default||Er),output:Bt(e.output||So),group:Bt(e.group||Vr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Bt(e[i]||Er),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Po=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=de(vh,ke),a=xh(e.onlyRenderVisibleElements),c=x.useRef(),l=x.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return x.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Br},a.map(u=>{var M,N,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",rt.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),w=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),v=!!(u.focusable||r&&typeof u.focusable>"u"),p=e.nodeExtent?Lr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(p==null?void 0:p.x)??0,$=(p==null?void 0:p.y)??0,b=bh({x:E,y:$,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||q.Bottom,targetPosition:u.targetPosition||q.Top,hidden:u.hidden,xPos:E,yPos:$,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:w,isConnectable:y,isFocusable:v,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((N=u[we])!=null&&N.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Po.displayName="NodeRenderer";var _h=x.memo(Po);const Eh=(e,t,n)=>n===q.Left?e-t:n===q.Right?e+t:e,Nh=(e,t,n)=>n===q.Top?e-t:n===q.Bottom?e+t:e,Ls="react-flow__edgeupdater",Ds=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:je([Ls,`${Ls}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var jt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,style:v,source:p,target:E,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,elementsSelectable:k,hidden:O,sourceHandleId:D,targetHandleId:B,onContextMenu:H,onMouseEnter:g,onMouseMove:C,onMouseLeave:S,reconnectRadius:I,onReconnect:L,onReconnectStart:j,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:X,ariaLabel:F,isFocusable:Z,isReconnectable:J,pathOptions:te,interactionWidth:oe,disableKeyboardA11y:ne})=>{const se=x.useRef(null),[pe,ce]=x.useState(!1),[ue,ge]=x.useState(!1),he=Ne(),ye=x.useMemo(()=>`url('#${vr(z,X)}')`,[z,X]),le=x.useMemo(()=>`url('#${vr(P,X)}')`,[P,X]);if(O)return null;const K=re=>{var ve;const{edges:me,addSelectedEdges:$e,unselectNodesAndEdges:W,multiSelectionActive:fe}=he.getState(),xe=me.find(Ge=>Ge.id===n);xe&&(k&&(he.setState({nodesSelectionActive:!1}),xe.selected&&fe?(W({nodes:[],edges:[xe]}),(ve=se.current)==null||ve.blur()):$e([n])),o&&o(re,xe))},Se=Ft(n,he.getState,a),Ce=Ft(n,he.getState,H),ft=Ft(n,he.getState,g),Ae=Ft(n,he.getState,C),qe=Ft(n,he.getState,S),Ie=(re,me)=>{if(re.button!==0)return;const{edges:$e,isValidConnection:W}=he.getState(),fe=me?E:p,xe=(me?B:D)||null,ve=me?"target":"source",Ge=W||Sh,it=me,Pe=$e.find(ze=>ze.id===n);ge(!0),j==null||j(re,Pe,ve);const ht=ze=>{ge(!1),T==null||T(ze,Pe,ve)};wo({event:re,handleId:xe,nodeId:fe,onConnect:ze=>L==null?void 0:L(Pe,ze),isTarget:it,getState:he.getState,setState:he.setState,isValidConnection:Ge,edgeUpdaterType:ve,onReconnectEnd:ht})},V=re=>Ie(re,!0),Y=re=>Ie(re,!1),G=()=>ce(!0),Q=()=>ce(!1),U=!k&&!o,ee=re=>{var me;if(!ne&&oo.includes(re.key)&&k){const{unselectNodesAndEdges:$e,addSelectedEdges:W,edges:fe}=he.getState();re.key==="Escape"?((me=se.current)==null||me.blur(),$e({edges:[fe.find(ve=>ve.id===n)]})):W([n])}};return A.createElement("g",{className:je(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:pe}]),onClick:K,onDoubleClick:Se,onContextMenu:Ce,onMouseEnter:ft,onMouseMove:Ae,onMouseLeave:qe,onKeyDown:Z?ee:void 0,tabIndex:Z?0:void 0,role:Z?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":F===null?void 0:F||`Edge from ${p} to ${E}`,"aria-describedby":Z?`${Co}-${X}`:void 0,ref:se},!ue&&A.createElement(e,{id:n,source:p,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,data:i,style:v,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,sourceHandleId:D,targetHandleId:B,markerStart:ye,markerEnd:le,pathOptions:te,interactionWidth:oe}),J&&A.createElement(A.Fragment,null,(J==="source"||J===!0)&&A.createElement(Ds,{position:_,centerX:$,centerY:b,radius:I,onMouseDown:V,onMouseEnter:G,onMouseOut:Q,type:"source"}),(J==="target"||J===!0)&&A.createElement(Ds,{position:R,centerX:M,centerY:N,radius:I,onMouseDown:Y,onMouseEnter:G,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",x.memo(t)};function kh(e){const t={default:jt(e.default||In),straight:jt(e.bezier||zr),step:jt(e.step||Pr),smoothstep:jt(e.step||Bn),simplebezier:jt(e.simplebezier||Dr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=jt(e[i]||In),s),n);return{...t,...r}}function Ps(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case q.Top:return{x:r+i/2,y:s};case q.Right:return{x:r+i,y:s+o/2};case q.Bottom:return{x:r+i/2,y:s+o};case q.Left:return{x:r,y:s+o/2}}}function zs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ps(n,e,t),a=Ps(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Jt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Hs(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Oe(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),w=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(w?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=de(x.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Fs={[An.Arrow]:Rh,[An.ArrowClosed]:Ih};function Th(e){const t=Ne();return x.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(Fs,e)?Fs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",rt.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=vr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},zo=({defaultColor:e,rfId:t})=>{const n=de(x.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};zo.displayName="MarkerDefinitions";var Dh=x.memo(zo);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ho=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,children:v,disableKeyboardA11y:p})=>{const{edgesFocusable:E,edgesUpdatable:$,elementsSelectable:b,width:M,height:N,connectionMode:_,nodeInternals:R,onError:k}=de(Ph,ke),O=Ah(t,R,n);return M?A.createElement(A.Fragment,null,O.map(({level:D,edges:B,isMaxLevel:H})=>A.createElement("svg",{key:D,style:{zIndex:D},width:M,height:N,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,B.map(g=>{const[C,S,I]=Hs(R.get(g.source)),[L,j,T]=Hs(R.get(g.target));if(!I||!T)return null;let P=g.type||"default";s[P]||(k==null||k("011",rt.error011(P)),P="default");const z=s[P]||s.default,X=_===_t.Strict?j.target:(j.target??[]).concat(j.source??[]),F=zs(S.source,g.sourceHandle),Z=zs(X,g.targetHandle),J=(F==null?void 0:F.position)||q.Bottom,te=(Z==null?void 0:Z.position)||q.Top,oe=!!(g.focusable||E&&typeof g.focusable>"u"),ne=g.reconnectable||g.updatable,se=typeof m<"u"&&(ne||$&&typeof ne>"u");if(!F||!Z)return k==null||k("008",rt.error008(F,g)),null;const{sourceX:pe,sourceY:ce,targetX:ue,targetY:ge}=jh(C,F,J,L,Z,te);return A.createElement(z,{key:g.id,id:g.id,className:je([g.className,i]),type:P,data:g.data,selected:!!g.selected,animated:!!g.animated,hidden:!!g.hidden,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,style:g.style,source:g.source,target:g.target,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerEnd:g.markerEnd,markerStart:g.markerStart,sourceX:pe,sourceY:ce,targetX:ue,targetY:ge,sourcePosition:J,targetPosition:te,elementsSelectable:b,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,rfId:r,ariaLabel:g.ariaLabel,isFocusable:oe,isReconnectable:se,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth,disableKeyboardA11y:p})})))),v):null};Ho.displayName="EdgeRenderer";var zh=x.memo(Ho);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=de(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=an(),n=x.useRef(!1);x.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[q.Left]:q.Right,[q.Right]:q.Left,[q.Top]:q.Bottom,[q.Bottom]:q.Top},Fo=({nodeId:e,handleType:t,style:n,type:r=lt.Bezier,CustomComponent:s,connectionStatus:i})=>{var N,_,R;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=de(x.useCallback(k=>({fromNode:k.nodeInternals.get(e),handleId:k.connectionHandleId,toX:(k.connectionPosition.x-k.transform[0])/k.transform[2],toY:(k.connectionPosition.y-k.transform[1])/k.transform[2],connectionMode:k.connectionMode}),[e]),ke),d=(N=o==null?void 0:o[we])==null?void 0:N.handleBounds;let m=d==null?void 0:d[t];if(u===_t.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(k=>k.id===a):m[0],w=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,v=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+w,p=(((R=o.positionAbsolute)==null?void 0:R.y)??0)+y,E=f==null?void 0:f.position,$=E?Bh[E]:null;if(!E||!$)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:v,fromY:p,toX:c,toY:l,fromPosition:E,toPosition:$,connectionStatus:i});let b="";const M={sourceX:v,sourceY:p,sourcePosition:E,targetX:c,targetY:l,targetPosition:$};return r===lt.Bezier?[b]=fo(M):r===lt.Step?[b]=Rn({...M,borderRadius:0}):r===lt.SmoothStep?[b]=Rn(M):r===lt.SimpleBezier?[b]=uo(M):b=`M${v},${p} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Fo.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=de(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:je(["react-flow__connection",l])},A.createElement(Fo,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Vs(e,t){return x.useRef(null),Ne(),x.useMemo(()=>t(e),[e])}const Vo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:w,onSelectionStart:y,onSelectionEnd:v,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:$,connectionLineContainerStyle:b,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,deleteKeyCode:D,onlyRenderVisibleElements:B,elementsSelectable:H,selectNodesOnDrag:g,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,preventScrolling:j,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:X,panOnScrollSpeed:F,panOnScrollMode:Z,zoomOnDoubleClick:J,panOnDrag:te,onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:se,onPaneMouseLeave:pe,onPaneScroll:ce,onPaneContextMenu:ue,onEdgeContextMenu:ge,onEdgeMouseEnter:he,onEdgeMouseMove:ye,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Se,onReconnectEnd:Ce,reconnectRadius:ft,noDragClassName:Ae,noWheelClassName:qe,noPanClassName:Ie,elevateEdgesOnSelect:V,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})=>{const ee=Vs(e,wh),re=Vs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:se,onPaneMouseLeave:pe,onPaneContextMenu:ue,onPaneScroll:ce,deleteKeyCode:D,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,onSelectionStart:y,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:J,panOnScroll:X,panOnScrollSpeed:F,panOnScrollMode:Z,panOnDrag:te,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,onSelectionContextMenu:w,preventScrolling:j,noDragClassName:Ae,noWheelClassName:qe,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:re,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:B,onEdgeContextMenu:ge,onEdgeMouseEnter:he,onEdgeMouseMove:ye,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Se,onReconnectEnd:Ce,reconnectRadius:ft,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!V,disableKeyboardA11y:Y,rfId:U},A.createElement(Yh,{style:E,type:p,component:$,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:ee,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:g,onlyRenderVisibleElements:B,noPanClassName:Ie,noDragClassName:Ae,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})))};Vo.displayName="GraphView";var Xh=x.memo(Vo);const Sr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ot={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Sr,nodeExtent:Sr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:_t.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Wh=()=>Rc((e,t)=>({...ot,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Jn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,v)=>{const p=s.get(v.id);if(p!=null&&p.hidden)s.set(p.id,{...p,[we]:{...p[we],handleBounds:void 0}});else if(p){const E=Or(v.nodeElement);!!(E.width&&E.height&&(p.width!==E.width||p.height!==E.height||v.forceUpdate))&&(s.set(p.id,{...p,[we]:{...p[we],handleBounds:{source:Os(".source",v.nodeElement,m,l),target:Os(".target",v.nodeElement,m,l)}},...E}),y.push({id:p.id,type:"dimensions",dimensions:E}))}return y},[]);Mo(s,l);const w=o||i&&!o&&Ao(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:w}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Jn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(i(),n),a=Ct(s,[])),gn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(s,n),a=Ct(i(),[])),gn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ct(u.id,!1))),l=a.map(u=>ct(u.id,!1));gn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ct(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ct(a.id,!1));gn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Lr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=tt.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:ot.connectionNodeId,connectionHandleId:ot.connectionHandleId,connectionHandleType:ot.connectionHandleType,connectionStatus:ot.connectionStatus,connectionStartHandle:ot.connectionStartHandle,connectionEndHandle:ot.connectionEndHandle}),reset:()=>e({...ot})}),Object.is),Bo=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Wh()),A.createElement(df,{value:t.current},e)};Bo.displayName="ReactFlowProvider";const Go=({children:e})=>x.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Bo,null,e);Go.displayName="ReactFlowWrapper";const Uh={input:Eo,default:Er,output:So,group:Vr},qh={default:In,straight:zr,step:Pr,smoothstep:Bn,simplebezier:Dr},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Yo=x.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Uh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onNodesDelete:O,onEdgesDelete:D,onSelectionChange:B,onSelectionDragStart:H,onSelectionDrag:g,onSelectionDragStop:C,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,connectionMode:j=_t.Strict,connectionLineType:T=lt.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,deleteKeyCode:F="Backspace",selectionKeyCode:Z="Shift",selectionOnDrag:J=!1,selectionMode:te=en.Full,panActivationKeyCode:oe="Space",multiSelectionKeyCode:ne=Mn()?"Meta":"Control",zoomActivationKeyCode:se=Mn()?"Meta":"Control",snapToGrid:pe=!1,snapGrid:ce=Zh,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:ge=!0,nodesDraggable:he,nodesConnectable:ye,nodesFocusable:le,nodeOrigin:K=Kh,edgesFocusable:Se,edgesUpdatable:Ce,elementsSelectable:ft,defaultViewport:Ae=Qh,minZoom:qe=.5,maxZoom:Ie=2,translateExtent:V=Sr,preventScrolling:Y=!0,nodeExtent:G,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:ee=!0,panOnScroll:re=!1,panOnScrollSpeed:me=.5,panOnScrollMode:$e=yt.Free,zoomOnDoubleClick:W=!0,panOnDrag:fe=!0,onPaneClick:xe,onPaneMouseEnter:ve,onPaneMouseMove:Ge,onPaneMouseLeave:it,onPaneScroll:Pe,onPaneContextMenu:ht,children:Lt,onEdgeContextMenu:ze,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ke,onEdgeMouseLeave:Pt,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:Zr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Xa,defaultEdgeOptions:Wa,elevateNodesOnSelect:Ua=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Qr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Jr,nodeDragThreshold:nc,...rc},sc)=>{const Xn=Jr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:je(["react-flow",s]),"data-testid":"rf__wrapper",id:Jr},A.createElement(Go,null,A.createElement(Xh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,selectionKeyCode:Z,selectionOnDrag:J,selectionMode:te,deleteKeyCode:F,multiSelectionKeyCode:ne,panActivationKeyCode:oe,zoomActivationKeyCode:se,onlyRenderVisibleElements:ue,selectNodesOnDrag:ge,defaultViewport:Ae,translateExtent:V,minZoom:qe,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:U,zoomOnPinch:ee,zoomOnDoubleClick:W,panOnScroll:re,panOnScrollSpeed:me,panOnScrollMode:$e,panOnDrag:fe,onPaneClick:xe,onPaneMouseEnter:ve,onPaneMouseMove:Ge,onPaneMouseLeave:it,onPaneScroll:Pe,onPaneContextMenu:ht,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,onEdgeContextMenu:ze,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ke,onEdgeMouseLeave:Pt,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:Zr,elevateEdgesOnSelect:qa,rfId:Xn,disableKeyboardA11y:Qr,nodeOrigin:K,nodeExtent:G}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,nodesDraggable:he,nodesConnectable:ye,nodesFocusable:le,edgesFocusable:Se,edgesUpdatable:Ce,elementsSelectable:ft,elevateNodesOnSelect:Ua,minZoom:qe,maxZoom:Ie,nodeExtent:G,onNodesChange:Pa,onEdgesChange:za,snapToGrid:pe,snapGrid:ce,connectionMode:j,translateExtent:V,connectOnClick:Ga,defaultEdgeOptions:Wa,fitView:Va,fitViewOptions:Ba,onNodesDelete:O,onEdgesDelete:D,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onSelectionDrag:g,onSelectionDragStart:H,onSelectionDragStop:C,noPanClassName:Zr,nodeOrigin:K,rfId:Xn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:B}),Lt,A.createElement(hf,{proOptions:Xa,position:Ya}),A.createElement(Wf,{rfId:Xn,disableKeyboardA11y:Qr})))});Yo.displayName="ReactFlow";const Xo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:w,backgroundColor:y}=i||{},v=o||w||y;return A.createElement("rect",{className:je(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?p=>m(p,e):void 0})};Xo.displayName="MiniMapNode";var em=x.memo(Xo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=de(nm,ke),c=de(tm),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:w,y}=wt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:w,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=x.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(on(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:w=!1,zoomable:y=!1,ariaLabel:v="React Flow mini map",inversePan:p=!1,zoomStep:E=10,offsetScale:$=5}){const b=Ne(),M=x.useRef(null),{boundingRect:N,viewBB:_,rfId:R}=de(am,ke),k=(e==null?void 0:e.width)??im,O=(e==null?void 0:e.height)??om,D=N.width/k,B=N.height/O,H=Math.max(D,B),g=H*k,C=H*O,S=$*H,I=N.x-(g-N.width)/2-S,L=N.y-(C-N.height)/2-S,j=g+S*2,T=C+S*2,P=`${cm}-${R}`,z=x.useRef(0);z.current=H,x.useEffect(()=>{if(M.current){const Z=Te(M.current),J=ne=>{const{transform:se,d3Selection:pe,d3Zoom:ce}=b.getState();if(ne.sourceEvent.type!=="wheel"||!pe||!ce)return;const ue=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,ge=se[2]*Math.pow(2,ue);ce.scaleTo(pe,ge)},te=ne=>{const{transform:se,d3Selection:pe,d3Zoom:ce,translateExtent:ue,width:ge,height:he}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!pe||!ce)return;const ye=z.current*Math.max(1,se[2])*(p?-1:1),le={x:se[0]-ne.sourceEvent.movementX*ye,y:se[1]-ne.sourceEvent.movementY*ye},K=[[0,0],[ge,he]],Se=tt.translate(le.x,le.y).scale(se[2]),Ce=ce.constrain()(Se,K,ue);ce.transform(pe,Ce)},oe=eo().on("zoom",w?te:null).on("zoom.wheel",y?J:null);return Z.call(oe),()=>{Z.on("zoom",null)}}},[w,y,p,E]);const X=m?Z=>{const J=He(Z);m(Z,{x:J[0],y:J[1]})}:void 0,F=f?(Z,J)=>{const te=b.getState().nodeInternals.get(J);f(Z,te)}:void 0;return A.createElement(Tr,{position:d,style:e,className:je(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:k,height:O,viewBox:`${I} ${L} ${j} ${T}`,role:"img","aria-labelledby":P,ref:M,onClick:X},v&&A.createElement("title",{id:P},v),A.createElement(sm,{onClick:F,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${I-S},${L-S}h${j+S*2}v${T+S*2}h${-j-S*2}z + M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Wo.displayName="MiniMap";var lm=x.memo(Wo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Xt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:je(["react-flow__controls-button",t]),...n},e);Xt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ne(),[f,w]=x.useState(!1),{isInteractive:y,minZoomReached:v,maxZoomReached:p}=de(pm,ke),{zoomIn:E,zoomOut:$,fitView:b}=an();if(x.useEffect(()=>{w(!0)},[]),!f)return null;const M=()=>{E(),i==null||i()},N=()=>{$(),o==null||o()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c==null||c(!y)};return A.createElement(Tr,{className:je(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Xt,{onClick:M,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:p},A.createElement(um,null)),A.createElement(Xt,{onClick:N,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(dm,null))),n&&A.createElement(Xt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Xt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},y?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=x.memo(Uo),Le;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Le||(Le={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[Le.Dots]:"#91919a",[Le.Lines]:"#eee",[Le.Cross]:"#e2e2e2"},bm={[Le.Dots]:1,[Le.Lines]:1,[Le.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function qo({id:e,variant:t=Le.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=x.useRef(null),{transform:u,patternId:d}=de(vm,ke),m=o||wm[t],f=r||bm[t],w=t===Le.Dots,y=t===Le.Cross,v=Array.isArray(n)?n:[n,n],p=[v[0]*u[2]||1,v[1]*u[2]||1],E=f*u[2],$=y?[E,E]:p,b=w?[E/i,E/i]:[$[0]/i,$[1]/i];return A.createElement("svg",{className:je(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%p[0],y:u[1]%p[1],width:p[0],height:p[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},w?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:$,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}qo.displayName="Background";var _m=x.memo(qo);const Gr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Gr+e}async function be(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function st(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new Ko(r.error??`${e}: ${n.status}`,n.status);return r}class Ko extends Error{constructor(n,r){super(n);_e(this,"status");this.status=r}}const Cx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),$x=()=>be("/api/diagnostics"),Zo=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Qo=()=>be("/api/ontology/ontologies"),Em=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>be("/api/ontology/stack"),Sm=()=>be("/api/ontology/coverage"),km=(e,t,n)=>st("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>be("/api/git/status"),Cm=()=>be("/api/git/diff"),$m=e=>st("/api/git/commit",{message:e}),Mm=()=>st("/api/git/discard",{}),Am=()=>be("/api/decisions"),Bs=(e,t)=>st(`/api/decisions/${e}/verdict`,{verdict:t}),Mx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Ax=()=>be("/api/glossary/config"),Rx=e=>st("/api/git/propose",e),Ix=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Tx=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),Ox=e=>st("/api/git/classify",{changes:e}),Lx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Dx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Px=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>be("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Gr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>st("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>st("/api/import/preview",{format:e,content:t}),zx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Hx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Fx=(e,t,n)=>fetch(`${Gr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new Ko(await r.text(),r.status);return await r.json()}),Vx=()=>be("/api/glossary/subject-areas"),Bx=e=>be(`/api/glossary/subject-area/${e}`),Gx=(e,t)=>st(`/api/glossary/subject-area/${e}/expand`,t);function Yx(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Yr="__entity_source",Xr="__entity_target",Pm=x.memo(function({data:t,selected:n}){var N;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:w}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>y(_.a)-y(R.a)||_.i-R.i).map(_=>_.a),p=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const $=!!c&&!l;let b=0;if($){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const M=(_,R)=>{const k="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:k,onMouseEnter:w?()=>w(_.id):void 0,onMouseLeave:w?()=>w(null):void 0,children:[h.jsx(ut,{id:_.id,type:"target",position:q.Left,className:"port attr-port"}),h.jsx(ut,{id:_.id,type:"source",position:q.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ut,{id:Xr,type:"target",position:q.Left,className:"port"}),h.jsx(ut,{id:Yr,type:"source",position:q.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((N=r.conceptual)==null?void 0:N.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var k;const _=(((k=r.conceptual)==null?void 0:k.ontology_refs)??[]).filter(O=>O.uri);if(_.length===0)return null;const R=_.map(O=>O.uri).join(` +`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),p.length>0&&h.jsx("div",{className:"attr-section keys",children:p.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,w,y,v,p,E,$,b,M,N,_,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(k=>k.from.entity===e.id||k.to.entity===e.id),d=k=>{var O;return((O=t.entities.find(D=>D.id===k))==null?void 0:O.name)??k};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Qe,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,name:k})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Qe,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,physical_name:k})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Qe,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:k=>r("set_definition",{id:e.id,definition:k})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((w=l==null?void 0:l.ontology_refs)==null?void 0:w.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((p=e.term_map)==null?void 0:p.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),($=e.term_map)!=null&&$.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((N=e.term_map)==null?void 0:N.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Qe,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:k,steward:((O=l==null?void 0:l.stewardship)==null?void 0:O.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Qe,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:((O=l==null?void 0:l.stewardship)==null?void 0:O.owner)??null,steward:k})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(k=>h.jsx(Xm,{a:k,entity:e,doc:t,readOnly:c,exec:r},k.id))})}),!c&&h.jsx(Wm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(k=>{const O=k.members.map(D=>{var B;return((B=e.attributes.find(H=>H.id===D))==null?void 0:B.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+k.type,children:k.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:k.name}),h.jsx("span",{className:"key-cols",children:O})]},k.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([k,O])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:k}),h.jsx("td",{className:"udp-val",children:String(O)})]},k))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(k=>{const O=k.from.entity===e.id?k.to.entity:k.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(O),children:[h.jsx("span",{className:"rel-card",children:Um(k,e.id)}),d(O)]}),(k.verb_phrase||k.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Qe,{value:k.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,verb_phrase:D})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Qe,{value:k.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,inverse_verb_phrase:D})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${k.name}`,onClick:()=>r("delete_relationship",{id:k.id}),children:"✕"})]},k.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var k;return(k=navigator.clipboard)==null?void 0:k.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Qe({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=x.useState(e);x.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Xm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Qe,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Qe,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Wm({entity:e,exec:t}){const[n,r]=x.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Um(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",mt="\0",Gs="";let Km=class{constructor(t){_e(this,"_isDirected",!0);_e(this,"_isMultigraph",!1);_e(this,"_isCompound",!1);_e(this,"_label");_e(this,"_defaultNodeLabelFn",()=>{});_e(this,"_defaultEdgeLabelFn",()=>{});_e(this,"_nodes",{});_e(this,"_in",{});_e(this,"_preds",{});_e(this,"_out",{});_e(this,"_sucs",{});_e(this,"_edgeObjs",{});_e(this,"_edgeLabels",{});_e(this,"_nodeCount",0);_e(this,"_edgeCount",0);_e(this,"_parent");_e(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[mt]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=mt,this._children[t]={},this._children[mt][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=mt;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==mt)return n}}children(t=mt){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===mt)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Ys(this._preds[n],t),Ys(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Xs(this._preds[n],t),Xs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Ys(e,t){e[t]?e[t]++:e[t]=1}function Xs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Gs+i+Gs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function sr(e,t){return Wt(e,t.v,t.w,t.name)}var Wr=Km,Qm="2.2.4",Jm={Graph:Wr,version:Qm},ep=Wr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){_e(this,"_arr",[]);_e(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=ea,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ta=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ta,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),ia(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),ia(t(i),o=>s.push(o)))}}function ia(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=sa,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=sa,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Wr,Lp=Jo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:ea,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ta,topsort:ra},Us=Jm,Be={Graph:Us.Graph,json:tp,alg:zp,version:Us.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return qs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&qs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function qs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Be.Graph,Gp=Vp;var Yp=Wp;let Xp=()=>1;function Wp(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Xp);return Up(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Up(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)ir(e,t,n,o);for(;o=s.dequeue();)ir(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(ir(e,t,n,o,!0));break}}}return r}function ir(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,jr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,jr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{jr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function jr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new oa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=da(la(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),aa(e,"border",s,t)}function og(e,t=ca){const n=[];for(let r=0;rca){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function la(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function ua(e){var t=++ug;return e+(""+t)}function da(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Ur(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=Ee.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=Ee;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=Ee;var Yn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Be.Graph,On=Yn.slack,fa=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!On(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=On(t,s)),it.node(r).rank+=n)}var Rg=fa,Ks=Yn.slack,Ig=Yn.longestPath,Tg=Be.alg.preorder,Og=Be.alg.postorder,Lg=Ee.simplify,Dg=Et;Et.initLowLimValues=Kr;Et.initCutValues=qr;Et.calcCutValue=ha;Et.leaveEdge=pa;Et.enterEdge=ga;Et.exchangeEdges=ya;function Et(e){e=Lg(e),Ig(e);var t=Rg(e);Kr(t),qr(t,e);for(var n,r;n=pa(t);)r=ga(t,e,n),ya(t,e,n,r)}function qr(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ha(e,t,n)}function ha(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Kr(e,t){arguments.length<2&&(t=e.nodes()[0]),ma(e,{},1,t)}function ma(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ma(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function pa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ga(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===Zs(e,e.node(u.v),a)&&c!==Zs(e,e.node(u.w),a));return l.reduce((u,d)=>Ks(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function Zs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Yn,xa=Fg.longestPath,Vg=fa,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Qs(e);break;case"tight-tree":Wg(e);break;case"longest-path":Xg(e);break;case"none":break;default:Qs(e)}}var Xg=xa;function Wg(e){xa(e),Vg(e)}function Qs(e){Bg(e)}var Ug=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Ln=Ee;var Qg={run:Jg,cleanup:n0};function Jg(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=e0(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=t0(e)+1;e.children().forEach(a=>wa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function wa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{wa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,w=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,v=f!==w?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:v,nestingEdge:!0}),e.setEdge(w,l,{weight:y,minlen:v,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function e0(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function t0(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function n0(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let r0=Ee;var s0=i0;function i0(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iei(e.node(t))),e.edges().forEach(t=>ei(e.edge(t)))}function ei(e){let t=e.width;e.width=e.height,e.height=t}function l0(e){e.nodes().forEach(t=>or(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(or),Object.hasOwn(n,"y")&&or(n)})}function or(e){e.y=-e.y}function u0(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let ti=Ee;var d0=f0;function f0(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=ti.applyWithChunking(Math.max,r),i=ti.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let h0=Ee.zipObject;var m0=p0;function p0(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var y0=x0;function x0(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let w0=Ee;var b0=v0;function v0(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _0(r)}function _0(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&E0(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>w0.pick(s,["vs","i","barycenter","weight"]))}function E0(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let N0=Ee;var S0=k0;function k0(e,t){let n=N0.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(j0(!!t)),c=ni(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ni(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ni(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function j0(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let C0=y0,$0=b0,M0=S0;var A0=va;function va(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=C0(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=va(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&I0(m,f)}});let u=$0(l,n);R0(u,c);let d=M0(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function R0(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function I0(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let T0=Be.Graph,O0=Ee;var L0=D0;function D0(e,t,n,r){r||(r=e.nodes());let s=P0(e),i=new T0({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function P0(e){for(var t;e.hasNode(t=O0.uniqueId("_root")););return t}var z0=H0;function H0(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let F0=d0,V0=m0,B0=A0,G0=L0,Y0=z0,X0=Be.Graph,xn=Ee;var W0=_a;function _a(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,_a);return}let n=xn.maxRank(e),r=ri(e,xn.range(1,n+1),"inEdges"),s=ri(e,xn.range(n-1,-1,-1),"outEdges"),i=F0(e);if(si(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){U0(c%2?r:s,c%4>=2),i=xn.buildLayerMatrix(e);let u=V0(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return G0(e,i,n,r.get(i)||[])})}function U0(e,t){let n=new X0;e.forEach(function(r){let s=r.graph().root,i=B0(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Y0(r,n,i.vs)})}function si(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let q0=Be.Graph,Je=Ee;var K0={positionX:ay};function Z0(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=J0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(w=>{e.predecessors(w).forEach(y=>{let v=e.node(y),p=v.order;(p{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&Ea(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function J0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ea(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function ey(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function ty(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let w=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((w,y)=>Math.min(w,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function ry(e,t,n,r){let s=new q0,i=e.graph(),o=cy(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function sy(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=ly(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-Je.applyWithChunking(Math.min,l);o!=="l"&&(u=s-Je.applyWithChunking(Math.max,l)),u&&(e[a]=Je.mapValues(c,d=>d+u))})})}function oy(e,t){return Je.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function ay(e){let t=Je.buildLayerMatrix(e),n=Object.assign(Z0(e,t),Q0(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=ty(e,s,n,c),u=ny(e,s,l.root,l.align,a==="r");a==="r"&&(u=Je.mapValues(u,d=>-d)),r[o+a]=u})});let i=sy(e,r);return iy(r,i),oy(r,e.graph().align)}function cy(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function ly(e,t){return e.node(t).width}let Na=Ee,uy=K0.positionX;var dy=fy;function fy(e){e=Na.asNonCompoundGraph(e),hy(e),Object.entries(uy(e)).forEach(([t,n])=>e.node(t).x=n)}function hy(e){let t=Na.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ii=pg,oi=bg,my=Gg,py=Ee.normalizeRanks,gy=Ug,yy=Ee.removeEmptyRanks,ai=Qg,xy=s0,ci=o0,wy=W0,by=dy,De=Ee,vy=Be.Graph;var _y=Ey;function Ey(e,t){let n=t&&t.debugTiming?De.time:De.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>Iy(e));n(" runLayout",()=>Ny(r,n,t)),n(" updateInputGraph",()=>Sy(e,r))})}function Ny(e,t,n){t(" makeSpaceForEdgeLabels",()=>Ty(e)),t(" removeSelfEdges",()=>By(e)),t(" acyclic",()=>ii.run(e)),t(" nestingGraph.run",()=>ai.run(e)),t(" rank",()=>my(De.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Oy(e)),t(" removeEmptyRanks",()=>yy(e)),t(" nestingGraph.cleanup",()=>ai.cleanup(e)),t(" normalizeRanks",()=>py(e)),t(" assignRankMinMax",()=>Ly(e)),t(" removeEdgeLabelProxies",()=>Dy(e)),t(" normalize.run",()=>oi.run(e)),t(" parentDummyChains",()=>gy(e)),t(" addBorderSegments",()=>xy(e)),t(" order",()=>wy(e,n)),t(" insertSelfEdges",()=>Gy(e)),t(" adjustCoordinateSystem",()=>ci.adjust(e)),t(" position",()=>by(e)),t(" positionSelfEdges",()=>Yy(e)),t(" removeBorderNodes",()=>Vy(e)),t(" normalize.undo",()=>oi.undo(e)),t(" fixupEdgeLabelCoords",()=>Hy(e)),t(" undoCoordinateSystem",()=>ci.undo(e)),t(" translateGraph",()=>Py(e)),t(" assignNodeIntersects",()=>zy(e)),t(" reversePoints",()=>Fy(e)),t(" acyclic.undo",()=>ii.undo(e))}function Sy(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let ky=["nodesep","edgesep","ranksep","marginx","marginy"],jy={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Cy=["acyclicer","ranker","rankdir","align"],$y=["width","height","rank"],li={width:0,height:0},My=["minlen","weight","width","height","labeloffset"],Ay={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ry=["labelpos"];function Iy(e){let t=new vy({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},jy,cr(n,ky),De.pick(n,Cy))),e.nodes().forEach(r=>{let s=lr(e.node(r));const i=cr(s,$y);Object.keys(li).forEach(o=>{i[o]===void 0&&(i[o]=li[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},Ay,cr(s,My),De.pick(s,Ry)))}),t}function Ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Oy(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};De.addDummyNode(e,"edge-proxy",i,"_ep")}})}function Ly(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Dy(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Py(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function zy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(De.intersectRect(r,i)),n.points.push(De.intersectRect(s,o))})}function Hy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Fy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Vy(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function By(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Gy(e){var t=De.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{De.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Yy(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return De.mapValues(De.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Xy=Ee,Wy=Be.Graph;var Uy={debugOrdering:qy};function qy(e){let t=Xy.buildLayerMatrix(e),n=new Wy({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var Ky="1.1.8",Zy={graphlib:Be,layout:_y,debug:Uy,util:{time:Ee.time,notime:Ee.notime},version:Ky};const ui=vi(Zy),We=264,Qy=44,Jy=26,ex=14;function bt(e){const t=Math.max(e.attributes.length,1);return Qy+t*Jy+ex}const tx=40;function ur(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?mi(e,n,o):r==="clustered"?hi(e,t,n,o,i):r==="hierarchical"||e.length<=tx?di(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?hi(e,t,n,o,i):mi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Sa(e,t,n,r=!1,s="LR"){const i=new ui.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:We,height:d?bt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ui.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?bt(m):120,w=d.x-We/2,y=d.y-f/2;return a=Math.max(a,w+We),c=Math.max(c,y+f),{...u,position:{x:w,y}}}),width:a,height:c}}function di(e,t,n,r="LR"){return Sa(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?bt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(We+ka);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+We)}),i+=Math.max(...c.map(l=>n(l.id)))+ja}return{nodes:s,width:o,height:i}}const fi=120;function hi(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),w=new Set(f.map(E=>E.id));let y=0;for(const E of t)w.has(E.source)&&w.has(E.target)&&y++;const p=f.length<=8&&y>=f.length-1?Sa(f,t,n,!0,s):rx(f,n);return{name:m,...p}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const ka=40,ja=40;function mi(e,t,n){const r=l=>{const u=t.get(l);return u?bt(u):120},s=[...e].sort((l,u)=>{var y,v;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,w=((v=t.get(u.id))==null?void 0:v.name)??u.id;return f.localeCompare(w)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(We+ka)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ja}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function cn({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ca=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var b,M;const[r,s]=x.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[i,o]=x.useState([]),[a,c]=x.useState(null),[l,u]=x.useState(null),[d,m]=x.useState("skos:exactMatch"),[f,w]=x.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,v]=x.useState([]),[p,E]=x.useState("");x.useEffect(()=>{Qo().then(N=>v(N.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const N=setTimeout(()=>{if(!r.trim())return o([]);Zo(r,p||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(N)},[r,p]);const $=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(cn,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(p===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(N=>h.jsx("button",{className:"src-chip"+(p===N.id?" active":""),title:N.count!=null?`${N.count} terms`:"live resolver",onClick:()=>E(N.id),children:N.name},N.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:p?`Search within ${p}…`:"Search vocabulary terms…",value:r,onChange:N=>s(N.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(N=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===N.iri?" picked":""),onClick:()=>u(N),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:N.label}),h.jsxs("span",{className:"term-source",children:[N.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),N.source]})]}),h.jsx("code",{className:"term-iri",children:N.prefixed}),N.definition&&h.jsx("p",{className:"term-def",children:N.definition})]},N.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:N=>m(N.target.value),children:sx.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:N=>w(N.target.value),children:Ca.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:$,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var b,M,N;const[s,i]=x.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[o,a]=x.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},w=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${w}:`,v=(N=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:N.members.map(_=>{var R;return(R=e.attributes.find(k=>k.id===_))==null?void 0:R.name}).filter(Boolean),p=v&&v.length?`${y}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,$=s.trim()||p;return h.jsxs(cn,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",$]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=x.useState(""),[o,a]=x.useState(""),[c,l]=x.useState(""),[u,d]=x.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const w=f==null?void 0:f.created_id;n(),w&&r(w)})};return h.jsxs(cn,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ca.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const $a=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=x.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=x.useState(r??""),[m,f]=x.useState(s??(l==null?void 0:l.id)??""),[w,y]=x.useState("many_to_one"),[v,p]=x.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",$=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:w,optionality:v}).then(o);return h.jsxs(cn,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:w,onChange:b=>y(b.target.value),children:$a.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>p(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:$,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=p=>{var E;return((E=t.entities.find($=>$.id===p))==null?void 0:E.name)??"?"},[i,o]=x.useState(e.name),[a,c]=x.useState(e.cardinality),[l,u]=x.useState(e.optionality),[d,m]=x.useState(e.identifying),[f,w]=x.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(cn,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:p=>o(p.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:p=>c(p.target.value),children:$a.map(p=>h.jsx("option",{children:p},p))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:p=>u(p.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:p=>m(p.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>w(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const pi=10,ux=6,Ye=24;function dx(e,t){return t?e:Math.round(e/pi)*pi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-Ye,o.right+Ye);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eF.transform[2]),[m,f]=x.useState(null),w=x.useRef(!1),y=x.useRef(0),v=c==null?void 0:c.onRouteChange,p=!!v,E=m??(c==null?void 0:c.routeX),[$,b,M]=Rn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),N=c==null?void 0:c.relationship,_=(c==null?void 0:c.dimmed)??!1,R=(N==null?void 0:N.cardinality)??"many_to_one",k=(N==null?void 0:N.optionality)==="optional",O=(N==null?void 0:N.identifying)??!1,D=R==="many_to_one"||R==="many_to_many",B=R==="one_to_many"||R==="many_to_many",H="rel-edge"+(l?" selected":"")+(_?" dimmed":""),g=((c==null?void 0:c.memberCount)??0)>1,C=c==null?void 0:c.onHoverEdge,S=E??b,I=M,L=S,j=I,T=x.useCallback(F=>v&&N&&v(N.id,F),[v,N]),P=x.useCallback(F=>{var pe,ce;if(!p||F.button!==0)return;F.stopPropagation(),(ce=(pe=F.target).setPointerCapture)==null||ce.call(pe,F.pointerId),w.current=!0,y.current=0;const J=u({x:F.clientX,y:F.clientY}).x;let te=0,oe=E??S;const ne=ue=>{const ge=u({x:ue.clientX,y:ue.clientY});y.current=Math.max(y.current,Math.abs(ge.x-J)),oe=mx(ge.x,{shift:ue.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),te||(te=requestAnimationFrame(()=>{te=0,f(oe)}))},se=()=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",se),te&&cancelAnimationFrame(te),w.current=!1,f(null),y.current>=gi&&T(oe)};window.addEventListener("pointermove",ne),window.addEventListener("pointerup",se)},[p,u,E,S,c,n,s,T]),z=x.useCallback(F=>{y.current>=gi&&(F.stopPropagation(),y.current=0)},[]),X=x.useCallback(F=>{p&&(F.stopPropagation(),T(null))},[p,T]);return h.jsxs("g",{className:H,onMouseEnter:C?()=>C(N.id):void 0,onMouseLeave:C?()=>C(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:$,fill:"none",strokeDasharray:O?void 0:"6 4"}),h.jsx("path",{d:$,fill:"none",strokeWidth:16/d,stroke:"transparent"}),h.jsx(yi,{x:n,y:r,side:o,many:D,optional:k}),h.jsx(yi,{x:s,y:i,side:a,many:B,optional:!1}),p&&((c==null?void 0:c.hovered)||l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:P,onClickCapture:z,onDoubleClick:X,children:[h.jsx("rect",{x:S-20/d,y:Math.min(r,i),width:40/d,height:Math.max(Math.abs(i-r),24/d),fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:S-5.5/d,y:I-11/d,width:11/d,height:22/d,rx:5/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I-4.5/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I+4.5/d,r:1.1/d})]}),(l||g)&&N&&h.jsxs("text",{className:"rel-label",x:L,y:j-8,children:[l?N.verb_phrase||N.name:"",g?`${l?" ":""}(${c.memberCount})`:""]})]})});function yi({x:e,y:t,side:n,many:r,optional:s}){const i=n===q.Left?-1:1,o=7,a=12,c=[];return r?c.push(h.jsx("path",{className:"rel-glyph",d:`M ${e+i*a} ${t} L ${e} ${t-o} M ${e+i*a} ${t} L ${e} ${t} M ${e+i*a} ${t} L ${e} ${t+o}`,fill:"none"},"foot")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a-3),y1:t-o,x2:e+i*(a-3),y2:t+o},"one")),s?c.push(h.jsx("circle",{className:"rel-glyph ring",cx:e+i*(a+6),cy:t,r:4},"opt")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a+5),y1:t-o,x2:e+i*(a+5),y2:t+o},"mand")),h.jsx(h.Fragment,{children:c})}const gx={entity:Pm},yx={relationship:px},xi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],wi="#8a7d6a";function xx(e,t,n){const s=We;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function wx(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Yr,targetHandle:n(e.to.entity,s)?s:Xr}}function qx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:w,fitBounds:y,getNodes:v}=an(),[p,E]=x.useState([]),[$,b]=x.useState([]),M=x.useRef(!1),N=x.useMemo(()=>{const V=u&&u.size>0?[...u].sort():null;return V?"sa:"+V.join("+"):"__all__"},[u]),_=x.useRef(null),[R,k]=x.useState(0),O=x.useRef(new Map),D=x.useRef(null);x.useEffect(()=>{if(!f){_.current=null;return}const V=O.current.get(N);if(V){_.current=V,M.current=!1,k(G=>G+1);return}let Y=!1;return f.load(N).then(G=>{Y||(O.current.set(N,G),_.current=G,M.current=!1,k(Q=>Q+1))}),()=>{Y=!0}},[f,N]);const[B,H]=x.useState(null),[g,C]=x.useState(null),[S,I]=x.useState(!1),[L,j]=x.useState(null),[T,P]=x.useState(null),[z,X]=x.useState(null),[F,Z]=x.useState(null),J=x.useRef({}),te=!t.canEdit,oe=x.useRef(null),ne=x.useCallback(()=>{f&&(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{const V={};for(const Q of v())Q.hidden||(V[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,U]of Object.entries(J.current))Y[Q]={routeX:Math.round(U)};const G={nodes:V,edges:Y};O.current.set(N,G),_.current=G,f.save(N,G)},800))},[f,v,N]),se=x.useCallback((V,Y)=>{Y==null?delete J.current[V]:J.current[V]=Y,b(G=>G.map(Q=>Q.id===V?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),ne()},[ne]),pe=x.useMemo(()=>{const V=new Map;return e.subject_areas.forEach((Y,G)=>V.set(Y.id,xi[G%xi.length])),V},[e]),ce=x.useMemo(()=>{const V=new Map;return e.entities.forEach(Y=>V.set(Y.id,Y)),V},[e]),ue=x.useMemo(()=>{const V=new Map,Y=new Map;return e.subject_areas.forEach(G=>{(G.members??[]).forEach(Q=>Y.set(Q,{id:G.id,name:G.name}))}),e.entities.forEach(G=>{var re,me;const Q=(re=G.conceptual)!=null&&re.id?Y.get(G.conceptual.id):void 0,U=(me=G.conceptual)==null?void 0:me.subject_area,ee=Q??(U?{id:U.id,name:U.name??U.id}:void 0);ee&&V.set(G.id,ee)}),V},[e]),ge=x.useCallback(V=>{var G;if(!u||u.size===0)return!1;const Y=(G=ue.get(V))==null?void 0:G.id;return!(Y&&u.has(Y))},[u,ue]),he=x.useMemo(()=>{const V=new Map,Y=(G,Q)=>{if(!Q.length)return;const U=V.get(G)??new Set;Q.forEach(ee=>U.add(ee)),V.set(G,U)};for(const G of e.relationships)Y(G.from.entity,G.from.attributes),Y(G.to.entity,G.to.attributes);return V},[e]);x.useEffect(()=>{var $e;const V=i.trim().toLowerCase(),Y=new Set;if(V)for(const W of e.entities)(W.name.toLowerCase()+" "+((($e=W.conceptual)==null?void 0:$e.name.toLowerCase())??"")+" "+W.attributes.map(xe=>xe.name.toLowerCase()).join(" ")).includes(V)&&Y.add(W.id);const G=new Set;if(r){G.add(r);for(const W of e.relationships)W.from.entity===r&&G.add(W.to.entity),W.to.entity===r&&G.add(W.from.entity)}const Q=e.entities.map(W=>{const fe=V!==""&&!Y.has(W.id),xe=r!==null&&!G.has(W.id);return{id:W.id,type:"entity",position:{x:0,y:0},hidden:ge(W.id),data:{entity:W,color:(()=>{const ve=ue.get(W.id);return ve?pe.get(ve.id)??wi:wi})(),dimmed:fe||xe,highlighted:V!==""&&Y.has(W.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(W.id))??!1,onToggleExpand:l,endpointAttrs:he.get(W.id),highlightAttrs:void 0,onHoverAttr:X}}}),U=e.relationships.filter(W=>ce.has(W.from.entity)&&ce.has(W.to.entity)).map(W=>{const{sourceHandle:fe,targetHandle:xe}=wx(W,ce),ve=r!==null&&W.from.entity!==r&&W.to.entity!==r;return{id:W.id,source:W.from.entity,target:W.to.entity,sourceHandle:fe,targetHandle:xe,type:"relationship",data:{relationship:W,dimmed:ve,memberCount:Math.max(W.from.attributes.length,W.to.attributes.length),onHoverEdge:Z}}}),ee=_.current;if(J.current={},ee)for(const[W,fe]of Object.entries(ee.edges))J.current[W]=fe.routeX;let re=Q;E(W=>{const fe=new Map(W.map(ae=>[ae.id,ae.position])),xe=Q.every(ae=>fe.has(ae.id)),ve=((u==null?void 0:u.size)??0)>0;if(M.current&&xe&&W.length>=Q.length&&!ve){const ae=Q.map(Ke=>({...Ke,position:fe.get(Ke.id)??Ke.position}));return re=ae,ae}const Ge=ve?Q.filter(ae=>!ae.hidden):Q,it=ur(Ge,U,ce,"auto",ue),Pe=new Map(it.map(ae=>[ae.id,ae.position])),ht=(ee==null?void 0:ee.nodes)??{},Lt=Object.keys(ht).length>0,ze=[],Dt=Q.map(ae=>{const Ke=ht[ae.id];if(Ke){const Pt={x:Ke.x,y:Ke.y};return ze.push({x:Pt.x,y:Pt.y,w:We,h:bt(ae.data.entity)}),{...ae,position:Pt}}return Pe.has(ae.id)?{...ae,position:Pe.get(ae.id)}:fe.has(ae.id)&&M.current?{...ae,position:fe.get(ae.id)}:ae});if(Lt)for(const ae of Dt)ht[ae.id]||ae.hidden||(ae.position=xx(ae.position,bt(ae.data.entity),ze),ze.push({x:ae.position.x,y:ae.position.y,w:We,h:bt(ae.data.entity)}));return M.current=!0,Lt||requestAnimationFrame(()=>w({padding:.15,duration:300})),re=Dt,Dt});const me=new Map;for(const W of re)me.set(W.id,{left:W.position.x,right:W.position.x+We});b(U.map(W=>({...W,data:{...W.data,routeX:J.current[W.id],onRouteChange:f?se:void 0,sourceCard:me.get(W.source),targetCard:me.get(W.target)}})))},[e,i,r,o,a,c,l,pe,ce,ue,ge,u,he,w,f,se,R]);const ye=x.useMemo(()=>{const V=new Set,Y=new Set,G=new Map,Q=(U,ee)=>{if(!ee.length)return;const re=G.get(U)??new Set;ee.forEach(me=>re.add(me)),G.set(U,re)};if(z)for(const U of e.relationships)(U.from.attributes.includes(z)||U.to.attributes.includes(z))&&(V.add(U.id),Y.add(U.from.entity),Y.add(U.to.entity),Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes));if(F){const U=e.relationships.find(ee=>ee.id===F);U&&(Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes))}return{active:z!==null,relsForAttr:V,entsForAttr:Y,hitAttrsByEntity:G}},[e,z,F]);x.useEffect(()=>{var Q;const V=i.trim().toLowerCase(),Y=new Set;if(V)for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(re=>re.name.toLowerCase()).join(" ")).includes(V)&&Y.add(U.id);const G=new Set;if(r){G.add(r);for(const U of e.relationships)U.from.entity===r&&G.add(U.to.entity),U.to.entity===r&&G.add(U.from.entity)}E(U=>U.map(ee=>{const re=V!==""&&!Y.has(ee.id),me=r!==null&&!G.has(ee.id),$e=ye.active&&!ye.entsForAttr.has(ee.id),W=re||me||$e,fe=V!==""&&Y.has(ee.id)||ye.active&&ye.entsForAttr.has(ee.id),xe=ye.hitAttrsByEntity.get(ee.id);return ee.data.dimmed===W&&ee.data.highlighted===fe&&ee.data.highlightAttrs===xe?ee:{...ee,data:{...ee.data,dimmed:W,highlighted:fe,highlightAttrs:xe}}})),b(U=>U.map(ee=>{var Ge,it,Pe;const re=(Ge=ee.data)==null?void 0:Ge.relationship,me=r!==null&&re!==void 0&&re.from.entity!==r&&re.to.entity!==r,$e=ye.active&&!ye.relsForAttr.has(ee.id),W=me||$e,fe=F===ee.id,xe=r!==null&&re!==void 0&&(re.from.entity===r||re.to.entity===r),ve=fe||xe?1e3:0;return((it=ee.data)==null?void 0:it.dimmed)===W&&((Pe=ee.data)==null?void 0:Pe.hovered)===fe&&ee.zIndex===ve?ee:{...ee,zIndex:ve,data:{...ee.data,dimmed:W,hovered:fe}}}))},[ye,F,i,r,e]),x.useEffect(()=>{var Q;const V=i.trim().toLowerCase();if(!V)return;const Y=new Set;for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(re=>re.name.toLowerCase()).join(" ")).includes(V)&&Y.add(U.id);if(!Y.size)return;const G=requestAnimationFrame(()=>{const U=v().filter(re=>Y.has(re.id));if(!U.length)return;const ee=Mf(U);y(ee,{padding:.35,duration:400})});return()=>cancelAnimationFrame(G)},[i,e,v,y]);const le=x.useCallback((V="auto",Y="LR")=>{D.current=Object.fromEntries(v().map(G=>[G.id,{x:G.position.x,y:G.position.y}])),E(G=>ur(G,$,ce,V,ue,Y)),requestAnimationFrame(()=>w({padding:.15,duration:300})),ne()},[$,ce,ue,w,v,ne]),K=x.useCallback(()=>{const V=D.current;V&&(E(Y=>Y.map(G=>V[G.id]?{...G,position:V[G.id]}:G)),D.current=null,ne())},[ne]),Se=x.useCallback(()=>{f==null||f.reset(N),O.current.delete(N),_.current=null,J.current={},M.current=!1,b(V=>V.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(V=>{const Y=ur(V,$,ce,"auto",ue);return requestAnimationFrame(()=>w({padding:.15,duration:300})),Y})},[f,N,$,ce,ue,w]),Ce=x.useCallback(V=>{s(V),E(Y=>(Y.find(Q=>Q.id===V)&&requestAnimationFrame(()=>w({nodes:[{id:V}],padding:.4,duration:400})),Y))},[w,s]);x.useImperativeHandle(m,()=>({relayout:le,fitView:()=>w({padding:.15,duration:300}),focusEntity:Ce,newEntity:()=>I(!0),resetLayout:Se,undoRelayout:K}),[le,w,Ce,Se,K]);const ft=x.useCallback(V=>{if(te||!V.source||!V.target||V.source===V.target)return;const Y=V.sourceHandle&&V.sourceHandle!==Yr?V.sourceHandle:void 0,G=V.targetHandle&&V.targetHandle!==Xr?V.targetHandle:void 0;j({from:V.source,to:V.target,fromAttr:Y,toAttr:G})},[te]),Ae=x.useCallback(async(V,Y)=>{try{return await n(V,Y)}catch(G){throw d==null||d(G instanceof Error?G.message:String(G)),G}},[n,d]),qe=r?ce.get(r)??null:null,Ie=e.relationships.find(V=>V.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Yo,{nodes:p,edges:$,nodeTypes:gx,edgeTypes:yx,onNodeClick:(V,Y)=>s(Y.id),onEdgeDoubleClick:(V,Y)=>!te&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(V,Y)=>{E(G=>G.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),ne()},onConnect:ft,nodesConnectable:!te,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:Le.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:V=>{var Y;return((Y=V.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),qe&&h.jsx(Hm,{entity:qe,doc:e,caps:t,exec:Ae,onClose:()=>s(null),onFocusEntity:Ce,onAlign:H,onEditMapping:C}),B&&h.jsx(ix,{entity:B,exec:Ae,onClose:()=>H(null)}),g&&h.jsx(ox,{entity:g,doc:e,exec:Ae,onClose:()=>C(null)}),S&&h.jsx(ax,{doc:e,exec:Ae,onClose:()=>I(!1),onCreated:Ce}),L&&h.jsx(cx,{doc:e,fromId:L.from,toId:L.to,initialFromAttr:L.fromAttr,initialToAttr:L.toAttr,exec:Ae,onClose:()=>j(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:Ae,onClose:()=>P(null)})]})}function Kx({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(bx,{}),e==="layers"&&h.jsx(_x,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(Ex,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Nx,{readOnly:n})]})}function bx(){const[e,t]=x.useState(""),[n,r]=x.useState([]),[s,i]=x.useState({loaded:0,vocabs:[]}),[o,a]=x.useState(null),[c,l]=x.useState([]),[u,d]=x.useState("");x.useEffect(()=>{Qo().then(f=>l(f.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const f=setTimeout(()=>{Zo(e||"a",u||void 0).then(w=>{r(e?w.results:[]),i({loaded:w.loaded_terms,vocabs:w.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=x.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const vx=["industry","core","domain","specialised"];function _x({refreshKey:e,onFocusEntity:t}){const[n,r]=x.useState(null),[s,i]=x.useState(null);if(x.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),vx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Ex({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=x.useState(null),[i,o]=x.useState(""),[a,c]=x.useState(""),[l,u]=x.useState(!1),d=x.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` `))).catch(()=>o(""))},[]);return x.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:i.split(` `).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index 0232928..4260232 100644 --- a/packages/server/src/mdl_server/static/index.html +++ b/packages/server/src/mdl_server/static/index.html @@ -4,9 +4,9 @@ Modelith - + - + diff --git a/packages/server/src/mdl_server/static/sme.html b/packages/server/src/mdl_server/static/sme.html index 87d79fe..0cf52f0 100644 --- a/packages/server/src/mdl_server/static/sme.html +++ b/packages/server/src/mdl_server/static/sme.html @@ -4,9 +4,9 @@ Modelith Glossary - + - + From 9f6b223b0e6e9e6d30c315b41b06141586b6db26 Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Mon, 12 Oct 2026 17:43:37 +1100 Subject: [PATCH 07/14] canvas: side-aware edge routing + resize cursor everywhere on the handle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two issues from real use: 1. Cursor. The ew-resize cursor only showed on the grip pill (the edge's own `cursor: pointer` won elsewhere), so you had to hunt for the exact spot. Now the whole handle group — grip + its full-segment grab zone — forces ew-resize. 2. Crow's-foot on a rerouted edge. getSmoothStepPath always attaches the edge to the left/right port, so a route dragged over a card still entered from the side and the crow's-foot pierced the card. Added a custom orthogonal router (edgeRouting.orthogonalPath, unit-tested) used when a route is set: when the run aligns over the target card, the line drops onto the target's top/bottom border and the crow's-foot reorients to that side. The route-clamp was relaxed to ALLOW alignment over the target card (vertical entry) while still barring the source card. EndGlyph was generalized to draw along any outward vector. Also fixed a real timing bug this surfaced: the edge card-rects were read AFTER setNodes returned, but React doesn't run the updater synchronously, so edges got stale (0,0) cards and the router never saw a real target. Edges are now emitted from inside the updater where the final positions exist. Verified live: a route dragged over a node enters from its top/bottom border with the crow's-foot on that edge; resize cursor shows anywhere on the segment. 43 canvas tests pass (incl. orthogonalPath + relaxed-clamp cases). --- canvas/src/ModelCanvas.tsx | 51 +++--- canvas/src/RelationshipEdge.tsx | 105 +++++++----- canvas/src/edgeRouting.test.ts | 79 +++++---- canvas/src/edgeRouting.ts | 160 ++++++++++++++---- canvas/src/styles.css | 5 + ...m-14z6V1AZ.js => ModelDiagram-nUeQsnnZ.js} | 2 +- .../{main-DtmhCCsm.js => main-C31opIYt.js} | 2 +- .../{sme-KzTYm7pE.js => sme-EpJn-HtT.js} | 4 +- .../static/assets/styles-BeQbzs5X.js | 23 --- .../static/assets/styles-CBRLc9al.js | 23 +++ ...tyles-BpoQ4C-h.css => styles-CK604yls.css} | 2 +- .../server/src/mdl_server/static/index.html | 6 +- .../server/src/mdl_server/static/sme.html | 6 +- 13 files changed, 307 insertions(+), 161 deletions(-) rename packages/server/src/mdl_server/static/assets/{ModelDiagram-14z6V1AZ.js => ModelDiagram-nUeQsnnZ.js} (97%) rename packages/server/src/mdl_server/static/assets/{main-DtmhCCsm.js => main-C31opIYt.js} (99%) rename packages/server/src/mdl_server/static/assets/{sme-KzTYm7pE.js => sme-EpJn-HtT.js} (99%) delete mode 100644 packages/server/src/mdl_server/static/assets/styles-BeQbzs5X.js create mode 100644 packages/server/src/mdl_server/static/assets/styles-CBRLc9al.js rename packages/server/src/mdl_server/static/assets/{styles-BpoQ4C-h.css => styles-CK604yls.css} (59%) diff --git a/canvas/src/ModelCanvas.tsx b/canvas/src/ModelCanvas.tsx index 164a709..3dd901b 100644 --- a/canvas/src/ModelCanvas.tsx +++ b/canvas/src/ModelCanvas.tsx @@ -405,7 +405,33 @@ export function ModelCanvas({ for (const [relId, r] of Object.entries(saved.edges)) routesRef.current[relId] = r.routeX; } - let mergedForCards: Node[] = newNodes; + // Build the edges from the FINAL node positions. We do this inside the setNodes + // updater (where the laid-out/saved positions exist) because React does not run the + // updater synchronously before the code after setNodes — reading positions outside it + // gave stale (0,0) card rects, so the side-aware router never saw a real target card. + const emitEdges = (ns: Node[]) => { + const cardById = new Map(); + for (const n of ns) { + cardById.set(n.id, { + left: n.position.x, + right: n.position.x + NODE_WIDTH, + top: n.position.y, + bottom: n.position.y + nodeHeight(n.data.entity), + }); + } + setEdges( + newEdges.map((e) => ({ + ...e, + data: { + ...e.data!, + routeX: routesRef.current[e.id], + onRouteChange: layoutStore ? onRouteCommit : undefined, + sourceCard: cardById.get(e.source), + targetCard: cardById.get(e.target), + }, + })), + ); + }; setNodes((prev) => { const posById = new Map(prev.map((n) => [n.id, n.position])); const known = newNodes.every((n) => posById.has(n.id)); @@ -415,7 +441,7 @@ export function ModelCanvas({ const filtering = (activeAreas?.size ?? 0) > 0; if (layoutedRef.current && known && prev.length >= newNodes.length && !filtering) { const kept = newNodes.map((n) => ({ ...n, position: posById.get(n.id) ?? n.position })); - mergedForCards = kept; + emitEdges(kept); return kept; } const toLay = filtering ? newNodes.filter((n) => !n.hidden) : newNodes; @@ -449,28 +475,9 @@ export function ModelCanvas({ // Only auto-fit when there is NO saved layout — a restored arrangement must not // be re-zoomed away. if (!hasSaved) requestAnimationFrame(() => fitView({ padding: 0.15, duration: 300 })); - mergedForCards = merged; + emitEdges(merged); return merged; }); - - // card rectangles (flow coords) so each edge can clamp its route out of its - // endpoint cards; attached to edge data to avoid a per-move node-store read. - const cardById = new Map(); - for (const n of mergedForCards) { - cardById.set(n.id, { left: n.position.x, right: n.position.x + NODE_WIDTH }); - } - setEdges( - newEdges.map((e) => ({ - ...e, - data: { - ...e.data!, - routeX: routesRef.current[e.id], - onRouteChange: layoutStore ? onRouteCommit : undefined, - sourceCard: cardById.get(e.source), - targetCard: cardById.get(e.target), - }, - })), - ); }, [ doc, query, diff --git a/canvas/src/RelationshipEdge.tsx b/canvas/src/RelationshipEdge.tsx index 2804eb2..7f96d2d 100644 --- a/canvas/src/RelationshipEdge.tsx +++ b/canvas/src/RelationshipEdge.tsx @@ -1,5 +1,6 @@ import { memo, useCallback, useRef, useState } from "react"; import { getSmoothStepPath, Position, useReactFlow, useStore, type EdgeProps } from "reactflow"; +import { adjustRouteX, orthogonalPath } from "./edgeRouting"; import type { Relationship } from "./types"; export interface RelationshipEdgeData { @@ -16,14 +17,12 @@ export interface RelationshipEdgeData { routeX?: number; /** commit a new route (or null to reset to automatic). Absent = not draggable. */ onRouteChange?: (relId: string, routeX: number | null) => void; - /** endpoint card rectangles (flow coords), for clamping the route out of cards */ - sourceCard?: { left: number; right: number }; - targetCard?: { left: number; right: number }; + /** endpoint card rectangles (flow coords), for clamping the route out of cards and for + * side-aware orthogonal routing (top/bottom entry) */ + sourceCard?: { left: number; right: number; top: number; bottom: number }; + targetCard?: { left: number; right: number; top: number; bottom: number }; } -// Keep in sync with edgeRouting.ts; imported there, inlined here to avoid a cycle -// of concerns (this file owns the pointer handling, edgeRouting owns the math). -import { adjustRouteX } from "./edgeRouting"; /** a press that moves less than this many px counts as a click, not a drag */ const CLICK_SLOP = 3; @@ -73,7 +72,7 @@ export const RelationshipEdge = memo(function RelationshipEdge({ // effective vertical-segment x: live drag wins, else the committed route. const routeX = dragX ?? data?.routeX; - const [path, autoLabelX, autoLabelY] = getSmoothStepPath({ + const [smoothPath, autoLabelX, autoLabelY] = getSmoothStepPath({ sourceX, sourceY, sourcePosition, @@ -84,6 +83,25 @@ export const RelationshipEdge = memo(function RelationshipEdge({ ...(routeX != null ? { centerX: routeX } : {}), }); + // When a route is set AND we know the card rectangles, use the side-aware orthogonal + // router so a run dragged over a node enters it from the top/bottom (and the crow's-foot + // follows). Otherwise keep the smooth-step path (the clean default / auto routing). + const sCard = data?.sourceCard; + const tCard = data?.targetCard; + const routed = + routeX != null && sCard && tCard + ? orthogonalPath( + { x: sourceX, y: sourceY }, + { x: targetX, y: targetY }, + routeX, + sourcePosition === Position.Left ? -1 : 1, + targetPosition === Position.Left ? -1 : 1, + sCard, + tCard, + ) + : null; + const path = routed ? routed.path : smoothPath; + const rel = data?.relationship; const dimmed = data?.dimmed ?? false; // from = many side (source), to = one side (target) per spec §2.3 @@ -108,6 +126,19 @@ export const RelationshipEdge = memo(function RelationshipEdge({ const labelX = handleX; const labelY = handleY; + // Crow's-foot orientation + position follow the edge's ACTUAL approach at each end. + // When the orthogonal router sends the line into a node's top/bottom, its out-vector is + // vertical and the target glyph sits on that border at routeX (not the side port). + const srcOut = routed ? routed.sourceOut : { ox: sourcePosition === Position.Left ? -1 : 1, oy: 0 }; + const tgtOut = routed ? routed.targetOut : { ox: targetPosition === Position.Left ? -1 : 1, oy: 0 }; + // glyph anchor points: the source always leaves its side port; the target glyph moves to + // the top/bottom border point when the router enters vertically. + const srcGlyph = { x: sourceX, y: sourceY }; + const tgtGlyph = + routed && tgtOut.oy !== 0 && tCard + ? { x: routeX!, y: tgtOut.oy < 0 ? tCard.top : tCard.bottom } + : { x: targetX, y: targetY }; + const commit = useCallback( (x: number | null) => onRouteChange && rel && onRouteChange(rel.id, x), [onRouteChange, rel], @@ -193,8 +224,8 @@ export const RelationshipEdge = memo(function RelationshipEdge({ /> {/* wider invisible path for easier hover/click — kept ~16px on screen at any zoom */} - - + + {/* drag handle on the vertical segment — shown while hovered, selected, or mid-drag. Sizes are divided by the zoom so the grip keeps a constant ON-SCREEN size and stays visible + grabbable however far the canvas is zoomed out. */} @@ -247,60 +278,56 @@ export const RelationshipEdge = memo(function RelationshipEdge({ function EndGlyph({ x, y, - side, + out, many, optional, }: { x: number; y: number; - side: Position; + /** outward unit vector: direction the edge leaves the node */ + out: { ox: number; oy: number }; many: boolean; optional: boolean; }) { - // dir = +1 when the glyph extends to the right of the anchor (edge leaves a - // node's right side or enters from the left); -1 mirrored. - const dir = side === Position.Left ? -1 : 1; - const s = 7; // glyph scale - const foot = 12; // crow's foot depth + const s = 7; // glyph half-width (perpendicular to the edge) + const foot = 12; // crow's foot depth (along the edge) + const { ox, oy } = out; + // perpendicular unit vector, for the bar width / crow's-foot spread + const px = -oy; + const py = ox; + // a point `d` px out from the anchor along the edge + const at = (d: number) => ({ x: x + ox * d, y: y + oy * d }); + // a point offset `w` perpendicular at distance `d` out + const off = (d: number, w: number) => ({ x: x + ox * d + px * w, y: y + oy * d + py * w }); const parts: JSX.Element[] = []; if (many) { - // three prongs fanning from a point `foot` px away from the node edge + const apex = at(foot); + const a = off(0, -s); + const b = at(0); + const c = off(0, s); parts.push( , ); } else { + const a = off(foot - 3, -s); + const b = off(foot - 3, s); parts.push( - , + , ); } if (optional) { - parts.push( - , - ); + const c = at(foot + 6); + parts.push(); } else { - parts.push( - , - ); + const a = off(foot + 5, -s); + const b = off(foot + 5, s); + parts.push(); } return <>{parts}; } diff --git a/canvas/src/edgeRouting.test.ts b/canvas/src/edgeRouting.test.ts index 4c7a2f1..a246c81 100644 --- a/canvas/src/edgeRouting.test.ts +++ b/canvas/src/edgeRouting.test.ts @@ -6,6 +6,7 @@ import { adjustRouteX, clampRouteX, magnetise, + orthogonalPath, snapRouteX, type CardX, } from "./edgeRouting"; @@ -52,41 +53,23 @@ describe("clampRouteX", () => { const sFwd: CardX = { left: 0, right: 264 }; const tFwd: CardX = { left: 600, right: 864 }; - it("forward edge keeps the run in the corridor", () => { - // corridor is [264+24, 600-24] = [288, 576] - expect(clampRouteX(400, sFwd, tFwd)).toBe(400); // already inside - expect(clampRouteX(100, sFwd, tFwd)).toBe(288); // inside source -> clamp lo - expect(clampRouteX(700, sFwd, tFwd)).toBe(576); // inside target -> clamp hi - expect(clampRouteX(280, sFwd, tFwd)).toBe(288); // in source margin -> lo + it("leaves a run that is in the corridor or outside both cards", () => { + expect(clampRouteX(400, sFwd, tFwd)).toBe(400); // corridor -> free + expect(clampRouteX(-50, sFwd, tFwd)).toBe(-50); // left of both -> free + expect(clampRouteX(950, sFwd, tFwd)).toBe(950); // right of both -> free }); - it("backward edge allows any x outside both cards", () => { - // target left of source - const s: CardX = { left: 600, right: 864 }; - const t: CardX = { left: 0, right: 264 }; - expect(clampRouteX(950, s, t)).toBe(950); // right of both -> allowed - expect(clampRouteX(-50, s, t)).toBe(-50); // left of both -> allowed - expect(clampRouteX(400, s, t)).toBe(400); // between the cards -> allowed + it("ALLOWS a run aligned over the TARGET card (vertical entry)", () => { + // 700 is inside target(600..864) -> allowed, so the orthogonal router can enter + // the target from top/bottom. + expect(clampRouteX(700, sFwd, tFwd)).toBe(700); }); - it("backward edge pushes an x that landed inside a card to its outer edge", () => { - const s: CardX = { left: 600, right: 864 }; - const t: CardX = { left: 0, right: 264 }; - // x=800 is inside source(600..864); nearer right edge (64 vs 200) -> 864+24 - expect(clampRouteX(800, s, t)).toBe(864 + CARD_MARGIN); - // x=620 is inside source; nearer left edge (20 vs 244) -> 600-24 - expect(clampRouteX(620, s, t)).toBe(600 - CARD_MARGIN); - // x=100 is inside target(0..264); nearer right edge (164 vs 100... left) -> 0-24 - expect(clampRouteX(100, s, t)).toBe(0 - CARD_MARGIN); - }); - - it("no corridor (cards too close) falls back to outside-both", () => { - const s: CardX = { left: 0, right: 264 }; - const t: CardX = { left: 280, right: 544 }; // gap 16 < 2*margin - // x inside the tiny gap but inside neither card is allowed - expect(clampRouteX(272, s, t)).toBe(272); - // x inside source -> nearest outer edge - expect(clampRouteX(10, s, t)).toBe(0 - CARD_MARGIN); + it("pushes a run out of the SOURCE card (no top/bottom port to exit)", () => { + // 100 is inside source(0..264); nearer left edge (100 vs 188) -> 0-24 + expect(clampRouteX(100, sFwd, tFwd)).toBe(0 - CARD_MARGIN); + // 200 is inside source; nearer right edge (88 vs 224) -> 264+24 + expect(clampRouteX(200, sFwd, tFwd)).toBe(264 + CARD_MARGIN); }); }); @@ -100,8 +83,9 @@ describe("adjustRouteX", () => { }); it("clamp still applies even with shift (free placement, but legal)", () => { - // shift bypasses snap+magnet but a drop inside the source card is still illegal - expect(adjustRouteX(100, { shift: true, source, target })).toBe(288); + // shift bypasses snap+magnet but a drop inside the source card is still illegal; + // 100 is inside source(0..264), nearer its left edge -> pushed to 0 - margin + expect(adjustRouteX(100, { shift: true, source, target })).toBe(0 - CARD_MARGIN); }); it("magnetises to a sibling segment when close", () => { @@ -111,3 +95,32 @@ describe("adjustRouteX", () => { ); }); }); + +describe("orthogonalPath", () => { + const src = { left: 0, right: 264, top: 0, bottom: 100 }; + const tgt = { left: 600, right: 864, top: 500, bottom: 620 }; + const s = { x: 264, y: 50 }; // source right port + const t = { x: 600, y: 560 }; // target left port + + it("routes horizontally at both ends when routeX is in the corridor", () => { + const r = orthogonalPath(s, t, 430, 1, -1, src, tgt); + expect(r.sourceOut).toEqual({ ox: 1, oy: 0 }); + expect(r.targetOut).toEqual({ ox: -1, oy: 0 }); // enters target horizontally + expect(r.path).toContain("M 264 50"); + }); + + it("enters the TARGET from the TOP when routeX is over it and source is above", () => { + // routeX = 700 is within target span (600..864); source(y=50) is above target(top=500) + const r = orthogonalPath(s, t, 700, 1, -1, src, tgt); + expect(r.targetOut).toEqual({ ox: 0, oy: -1 }); // vertical, pointing up (top entry) + // the path's last point is on the target's TOP border at routeX + expect(r.path.trimEnd().endsWith("L 700 500")).toBe(true); + }); + + it("enters the TARGET from the BOTTOM when the source sits below it", () => { + const sBelow = { x: 264, y: 900 }; + const r = orthogonalPath(sBelow, t, 700, 1, -1, src, tgt); + expect(r.targetOut).toEqual({ ox: 0, oy: 1 }); // pointing down (bottom entry) + expect(r.path.trimEnd().endsWith("L 700 620")).toBe(true); + }); +}) diff --git a/canvas/src/edgeRouting.ts b/canvas/src/edgeRouting.ts index 3ecac30..11a0bd3 100644 --- a/canvas/src/edgeRouting.ts +++ b/canvas/src/edgeRouting.ts @@ -57,44 +57,33 @@ function insideCard(x: number, card: CardX): boolean { } /** - * Keep the vertical segment out of both endpoint cards' horizontal extents. + * Keep the vertical segment legal while allowing a VERTICAL entry into the target. * - * - Forward edge (source left of target) with room between the cards: clamp to - * `[sourceRight + CARD_MARGIN, targetLeft - CARD_MARGIN]` so the run sits in - * the corridor between them. - * - Otherwise (backward edge, or overlapping cards with no corridor): allow any - * x that is outside BOTH cards; if the proposed x landed inside a card, push - * it to that card's nearest outer edge ± CARD_MARGIN. + * Valid positions for the run: + * - in the corridor outside both cards (horizontal entry), OR + * - aligned OVER the target card's horizontal span (a top/bottom entry — the + * orthogonal router then drops the line onto the target's top/bottom border). + * Never inside the SOURCE card (there is no top/bottom port to exit from there). * - * `source`/`target` are the two endpoint cards. Returns a safe x. + * So: if x is inside the source card, push it to the source's nearest outer edge. + * If x is inside the target card, LEAVE IT (vertical entry). Otherwise x is free. + * + * `source`/`target` are the two endpoint cards. Returns a legal x. */ export function clampRouteX(x: number, source: CardX, target: CardX): number { - const forward = source.right <= target.left; - if (forward) { - const lo = source.right + CARD_MARGIN; - const hi = target.left - CARD_MARGIN; - if (lo <= hi) { - // There is a corridor between the cards — keep the run inside it. - return Math.min(Math.max(x, lo), hi); - } - // Cards too close for a corridor; fall through to the outside-both rule. + // Over the target card -> allow (vertical entry into target). + if (insideCard(x, target)) return x; + // Inside the source card -> push to its nearest outer edge (+ margin). + if (insideCard(x, source)) { + const toLeft = x - (source.left - CARD_MARGIN); + const toRight = source.right + CARD_MARGIN - x; + const candidate = + toRight <= toLeft ? source.right + CARD_MARGIN : source.left - CARD_MARGIN; + // if that nudges onto the target card, that's fine (vertical entry); else return it + return candidate; } - // Backward edge, or no corridor: any x outside both cards is allowed. - if (!insideCard(x, source) && !insideCard(x, target)) return x; - // Landed inside a card — move to the nearest outer edge of whichever card - // contains it (prefer the one it is actually inside). - const offender = insideCard(x, source) ? source : target; - const toLeft = x - (offender.left - CARD_MARGIN); - const toRight = offender.right + CARD_MARGIN - x; - const candidate = - toRight <= toLeft ? offender.right + CARD_MARGIN : offender.left - CARD_MARGIN; - // The nudged candidate might now sit inside the OTHER card; if so, bounce to - // that card's far side instead. - const other = offender === source ? target : source; - if (insideCard(candidate, other)) { - return candidate <= other.left ? other.left - CARD_MARGIN : other.right + CARD_MARGIN; - } - return candidate; + // Outside both cards -> free. + return x; } /** @@ -118,3 +107,108 @@ export function adjustRouteX( : magnetise(snapped, opts.otherSegmentXs ?? [], opts.otherCards ?? []); return clampRouteX(magnetised, opts.source, opts.target); } + +// --- orthogonal edge path with side-aware entry ------------------------------ + +/** A 2D point in flow coordinates. */ +export interface Pt { + x: number; + y: number; +} + +/** An endpoint's outward unit vector (direction the edge leaves the node). */ +export interface Out { + ox: number; + oy: number; +} + +/** The result of routing one edge: the SVG path plus each end's approach vector, + * so the crow's-foot glyph can be drawn on the side the line actually crosses. */ +export interface Routed { + path: string; + sourceOut: Out; + targetOut: Out; +} + +const R = 10; // corner radius + +/** Round a corner from `prev`→`corner`→`next` with radius `r` (clamped to the shorter + * leg), returning the SVG snippet from the entry tangent to the exit tangent. */ +function corner(prev: Pt, c: Pt, next: Pt, r: number): string { + const d1 = Math.hypot(c.x - prev.x, c.y - prev.y); + const d2 = Math.hypot(next.x - c.x, next.y - c.y); + const rr = Math.max(0, Math.min(r, d1 / 2, d2 / 2)); + const t1 = { x: c.x + ((prev.x - c.x) / (d1 || 1)) * rr, y: c.y + ((prev.y - c.y) / (d1 || 1)) * rr }; + const t2 = { x: c.x + ((next.x - c.x) / (d2 || 1)) * rr, y: c.y + ((next.y - c.y) / (d2 || 1)) * rr }; + return `L ${t1.x} ${t1.y} Q ${c.x} ${c.y} ${t2.x} ${t2.y} `; +} + +/** Build an orthogonal SVG path through the given waypoints with rounded corners. */ +function polyline(pts: Pt[]): string { + if (pts.length < 2) return ""; + let d = `M ${pts[0].x} ${pts[0].y} `; + for (let i = 1; i < pts.length - 1; i++) d += corner(pts[i - 1], pts[i], pts[i + 1], R); + const last = pts[pts.length - 1]; + d += `L ${last.x} ${last.y}`; + return d; +} + +/** + * Route an orthogonal edge whose vertical segment sits at `routeX`, choosing which SIDE + * of each node the line enters so the crow's-foot lands on the border the line crosses. + * + * Ports are on the node's left/right (source exits right, target enters left by default). + * Cases: + * - routeX in the corridor between the cards → classic 3-segment Z, both ends horizontal. + * - routeX aligned over/under the TARGET card → the line drops straight onto the target's + * top or bottom edge; target approach becomes vertical, so its glyph reorients. + * - likewise for the SOURCE when routeX is over/under it. + * + * `srcSide`/`tgtSide` are the horizontal port sides (+1 right, -1 left). `cards` give the + * vertical extent (top/bottom) and horizontal extent so we can pick the entry border. + */ +export function orthogonalPath( + s: Pt, + t: Pt, + routeX: number, + srcSide: 1 | -1, + tgtSide: 1 | -1, + srcCard: { left: number; right: number; top: number; bottom: number }, + tgtCard: { left: number; right: number; top: number; bottom: number }, +): Routed { + const STUB = 12; // minimum horizontal stub out of a port before turning + + // Does routeX fall within a card's horizontal span (i.e. the vertical run is over/under it)? + const overTarget = routeX > tgtCard.left && routeX < tgtCard.right; + const overSource = routeX > srcCard.left && routeX < srcCard.right; + + const pts: Pt[] = []; + let sourceOut: Out = { ox: srcSide, oy: 0 }; + let targetOut: Out = { ox: tgtSide, oy: 0 }; + + // --- SOURCE exit: horizontal stub out of the side port, then vertical at routeX. + // (When routeX is over the source, the stub direction is still the port side; the run + // then rises/falls at routeX. A vertical source exit would need a top/bottom port, which + // we do not have, so the source keeps a horizontal stub.) --- + if (overSource) { + pts.push({ x: s.x, y: s.y }, { x: s.x + srcSide * STUB, y: s.y }, { x: routeX, y: s.y }); + } else { + pts.push({ x: s.x, y: s.y }, { x: routeX, y: s.y }); + } + + // --- TARGET entry --- + if (overTarget) { + // The run drops straight onto the target's nearest horizontal border at routeX. + // fromAbove: the vertical run reaches the target from above (source sits higher), so + // it lands on the TOP border and the glyph points up; else the BOTTOM border, pointing + // down. The endpoint moves to (routeX, border) — a true vertical entry. + const fromAbove = s.y <= t.y; + const border = fromAbove ? tgtCard.top : tgtCard.bottom; + pts.push({ x: routeX, y: border }); + targetOut = { ox: 0, oy: fromAbove ? -1 : 1 }; + } else { + pts.push({ x: routeX, y: t.y }, { x: t.x, y: t.y }); + } + + return { path: polyline(pts), sourceOut, targetOut }; +} diff --git a/canvas/src/styles.css b/canvas/src/styles.css index c310b28..64dc955 100644 --- a/canvas/src/styles.css +++ b/canvas/src/styles.css @@ -257,6 +257,11 @@ body { font-family: var(--font); background: var(--bg); color: var(--text); } .rel-label { fill: var(--text); font-size: 11px; text-anchor: middle; paint-order: stroke; stroke: var(--bg); stroke-width: 4px; } /* draggable edge route handle (grip on the vertical segment). Sizes are set per-zoom in the component (zoom-invariant), so here we only style colour. */ +.rel-handle { cursor: ew-resize; } +/* the whole handle group (grip + its grab zone) shows the resize cursor, overriding + the edge's default pointer so you get drag feedback anywhere along the segment, + not only on the grip pill. */ +.rel-handle, .rel-handle * { cursor: ew-resize !important; } .rel-handle .rel-grip { fill: var(--accent); stroke: var(--bg); opacity: 0.95; } .rel-handle .rel-grip-dot { fill: var(--bg); } .rel-handle:hover .rel-grip { fill: var(--accent); filter: brightness(1.15); } diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-14z6V1AZ.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-nUeQsnnZ.js similarity index 97% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-14z6V1AZ.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-nUeQsnnZ.js index bd79f2d..a486e57 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-14z6V1AZ.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-nUeQsnnZ.js @@ -1 +1 @@ -import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-BeQbzs5X.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; +import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-CBRLc9al.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; diff --git a/packages/server/src/mdl_server/static/assets/main-DtmhCCsm.js b/packages/server/src/mdl_server/static/assets/main-C31opIYt.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-DtmhCCsm.js rename to packages/server/src/mdl_server/static/assets/main-C31opIYt.js index 057253e..3c1eb7d 100644 --- a/packages/server/src/mdl_server/static/assets/main-DtmhCCsm.js +++ b/packages/server/src/mdl_server/static/assets/main-C31opIYt.js @@ -1,2 +1,2 @@ -import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-BeQbzs5X.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` +import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-CBRLc9al.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` `)||"model valid",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),M]}):F?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14}),F]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!u&&e.jsxs("button",{className:"tool-btn primary",onClick:A,title:"New entity (n)",children:[e.jsx(ye,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),E("ontology",e.jsx(be,{size:15}),"Ontology","Ontology browser"),E("layers",e.jsx(we,{size:15}),"Layers","Four-layer stack & coverage"),E("changes",e.jsx(ve,{size:15}),"Changes",k?"Uncommitted changes":"Changes",k),E("decisions",e.jsx(Me,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(w?" active":""),onClick:g,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(m?" active":""),onClick:p,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Ne,{size:15})}),e.jsx(Ke,{onRelayout:f,onReset:v}),e.jsx("button",{className:"grp-btn icon-only",onClick:y,title:"Fit view","aria-label":"Fit view",children:e.jsx(ke,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:r,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Se,{size:15})}),e.jsx(de,{exec:S,canEdit:!u,onImported:I,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:_,openImport:$})]})]})]})}const U=["LR","TB","RL","BT"],$e={LR:0,TB:90,RL:180,BT:270},se={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function Ke({onRelayout:s,onReset:l}){const[j,h]=a.useState(!1),[x,w]=a.useState("LR"),[g,m]=a.useState("auto"),p=a.useRef(null);a.useEffect(()=>{if(!j)return;const r=u=>{p.current&&!p.current.contains(u.target)&&h(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[j]);const y=r=>{m(r),s(r,x)},f=r=>{y(r),h(!1)},v=()=>{const r=U[(U.indexOf(x)+1)%U.length];w(r),s(g,r)};return e.jsxs("div",{className:"layout-picker",ref:p,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>y("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ee,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(j?" active":""),onClick:()=>h(r=>!r),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:v,title:`Flow direction: ${se[x]} (click to rotate)`,"aria-label":`Flow direction: ${se[x]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${$e[x]}deg)`},children:e.jsx(Pe,{size:15})})}),j&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>f("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>f("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>f("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>f("grid"),children:"Grid"}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"layout-menu-sep",role:"separator"}),e.jsx("button",{onClick:()=>{l(),h(!1)},title:"Clear saved positions and routes for this view",children:"Reset layout"})]})]})]})}function He(){const[s,l]=a.useState(null),[j,h]=a.useState(null),[x,w]=a.useState(null),[g,m]=a.useState(null),[p,y]=a.useState(""),[f,v]=a.useState(!0),[r,u]=a.useState(!1),[k,b]=a.useState(()=>new Set),[q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[z,D]=a.useState(()=>new Set),[K,M]=a.useState(!1),[F,E]=a.useState(0),o=a.useRef(null),L=a.useRef(""),B=a.useRef(!1),O=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((c,n)=>t.set(c.id,Y[n%Y.length])),t},[s]),H=a.useMemo(()=>{const t=new Map;if(!s)return t;const c=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(d=>c.set(d,n.id))}),s.entities.forEach(n=>{var N,Q,X;const P=((N=n.conceptual)!=null&&N.id?c.get(n.conceptual.id):void 0)??((X=(Q=n.conceptual)==null?void 0:Q.subject_area)==null?void 0:X.id)??"";t.set(n.id,P)}),t},[s]),te=a.useMemo(()=>{const t=new Map;return H.forEach(c=>t.set(c,(t.get(c)??0)+1)),t},[H]),R=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>ge(R),[R]),ae=a.useMemo(()=>ue(),[]),V=a.useMemo(()=>new URLSearchParams(window.location.search),[]),T=V.get("minimal")==="1";a.useEffect(()=>{T&&u(!0)},[T]);const re=a.useCallback(t=>{b(c=>{const n=new Set(c);return n.has(t)?n.delete(t):n.add(t),n})},[]),ce=V.get("import")==="1",W=a.useRef(!1),C=a.useCallback(()=>{J().then(l).catch(t=>w(String(t))),Z().then(h).catch(()=>h(null)),ee().then(t=>M(!!(t.git&&!t.clean))).catch(()=>M(!1)),E(t=>t+1)},[]);a.useEffect(C,[C]),a.useEffect(()=>{const t=setInterval(()=>{J().then(c=>{l(n=>n&&c.fingerprint===n.fingerprint?n:(B.current||(L.current=c.fingerprint),T||(Z().then(h).catch(()=>h(null)),ee().then(d=>M(!!(d.git&&!d.clean))).catch(()=>M(!1))),E(d=>d+1),c))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[T]),a.useEffect(()=>{s!=null&&s.fingerprint&&(L.current=s.fingerprint)},[s]);const G=a.useCallback(async(t,c)=>{if(s){B.current=!0;try{const n=await xe(t,c,L.current||s.fingerprint);return n!=null&&n.fingerprint&&(L.current=n.fingerprint),C(),n}catch(n){throw n instanceof pe&&n.status===409?(m("Model changed on disk — view refreshed, please retry."),C()):m(n instanceof Error?n.message:String(n)),n}finally{B.current=!1}}},[s,C]);a.useEffect(()=>{if(!g)return;const t=setTimeout(()=>m(null),5e3);return()=>clearTimeout(t)},[g]),a.useEffect(()=>{if(!s||W.current)return;const t=V.get("focus");if(!t)return;const c=s.entities.find(n=>{var d;return n.name===t||((d=n.conceptual)==null?void 0:d.name)===t});c&&(W.current=!0,requestAnimationFrame(()=>{var n;return(n=o.current)==null?void 0:n.focusEntity(c.id)}))},[s,V]);const oe=a.useCallback(()=>{var n;if(!s)return;const t=p.trim().toLowerCase();if(!t)return;const c=s.entities.find(d=>{var N;return(d.name.toLowerCase()+" "+(((N=d.conceptual)==null?void 0:N.name.toLowerCase())??"")+" "+d.attributes.map(Q=>Q.name.toLowerCase()).join(" ")).includes(t)});c&&((n=o.current)==null||n.focusEntity(c.id))},[s,p]);return a.useEffect(()=>{const t=c=>{var d,P,N;const n=(d=document.activeElement)==null?void 0:d.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(c.key==="/"&&(c.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),c.key==="n"&&!R&&((N=o.current)==null||N.newEntity()),c.key==="Escape"&&(A(null),y(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[R]),x?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:x}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!T&&e.jsx(_e,{doc:s,diagnostics:j,query:p,onQuery:y,onSubmitQuery:oe,showTypes:f,onToggleTypes:()=>v(t=>!t),collapseDetail:r,onToggleCollapse:()=>u(t=>!t),onFitView:()=>{var t;return(t=o.current)==null?void 0:t.fitView()},onRelayout:(t,c)=>{var n;return(n=o.current)==null?void 0:n.relayout(t,c)},onResetLayout:()=>{var t;return(t=o.current)==null?void 0:t.resetLayout()},onRefresh:C,readOnly:R,dirty:K,panelTab:S,onPanelTab:t=>I(c=>c===t?null:t),onNewEntity:()=>{var t;return(t=o.current)==null?void 0:t.newEntity()},exec:G,onImported:C,onImportBatch:je,openImport:ce,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:z.size}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(me,{doc:s,caps:ne,exec:G,selectedId:S?null:q,onSelect:A,query:p,showTypes:f,collapseDetail:r,expandedEntities:k,onToggleExpand:re,activeAreas:z,onError:m,handleRef:o,layoutStore:ae}),!T&&e.jsx(Ae,{doc:s,saColors:O,countByArea:te,activeAreas:z,onSetActive:D,open:_,onClose:()=>$(!1)}),S&&e.jsx(fe,{tab:S,onClose:()=>I(null),readOnly:R,refreshKey:F,onModelChanged:C,onFocusEntity:t=>{var c;I(null),(c=o.current)==null||c.focusEntity(t)}}),g&&e.jsx("div",{className:"toast",children:g})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ve(){return e.jsx(he,{children:e.jsx(He,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(le.StrictMode,{children:e.jsx(Ve,{})})); diff --git a/packages/server/src/mdl_server/static/assets/sme-KzTYm7pE.js b/packages/server/src/mdl_server/static/assets/sme-EpJn-HtT.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-KzTYm7pE.js rename to packages/server/src/mdl_server/static/assets/sme-EpJn-HtT.js index 29a8779..a101f0c 100644 --- a/packages/server/src/mdl_server/static/assets/sme-KzTYm7pE.js +++ b/packages/server/src/mdl_server/static/assets/sme-EpJn-HtT.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-14z6V1AZ.js","assets/client-DOmNpTln.js","assets/styles-BeQbzs5X.js","assets/styles-BpoQ4C-h.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-BeQbzs5X.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-14z6V1AZ.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-nUeQsnnZ.js","assets/client-DOmNpTln.js","assets/styles-CBRLc9al.js","assets/styles-CK604yls.css"])))=>i.map(i=>d[i]); +import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-CBRLc9al.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-nUeQsnnZ.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); diff --git a/packages/server/src/mdl_server/static/assets/styles-BeQbzs5X.js b/packages/server/src/mdl_server/static/assets/styles-BeQbzs5X.js deleted file mode 100644 index 50bcf0b..0000000 --- a/packages/server/src/mdl_server/static/assets/styles-BeQbzs5X.js +++ /dev/null @@ -1,23 +0,0 @@ -var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _e=(e,t,n)=>oc(e,typeof t!="symbol"?t+"":t,n);import{r as x,g as vi,R as A,j as h}from"./client-DOmNpTln.js";function je(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?mc:hc;Si.useSyncExternalStore=Rt.useSyncExternalStore!==void 0?Rt.useSyncExternalStore:pc;Ni.exports=Si;var gc=Ni.exports;/** - * @license React - * use-sync-external-store-shim/with-selector.production.js - * - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var Dn=x,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=Dn.useRef,_c=Dn.useEffect,Ec=Dn.useMemo,Nc=Dn.useDebugValue;Ei.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var w=o.value;if(s(w,f))return d=w}return d=f}if(w=d,wc(u,f))return w;var y=r(f);return s!==void 0&&s(w,y)?(u=f,w):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};_i.exports=Ei;var Sc=_i.exports;const kc=vi(Sc),jc={},es=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(w=>w(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?es(e):es,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function ki(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const ts=(e,t)=>{const n=Cc(e),r=(s,i=t)=>ki(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?ts(e,t):ts;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rs.hasOwnProperty(t)?{space:rs[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===dr&&t.documentElement.namespaceURI===dr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ji(e){var t=zn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function Cr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=Cr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=$&&($=E+1);!(M=v[$])&&++$=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):It(this.node(),e)}function It(e,t){return e.style.getPropertyValue(t)||Ri(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ii(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Ti(e)}function Ti(e){this._node=e,this._names=Ii(e.getAttribute("class")||"")}Ti.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Oi(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function fr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}fr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Pn("start","drag","end"),o=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",p,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,M){if(!(u||!e.call(this,b,M))){var N=$(this,t.call(this,b,M),b,M,"mouse");N&&(Te(b.view).on("mousemove.drag",w,Ut).on("mouseup.drag",y,Ut),zi(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,N("start",b))}}function w(b){if($t(b),!l){var M=b.clientX-a,N=b.clientY-c;l=M*M+N*N>d}s.mouse("drag",b)}function y(b){Te(b.view).on("mousemove.drag mouseup.drag",null),Hi(b.view,l),$t(b),s.mouse("end",b)}function v(b,M){if(e.call(this,b,M)){var N=b.changedTouches,_=t.call(this,b,M),R=N.length,k,O;for(k=0;k>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?un(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?un(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Me(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Me(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?un(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?un(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?us(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?us(t[1],t[2]/100,t[3]/100,t[4]):ss.hasOwnProperty(e)?as(ss[e]):e==="transparent"?new Me(NaN,NaN,NaN,0):null}function as(e){return new Me(e>>16&255,e>>8&255,e&255,1)}function un(e,t,n,r){return r<=0&&(e=t=n=NaN),new Me(e,t,n,r)}function Mu(e){return e instanceof rn||(e=Zt(e)),e?(e=e.rgb(),new Me(e.r,e.g,e.b,e.opacity)):new Me}function hr(e,t,n,r){return arguments.length===1?Mu(e):new Me(e,t,n,r??1)}function Me(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Mr(Me,hr,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Me(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Me(xt(this.r),xt(this.g),xt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:cs,formatHex:cs,formatHex8:Au,formatRgb:ls,toString:ls}));function cs(){return`#${gt(this.r)}${gt(this.g)}${gt(this.b)}`}function Au(){return`#${gt(this.r)}${gt(this.g)}${gt(this.b)}${gt((isNaN(this.opacity)?1:this.opacity)*255)}`}function ls(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${xt(this.r)}, ${xt(this.g)}, ${xt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function xt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function gt(e){return e=xt(e),(e<16?"0":"")+e.toString(16)}function us(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Fe(e,t,n,r)}function Vi(e){if(e instanceof Fe)return new Fe(e.h,e.s,e.l,e.opacity);if(e instanceof rn||(e=Zt(e)),!e)return new Fe;if(e instanceof Fe)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new Fe(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Vi(e):new Fe(e,t,n,r??1)}function Fe(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Mr(Fe,Ru,Fi(rn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Fe(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?qt:Math.pow(qt,e),new Fe(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Me(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Fe(ds(this.h),dn(this.s),dn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${ds(this.h)}, ${dn(this.s)*100}%, ${dn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ds(e){return e=(e||0)%360,e<0?e+360:e}function dn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Bi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Gi:function(t,n){return n-t?Tu(t,n,e):Bi(isNaN(t)?n:t)}}function Gi(e,t){var n=t-e;return n?Iu(e,n):Bi(isNaN(e)?t:e)}const fs=function e(t){var n=Ou(t);function r(s,i){var o=n((s=hr(s)).r,(i=hr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Gi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function at(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var mr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(mr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=mr.lastIndex=Kn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=mr.exec(e))&&(s=Kn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:at(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:at(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:at(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,w){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");w.push({i:y-4,x:at(l,d)},{i:y-2,x:at(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var w=-1,y=m.length,v;++w=0&&e._call.call(void 0,t),e=e._next;--Tt}function ps(){vt=(Cn=Qt.now())+Hn,Tt=Gt=0;try{Uu()}finally{Tt=0,Ku(),vt=0}}function qu(){var e=Qt.now(),t=e-Cn;t>Wi&&(Hn-=t,Cn=e)}function Ku(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Yt=e,gr(r)}function gr(e){if(!Tt){Gt&&(Gt=clearTimeout(Gt));var t=e-vt;t>24?(e<1/0&&(Gt=setTimeout(ps,e-Qt.now()-Hn)),zt&&(zt=clearInterval(zt))):(zt||(Cn=Qt.now(),zt=setInterval(qu,Wi)),Tt=1,Ui(ps))}}function gs(e,t,n){var r=new $n;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Pn("start","end","cancel","interrupt"),Qu=[],Ki=0,ys=1,yr=2,vn=3,xs=4,xr=5,_n=6;function Fn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Ki})}function Rr(e,t){var n=Ve(e,t);if(n.state>Ki)throw new Error("too late; already scheduled");return n}function Ue(e,t){var n=Ve(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Ve(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=qi(i,0,n.time);function i(l){n.state=ys,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ys)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return gs(o);f.state===xs?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uyr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Rr:Ue;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Ve(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Cr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function et(e,t,n){this.k=e,this.x=t,this.y=n}et.prototype={constructor:et,scale:function(e){return e===1?this:new et(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new et(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var tt=new et(1,0,0);et.prototype;function Zn(e){e.stopImmediatePropagation()}function Ht(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ws(){return this.__zoom||tt}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function eo(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Xu,l=Pn("start","zoom","end"),u,d,m,f=500,w=150,y=0,v=10;function p(g){g.property("__zoom",ws).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",D).on("touchmove.zoom",B).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}p.transform=function(g,C,S,I){var L=g.selection?g.selection():g;L.property("__zoom",ws),g!==L?M(g,C,S,I):L.interrupt().each(function(){N(this,arguments).event(I).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},p.scaleBy=function(g,C,S,I){p.scaleTo(g,function(){var L=this.__zoom.k,j=typeof C=="function"?C.apply(this,arguments):C;return L*j},S,I)},p.scaleTo=function(g,C,S,I){p.transform(g,function(){var L=t.apply(this,arguments),j=this.__zoom,T=S==null?b(L):typeof S=="function"?S.apply(this,arguments):S,P=j.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n($(E(j,z),T,P),L,o)},S,I)},p.translateBy=function(g,C,S,I){p.transform(g,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,I)},p.translateTo=function(g,C,S,I,L){p.transform(g,function(){var j=t.apply(this,arguments),T=this.__zoom,P=I==null?b(j):typeof I=="function"?I.apply(this,arguments):I;return n(tt.translate(P[0],P[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof S=="function"?-S.apply(this,arguments):-S),j,o)},I,L)};function E(g,C){return C=Math.max(i[0],Math.min(i[1],C)),C===g.k?g:new et(C,g.x,g.y)}function $(g,C,S){var I=C[0]-S[0]*g.k,L=C[1]-S[1]*g.k;return I===g.x&&L===g.y?g:new et(g.k,I,L)}function b(g){return[(+g[0][0]+ +g[1][0])/2,(+g[0][1]+ +g[1][1])/2]}function M(g,C,S,I){g.on("start.zoom",function(){N(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(I).end()}).tween("zoom",function(){var L=this,j=arguments,T=N(L,j).event(I),P=t.apply(L,j),z=S==null?b(P):typeof S=="function"?S.apply(L,j):S,X=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),F=L.__zoom,Z=typeof C=="function"?C.apply(L,j):C,J=c(F.invert(z).concat(X/F.k),Z.invert(z).concat(X/Z.k));return function(te){if(te===1)te=Z;else{var oe=J(te),ne=X/oe[2];te=new et(ne,z[0]-oe[0]*ne,z[1]-oe[1]*ne)}T.zoom(null,te)}})}function N(g,C,S){return!S&&g.__zooming||new _(g,C)}function _(g,C){this.that=g,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(g,C),this.taps=0}_.prototype={event:function(g){return g&&(this.sourceEvent=g),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(g,C){return this.mouse&&g!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&g!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&g!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(g){var C=Te(this.that).datum();l.call(g,this.that,new sf(g,{sourceEvent:this.sourceEvent,target:p,transform:this.that.__zoom,dispatch:l}),C)}};function R(g,...C){if(!e.apply(this,arguments))return;var S=N(this,C).event(g),I=this.__zoom,L=Math.max(i[0],Math.min(i[1],I.k*Math.pow(2,r.apply(this,arguments)))),j=He(g);if(S.wheel)(S.mouse[0][0]!==j[0]||S.mouse[0][1]!==j[1])&&(S.mouse[1]=I.invert(S.mouse[0]=j)),clearTimeout(S.wheel);else{if(I.k===L)return;S.mouse=[j,I.invert(j)],En(this),S.start()}Ht(g),S.wheel=setTimeout(T,w),S.zoom("mouse",n($(E(I,L),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function k(g,...C){if(m||!e.apply(this,arguments))return;var S=g.currentTarget,I=N(this,C,!0).event(g),L=Te(g.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",X,!0),j=He(g,S),T=g.clientX,P=g.clientY;zi(g.view),Zn(g),I.mouse=[j,this.__zoom.invert(j)],En(this),I.start();function z(F){if(Ht(F),!I.moved){var Z=F.clientX-T,J=F.clientY-P;I.moved=Z*Z+J*J>y}I.event(F).zoom("mouse",n($(I.that.__zoom,I.mouse[0]=He(F,S),I.mouse[1]),I.extent,o))}function X(F){L.on("mousemove.zoom mouseup.zoom",null),Hi(F.view,I.moved),Ht(F),I.event(F).end()}}function O(g,...C){if(e.apply(this,arguments)){var S=this.__zoom,I=He(g.changedTouches?g.changedTouches[0]:g,this),L=S.invert(I),j=S.k*(g.shiftKey?.5:2),T=n($(E(S,j),I,L),t.apply(this,C),o);Ht(g),a>0?Te(this).transition().duration(a).call(M,T,I,g):Te(this).call(p.transform,T,I,g)}}function D(g,...C){if(e.apply(this,arguments)){var S=g.touches,I=S.length,L=N(this,C,g.changedTouches.length===I).event(g),j,T,P,z;for(Zn(g),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},to=rt.error001();function de(e,t){const n=x.useContext(Vn);if(n===null)throw new Error(to);return ki(n,e,t)}const Ne=()=>{const e=x.useContext(Vn);if(e===null)throw new Error(to);return x.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Tr({position:e,children:t,className:n,style:r,...s}){const i=de(ff),o=`${e}`.split("-");return A.createElement("div",{className:je(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Tr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=x.useRef(null),[m,f]=x.useState({x:0,y:0,width:0,height:0}),w=je(["react-flow__edge-textwrapper",l]);return x.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:w,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=x.memo(mf);const Or=e=>({width:e.offsetWidth,height:e.offsetHeight}),Ot=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Lr=(e={x:0,y:0},t)=>({x:Ot(e.x,t[0][0],t[1][0]),y:Ot(e.y,t[0][1],t[1][1])}),bs=(e,t,n)=>en?-Ot(Math.abs(e-n),1,50)/50:0,no=(e,t)=>{const n=bs(e.x,35,t.width-35)*20,r=bs(e.y,35,t.height-35)*20;return[n,r]},ro=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},so=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Jt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),io=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),vs=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>io(so(Jt(e),Jt(t))),wr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Oe(e.width)&&Oe(e.height)&&Oe(e.x)&&Oe(e.y),Oe=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),oo=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function br(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const ao=e=>"clientX"in e,dt=(e,t)=>{var i,o;const n=ao(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Mn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},sn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Oe(n)&&Oe(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);sn.displayName="BaseEdge";function Ft(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function co({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[v,p,E]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(sn,{path:v,labelX:p,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:y})});Dr.displayName="SimpleBezierEdge";const Es={[q.Left]:{x:-1,y:0},[q.Right]:{x:1,y:0},[q.Top]:{x:0,y:-1},[q.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=q.Bottom,target:n})=>t===q.Left||t===q.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=q.Bottom,target:n,targetPosition:r=q.Top,center:s,offset:i}){const o=Es[t],a=Es[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],w,y;const v={x:0,y:0},p={x:0,y:0},[E,$,b,M]=co({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){w=s.x??E,y=s.y??$;const _=[{x:w,y:c.y},{x:w,y:l.y}],R=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?R:_:f=o.y===m?_:R,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const g=Math.min(i-1,i-H);o[d]===m?v[d]=(c[d]>e[d]?-1:1)*g:p[d]=(l[d]>n[d]?-1:1)*g}}if(t!==r){const H=d==="x"?"y":"x",g=o[d]===a[H],C=c[H]>l[H],S=c[H]=B?(w=(k.x+O.x)/2,y=f[0].y):(w=f[0].x,y=(k.y+O.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:l.x+p.x,y:l.y+p.y},n],w,y,b,M]}function _f(e,t,n,r){const s=Math.min(Ns(e,t)/2,Ns(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let $="";return E>0&&E{const[p,E,$]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:w,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const Pr=x.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:x.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Pr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=co({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const zr=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[w,y,v]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(sn,{path:w,labelX:y,labelY:v,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});zr.displayName="StraightEdge";function mn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Ss({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case q.Left:return[t-mn(t-r,i),n];case q.Right:return[t+mn(r-t,i),n];case q.Top:return[t,n-mn(n-s,i)];case q.Bottom:return[t,n+mn(s-n,i)]}}function fo({sourceX:e,sourceY:t,sourcePosition:n=q.Bottom,targetX:r,targetY:s,targetPosition:i=q.Top,curvature:o=.25}){const[a,c]=Ss({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Ss({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,w]=lo({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,w]}const In=x.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=q.Bottom,targetPosition:i=q.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,pathOptions:y,interactionWidth:v})=>{const[p,E,$]=fo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(sn,{path:p,labelX:E,labelY:$,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:w,interactionWidth:v})});In.displayName="BezierEdge";const Hr=x.createContext(null),Nf=Hr.Provider;Hr.Consumer;const Sf=()=>x.useContext(Hr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,vr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},_r=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},ho=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),wt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},on=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=wt(s,t).positionAbsolute;return so(r,Jt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return io(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),on(e,t)),mo=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:w=!1}=u;if(o&&!f||w)return!1;const{positionAbsolute:y}=wt(u,a),v={x:y.x,y:y.y,width:d||0,height:m||0},p=wr(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,$=i&&p>0,b=(d||0)*(m||0);(E||$||p>=b||u.dragging)&&l.push(u)}),l},po=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},go=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Ot(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},pt=(e,t=0)=>e.transition().duration(t);function ks(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=dt(e),l=t.elementsFromPoint(o,a).find(w=>w.classList.contains("react-flow__handle"));if(l){const w=l.getAttribute("data-nodeid");if(w){const y=Fr(void 0,l),v=l.getAttribute("data-handleid"),p=i({nodeId:w,id:v,type:y});if(p){const E=s.find($=>$.nodeId===w&&$.type===y&&$.id===v);return{handle:{id:v,type:y,nodeId:w,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:p}}}}let u=[],d=1/0;if(s.forEach(w=>{const y=Math.sqrt((w.x-n.x)**2+(w.y-n.y)**2);if(y<=r){const v=i(w);y<=d&&(yw.isValid),f=u.some(({handle:w})=>w.type==="target");return u.find(({handle:w,validHandleResult:y})=>f?w.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},yo=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function xo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...yo(),handleDomNode:c};if(c){const u=Fr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),w=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&w&&(t===_t.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=ks(i,o,"source",`${t}-${n}-${r}`),c=ks(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Fr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function wo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ro(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:w,onConnectStart:y,panBy:v,getNodes:p,cancelConnection:E}=i();let $=0,b;const{x:M,y:N}=dt(e),_=u==null?void 0:u.elementFromPoint(M,N),R=Fr(c,_),k=m==null?void 0:m.getBoundingClientRect();if(!k||!R)return;let O,D=dt(e,k),B=!1,H=null,g=!1,C=null;const S=If({nodes:p(),nodeId:n,handleId:t,handleType:R}),I=()=>{if(!f)return;const[T,P]=no(D,k);v({x:T,y:P}),$=requestAnimationFrame(I)};o({connectionPosition:D,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:R});function L(T){const{transform:P}=i();D=dt(T,k);const{handle:z,validHandleResult:X}=Af(T,u,_r(D,P,!1,[1,1]),w,S,F=>xo(F,d,n,t,s?"target":"source",a,u));if(b=z,B||(I(),B=!0),C=X.handleDomNode,H=X.connection,g=X.isValid,o({connectionPosition:b&&g?ho({x:b.x,y:b.y},P):D,connectionStatus:Tf(!!b,g),connectionEndHandle:X.endHandle}),!b&&!g&&!C)return Qn(O);H.source!==H.target&&C&&(Qn(O),O=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",g),C.classList.toggle("react-flow__handle-valid",g))}function j(T){var P,z;(b||C)&&H&&g&&(r==null||r(H)),(z=(P=i()).onConnectEnd)==null||z.call(P,T),c&&(l==null||l(T)),Qn(O),E(),cancelAnimationFrame($),B=!1,g=!1,H=null,C=null,u.removeEventListener("mousemove",L),u.removeEventListener("mouseup",j),u.removeEventListener("touchmove",L),u.removeEventListener("touchend",j)}u.addEventListener("mousemove",L),u.addEventListener("mouseup",j),u.addEventListener("touchmove",L),u.addEventListener("touchend",j)}const js=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},bo=x.forwardRef(({type:e="source",position:t=q.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var k,O;const w=o||null,y=e==="target",v=Ne(),p=Sf(),{connectOnClick:E,noPanClassName:$}=de(Of,ke),{connecting:b,clickConnecting:M}=de(Lf(p,w,e),ke);p||(O=(k=v.getState()).onError)==null||O.call(k,"010",rt.error010());const N=D=>{const{defaultEdgeOptions:B,onConnect:H,hasDefaultEdges:g}=v.getState(),C={...B,...D};if(g){const{edges:S,setEdges:I}=v.getState();I($f(C,S))}H==null||H(C),a==null||a(C)},_=D=>{if(!p)return;const B=ao(D);s&&(B&&D.button===0||!B)&&wo({event:D,handleId:w,nodeId:p,onConnect:N,isTarget:y,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||js}),B?u==null||u(D):d==null||d(D)},R=D=>{const{onClickConnectStart:B,onClickConnectEnd:H,connectionClickStartHandle:g,connectionMode:C,isValidConnection:S}=v.getState();if(!p||!g&&!s)return;if(!g){B==null||B(D,{nodeId:p,handleId:w,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:p,type:e,handleId:w}});return}const I=ro(D.target),L=n||S||js,{connection:j,isValid:T}=xo({nodeId:p,id:w,type:e},C,g.nodeId,g.handleId||null,g.type,L,I);T&&N(j),H==null||H(D),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":w,"data-nodeid":p,"data-handlepos":t,"data-id":`${p}-${w}-${e}`,className:je(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",$,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!b||i&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});bo.displayName="Handle";var ut=x.memo(bo);const vo=({data:e,isConnectable:t,targetPosition:n=q.Top,sourcePosition:r=q.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ut,{type:"source",position:r,isConnectable:t}));vo.displayName="DefaultNode";var Er=x.memo(vo);const _o=({data:e,isConnectable:t,sourcePosition:n=q.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ut,{type:"source",position:n,isConnectable:t}));_o.displayName="InputNode";var Eo=x.memo(_o);const No=({data:e,isConnectable:t,targetPosition:n=q.Top})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);No.displayName="OutputNode";var So=x.memo(No);const Vr=()=>null;Vr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),pn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(pn),t.selectedNodes.map(pn))&&ke(e.selectedEdges.map(pn),t.selectedEdges.map(pn))}const ko=x.memo(({onSelectionChange:e})=>{const t=Ne(),{selectedNodes:n,selectedEdges:r}=de(Df,Pf);return x.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});ko.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=de(zf);return e||t?A.createElement(ko,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Nt(e,t){x.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ie(e,t,n){x.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:w,minZoom:y,maxZoom:v,nodeExtent:p,onNodesChange:E,onEdgesChange:$,elementsSelectable:b,connectionMode:M,snapGrid:N,snapToGrid:_,translateExtent:R,connectOnClick:k,defaultEdgeOptions:O,fitView:D,fitViewOptions:B,onNodesDelete:H,onEdgesDelete:g,onNodeDrag:C,onNodeDragStart:S,onNodeDragStop:I,onSelectionDrag:L,onSelectionDragStart:j,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:X,autoPanOnConnect:F,autoPanOnNodeDrag:Z,onError:J,connectionRadius:te,isValidConnection:oe,nodeDragThreshold:ne})=>{const{setNodes:se,setEdges:pe,setDefaultNodesAndEdges:ce,setMinZoom:ue,setMaxZoom:ge,setTranslateExtent:he,setNodeExtent:ye,reset:le}=de(Ff,ke),K=Ne();return x.useEffect(()=>{const Se=r==null?void 0:r.map(Ce=>({...Ce,...O}));return ce(n,Se),()=>{le()}},[]),ie("defaultEdgeOptions",O,K.setState),ie("connectionMode",M,K.setState),ie("onConnect",s,K.setState),ie("onConnectStart",i,K.setState),ie("onConnectEnd",o,K.setState),ie("onClickConnectStart",a,K.setState),ie("onClickConnectEnd",c,K.setState),ie("nodesDraggable",l,K.setState),ie("nodesConnectable",u,K.setState),ie("nodesFocusable",d,K.setState),ie("edgesFocusable",m,K.setState),ie("edgesUpdatable",f,K.setState),ie("elementsSelectable",b,K.setState),ie("elevateNodesOnSelect",w,K.setState),ie("snapToGrid",_,K.setState),ie("snapGrid",N,K.setState),ie("onNodesChange",E,K.setState),ie("onEdgesChange",$,K.setState),ie("connectOnClick",k,K.setState),ie("fitViewOnInit",D,K.setState),ie("fitViewOnInitOptions",B,K.setState),ie("onNodesDelete",H,K.setState),ie("onEdgesDelete",g,K.setState),ie("onNodeDrag",C,K.setState),ie("onNodeDragStart",S,K.setState),ie("onNodeDragStop",I,K.setState),ie("onSelectionDrag",L,K.setState),ie("onSelectionDragStart",j,K.setState),ie("onSelectionDragStop",T,K.setState),ie("noPanClassName",P,K.setState),ie("nodeOrigin",z,K.setState),ie("rfId",X,K.setState),ie("autoPanOnConnect",F,K.setState),ie("autoPanOnNodeDrag",Z,K.setState),ie("onError",J,K.setState),ie("connectionRadius",te,K.setState),ie("isValidConnection",oe,K.setState),ie("nodeDragThreshold",ne,K.setState),Nt(e,se),Nt(t,pe),Nt(y,ue),Nt(v,ge),Nt(R,he),Nt(p,ye),null},Cs={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},jo="react-flow__node-desc",Co="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Xf({rfId:e}){const t=de(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Wf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${jo}-${e}`,style:Cs},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Co}-${e}`,style:Cs},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Xf,{rfId:e}))}var tn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=x.useState(!1),s=x.useRef(!1),i=x.useRef(new Set([])),[o,a]=x.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return x.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);i.current.add(f[y]),$s(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&br(f))return!1;const y=Ms(f.code,a);$s(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Ms(e,t){return t.includes(e)?"code":"key"}function $o(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=wt(i,r);return $o(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function Mo(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=$o(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Oe(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Mo(s,n,i),s}function Ao(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const w=n().filter(v=>{var E;const p=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?p&&t.nodes.some($=>$.id===v.id):p}),y=w.every(v=>v.width&&v.height);if(w.length>0&&y){const v=on(w,d),{x:p,y:E,zoom:$}=go(v,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),b=tt.translate(p,E).scale($);return typeof t.duration=="number"&&t.duration>0?a.transform(pt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Uf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function gn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Uf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const St=()=>{},Kf={zoomIn:St,zoomOut:St,zoomTo:St,getZoom:()=>1,setViewport:St,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:St,fitBounds:St,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Ne(),{d3Zoom:t,d3Selection:n}=de(Zf,ke);return x.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(pt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(pt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(pt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=tt.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(pt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Ao(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=tt.translate(d,m).scale(u);t.transform(pt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=go(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=tt.translate(u,d).scale(m);t.transform(pt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),_r(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return _r(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=ho(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function an(){const e=Qf(),t=Ne(),n=x.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=x.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=x.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(v=>({...v}))},[]),i=x.useCallback(y=>{const{edges:v=[]}=t.getState();return v.find(p=>p.id===y)},[]),o=x.useCallback(y=>{const{getNodes:v,setNodes:p,hasDefaultNodes:E,onNodesChange:$}=t.getState(),b=v(),M=typeof y=="function"?y(b):y;if(E)p(M);else if($){const N=M.length===0?b.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));$(N)}},[]),a=x.useCallback(y=>{const{edges:v=[],setEdges:p,hasDefaultEdges:E,onEdgesChange:$}=t.getState(),b=typeof y=="function"?y(v):y;if(E)p(b);else if($){const M=b.length===0?v.map(N=>({type:"remove",id:N.id})):b.map(N=>({item:N,type:"reset"}));$(M)}},[]),c=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{getNodes:p,setNodes:E,hasDefaultNodes:$,onNodesChange:b}=t.getState();if($){const N=[...p(),...v];E(N)}else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),l=x.useCallback(y=>{const v=Array.isArray(y)?y:[y],{edges:p=[],setEdges:E,hasDefaultEdges:$,onEdgesChange:b}=t.getState();if($)E([...p,...v]);else if(b){const M=v.map(N=>({item:N,type:"add"}));b(M)}},[]),u=x.useCallback(()=>{const{getNodes:y,edges:v=[],transform:p}=t.getState(),[E,$,b]=p;return{nodes:y().map(M=>({...M})),edges:v.map(M=>({...M})),viewport:{x:E,y:$,zoom:b}}},[]),d=x.useCallback(({nodes:y,edges:v})=>{const{nodeInternals:p,getNodes:E,edges:$,hasDefaultNodes:b,hasDefaultEdges:M,onNodesDelete:N,onEdgesDelete:_,onNodesChange:R,onEdgesChange:k}=t.getState(),O=(y||[]).map(C=>C.id),D=(v||[]).map(C=>C.id),B=E().reduce((C,S)=>{const I=S.parentNode||S.parentId,L=!O.includes(S.id)&&I&&C.find(T=>T.id===I);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(O.includes(S.id)||L)&&C.push(S),C},[]),H=$.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),g=H.filter(C=>D.includes(C.id));if(B||g){const C=po(B,H),S=[...g,...C],I=S.reduce((L,j)=>(L.includes(j.id)||L.push(j.id),L),[]);if((M||b)&&(M&&t.setState({edges:$.filter(L=>!I.includes(L.id))}),b&&(B.forEach(L=>{p.delete(L.id)}),t.setState({nodeInternals:new Map(p)}))),I.length>0&&(_==null||_(S),k&&k(I.map(L=>({id:L,type:"remove"})))),B.length>0&&(N==null||N(B),R)){const L=B.map(j=>({id:j.id,type:"remove"}));R(L)}}},[]),m=x.useCallback(y=>{const v=yf(y),p=v?null:t.getState().nodeInternals.get(y.id);return!v&&!p?[null,null,v]:[v?y:vs(p),p,v]},[]),f=x.useCallback((y,v=!0,p)=>{const[E,$,b]=m(y);return E?(p||t.getState().getNodes()).filter(M=>{if(!b&&(M.id===$.id||!M.positionAbsolute))return!1;const N=vs(M),_=wr(N,E);return v&&_>0||_>=E.width*E.height}):[]},[]),w=x.useCallback((y,v,p=!0)=>{const[E]=m(y);if(!E)return!1;const $=wr(E,v);return p&&$>0||$>=E.width*E.height},[]);return x.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:w}),[e,n,r,s,i,o,a,c,l,u,d,f,w])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ne(),{deleteElements:r}=an(),s=tn(e,Jf),i=tn(t);x.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),x.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Ne();x.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Or(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",rt.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Br={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,yn=e=>({x:e.x,y:e.y,zoom:e.k}),kt=(e,t)=>e.target.closest(`.${t}`),As=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rs=e=>{const t=e.ctrlKey&&Mn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=yt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:w,maxZoom:y,zoomActivationKeyCode:v,preventScrolling:p=!0,children:E,noWheelClassName:$,noPanClassName:b})=>{const M=x.useRef(),N=Ne(),_=x.useRef(!1),R=x.useRef(!1),k=x.useRef(null),O=x.useRef({x:0,y:0,zoom:0}),{d3Zoom:D,d3Selection:B,d3ZoomHandler:H,userSelectionActive:g}=de(rh,ke),C=tn(v),S=x.useRef(0),I=x.useRef(!1),L=x.useRef();return th(k),x.useEffect(()=>{if(k.current){const j=k.current.getBoundingClientRect(),T=eo().scaleExtent([w,y]).translateExtent(f),P=Te(k.current).call(T),z=tt.translate(m.x,m.y).scale(Ot(m.zoom,w,y)),X=[[0,0],[j.width,j.height]],F=T.constrain()(z,X,f);T.transform(P,F),T.wheelDelta(Rs),N.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[F.x,F.y,F.k],domNode:k.current.closest(".react-flow")})}},[]),x.useEffect(()=>{B&&D&&(o&&!C&&!g?B.on("wheel.zoom",j=>{if(kt(j,$))return!1;j.preventDefault(),j.stopImmediatePropagation();const T=B.property("__zoom").k||1;if(j.ctrlKey&&i){const oe=He(j),ne=Rs(j),se=T*Math.pow(2,ne);D.scaleTo(B,se,oe,j);return}const P=j.deltaMode===1?20:1;let z=c===yt.Vertical?0:j.deltaX*P,X=c===yt.Horizontal?0:j.deltaY*P;!Mn()&&j.shiftKey&&c!==yt.Vertical&&(z=j.deltaY*P,X=0),D.translateBy(B,-(z/T)*a,-(X/T)*a,{internal:!0});const F=yn(B.property("__zoom")),{onViewportChangeStart:Z,onViewportChange:J,onViewportChangeEnd:te}=N.getState();clearTimeout(L.current),I.current||(I.current=!0,t==null||t(j,F),Z==null||Z(F)),I.current&&(e==null||e(j,F),J==null||J(F),L.current=setTimeout(()=>{n==null||n(j,F),te==null||te(F),I.current=!1},150))},{passive:!1}):typeof H<"u"&&B.on("wheel.zoom",function(j,T){if(!p&&j.type==="wheel"&&!j.ctrlKey||kt(j,$))return null;j.preventDefault(),H.call(this,j,T)},{passive:!1}))},[g,o,c,B,D,H,C,i,p,$,t,e,n]),x.useEffect(()=>{D&&D.on("start",j=>{var z,X;if(!j.sourceEvent||j.sourceEvent.internal)return null;S.current=(z=j.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=N.getState(),P=yn(j.transform);_.current=!0,O.current=P,((X=j.sourceEvent)==null?void 0:X.type)==="mousedown"&&N.setState({paneDragging:!0}),T==null||T(P),t==null||t(j.sourceEvent,P)})},[D,t]),x.useEffect(()=>{D&&(g&&!_.current?D.on("zoom",null):g||D.on("zoom",j=>{var P;const{onViewportChange:T}=N.getState();if(N.setState({transform:[j.transform.x,j.transform.y,j.transform.k]}),R.current=!!(r&&As(d,S.current??0)),(e||T)&&!((P=j.sourceEvent)!=null&&P.internal)){const z=yn(j.transform);T==null||T(z),e==null||e(j.sourceEvent,z)}}))},[g,D,e,d,r]),x.useEffect(()=>{D&&D.on("end",j=>{if(!j.sourceEvent||j.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=N.getState();if(_.current=!1,N.setState({paneDragging:!1}),r&&As(d,S.current??0)&&!R.current&&r(j.sourceEvent),R.current=!1,(n||T)&&nh(O.current,j.transform)){const P=yn(j.transform);O.current=P,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(P),n==null||n(j.sourceEvent,P)},o?150:0)}})},[D,o,d,n,r]),x.useEffect(()=>{D&&D.filter(j=>{const T=C||s,P=i&&j.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&j.button===1&&j.type==="mousedown"&&(kt(j,"react-flow__node")||kt(j,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||g||!l&&j.type==="dblclick"||kt(j,$)&&j.type==="wheel"||kt(j,b)&&(j.type!=="wheel"||o&&j.type==="wheel"&&!C)||!i&&j.ctrlKey&&j.type==="wheel"||!T&&!o&&!P&&j.type==="wheel"||!d&&(j.type==="mousedown"||j.type==="touchstart")||Array.isArray(d)&&!d.includes(j.button)&&j.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(j.button)||!j.button||j.button<=1;return(!j.ctrlKey||j.type==="wheel")&&z})},[g,D,s,i,o,l,d,u,C]),A.createElement("div",{className:"react-flow__renderer",ref:k,style:Br},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=de(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Is(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&Is(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&Is(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ct=(e,t)=>({id:e,type:"select",selected:t});function Ct(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ct(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ct(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ro=x.memo(({isSelecting:e,selectionMode:t=en.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=x.useRef(null),f=Ne(),w=x.useRef(0),y=x.useRef(0),v=x.useRef(),{userSelectionActive:p,elementsSelectable:E,dragging:$}=de(lh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),w.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},N=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,R=H=>{const{resetSelectedElements:g,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!v.current)return;const{x:S,y:I}=dt(H,v.current);g(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:I,x:S,y:I}}),r==null||r(H)},k=H=>{const{userSelectionRect:g,nodeInternals:C,edges:S,transform:I,onNodesChange:L,onEdgesChange:j,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!g)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=dt(H,v.current),X=g.startX??0,F=g.startY??0,Z={...g,x:z.xse.id),ne=te.map(se=>se.id);if(w.current!==ne.length){w.current=ne.length;const se=Ct(J,ne);se.length&&(L==null||L(se))}if(y.current!==oe.length){y.current=oe.length;const se=Ct(S,oe);se.length&&(j==null||j(se))}f.setState({userSelectionRect:Z})},O=H=>{if(H.button!==0)return;const{userSelectionRect:g}=f.getState();!p&&g&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:w.current>0}),b(),s==null||s(H)},D=H=>{p&&(f.setState({nodesSelectionActive:w.current>0}),s==null||s(H)),b()},B=E&&(e||p);return A.createElement("div",{className:je(["react-flow__pane",{dragging:$,selection:e}]),onClick:B?void 0:er(M,m),onContextMenu:er(N,m),onWheel:er(_,m),onMouseEnter:B?void 0:c,onMouseDown:B?R:void 0,onMouseMove:B?k:l,onMouseUp:B?O:void 0,onMouseLeave:B?D:u,ref:m,style:Br},d,A.createElement(oh,null))});Ro.displayName="Pane";function Io(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Io(r,t):!1}function Ts(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Io(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function To(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=wt(d,s).positionAbsolute;a=d&&Oe(m)&&Oe(f)&&Oe(d.width)&&Oe(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",rt.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=wt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=wt(d,s).positionAbsolute}const u=a&&a!=="parent"?Lr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Os=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Or(c)}})};function Vt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Nr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",rt.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Ne();return x.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Oo({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Ne(),[c,l]=x.useState(!1),u=x.useRef([]),d=x.useRef({x:null,y:null}),m=x.useRef(0),f=x.useRef(null),w=x.useRef({x:0,y:0}),y=x.useRef(null),v=x.useRef(!1),p=x.useRef(!1),E=x.useRef(!1),$=fh();return x.useEffect(()=>{if(e!=null&&e.current){const b=Te(e.current),M=({x:R,y:k})=>{const{nodeInternals:O,onNodeDrag:D,onSelectionDrag:B,updateNodePositions:H,nodeExtent:g,snapGrid:C,snapToGrid:S,nodeOrigin:I,onError:L}=a.getState();d.current={x:R,y:k};let j=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&g){const z=on(u.current,I);T=Jt(z)}if(u.current=u.current.map(z=>{const X={x:R-z.distance.x,y:k-z.distance.y};S&&(X.x=C[0]*Math.round(X.x/C[0]),X.y=C[1]*Math.round(X.y/C[1]));const F=[[g[0][0],g[0][1]],[g[1][0],g[1][1]]];u.current.length>1&&g&&!z.extent&&(F[0][0]=z.positionAbsolute.x-T.x+g[0][0],F[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+g[1][0],F[0][1]=z.positionAbsolute.y-T.y+g[0][1],F[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+g[1][1]);const Z=To(z,X,O,F,I,L);return j=j||z.position.x!==Z.position.x||z.position.y!==Z.position.y,z.position=Z.position,z.positionAbsolute=Z.positionAbsolute,z}),!j)return;H(u.current,!0,!0),l(!0);const P=s?D:nr(B);if(P&&y.current){const[z,X]=tr({nodeId:s,dragItems:u.current,nodeInternals:O});P(y.current,z,X)}},N=()=>{if(!f.current)return;const[R,k]=no(w.current,f.current);if(R!==0||k!==0){const{transform:O,panBy:D}=a.getState();d.current.x=(d.current.x??0)-R/O[2],d.current.y=(d.current.y??0)-k/O[2],D({x:R,y:k})&&M(d.current)}m.current=requestAnimationFrame(N)},_=R=>{var I;const{nodeInternals:k,multiSelectionActive:O,nodesDraggable:D,unselectNodesAndEdges:B,onNodeDragStart:H,onSelectionDragStart:g}=a.getState();p.current=!0;const C=s?H:nr(g);(!o||!i)&&!O&&s&&((I=k.get(s))!=null&&I.selected||B()),s&&i&&o&&Nr({id:s,store:a,nodeRef:e});const S=$(R);if(d.current=S,u.current=uh(k,D,S,s),C&&u.current){const[L,j]=tr({nodeId:s,dragItems:u.current,nodeInternals:k});C(R.sourceEvent,L,j)}};if(t)b.on(".drag",null);else{const R=bu().on("start",k=>{const{domNode:O,nodeDragThreshold:D}=a.getState();D===0&&_(k),E.current=!1;const B=$(k);d.current=B,f.current=(O==null?void 0:O.getBoundingClientRect())||null,w.current=dt(k.sourceEvent,f.current)}).on("drag",k=>{var H,g;const O=$(k),{autoPanOnNodeDrag:D,nodeDragThreshold:B}=a.getState();if(k.sourceEvent.type==="touchmove"&&k.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&p.current&&D&&(v.current=!0,N()),!p.current){const C=O.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=O.ySnapped-(((g=d==null?void 0:d.current)==null?void 0:g.y)??0);Math.sqrt(C*C+S*S)>B&&_(k)}(d.current.x!==O.xSnapped||d.current.y!==O.ySnapped)&&u.current&&p.current&&(y.current=k.sourceEvent,w.current=dt(k.sourceEvent,f.current),M(O))}}).on("end",k=>{if(!(!p.current||E.current)&&(l(!1),v.current=!1,p.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:O,nodeInternals:D,onNodeDragStop:B,onSelectionDragStop:H}=a.getState(),g=s?B:nr(H);if(O(u.current,!1,!1),g){const[C,S]=tr({nodeId:s,dragItems:u.current,nodeInternals:D});g(k.sourceEvent,C,S)}}}).filter(k=>{const O=k.target;return!k.button&&(!n||!Ts(O,`.${n}`,e))&&(!r||Ts(O,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,$]),c}function Lo(){const e=Ne();return x.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,w=n.isShiftPressed?4:1,y=n.x*m*w,v=n.y*f*w,p=d.map(E=>{if(E.positionAbsolute){const $={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+v};a&&($.x=c[0]*Math.round($.x/c[0]),$.y=c[1]*Math.round($.y/c[1]));const{positionAbsolute:b,position:M}=To(E,$,r,s,void 0,l);E.position=M,E.positionAbsolute=b}return E});i(p,!0,!1)},[])}const At={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Bt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:w,onDoubleClick:y,style:v,className:p,isDraggable:E,isSelectable:$,isConnectable:b,isFocusable:M,selectNodesOnDrag:N,sourcePosition:_,targetPosition:R,hidden:k,resizeObserver:O,dragHandle:D,zIndex:B,isParent:H,noDragClassName:g,noPanClassName:C,initialized:S,disableKeyboardA11y:I,ariaLabel:L,rfId:j,hasHandleBounds:T})=>{const P=Ne(),z=x.useRef(null),X=x.useRef(null),F=x.useRef(_),Z=x.useRef(R),J=x.useRef(r),te=$||E||u||d||m||f,oe=Lo(),ne=Vt(n,P.getState,d),se=Vt(n,P.getState,m),pe=Vt(n,P.getState,f),ce=Vt(n,P.getState,w),ue=Vt(n,P.getState,y),ge=le=>{const{nodeDragThreshold:K}=P.getState();if($&&(!N||!E||K>0)&&Nr({id:n,store:P,nodeRef:z}),u){const Se=P.getState().nodeInternals.get(n);Se&&u(le,{...Se})}},he=le=>{if(!br(le)&&!I)if(oo.includes(le.key)&&$){const K=le.key==="Escape";Nr({id:n,store:P,unselect:K,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(At,le.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),oe({x:At[le.key].x,y:At[le.key].y,isShiftPressed:le.shiftKey}))};x.useEffect(()=>()=>{X.current&&(O==null||O.unobserve(X.current),X.current=null)},[]),x.useEffect(()=>{if(z.current&&!k){const le=z.current;(!S||!T||X.current!==le)&&(X.current&&(O==null||O.unobserve(X.current)),O==null||O.observe(le),X.current=le)}},[k,S,T]),x.useEffect(()=>{const le=J.current!==r,K=F.current!==_,Se=Z.current!==R;z.current&&(le||K||Se)&&(le&&(J.current=r),K&&(F.current=_),Se&&(Z.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const ye=Oo({nodeRef:z,disabled:k||!E,noDragClassName:g,handleSelector:D,nodeId:n,isSelectable:$,selectNodesOnDrag:N});return k?null:A.createElement("div",{className:je(["react-flow__node",`react-flow__node-${r}`,{[C]:E},p,{selected:l,selectable:$,parent:H,dragging:ye}]),ref:z,style:{zIndex:B,transform:`translate(${a}px,${c}px)`,pointerEvents:te?"all":"none",visibility:S?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:se,onMouseLeave:pe,onContextMenu:ce,onClick:ge,onDoubleClick:ue,onKeyDown:M?he:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":I?void 0:`${jo}-${j}`,"aria-label":L},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:ye,dragHandle:D,zIndex:B})))};return t.displayName="NodeWrapper",x.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...on(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ne(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=de(hh,ke),u=Lo(),d=x.useRef(null);if(x.useEffect(()=>{var w;n||(w=d.current)==null||w.focus({preventScroll:!0})},[n]),Oo({nodeRef:d}),l||!s||!i)return null;const m=e?w=>{const y=r.getState().getNodes().filter(v=>v.selected);e(w,y)}:void 0,f=w=>{Object.prototype.hasOwnProperty.call(At,w.key)&&u({x:At[w.key].x,y:At[w.key].y,isShiftPressed:w.shiftKey})};return A.createElement("div",{className:je(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=x.memo(mh);const gh=e=>e.nodesSelectionActive,Do=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:w,onSelectionEnd:y,multiSelectionKeyCode:v,panActivationKeyCode:p,zoomActivationKeyCode:E,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:N,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:O,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,preventScrolling:C,onSelectionContextMenu:S,noWheelClassName:I,noPanClassName:L,disableKeyboardA11y:j})=>{const T=de(gh),P=tn(d),z=tn(p),X=z||O,F=z||N,Z=P||m&&X!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:$,zoomOnScroll:b,zoomOnPinch:M,panOnScroll:F,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:k,panOnDrag:!P&&X,defaultViewport:D,translateExtent:B,minZoom:H,maxZoom:g,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:I,noPanClassName:L},A.createElement(Ro,{onSelectionStart:w,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:X,isSelecting:!!Z,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:L,disableKeyboardA11y:j})))};Do.displayName="FlowRenderer";var yh=x.memo(Do);function xh(e){return de(x.useCallback(n=>e?mo(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Bt(e.input||Eo),default:Bt(e.default||Er),output:Bt(e.output||So),group:Bt(e.group||Vr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Bt(e[i]||Er),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Po=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=de(vh,ke),a=xh(e.onlyRenderVisibleElements),c=x.useRef(),l=x.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return x.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Br},a.map(u=>{var M,N,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",rt.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),w=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),v=!!(u.focusable||r&&typeof u.focusable>"u"),p=e.nodeExtent?Lr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(p==null?void 0:p.x)??0,$=(p==null?void 0:p.y)??0,b=bh({x:E,y:$,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||q.Bottom,targetPosition:u.targetPosition||q.Top,hidden:u.hidden,xPos:E,yPos:$,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:w,isConnectable:y,isFocusable:v,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((N=u[we])!=null&&N.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Po.displayName="NodeRenderer";var _h=x.memo(Po);const Eh=(e,t,n)=>n===q.Left?e-t:n===q.Right?e+t:e,Nh=(e,t,n)=>n===q.Top?e-t:n===q.Bottom?e+t:e,Ls="react-flow__edgeupdater",Ds=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:je([Ls,`${Ls}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var jt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,style:v,source:p,target:E,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,elementsSelectable:k,hidden:O,sourceHandleId:D,targetHandleId:B,onContextMenu:H,onMouseEnter:g,onMouseMove:C,onMouseLeave:S,reconnectRadius:I,onReconnect:L,onReconnectStart:j,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:X,ariaLabel:F,isFocusable:Z,isReconnectable:J,pathOptions:te,interactionWidth:oe,disableKeyboardA11y:ne})=>{const se=x.useRef(null),[pe,ce]=x.useState(!1),[ue,ge]=x.useState(!1),he=Ne(),ye=x.useMemo(()=>`url('#${vr(z,X)}')`,[z,X]),le=x.useMemo(()=>`url('#${vr(P,X)}')`,[P,X]);if(O)return null;const K=re=>{var ve;const{edges:me,addSelectedEdges:$e,unselectNodesAndEdges:W,multiSelectionActive:fe}=he.getState(),xe=me.find(Ge=>Ge.id===n);xe&&(k&&(he.setState({nodesSelectionActive:!1}),xe.selected&&fe?(W({nodes:[],edges:[xe]}),(ve=se.current)==null||ve.blur()):$e([n])),o&&o(re,xe))},Se=Ft(n,he.getState,a),Ce=Ft(n,he.getState,H),ft=Ft(n,he.getState,g),Ae=Ft(n,he.getState,C),qe=Ft(n,he.getState,S),Ie=(re,me)=>{if(re.button!==0)return;const{edges:$e,isValidConnection:W}=he.getState(),fe=me?E:p,xe=(me?B:D)||null,ve=me?"target":"source",Ge=W||Sh,it=me,Pe=$e.find(ze=>ze.id===n);ge(!0),j==null||j(re,Pe,ve);const ht=ze=>{ge(!1),T==null||T(ze,Pe,ve)};wo({event:re,handleId:xe,nodeId:fe,onConnect:ze=>L==null?void 0:L(Pe,ze),isTarget:it,getState:he.getState,setState:he.setState,isValidConnection:Ge,edgeUpdaterType:ve,onReconnectEnd:ht})},V=re=>Ie(re,!0),Y=re=>Ie(re,!1),G=()=>ce(!0),Q=()=>ce(!1),U=!k&&!o,ee=re=>{var me;if(!ne&&oo.includes(re.key)&&k){const{unselectNodesAndEdges:$e,addSelectedEdges:W,edges:fe}=he.getState();re.key==="Escape"?((me=se.current)==null||me.blur(),$e({edges:[fe.find(ve=>ve.id===n)]})):W([n])}};return A.createElement("g",{className:je(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:pe}]),onClick:K,onDoubleClick:Se,onContextMenu:Ce,onMouseEnter:ft,onMouseMove:Ae,onMouseLeave:qe,onKeyDown:Z?ee:void 0,tabIndex:Z?0:void 0,role:Z?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":F===null?void 0:F||`Edge from ${p} to ${E}`,"aria-describedby":Z?`${Co}-${X}`:void 0,ref:se},!ue&&A.createElement(e,{id:n,source:p,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:w,labelBgBorderRadius:y,data:i,style:v,sourceX:$,sourceY:b,targetX:M,targetY:N,sourcePosition:_,targetPosition:R,sourceHandleId:D,targetHandleId:B,markerStart:ye,markerEnd:le,pathOptions:te,interactionWidth:oe}),J&&A.createElement(A.Fragment,null,(J==="source"||J===!0)&&A.createElement(Ds,{position:_,centerX:$,centerY:b,radius:I,onMouseDown:V,onMouseEnter:G,onMouseOut:Q,type:"source"}),(J==="target"||J===!0)&&A.createElement(Ds,{position:R,centerX:M,centerY:N,radius:I,onMouseDown:Y,onMouseEnter:G,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",x.memo(t)};function kh(e){const t={default:jt(e.default||In),straight:jt(e.bezier||zr),step:jt(e.step||Pr),smoothstep:jt(e.step||Bn),simplebezier:jt(e.simplebezier||Dr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=jt(e[i]||In),s),n);return{...t,...r}}function Ps(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case q.Top:return{x:r+i/2,y:s};case q.Right:return{x:r+i,y:s+o/2};case q.Bottom:return{x:r+i/2,y:s+o};case q.Left:return{x:r,y:s+o/2}}}function zs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ps(n,e,t),a=Ps(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Jt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Hs(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Oe(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),w=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(w?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=de(x.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Fs={[An.Arrow]:Rh,[An.ArrowClosed]:Ih};function Th(e){const t=Ne();return x.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(Fs,e)?Fs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",rt.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=vr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},zo=({defaultColor:e,rfId:t})=>{const n=de(x.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};zo.displayName="MarkerDefinitions";var Dh=x.memo(zo);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ho=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,children:v,disableKeyboardA11y:p})=>{const{edgesFocusable:E,edgesUpdatable:$,elementsSelectable:b,width:M,height:N,connectionMode:_,nodeInternals:R,onError:k}=de(Ph,ke),O=Ah(t,R,n);return M?A.createElement(A.Fragment,null,O.map(({level:D,edges:B,isMaxLevel:H})=>A.createElement("svg",{key:D,style:{zIndex:D},width:M,height:N,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,B.map(g=>{const[C,S,I]=Hs(R.get(g.source)),[L,j,T]=Hs(R.get(g.target));if(!I||!T)return null;let P=g.type||"default";s[P]||(k==null||k("011",rt.error011(P)),P="default");const z=s[P]||s.default,X=_===_t.Strict?j.target:(j.target??[]).concat(j.source??[]),F=zs(S.source,g.sourceHandle),Z=zs(X,g.targetHandle),J=(F==null?void 0:F.position)||q.Bottom,te=(Z==null?void 0:Z.position)||q.Top,oe=!!(g.focusable||E&&typeof g.focusable>"u"),ne=g.reconnectable||g.updatable,se=typeof m<"u"&&(ne||$&&typeof ne>"u");if(!F||!Z)return k==null||k("008",rt.error008(F,g)),null;const{sourceX:pe,sourceY:ce,targetX:ue,targetY:ge}=jh(C,F,J,L,Z,te);return A.createElement(z,{key:g.id,id:g.id,className:je([g.className,i]),type:P,data:g.data,selected:!!g.selected,animated:!!g.animated,hidden:!!g.hidden,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,style:g.style,source:g.source,target:g.target,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerEnd:g.markerEnd,markerStart:g.markerStart,sourceX:pe,sourceY:ce,targetX:ue,targetY:ge,sourcePosition:J,targetPosition:te,elementsSelectable:b,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:w,reconnectRadius:y,rfId:r,ariaLabel:g.ariaLabel,isFocusable:oe,isReconnectable:se,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth,disableKeyboardA11y:p})})))),v):null};Ho.displayName="EdgeRenderer";var zh=x.memo(Ho);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=de(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=an(),n=x.useRef(!1);x.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[q.Left]:q.Right,[q.Right]:q.Left,[q.Top]:q.Bottom,[q.Bottom]:q.Top},Fo=({nodeId:e,handleType:t,style:n,type:r=lt.Bezier,CustomComponent:s,connectionStatus:i})=>{var N,_,R;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=de(x.useCallback(k=>({fromNode:k.nodeInternals.get(e),handleId:k.connectionHandleId,toX:(k.connectionPosition.x-k.transform[0])/k.transform[2],toY:(k.connectionPosition.y-k.transform[1])/k.transform[2],connectionMode:k.connectionMode}),[e]),ke),d=(N=o==null?void 0:o[we])==null?void 0:N.handleBounds;let m=d==null?void 0:d[t];if(u===_t.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(k=>k.id===a):m[0],w=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,v=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+w,p=(((R=o.positionAbsolute)==null?void 0:R.y)??0)+y,E=f==null?void 0:f.position,$=E?Bh[E]:null;if(!E||!$)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:v,fromY:p,toX:c,toY:l,fromPosition:E,toPosition:$,connectionStatus:i});let b="";const M={sourceX:v,sourceY:p,sourcePosition:E,targetX:c,targetY:l,targetPosition:$};return r===lt.Bezier?[b]=fo(M):r===lt.Step?[b]=Rn({...M,borderRadius:0}):r===lt.SmoothStep?[b]=Rn(M):r===lt.SimpleBezier?[b]=uo(M):b=`M${v},${p} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Fo.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=de(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:je(["react-flow__connection",l])},A.createElement(Fo,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Vs(e,t){return x.useRef(null),Ne(),x.useMemo(()=>t(e),[e])}const Vo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:w,onSelectionStart:y,onSelectionEnd:v,connectionLineType:p,connectionLineStyle:E,connectionLineComponent:$,connectionLineContainerStyle:b,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,deleteKeyCode:D,onlyRenderVisibleElements:B,elementsSelectable:H,selectNodesOnDrag:g,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,preventScrolling:j,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:X,panOnScrollSpeed:F,panOnScrollMode:Z,zoomOnDoubleClick:J,panOnDrag:te,onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:se,onPaneMouseLeave:pe,onPaneScroll:ce,onPaneContextMenu:ue,onEdgeContextMenu:ge,onEdgeMouseEnter:he,onEdgeMouseMove:ye,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Se,onReconnectEnd:Ce,reconnectRadius:ft,noDragClassName:Ae,noWheelClassName:qe,noPanClassName:Ie,elevateEdgesOnSelect:V,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})=>{const ee=Vs(e,wh),re=Vs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:oe,onPaneMouseEnter:ne,onPaneMouseMove:se,onPaneMouseLeave:pe,onPaneContextMenu:ue,onPaneScroll:ce,deleteKeyCode:D,selectionKeyCode:M,selectionOnDrag:N,selectionMode:_,onSelectionStart:y,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:k,zoomActivationKeyCode:O,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:J,panOnScroll:X,panOnScrollSpeed:F,panOnScrollMode:Z,panOnDrag:te,defaultViewport:C,translateExtent:S,minZoom:I,maxZoom:L,onSelectionContextMenu:w,preventScrolling:j,noDragClassName:Ae,noWheelClassName:qe,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:re,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:B,onEdgeContextMenu:ge,onEdgeMouseEnter:he,onEdgeMouseMove:ye,onEdgeMouseLeave:le,onReconnect:K,onReconnectStart:Se,onReconnectEnd:Ce,reconnectRadius:ft,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!V,disableKeyboardA11y:Y,rfId:U},A.createElement(Yh,{style:E,type:p,component:$,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:ee,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:g,onlyRenderVisibleElements:B,noPanClassName:Ie,noDragClassName:Ae,disableKeyboardA11y:Y,nodeOrigin:G,nodeExtent:Q,rfId:U})))};Vo.displayName="GraphView";var Xh=x.memo(Vo);const Sr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ot={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Sr,nodeExtent:Sr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:_t.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Wh=()=>Rc((e,t)=>({...ot,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Jn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,v)=>{const p=s.get(v.id);if(p!=null&&p.hidden)s.set(p.id,{...p,[we]:{...p[we],handleBounds:void 0}});else if(p){const E=Or(v.nodeElement);!!(E.width&&E.height&&(p.width!==E.width||p.height!==E.height||v.forceUpdate))&&(s.set(p.id,{...p,[we]:{...p[we],handleBounds:{source:Os(".source",v.nodeElement,m,l),target:Os(".target",v.nodeElement,m,l)}},...E}),y.push({id:p.id,type:"dimensions",dimensions:E}))}return y},[]);Mo(s,l);const w=o||i&&!o&&Ao(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:w}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Jn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(i(),n),a=Ct(s,[])),gn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(s,n),a=Ct(i(),[])),gn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ct(u.id,!1))),l=a.map(u=>ct(u.id,!1));gn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ct(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ct(a.id,!1));gn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Lr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=tt.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:ot.connectionNodeId,connectionHandleId:ot.connectionHandleId,connectionHandleType:ot.connectionHandleType,connectionStatus:ot.connectionStatus,connectionStartHandle:ot.connectionStartHandle,connectionEndHandle:ot.connectionEndHandle}),reset:()=>e({...ot})}),Object.is),Bo=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Wh()),A.createElement(df,{value:t.current},e)};Bo.displayName="ReactFlowProvider";const Go=({children:e})=>x.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Bo,null,e);Go.displayName="ReactFlowWrapper";const Uh={input:Eo,default:Er,output:So,group:Vr},qh={default:In,straight:zr,step:Pr,smoothstep:Bn,simplebezier:Dr},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Yo=x.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Uh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onNodesDelete:O,onEdgesDelete:D,onSelectionChange:B,onSelectionDragStart:H,onSelectionDrag:g,onSelectionDragStop:C,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,connectionMode:j=_t.Strict,connectionLineType:T=lt.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,deleteKeyCode:F="Backspace",selectionKeyCode:Z="Shift",selectionOnDrag:J=!1,selectionMode:te=en.Full,panActivationKeyCode:oe="Space",multiSelectionKeyCode:ne=Mn()?"Meta":"Control",zoomActivationKeyCode:se=Mn()?"Meta":"Control",snapToGrid:pe=!1,snapGrid:ce=Zh,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:ge=!0,nodesDraggable:he,nodesConnectable:ye,nodesFocusable:le,nodeOrigin:K=Kh,edgesFocusable:Se,edgesUpdatable:Ce,elementsSelectable:ft,defaultViewport:Ae=Qh,minZoom:qe=.5,maxZoom:Ie=2,translateExtent:V=Sr,preventScrolling:Y=!0,nodeExtent:G,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:ee=!0,panOnScroll:re=!1,panOnScrollSpeed:me=.5,panOnScrollMode:$e=yt.Free,zoomOnDoubleClick:W=!0,panOnDrag:fe=!0,onPaneClick:xe,onPaneMouseEnter:ve,onPaneMouseMove:Ge,onPaneMouseLeave:it,onPaneScroll:Pe,onPaneContextMenu:ht,children:Lt,onEdgeContextMenu:ze,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ke,onEdgeMouseLeave:Pt,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:Zr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Xa,defaultEdgeOptions:Wa,elevateNodesOnSelect:Ua=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Qr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Jr,nodeDragThreshold:nc,...rc},sc)=>{const Xn=Jr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:je(["react-flow",s]),"data-testid":"rf__wrapper",id:Jr},A.createElement(Go,null,A.createElement(Xh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:$,onNodeMouseLeave:b,onNodeContextMenu:M,onNodeDoubleClick:N,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:X,selectionKeyCode:Z,selectionOnDrag:J,selectionMode:te,deleteKeyCode:F,multiSelectionKeyCode:ne,panActivationKeyCode:oe,zoomActivationKeyCode:se,onlyRenderVisibleElements:ue,selectNodesOnDrag:ge,defaultViewport:Ae,translateExtent:V,minZoom:qe,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:U,zoomOnPinch:ee,zoomOnDoubleClick:W,panOnScroll:re,panOnScrollSpeed:me,panOnScrollMode:$e,panOnDrag:fe,onPaneClick:xe,onPaneMouseEnter:ve,onPaneMouseMove:Ge,onPaneMouseLeave:it,onPaneScroll:Pe,onPaneContextMenu:ht,onSelectionContextMenu:S,onSelectionStart:I,onSelectionEnd:L,onEdgeContextMenu:ze,onEdgeDoubleClick:Dt,onEdgeMouseEnter:ae,onEdgeMouseMove:Ke,onEdgeMouseLeave:Pt,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:Zr,elevateEdgesOnSelect:qa,rfId:Xn,disableKeyboardA11y:Qr,nodeOrigin:K,nodeExtent:G}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:w,onConnectEnd:y,onClickConnectStart:v,onClickConnectEnd:p,nodesDraggable:he,nodesConnectable:ye,nodesFocusable:le,edgesFocusable:Se,edgesUpdatable:Ce,elementsSelectable:ft,elevateNodesOnSelect:Ua,minZoom:qe,maxZoom:Ie,nodeExtent:G,onNodesChange:Pa,onEdgesChange:za,snapToGrid:pe,snapGrid:ce,connectionMode:j,translateExtent:V,connectOnClick:Ga,defaultEdgeOptions:Wa,fitView:Va,fitViewOptions:Ba,onNodesDelete:O,onEdgesDelete:D,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:k,onSelectionDrag:g,onSelectionDragStart:H,onSelectionDragStop:C,noPanClassName:Zr,nodeOrigin:K,rfId:Xn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:B}),Lt,A.createElement(hf,{proOptions:Xa,position:Ya}),A.createElement(Wf,{rfId:Xn,disableKeyboardA11y:Qr})))});Yo.displayName="ReactFlow";const Xo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:w,backgroundColor:y}=i||{},v=o||w||y;return A.createElement("rect",{className:je(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?p=>m(p,e):void 0})};Xo.displayName="MiniMapNode";var em=x.memo(Xo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=de(nm,ke),c=de(tm),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:w,y}=wt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:w,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=x.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(on(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:w=!1,zoomable:y=!1,ariaLabel:v="React Flow mini map",inversePan:p=!1,zoomStep:E=10,offsetScale:$=5}){const b=Ne(),M=x.useRef(null),{boundingRect:N,viewBB:_,rfId:R}=de(am,ke),k=(e==null?void 0:e.width)??im,O=(e==null?void 0:e.height)??om,D=N.width/k,B=N.height/O,H=Math.max(D,B),g=H*k,C=H*O,S=$*H,I=N.x-(g-N.width)/2-S,L=N.y-(C-N.height)/2-S,j=g+S*2,T=C+S*2,P=`${cm}-${R}`,z=x.useRef(0);z.current=H,x.useEffect(()=>{if(M.current){const Z=Te(M.current),J=ne=>{const{transform:se,d3Selection:pe,d3Zoom:ce}=b.getState();if(ne.sourceEvent.type!=="wheel"||!pe||!ce)return;const ue=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,ge=se[2]*Math.pow(2,ue);ce.scaleTo(pe,ge)},te=ne=>{const{transform:se,d3Selection:pe,d3Zoom:ce,translateExtent:ue,width:ge,height:he}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!pe||!ce)return;const ye=z.current*Math.max(1,se[2])*(p?-1:1),le={x:se[0]-ne.sourceEvent.movementX*ye,y:se[1]-ne.sourceEvent.movementY*ye},K=[[0,0],[ge,he]],Se=tt.translate(le.x,le.y).scale(se[2]),Ce=ce.constrain()(Se,K,ue);ce.transform(pe,Ce)},oe=eo().on("zoom",w?te:null).on("zoom.wheel",y?J:null);return Z.call(oe),()=>{Z.on("zoom",null)}}},[w,y,p,E]);const X=m?Z=>{const J=He(Z);m(Z,{x:J[0],y:J[1]})}:void 0,F=f?(Z,J)=>{const te=b.getState().nodeInternals.get(J);f(Z,te)}:void 0;return A.createElement(Tr,{position:d,style:e,className:je(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:k,height:O,viewBox:`${I} ${L} ${j} ${T}`,role:"img","aria-labelledby":P,ref:M,onClick:X},v&&A.createElement("title",{id:P},v),A.createElement(sm,{onClick:F,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${I-S},${L-S}h${j+S*2}v${T+S*2}h${-j-S*2}z - M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Wo.displayName="MiniMap";var lm=x.memo(Wo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Xt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:je(["react-flow__controls-button",t]),...n},e);Xt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ne(),[f,w]=x.useState(!1),{isInteractive:y,minZoomReached:v,maxZoomReached:p}=de(pm,ke),{zoomIn:E,zoomOut:$,fitView:b}=an();if(x.useEffect(()=>{w(!0)},[]),!f)return null;const M=()=>{E(),i==null||i()},N=()=>{$(),o==null||o()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c==null||c(!y)};return A.createElement(Tr,{className:je(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Xt,{onClick:M,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:p},A.createElement(um,null)),A.createElement(Xt,{onClick:N,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(dm,null))),n&&A.createElement(Xt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Xt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},y?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=x.memo(Uo),Le;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Le||(Le={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[Le.Dots]:"#91919a",[Le.Lines]:"#eee",[Le.Cross]:"#e2e2e2"},bm={[Le.Dots]:1,[Le.Lines]:1,[Le.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function qo({id:e,variant:t=Le.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=x.useRef(null),{transform:u,patternId:d}=de(vm,ke),m=o||wm[t],f=r||bm[t],w=t===Le.Dots,y=t===Le.Cross,v=Array.isArray(n)?n:[n,n],p=[v[0]*u[2]||1,v[1]*u[2]||1],E=f*u[2],$=y?[E,E]:p,b=w?[E/i,E/i]:[$[0]/i,$[1]/i];return A.createElement("svg",{className:je(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%p[0],y:u[1]%p[1],width:p[0],height:p[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},w?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:$,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}qo.displayName="Background";var _m=x.memo(qo);const Gr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Gr+e}async function be(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function st(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new Ko(r.error??`${e}: ${n.status}`,n.status);return r}class Ko extends Error{constructor(n,r){super(n);_e(this,"status");this.status=r}}const Cx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),$x=()=>be("/api/diagnostics"),Zo=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Qo=()=>be("/api/ontology/ontologies"),Em=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>be("/api/ontology/stack"),Sm=()=>be("/api/ontology/coverage"),km=(e,t,n)=>st("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>be("/api/git/status"),Cm=()=>be("/api/git/diff"),$m=e=>st("/api/git/commit",{message:e}),Mm=()=>st("/api/git/discard",{}),Am=()=>be("/api/decisions"),Bs=(e,t)=>st(`/api/decisions/${e}/verdict`,{verdict:t}),Mx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Ax=()=>be("/api/glossary/config"),Rx=e=>st("/api/git/propose",e),Ix=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Tx=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),Ox=e=>st("/api/git/classify",{changes:e}),Lx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Dx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Px=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>be("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Gr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>st("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>st("/api/import/preview",{format:e,content:t}),zx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Hx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Fx=(e,t,n)=>fetch(`${Gr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new Ko(await r.text(),r.status);return await r.json()}),Vx=()=>be("/api/glossary/subject-areas"),Bx=e=>be(`/api/glossary/subject-area/${e}`),Gx=(e,t)=>st(`/api/glossary/subject-area/${e}/expand`,t);function Yx(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Yr="__entity_source",Xr="__entity_target",Pm=x.memo(function({data:t,selected:n}){var N;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:w}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>y(_.a)-y(R.a)||_.i-R.i).map(_=>_.a),p=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const $=!!c&&!l;let b=0;if($){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const M=(_,R)=>{const k="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:k,onMouseEnter:w?()=>w(_.id):void 0,onMouseLeave:w?()=>w(null):void 0,children:[h.jsx(ut,{id:_.id,type:"target",position:q.Left,className:"port attr-port"}),h.jsx(ut,{id:_.id,type:"source",position:q.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ut,{id:Xr,type:"target",position:q.Left,className:"port"}),h.jsx(ut,{id:Yr,type:"source",position:q.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((N=r.conceptual)==null?void 0:N.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var k;const _=(((k=r.conceptual)==null?void 0:k.ontology_refs)??[]).filter(O=>O.uri);if(_.length===0)return null;const R=_.map(O=>O.uri).join(` -`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),p.length>0&&h.jsx("div",{className:"attr-section keys",children:p.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,w,y,v,p,E,$,b,M,N,_,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(k=>k.from.entity===e.id||k.to.entity===e.id),d=k=>{var O;return((O=t.entities.find(D=>D.id===k))==null?void 0:O.name)??k};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Qe,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,name:k})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Qe,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:k=>r("rename_entity",{id:e.id,physical_name:k})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Qe,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:k=>r("set_definition",{id:e.id,definition:k})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((w=l==null?void 0:l.ontology_refs)==null?void 0:w.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((p=e.term_map)==null?void 0:p.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),($=e.term_map)!=null&&$.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((N=e.term_map)==null?void 0:N.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Qe,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:k,steward:((O=l==null?void 0:l.stewardship)==null?void 0:O.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Qe,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:k=>{var O;return r("set_stewardship",{id:e.id,owner:((O=l==null?void 0:l.stewardship)==null?void 0:O.owner)??null,steward:k})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(k=>h.jsx(Xm,{a:k,entity:e,doc:t,readOnly:c,exec:r},k.id))})}),!c&&h.jsx(Wm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(k=>{const O=k.members.map(D=>{var B;return((B=e.attributes.find(H=>H.id===D))==null?void 0:B.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+k.type,children:k.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:k.name}),h.jsx("span",{className:"key-cols",children:O})]},k.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([k,O])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:k}),h.jsx("td",{className:"udp-val",children:String(O)})]},k))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(k=>{const O=k.from.entity===e.id?k.to.entity:k.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(O),children:[h.jsx("span",{className:"rel-card",children:Um(k,e.id)}),d(O)]}),(k.verb_phrase||k.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Qe,{value:k.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,verb_phrase:D})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Qe,{value:k.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:D=>r("update_relationship",{id:k.id,inverse_verb_phrase:D})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${k.name}`,onClick:()=>r("delete_relationship",{id:k.id}),children:"✕"})]},k.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var k;return(k=navigator.clipboard)==null?void 0:k.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Qe({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=x.useState(e);x.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Xm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Qe,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Qe,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Wm({entity:e,exec:t}){const[n,r]=x.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Um(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",mt="\0",Gs="";let Km=class{constructor(t){_e(this,"_isDirected",!0);_e(this,"_isMultigraph",!1);_e(this,"_isCompound",!1);_e(this,"_label");_e(this,"_defaultNodeLabelFn",()=>{});_e(this,"_defaultEdgeLabelFn",()=>{});_e(this,"_nodes",{});_e(this,"_in",{});_e(this,"_preds",{});_e(this,"_out",{});_e(this,"_sucs",{});_e(this,"_edgeObjs",{});_e(this,"_edgeLabels",{});_e(this,"_nodeCount",0);_e(this,"_edgeCount",0);_e(this,"_parent");_e(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[mt]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=mt,this._children[t]={},this._children[mt][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=mt;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==mt)return n}}children(t=mt){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===mt)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Ys(this._preds[n],t),Ys(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Xs(this._preds[n],t),Xs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Ys(e,t){e[t]?e[t]++:e[t]=1}function Xs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Gs+i+Gs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function sr(e,t){return Wt(e,t.v,t.w,t.name)}var Wr=Km,Qm="2.2.4",Jm={Graph:Wr,version:Qm},ep=Wr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){_e(this,"_arr",[]);_e(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=ea,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ta=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ta,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),ia(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),ia(t(i),o=>s.push(o)))}}function ia(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=sa,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=sa,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Wr,Lp=Jo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:ea,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ta,topsort:ra},Us=Jm,Be={Graph:Us.Graph,json:tp,alg:zp,version:Us.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return qs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&qs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function qs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Be.Graph,Gp=Vp;var Yp=Wp;let Xp=()=>1;function Wp(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Xp);return Up(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Up(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)ir(e,t,n,o);for(;o=s.dequeue();)ir(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(ir(e,t,n,o,!0));break}}}return r}function ir(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,jr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,jr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{jr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function jr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new oa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Ur(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=da(la(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),aa(e,"border",s,t)}function og(e,t=ca){const n=[];for(let r=0;rca){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function la(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function ua(e){var t=++ug;return e+(""+t)}function da(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Ur(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=Ee.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=Ee;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=Ee;var Yn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Be.Graph,On=Yn.slack,fa=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!On(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=On(t,s)),it.node(r).rank+=n)}var Rg=fa,Ks=Yn.slack,Ig=Yn.longestPath,Tg=Be.alg.preorder,Og=Be.alg.postorder,Lg=Ee.simplify,Dg=Et;Et.initLowLimValues=Kr;Et.initCutValues=qr;Et.calcCutValue=ha;Et.leaveEdge=pa;Et.enterEdge=ga;Et.exchangeEdges=ya;function Et(e){e=Lg(e),Ig(e);var t=Rg(e);Kr(t),qr(t,e);for(var n,r;n=pa(t);)r=ga(t,e,n),ya(t,e,n,r)}function qr(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ha(e,t,n)}function ha(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Kr(e,t){arguments.length<2&&(t=e.nodes()[0]),ma(e,{},1,t)}function ma(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ma(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function pa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ga(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===Zs(e,e.node(u.v),a)&&c!==Zs(e,e.node(u.w),a));return l.reduce((u,d)=>Ks(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function Zs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Yn,xa=Fg.longestPath,Vg=fa,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Qs(e);break;case"tight-tree":Wg(e);break;case"longest-path":Xg(e);break;case"none":break;default:Qs(e)}}var Xg=xa;function Wg(e){xa(e),Vg(e)}function Qs(e){Bg(e)}var Ug=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Ln=Ee;var Qg={run:Jg,cleanup:n0};function Jg(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=e0(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=t0(e)+1;e.children().forEach(a=>wa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function wa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{wa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,w=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,v=f!==w?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:v,nestingEdge:!0}),e.setEdge(w,l,{weight:y,minlen:v,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function e0(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function t0(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function n0(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let r0=Ee;var s0=i0;function i0(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iei(e.node(t))),e.edges().forEach(t=>ei(e.edge(t)))}function ei(e){let t=e.width;e.width=e.height,e.height=t}function l0(e){e.nodes().forEach(t=>or(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(or),Object.hasOwn(n,"y")&&or(n)})}function or(e){e.y=-e.y}function u0(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let ti=Ee;var d0=f0;function f0(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=ti.applyWithChunking(Math.max,r),i=ti.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let h0=Ee.zipObject;var m0=p0;function p0(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var y0=x0;function x0(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let w0=Ee;var b0=v0;function v0(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _0(r)}function _0(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&E0(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>w0.pick(s,["vs","i","barycenter","weight"]))}function E0(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let N0=Ee;var S0=k0;function k0(e,t){let n=N0.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(j0(!!t)),c=ni(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ni(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ni(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function j0(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let C0=y0,$0=b0,M0=S0;var A0=va;function va(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=C0(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=va(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&I0(m,f)}});let u=$0(l,n);R0(u,c);let d=M0(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function R0(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function I0(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let T0=Be.Graph,O0=Ee;var L0=D0;function D0(e,t,n,r){r||(r=e.nodes());let s=P0(e),i=new T0({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function P0(e){for(var t;e.hasNode(t=O0.uniqueId("_root")););return t}var z0=H0;function H0(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let F0=d0,V0=m0,B0=A0,G0=L0,Y0=z0,X0=Be.Graph,xn=Ee;var W0=_a;function _a(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,_a);return}let n=xn.maxRank(e),r=ri(e,xn.range(1,n+1),"inEdges"),s=ri(e,xn.range(n-1,-1,-1),"outEdges"),i=F0(e);if(si(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){U0(c%2?r:s,c%4>=2),i=xn.buildLayerMatrix(e);let u=V0(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return G0(e,i,n,r.get(i)||[])})}function U0(e,t){let n=new X0;e.forEach(function(r){let s=r.graph().root,i=B0(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Y0(r,n,i.vs)})}function si(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let q0=Be.Graph,Je=Ee;var K0={positionX:ay};function Z0(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=J0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(w=>{e.predecessors(w).forEach(y=>{let v=e.node(y),p=v.order;(p{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&Ea(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function J0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ea(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function ey(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function ty(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let w=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((w,y)=>Math.min(w,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function ry(e,t,n,r){let s=new q0,i=e.graph(),o=cy(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function sy(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=ly(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-Je.applyWithChunking(Math.min,l);o!=="l"&&(u=s-Je.applyWithChunking(Math.max,l)),u&&(e[a]=Je.mapValues(c,d=>d+u))})})}function oy(e,t){return Je.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function ay(e){let t=Je.buildLayerMatrix(e),n=Object.assign(Z0(e,t),Q0(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=ty(e,s,n,c),u=ny(e,s,l.root,l.align,a==="r");a==="r"&&(u=Je.mapValues(u,d=>-d)),r[o+a]=u})});let i=sy(e,r);return iy(r,i),oy(r,e.graph().align)}function cy(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function ly(e,t){return e.node(t).width}let Na=Ee,uy=K0.positionX;var dy=fy;function fy(e){e=Na.asNonCompoundGraph(e),hy(e),Object.entries(uy(e)).forEach(([t,n])=>e.node(t).x=n)}function hy(e){let t=Na.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ii=pg,oi=bg,my=Gg,py=Ee.normalizeRanks,gy=Ug,yy=Ee.removeEmptyRanks,ai=Qg,xy=s0,ci=o0,wy=W0,by=dy,De=Ee,vy=Be.Graph;var _y=Ey;function Ey(e,t){let n=t&&t.debugTiming?De.time:De.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>Iy(e));n(" runLayout",()=>Ny(r,n,t)),n(" updateInputGraph",()=>Sy(e,r))})}function Ny(e,t,n){t(" makeSpaceForEdgeLabels",()=>Ty(e)),t(" removeSelfEdges",()=>By(e)),t(" acyclic",()=>ii.run(e)),t(" nestingGraph.run",()=>ai.run(e)),t(" rank",()=>my(De.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>Oy(e)),t(" removeEmptyRanks",()=>yy(e)),t(" nestingGraph.cleanup",()=>ai.cleanup(e)),t(" normalizeRanks",()=>py(e)),t(" assignRankMinMax",()=>Ly(e)),t(" removeEdgeLabelProxies",()=>Dy(e)),t(" normalize.run",()=>oi.run(e)),t(" parentDummyChains",()=>gy(e)),t(" addBorderSegments",()=>xy(e)),t(" order",()=>wy(e,n)),t(" insertSelfEdges",()=>Gy(e)),t(" adjustCoordinateSystem",()=>ci.adjust(e)),t(" position",()=>by(e)),t(" positionSelfEdges",()=>Yy(e)),t(" removeBorderNodes",()=>Vy(e)),t(" normalize.undo",()=>oi.undo(e)),t(" fixupEdgeLabelCoords",()=>Hy(e)),t(" undoCoordinateSystem",()=>ci.undo(e)),t(" translateGraph",()=>Py(e)),t(" assignNodeIntersects",()=>zy(e)),t(" reversePoints",()=>Fy(e)),t(" acyclic.undo",()=>ii.undo(e))}function Sy(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let ky=["nodesep","edgesep","ranksep","marginx","marginy"],jy={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Cy=["acyclicer","ranker","rankdir","align"],$y=["width","height","rank"],li={width:0,height:0},My=["minlen","weight","width","height","labeloffset"],Ay={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ry=["labelpos"];function Iy(e){let t=new vy({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},jy,cr(n,ky),De.pick(n,Cy))),e.nodes().forEach(r=>{let s=lr(e.node(r));const i=cr(s,$y);Object.keys(li).forEach(o=>{i[o]===void 0&&(i[o]=li[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},Ay,cr(s,My),De.pick(s,Ry)))}),t}function Ty(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Oy(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};De.addDummyNode(e,"edge-proxy",i,"_ep")}})}function Ly(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Dy(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Py(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function zy(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(De.intersectRect(r,i)),n.points.push(De.intersectRect(s,o))})}function Hy(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Fy(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Vy(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function By(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Gy(e){var t=De.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{De.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Yy(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return De.mapValues(De.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Xy=Ee,Wy=Be.Graph;var Uy={debugOrdering:qy};function qy(e){let t=Xy.buildLayerMatrix(e),n=new Wy({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var Ky="1.1.8",Zy={graphlib:Be,layout:_y,debug:Uy,util:{time:Ee.time,notime:Ee.notime},version:Ky};const ui=vi(Zy),We=264,Qy=44,Jy=26,ex=14;function bt(e){const t=Math.max(e.attributes.length,1);return Qy+t*Jy+ex}const tx=40;function ur(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?mi(e,n,o):r==="clustered"?hi(e,t,n,o,i):r==="hierarchical"||e.length<=tx?di(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?hi(e,t,n,o,i):mi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Sa(e,t,n,r=!1,s="LR"){const i=new ui.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:We,height:d?bt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ui.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?bt(m):120,w=d.x-We/2,y=d.y-f/2;return a=Math.max(a,w+We),c=Math.max(c,y+f),{...u,position:{x:w,y}}}),width:a,height:c}}function di(e,t,n,r="LR"){return Sa(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?bt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(We+ka);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+We)}),i+=Math.max(...c.map(l=>n(l.id)))+ja}return{nodes:s,width:o,height:i}}const fi=120;function hi(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),w=new Set(f.map(E=>E.id));let y=0;for(const E of t)w.has(E.source)&&w.has(E.target)&&y++;const p=f.length<=8&&y>=f.length-1?Sa(f,t,n,!0,s):rx(f,n);return{name:m,...p}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const ka=40,ja=40;function mi(e,t,n){const r=l=>{const u=t.get(l);return u?bt(u):120},s=[...e].sort((l,u)=>{var y,v;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,w=((v=t.get(u.id))==null?void 0:v.name)??u.id;return f.localeCompare(w)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(We+ka)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ja}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function cn({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ca=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var b,M;const[r,s]=x.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[i,o]=x.useState([]),[a,c]=x.useState(null),[l,u]=x.useState(null),[d,m]=x.useState("skos:exactMatch"),[f,w]=x.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,v]=x.useState([]),[p,E]=x.useState("");x.useEffect(()=>{Qo().then(N=>v(N.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const N=setTimeout(()=>{if(!r.trim())return o([]);Zo(r,p||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(N)},[r,p]);const $=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(cn,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(p===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(N=>h.jsx("button",{className:"src-chip"+(p===N.id?" active":""),title:N.count!=null?`${N.count} terms`:"live resolver",onClick:()=>E(N.id),children:N.name},N.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:p?`Search within ${p}…`:"Search vocabulary terms…",value:r,onChange:N=>s(N.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(N=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===N.iri?" picked":""),onClick:()=>u(N),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:N.label}),h.jsxs("span",{className:"term-source",children:[N.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),N.source]})]}),h.jsx("code",{className:"term-iri",children:N.prefixed}),N.definition&&h.jsx("p",{className:"term-def",children:N.definition})]},N.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:N=>m(N.target.value),children:sx.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:N=>w(N.target.value),children:Ca.map(N=>h.jsx("option",{children:N},N))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:$,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var b,M,N;const[s,i]=x.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[o,a]=x.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},w=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${w}:`,v=(N=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:N.members.map(_=>{var R;return(R=e.attributes.find(k=>k.id===_))==null?void 0:R.name}).filter(Boolean),p=v&&v.length?`${y}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,$=s.trim()||p;return h.jsxs(cn,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",$]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=x.useState(""),[o,a]=x.useState(""),[c,l]=x.useState(""),[u,d]=x.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const w=f==null?void 0:f.created_id;n(),w&&r(w)})};return h.jsxs(cn,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ca.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const $a=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=x.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=x.useState(r??""),[m,f]=x.useState(s??(l==null?void 0:l.id)??""),[w,y]=x.useState("many_to_one"),[v,p]=x.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",$=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:w,optionality:v}).then(o);return h.jsxs(cn,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:w,onChange:b=>y(b.target.value),children:$a.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>p(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:$,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=p=>{var E;return((E=t.entities.find($=>$.id===p))==null?void 0:E.name)??"?"},[i,o]=x.useState(e.name),[a,c]=x.useState(e.cardinality),[l,u]=x.useState(e.optionality),[d,m]=x.useState(e.identifying),[f,w]=x.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(cn,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:p=>o(p.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:p=>c(p.target.value),children:$a.map(p=>h.jsx("option",{children:p},p))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:p=>u(p.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:p=>m(p.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>w(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const pi=10,ux=6,Ye=24;function dx(e,t){return t?e:Math.round(e/pi)*pi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-Ye,o.right+Ye);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eF.transform[2]),[m,f]=x.useState(null),w=x.useRef(!1),y=x.useRef(0),v=c==null?void 0:c.onRouteChange,p=!!v,E=m??(c==null?void 0:c.routeX),[$,b,M]=Rn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),N=c==null?void 0:c.relationship,_=(c==null?void 0:c.dimmed)??!1,R=(N==null?void 0:N.cardinality)??"many_to_one",k=(N==null?void 0:N.optionality)==="optional",O=(N==null?void 0:N.identifying)??!1,D=R==="many_to_one"||R==="many_to_many",B=R==="one_to_many"||R==="many_to_many",H="rel-edge"+(l?" selected":"")+(_?" dimmed":""),g=((c==null?void 0:c.memberCount)??0)>1,C=c==null?void 0:c.onHoverEdge,S=E??b,I=M,L=S,j=I,T=x.useCallback(F=>v&&N&&v(N.id,F),[v,N]),P=x.useCallback(F=>{var pe,ce;if(!p||F.button!==0)return;F.stopPropagation(),(ce=(pe=F.target).setPointerCapture)==null||ce.call(pe,F.pointerId),w.current=!0,y.current=0;const J=u({x:F.clientX,y:F.clientY}).x;let te=0,oe=E??S;const ne=ue=>{const ge=u({x:ue.clientX,y:ue.clientY});y.current=Math.max(y.current,Math.abs(ge.x-J)),oe=mx(ge.x,{shift:ue.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),te||(te=requestAnimationFrame(()=>{te=0,f(oe)}))},se=()=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",se),te&&cancelAnimationFrame(te),w.current=!1,f(null),y.current>=gi&&T(oe)};window.addEventListener("pointermove",ne),window.addEventListener("pointerup",se)},[p,u,E,S,c,n,s,T]),z=x.useCallback(F=>{y.current>=gi&&(F.stopPropagation(),y.current=0)},[]),X=x.useCallback(F=>{p&&(F.stopPropagation(),T(null))},[p,T]);return h.jsxs("g",{className:H,onMouseEnter:C?()=>C(N.id):void 0,onMouseLeave:C?()=>C(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:$,fill:"none",strokeDasharray:O?void 0:"6 4"}),h.jsx("path",{d:$,fill:"none",strokeWidth:16/d,stroke:"transparent"}),h.jsx(yi,{x:n,y:r,side:o,many:D,optional:k}),h.jsx(yi,{x:s,y:i,side:a,many:B,optional:!1}),p&&((c==null?void 0:c.hovered)||l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:P,onClickCapture:z,onDoubleClick:X,children:[h.jsx("rect",{x:S-20/d,y:Math.min(r,i),width:40/d,height:Math.max(Math.abs(i-r),24/d),fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:S-5.5/d,y:I-11/d,width:11/d,height:22/d,rx:5/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I-4.5/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:S,cy:I+4.5/d,r:1.1/d})]}),(l||g)&&N&&h.jsxs("text",{className:"rel-label",x:L,y:j-8,children:[l?N.verb_phrase||N.name:"",g?`${l?" ":""}(${c.memberCount})`:""]})]})});function yi({x:e,y:t,side:n,many:r,optional:s}){const i=n===q.Left?-1:1,o=7,a=12,c=[];return r?c.push(h.jsx("path",{className:"rel-glyph",d:`M ${e+i*a} ${t} L ${e} ${t-o} M ${e+i*a} ${t} L ${e} ${t} M ${e+i*a} ${t} L ${e} ${t+o}`,fill:"none"},"foot")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a-3),y1:t-o,x2:e+i*(a-3),y2:t+o},"one")),s?c.push(h.jsx("circle",{className:"rel-glyph ring",cx:e+i*(a+6),cy:t,r:4},"opt")):c.push(h.jsx("line",{className:"rel-glyph",x1:e+i*(a+5),y1:t-o,x2:e+i*(a+5),y2:t+o},"mand")),h.jsx(h.Fragment,{children:c})}const gx={entity:Pm},yx={relationship:px},xi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],wi="#8a7d6a";function xx(e,t,n){const s=We;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function wx(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Yr,targetHandle:n(e.to.entity,s)?s:Xr}}function qx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:w,fitBounds:y,getNodes:v}=an(),[p,E]=x.useState([]),[$,b]=x.useState([]),M=x.useRef(!1),N=x.useMemo(()=>{const V=u&&u.size>0?[...u].sort():null;return V?"sa:"+V.join("+"):"__all__"},[u]),_=x.useRef(null),[R,k]=x.useState(0),O=x.useRef(new Map),D=x.useRef(null);x.useEffect(()=>{if(!f){_.current=null;return}const V=O.current.get(N);if(V){_.current=V,M.current=!1,k(G=>G+1);return}let Y=!1;return f.load(N).then(G=>{Y||(O.current.set(N,G),_.current=G,M.current=!1,k(Q=>Q+1))}),()=>{Y=!0}},[f,N]);const[B,H]=x.useState(null),[g,C]=x.useState(null),[S,I]=x.useState(!1),[L,j]=x.useState(null),[T,P]=x.useState(null),[z,X]=x.useState(null),[F,Z]=x.useState(null),J=x.useRef({}),te=!t.canEdit,oe=x.useRef(null),ne=x.useCallback(()=>{f&&(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{const V={};for(const Q of v())Q.hidden||(V[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,U]of Object.entries(J.current))Y[Q]={routeX:Math.round(U)};const G={nodes:V,edges:Y};O.current.set(N,G),_.current=G,f.save(N,G)},800))},[f,v,N]),se=x.useCallback((V,Y)=>{Y==null?delete J.current[V]:J.current[V]=Y,b(G=>G.map(Q=>Q.id===V?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),ne()},[ne]),pe=x.useMemo(()=>{const V=new Map;return e.subject_areas.forEach((Y,G)=>V.set(Y.id,xi[G%xi.length])),V},[e]),ce=x.useMemo(()=>{const V=new Map;return e.entities.forEach(Y=>V.set(Y.id,Y)),V},[e]),ue=x.useMemo(()=>{const V=new Map,Y=new Map;return e.subject_areas.forEach(G=>{(G.members??[]).forEach(Q=>Y.set(Q,{id:G.id,name:G.name}))}),e.entities.forEach(G=>{var re,me;const Q=(re=G.conceptual)!=null&&re.id?Y.get(G.conceptual.id):void 0,U=(me=G.conceptual)==null?void 0:me.subject_area,ee=Q??(U?{id:U.id,name:U.name??U.id}:void 0);ee&&V.set(G.id,ee)}),V},[e]),ge=x.useCallback(V=>{var G;if(!u||u.size===0)return!1;const Y=(G=ue.get(V))==null?void 0:G.id;return!(Y&&u.has(Y))},[u,ue]),he=x.useMemo(()=>{const V=new Map,Y=(G,Q)=>{if(!Q.length)return;const U=V.get(G)??new Set;Q.forEach(ee=>U.add(ee)),V.set(G,U)};for(const G of e.relationships)Y(G.from.entity,G.from.attributes),Y(G.to.entity,G.to.attributes);return V},[e]);x.useEffect(()=>{var $e;const V=i.trim().toLowerCase(),Y=new Set;if(V)for(const W of e.entities)(W.name.toLowerCase()+" "+((($e=W.conceptual)==null?void 0:$e.name.toLowerCase())??"")+" "+W.attributes.map(xe=>xe.name.toLowerCase()).join(" ")).includes(V)&&Y.add(W.id);const G=new Set;if(r){G.add(r);for(const W of e.relationships)W.from.entity===r&&G.add(W.to.entity),W.to.entity===r&&G.add(W.from.entity)}const Q=e.entities.map(W=>{const fe=V!==""&&!Y.has(W.id),xe=r!==null&&!G.has(W.id);return{id:W.id,type:"entity",position:{x:0,y:0},hidden:ge(W.id),data:{entity:W,color:(()=>{const ve=ue.get(W.id);return ve?pe.get(ve.id)??wi:wi})(),dimmed:fe||xe,highlighted:V!==""&&Y.has(W.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(W.id))??!1,onToggleExpand:l,endpointAttrs:he.get(W.id),highlightAttrs:void 0,onHoverAttr:X}}}),U=e.relationships.filter(W=>ce.has(W.from.entity)&&ce.has(W.to.entity)).map(W=>{const{sourceHandle:fe,targetHandle:xe}=wx(W,ce),ve=r!==null&&W.from.entity!==r&&W.to.entity!==r;return{id:W.id,source:W.from.entity,target:W.to.entity,sourceHandle:fe,targetHandle:xe,type:"relationship",data:{relationship:W,dimmed:ve,memberCount:Math.max(W.from.attributes.length,W.to.attributes.length),onHoverEdge:Z}}}),ee=_.current;if(J.current={},ee)for(const[W,fe]of Object.entries(ee.edges))J.current[W]=fe.routeX;let re=Q;E(W=>{const fe=new Map(W.map(ae=>[ae.id,ae.position])),xe=Q.every(ae=>fe.has(ae.id)),ve=((u==null?void 0:u.size)??0)>0;if(M.current&&xe&&W.length>=Q.length&&!ve){const ae=Q.map(Ke=>({...Ke,position:fe.get(Ke.id)??Ke.position}));return re=ae,ae}const Ge=ve?Q.filter(ae=>!ae.hidden):Q,it=ur(Ge,U,ce,"auto",ue),Pe=new Map(it.map(ae=>[ae.id,ae.position])),ht=(ee==null?void 0:ee.nodes)??{},Lt=Object.keys(ht).length>0,ze=[],Dt=Q.map(ae=>{const Ke=ht[ae.id];if(Ke){const Pt={x:Ke.x,y:Ke.y};return ze.push({x:Pt.x,y:Pt.y,w:We,h:bt(ae.data.entity)}),{...ae,position:Pt}}return Pe.has(ae.id)?{...ae,position:Pe.get(ae.id)}:fe.has(ae.id)&&M.current?{...ae,position:fe.get(ae.id)}:ae});if(Lt)for(const ae of Dt)ht[ae.id]||ae.hidden||(ae.position=xx(ae.position,bt(ae.data.entity),ze),ze.push({x:ae.position.x,y:ae.position.y,w:We,h:bt(ae.data.entity)}));return M.current=!0,Lt||requestAnimationFrame(()=>w({padding:.15,duration:300})),re=Dt,Dt});const me=new Map;for(const W of re)me.set(W.id,{left:W.position.x,right:W.position.x+We});b(U.map(W=>({...W,data:{...W.data,routeX:J.current[W.id],onRouteChange:f?se:void 0,sourceCard:me.get(W.source),targetCard:me.get(W.target)}})))},[e,i,r,o,a,c,l,pe,ce,ue,ge,u,he,w,f,se,R]);const ye=x.useMemo(()=>{const V=new Set,Y=new Set,G=new Map,Q=(U,ee)=>{if(!ee.length)return;const re=G.get(U)??new Set;ee.forEach(me=>re.add(me)),G.set(U,re)};if(z)for(const U of e.relationships)(U.from.attributes.includes(z)||U.to.attributes.includes(z))&&(V.add(U.id),Y.add(U.from.entity),Y.add(U.to.entity),Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes));if(F){const U=e.relationships.find(ee=>ee.id===F);U&&(Q(U.from.entity,U.from.attributes),Q(U.to.entity,U.to.attributes))}return{active:z!==null,relsForAttr:V,entsForAttr:Y,hitAttrsByEntity:G}},[e,z,F]);x.useEffect(()=>{var Q;const V=i.trim().toLowerCase(),Y=new Set;if(V)for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(re=>re.name.toLowerCase()).join(" ")).includes(V)&&Y.add(U.id);const G=new Set;if(r){G.add(r);for(const U of e.relationships)U.from.entity===r&&G.add(U.to.entity),U.to.entity===r&&G.add(U.from.entity)}E(U=>U.map(ee=>{const re=V!==""&&!Y.has(ee.id),me=r!==null&&!G.has(ee.id),$e=ye.active&&!ye.entsForAttr.has(ee.id),W=re||me||$e,fe=V!==""&&Y.has(ee.id)||ye.active&&ye.entsForAttr.has(ee.id),xe=ye.hitAttrsByEntity.get(ee.id);return ee.data.dimmed===W&&ee.data.highlighted===fe&&ee.data.highlightAttrs===xe?ee:{...ee,data:{...ee.data,dimmed:W,highlighted:fe,highlightAttrs:xe}}})),b(U=>U.map(ee=>{var Ge,it,Pe;const re=(Ge=ee.data)==null?void 0:Ge.relationship,me=r!==null&&re!==void 0&&re.from.entity!==r&&re.to.entity!==r,$e=ye.active&&!ye.relsForAttr.has(ee.id),W=me||$e,fe=F===ee.id,xe=r!==null&&re!==void 0&&(re.from.entity===r||re.to.entity===r),ve=fe||xe?1e3:0;return((it=ee.data)==null?void 0:it.dimmed)===W&&((Pe=ee.data)==null?void 0:Pe.hovered)===fe&&ee.zIndex===ve?ee:{...ee,zIndex:ve,data:{...ee.data,dimmed:W,hovered:fe}}}))},[ye,F,i,r,e]),x.useEffect(()=>{var Q;const V=i.trim().toLowerCase();if(!V)return;const Y=new Set;for(const U of e.entities)(U.name.toLowerCase()+" "+(((Q=U.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+U.attributes.map(re=>re.name.toLowerCase()).join(" ")).includes(V)&&Y.add(U.id);if(!Y.size)return;const G=requestAnimationFrame(()=>{const U=v().filter(re=>Y.has(re.id));if(!U.length)return;const ee=Mf(U);y(ee,{padding:.35,duration:400})});return()=>cancelAnimationFrame(G)},[i,e,v,y]);const le=x.useCallback((V="auto",Y="LR")=>{D.current=Object.fromEntries(v().map(G=>[G.id,{x:G.position.x,y:G.position.y}])),E(G=>ur(G,$,ce,V,ue,Y)),requestAnimationFrame(()=>w({padding:.15,duration:300})),ne()},[$,ce,ue,w,v,ne]),K=x.useCallback(()=>{const V=D.current;V&&(E(Y=>Y.map(G=>V[G.id]?{...G,position:V[G.id]}:G)),D.current=null,ne())},[ne]),Se=x.useCallback(()=>{f==null||f.reset(N),O.current.delete(N),_.current=null,J.current={},M.current=!1,b(V=>V.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(V=>{const Y=ur(V,$,ce,"auto",ue);return requestAnimationFrame(()=>w({padding:.15,duration:300})),Y})},[f,N,$,ce,ue,w]),Ce=x.useCallback(V=>{s(V),E(Y=>(Y.find(Q=>Q.id===V)&&requestAnimationFrame(()=>w({nodes:[{id:V}],padding:.4,duration:400})),Y))},[w,s]);x.useImperativeHandle(m,()=>({relayout:le,fitView:()=>w({padding:.15,duration:300}),focusEntity:Ce,newEntity:()=>I(!0),resetLayout:Se,undoRelayout:K}),[le,w,Ce,Se,K]);const ft=x.useCallback(V=>{if(te||!V.source||!V.target||V.source===V.target)return;const Y=V.sourceHandle&&V.sourceHandle!==Yr?V.sourceHandle:void 0,G=V.targetHandle&&V.targetHandle!==Xr?V.targetHandle:void 0;j({from:V.source,to:V.target,fromAttr:Y,toAttr:G})},[te]),Ae=x.useCallback(async(V,Y)=>{try{return await n(V,Y)}catch(G){throw d==null||d(G instanceof Error?G.message:String(G)),G}},[n,d]),qe=r?ce.get(r)??null:null,Ie=e.relationships.find(V=>V.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Yo,{nodes:p,edges:$,nodeTypes:gx,edgeTypes:yx,onNodeClick:(V,Y)=>s(Y.id),onEdgeDoubleClick:(V,Y)=>!te&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(V,Y)=>{E(G=>G.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),ne()},onConnect:ft,nodesConnectable:!te,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:Le.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:V=>{var Y;return((Y=V.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),qe&&h.jsx(Hm,{entity:qe,doc:e,caps:t,exec:Ae,onClose:()=>s(null),onFocusEntity:Ce,onAlign:H,onEditMapping:C}),B&&h.jsx(ix,{entity:B,exec:Ae,onClose:()=>H(null)}),g&&h.jsx(ox,{entity:g,doc:e,exec:Ae,onClose:()=>C(null)}),S&&h.jsx(ax,{doc:e,exec:Ae,onClose:()=>I(!1),onCreated:Ce}),L&&h.jsx(cx,{doc:e,fromId:L.from,toId:L.to,initialFromAttr:L.fromAttr,initialToAttr:L.toAttr,exec:Ae,onClose:()=>j(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:Ae,onClose:()=>P(null)})]})}function Kx({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(bx,{}),e==="layers"&&h.jsx(_x,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(Ex,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Nx,{readOnly:n})]})}function bx(){const[e,t]=x.useState(""),[n,r]=x.useState([]),[s,i]=x.useState({loaded:0,vocabs:[]}),[o,a]=x.useState(null),[c,l]=x.useState([]),[u,d]=x.useState("");x.useEffect(()=>{Qo().then(f=>l(f.ontologies)).catch(()=>{})},[]),x.useEffect(()=>{const f=setTimeout(()=>{Zo(e||"a",u||void 0).then(w=>{r(e?w.results:[]),i({loaded:w.loaded_terms,vocabs:w.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=x.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const vx=["industry","core","domain","specialised"];function _x({refreshKey:e,onFocusEntity:t}){const[n,r]=x.useState(null),[s,i]=x.useState(null);if(x.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),vx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Ex({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=x.useState(null),[i,o]=x.useState(""),[a,c]=x.useState(""),[l,u]=x.useState(!1),d=x.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` - -`))).catch(()=>o(""))},[]);return x.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:i.split(` -`).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` -`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:l,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(u(!0),Mm().then(()=>{u(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:l||!a.trim(),onClick:()=>{u(!0),$m(a).then(()=>{u(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Nx({readOnly:e}){const[t,n]=x.useState([]),r=x.useCallback(()=>{Am().then(i=>n(i.decisions)).catch(()=>n([]))},[]);if(x.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(i=>h.jsxs("div",{className:"decision "+i.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[i.verdict]}),h.jsx("span",{className:"chip",children:i.confidence}),h.jsx("span",{className:"chip",children:i.signal})]}),h.jsx("p",{className:"decision-subject",children:i.subject}),!e&&i.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Bs(i.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Bs(i.signal_key,"rejected").then(r),children:"Reject"})]})]},i.signal_key))})}function Zx({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:i,openImport:o=!1,prefillImport:a="",onPreview:c}){const[l,u]=x.useState(o&&t?"import":null),[d,m]=x.useState([]),[f,w]=x.useState("postgres"),y=x.useRef(null);x.useEffect(()=>{Rm().then(p=>m(p.formats)).catch(()=>m([]))},[]),x.useEffect(()=>{if(!l)return;const p=E=>{y.current&&!y.current.contains(E.target)&&u(null)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[l]);const v=d.find(p=>p.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:y,children:[h.jsxs("button",{className:s+(l==="export"?" on":""),onClick:()=>u(l==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(l==="import"?" on":""),onClick:()=>u(l==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),l==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(v==null?void 0:v.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:p=>w(p.target.value),children:v.dialects.map(p=>h.jsx("option",{value:p,children:p},p))})]}),d.map(p=>h.jsx("a",{className:"ie-item",href:Im(p.id,p.id==="sql"?f:void 0),download:!0,onClick:()=>u(null),children:p.label},p.id))]}),l==="import"&&h.jsx(Sx,{exec:e,submitLabel:r,buttonClass:s,applyBatch:i,onClose:()=>u(null),onImported:p=>{u(null),n==null||n(p)},onPreview:c,prefillImport:a})]})}const bi=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function Sx({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:i,onPreview:o,prefillImport:a}){var N;const[c,l]=x.useState(o?"erwin":"sql"),[u,d]=x.useState("postgres"),[m,f]=x.useState(a??""),[w,y]=x.useState(!1),[v,p]=x.useState(null),[E,$]=x.useState([]);x.useEffect(()=>{a&&f(a)},[a]);const b=_=>{_&&_.text().then(f).catch(()=>p("could not read that file"))},M=async()=>{y(!0),p(null),$([]);try{if(o&&c==="erwin"){const R=await Om(c,m);if(!R.changes.length){p(R.warnings[0]??"nothing to import from that document"),y(!1);return}s(),o(R),y(!1);return}const _=await Tm(c,m,c==="sql"?u:void 0);if(!_.changes.length){p(_.warnings[0]??"nothing to import from that document"),y(!1);return}if(r)await r(_.changes);else for(const R of _.changes)await e(R.op,R.payload);$(_.warnings),i(_.tables)}catch(_){p(_ instanceof Error?_.message:String(_))}finally{y(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:bi.map(_=>h.jsx("button",{className:"ie-tab"+(c===_.id?" active":""),onClick:()=>l(_.id),children:_.label},_.id))}),h.jsx("p",{className:"ie-hint",children:(N=bi.find(_=>_.id===c))==null?void 0:N.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:u,onChange:_=>d(_.target.value),children:["postgres","snowflake","mysql","duckdb"].map(_=>h.jsx("option",{children:_},_))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:_=>f(_.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:_=>{var R;return b(((R=_.target.files)==null?void 0:R[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((_,R)=>h.jsx("p",{className:"ie-warn",children:_},R)),v&&h.jsx("p",{className:"ie-error",children:v}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:w||!m.trim(),onClick:M,children:w?"Importing…":t})]})]})}export{Ko as A,_m as B,gm as C,Pm as E,Zx as I,_x as L,qx as M,bx as O,xi as P,Bo as R,Kx as S,$x as a,Hx as b,Dx as c,Vx as d,Bx as e,Cx as f,jm as g,Yx as h,Gx as i,Px as j,Rx as k,Ix as l,Tx as m,Lx as n,Zo as o,Fx as p,zx as q,Ox as r,km as s,Mx as t,Ax as u,ur as v,Yo as w,px as x,lm as y}; diff --git a/packages/server/src/mdl_server/static/assets/styles-CBRLc9al.js b/packages/server/src/mdl_server/static/assets/styles-CBRLc9al.js new file mode 100644 index 0000000..1c9360f --- /dev/null +++ b/packages/server/src/mdl_server/static/assets/styles-CBRLc9al.js @@ -0,0 +1,23 @@ +var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Ee=(e,t,n)=>oc(e,typeof t!="symbol"?t+"":t,n);import{r as w,g as bi,R as A,j as h}from"./client-DOmNpTln.js";function Ce(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?mc:hc;Ni.useSyncExternalStore=It.useSyncExternalStore!==void 0?It.useSyncExternalStore:pc;Ei.exports=Ni;var gc=Ei.exports;/** + * @license React + * use-sync-external-store-shim/with-selector.production.js + * + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var On=w,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=On.useRef,_c=On.useEffect,Ec=On.useMemo,Nc=On.useDebugValue;_i.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var p=o.value;if(s(p,f))return d=p}return d=f}if(p=d,wc(u,f))return p;var y=r(f);return s!==void 0&&s(p,y)?(u=f,p):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};vi.exports=_i;var Sc=vi.exports;const kc=bi(Sc),jc={},Qr=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(p=>p(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?Qr(e):Qr,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function Si(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const Jr=(e,t)=>{const n=Cc(e),r=(s,i=t)=>Si(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?Jr(e,t):Jr;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Ln(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}xn.prototype=Ln.prototype={constructor:xn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),ts.hasOwnProperty(t)?{space:ts[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===lr&&t.documentElement.namespaceURI===lr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ki(e){var t=Dn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function kr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=kr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=C&&(C=E+1);!(M=b[C])&&++C=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Tt(this.node(),e)}function Tt(e,t){return e.style.getPropertyValue(t)||Ai(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ri(e){return e.trim().split(/^|\s+/)}function jr(e){return e.classList||new Ii(e)}function Ii(e){this._node=e,this._names=Ri(e.getAttribute("class")||"")}Ii.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Ti(e,t){for(var n=jr(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function ur(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}ur.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Ln("start","drag","end"),o=0,a,c,l,u,d=0;function m(v){v.on("mousedown.drag",f).filter(r).on("touchstart.drag",b).on("touchmove.drag",g,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(v,M){if(!(u||!e.call(this,v,M))){var j=C(this,t.call(this,v,M),v,M,"mouse");j&&(Oe(v.view).on("mousemove.drag",p,Ut).on("mouseup.drag",y,Ut),Pi(v.view),Wn(v),l=!1,a=v.clientX,c=v.clientY,j("start",v))}}function p(v){if(Mt(v),!l){var M=v.clientX-a,j=v.clientY-c;l=M*M+j*j>d}s.mouse("drag",v)}function y(v){Oe(v.view).on("mousemove.drag mouseup.drag",null),zi(v.view,l),Mt(v),s.mouse("end",v)}function b(v,M){if(e.call(this,v,M)){var j=v.changedTouches,_=t.call(this,v,M),I=j.length,N,R;for(N=0;N>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?ln(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?ln(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Ae(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Ae(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?ln(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?ln(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?cs(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?cs(t[1],t[2]/100,t[3]/100,t[4]):ns.hasOwnProperty(e)?is(ns[e]):e==="transparent"?new Ae(NaN,NaN,NaN,0):null}function is(e){return new Ae(e>>16&255,e>>8&255,e&255,1)}function ln(e,t,n,r){return r<=0&&(e=t=n=NaN),new Ae(e,t,n,r)}function Mu(e){return e instanceof nn||(e=Kt(e)),e?(e=e.rgb(),new Ae(e.r,e.g,e.b,e.opacity)):new Ae}function dr(e,t,n,r){return arguments.length===1?Mu(e):new Ae(e,t,n,r??1)}function Ae(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Cr(Ae,dr,Hi(nn,{brighter(e){return e=e==null?En:Math.pow(En,e),new Ae(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Xt:Math.pow(Xt,e),new Ae(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Ae(yt(this.r),yt(this.g),yt(this.b),Nn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:os,formatHex:os,formatHex8:Au,formatRgb:as,toString:as}));function os(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function as(){const e=Nn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function Nn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function cs(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ve(e,t,n,r)}function Fi(e){if(e instanceof Ve)return new Ve(e.h,e.s,e.l,e.opacity);if(e instanceof nn||(e=Kt(e)),!e)return new Ve;if(e instanceof Ve)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new Ve(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Fi(e):new Ve(e,t,n,r??1)}function Ve(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Cr(Ve,Ru,Hi(nn,{brighter(e){return e=e==null?En:Math.pow(En,e),new Ve(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Xt:Math.pow(Xt,e),new Ve(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Ae(Un(e>=240?e-240:e+120,s,r),Un(e,s,r),Un(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Ve(ls(this.h),un(this.s),un(this.l),Nn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Nn(this.opacity);return`${e===1?"hsl(":"hsla("}${ls(this.h)}, ${un(this.s)*100}%, ${un(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ls(e){return e=(e||0)%360,e<0?e+360:e}function un(e){return Math.max(0,Math.min(1,e||0))}function Un(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Vi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Bi:function(t,n){return n-t?Tu(t,n,e):Vi(isNaN(t)?n:t)}}function Bi(e,t){var n=t-e;return n?Iu(e,n):Vi(isNaN(e)?t:e)}const us=function e(t){var n=Ou(t);function r(s,i){var o=n((s=dr(s)).r,(i=dr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Bi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function at(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var fr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Xn=new RegExp(fr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=fr.lastIndex=Xn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=fr.exec(e))&&(s=Xn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:at(r,s)})),n=Xn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:at(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:at(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,p){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");p.push({i:y-4,x:at(l,d)},{i:y-2,x:at(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var p=-1,y=m.length,b;++p=0&&e._call.call(void 0,t),e=e._next;--Ot}function hs(){wt=(kn=Zt.now())+Pn,Ot=Bt=0;try{Xu()}finally{Ot=0,Ku(),wt=0}}function qu(){var e=Zt.now(),t=e-kn;t>Wi&&(Pn-=t,kn=e)}function Ku(){for(var e,t=Sn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Sn=n);Gt=e,mr(r)}function mr(e){if(!Ot){Bt&&(Bt=clearTimeout(Bt));var t=e-wt;t>24?(e<1/0&&(Bt=setTimeout(hs,e-Zt.now()-Pn)),Pt&&(Pt=clearInterval(Pt))):(Pt||(kn=Zt.now(),Pt=setInterval(qu,Wi)),Ot=1,Ui(hs))}}function ms(e,t,n){var r=new jn;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Ln("start","end","cancel","interrupt"),Qu=[],qi=0,ps=1,pr=2,wn=3,gs=4,gr=5,bn=6;function zn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:qi})}function Mr(e,t){var n=Be(e,t);if(n.state>qi)throw new Error("too late; already scheduled");return n}function Xe(e,t){var n=Be(e,t);if(n.state>wn)throw new Error("too late; already running");return n}function Be(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=Xi(i,0,n.time);function i(l){n.state=ps,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ps)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===wn)return ms(o);f.state===gs?(f.state=bn,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+upr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Mr:Xe;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Be(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=kr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function tt(e,t,n){this.k=e,this.x=t,this.y=n}tt.prototype={constructor:tt,scale:function(e){return e===1?this:new tt(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new tt(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var nt=new tt(1,0,0);tt.prototype;function qn(e){e.stopImmediatePropagation()}function zt(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ys(){return this.__zoom||nt}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function Ji(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Wu,l=Ln("start","zoom","end"),u,d,m,f=500,p=150,y=0,b=10;function g(x){x.property("__zoom",ys).on("wheel.zoom",I,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",R).filter(s).on("touchstart.zoom",P).on("touchmove.zoom",V).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(x,$,S,O){var D=x.selection?x.selection():x;D.property("__zoom",ys),x!==D?M(x,$,S,O):D.interrupt().each(function(){j(this,arguments).event(O).start().zoom(null,typeof $=="function"?$.apply(this,arguments):$).end()})},g.scaleBy=function(x,$,S,O){g.scaleTo(x,function(){var D=this.__zoom.k,k=typeof $=="function"?$.apply(this,arguments):$;return D*k},S,O)},g.scaleTo=function(x,$,S,O){g.transform(x,function(){var D=t.apply(this,arguments),k=this.__zoom,T=S==null?v(D):typeof S=="function"?S.apply(this,arguments):S,L=k.invert(T),z=typeof $=="function"?$.apply(this,arguments):$;return n(C(E(k,z),T,L),D,o)},S,O)},g.translateBy=function(x,$,S,O){g.transform(x,function(){return n(this.__zoom.translate(typeof $=="function"?$.apply(this,arguments):$,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,O)},g.translateTo=function(x,$,S,O,D){g.transform(x,function(){var k=t.apply(this,arguments),T=this.__zoom,L=O==null?v(k):typeof O=="function"?O.apply(this,arguments):O;return n(nt.translate(L[0],L[1]).scale(T.k).translate(typeof $=="function"?-$.apply(this,arguments):-$,typeof S=="function"?-S.apply(this,arguments):-S),k,o)},O,D)};function E(x,$){return $=Math.max(i[0],Math.min(i[1],$)),$===x.k?x:new tt($,x.x,x.y)}function C(x,$,S){var O=$[0]-S[0]*x.k,D=$[1]-S[1]*x.k;return O===x.x&&D===x.y?x:new tt(x.k,O,D)}function v(x){return[(+x[0][0]+ +x[1][0])/2,(+x[0][1]+ +x[1][1])/2]}function M(x,$,S,O){x.on("start.zoom",function(){j(this,arguments).event(O).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(O).end()}).tween("zoom",function(){var D=this,k=arguments,T=j(D,k).event(O),L=t.apply(D,k),z=S==null?v(L):typeof S=="function"?S.apply(D,k):S,W=Math.max(L[1][0]-L[0][0],L[1][1]-L[0][1]),G=D.__zoom,K=typeof $=="function"?$.apply(D,k):$,Z=c(G.invert(z).concat(W/G.k),K.invert(z).concat(W/K.k));return function(ne){if(ne===1)ne=K;else{var ie=Z(ne),re=W/ie[2];ne=new tt(re,z[0]-ie[0]*re,z[1]-ie[1]*re)}T.zoom(null,ne)}})}function j(x,$,S){return!S&&x.__zooming||new _(x,$)}function _(x,$){this.that=x,this.args=$,this.active=0,this.sourceEvent=null,this.extent=t.apply(x,$),this.taps=0}_.prototype={event:function(x){return x&&(this.sourceEvent=x),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(x,$){return this.mouse&&x!=="mouse"&&(this.mouse[1]=$.invert(this.mouse[0])),this.touch0&&x!=="touch"&&(this.touch0[1]=$.invert(this.touch0[0])),this.touch1&&x!=="touch"&&(this.touch1[1]=$.invert(this.touch1[0])),this.that.__zoom=$,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(x){var $=Oe(this.that).datum();l.call(x,this.that,new sf(x,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:l}),$)}};function I(x,...$){if(!e.apply(this,arguments))return;var S=j(this,$).event(x),O=this.__zoom,D=Math.max(i[0],Math.min(i[1],O.k*Math.pow(2,r.apply(this,arguments)))),k=Fe(x);if(S.wheel)(S.mouse[0][0]!==k[0]||S.mouse[0][1]!==k[1])&&(S.mouse[1]=O.invert(S.mouse[0]=k)),clearTimeout(S.wheel);else{if(O.k===D)return;S.mouse=[k,O.invert(k)],vn(this),S.start()}zt(x),S.wheel=setTimeout(T,p),S.zoom("mouse",n(C(E(O,D),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function N(x,...$){if(m||!e.apply(this,arguments))return;var S=x.currentTarget,O=j(this,$,!0).event(x),D=Oe(x.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",W,!0),k=Fe(x,S),T=x.clientX,L=x.clientY;Pi(x.view),qn(x),O.mouse=[k,this.__zoom.invert(k)],vn(this),O.start();function z(G){if(zt(G),!O.moved){var K=G.clientX-T,Z=G.clientY-L;O.moved=K*K+Z*Z>y}O.event(G).zoom("mouse",n(C(O.that.__zoom,O.mouse[0]=Fe(G,S),O.mouse[1]),O.extent,o))}function W(G){D.on("mousemove.zoom mouseup.zoom",null),zi(G.view,O.moved),zt(G),O.event(G).end()}}function R(x,...$){if(e.apply(this,arguments)){var S=this.__zoom,O=Fe(x.changedTouches?x.changedTouches[0]:x,this),D=S.invert(O),k=S.k*(x.shiftKey?.5:2),T=n(C(E(S,k),O,D),t.apply(this,$),o);zt(x),a>0?Oe(this).transition().duration(a).call(M,T,O,x):Oe(this).call(g.transform,T,O,x)}}function P(x,...$){if(e.apply(this,arguments)){var S=x.touches,O=S.length,D=j(this,$,x.changedTouches.length===O).event(x),k,T,L,z;for(qn(x),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},eo=st.error001();function he(e,t){const n=w.useContext(Hn);if(n===null)throw new Error(eo);return Si(n,e,t)}const Se=()=>{const e=w.useContext(Hn);if(e===null)throw new Error(eo);return w.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Rr({position:e,children:t,className:n,style:r,...s}){const i=he(ff),o=`${e}`.split("-");return A.createElement("div",{className:Ce(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Rr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=w.useRef(null),[m,f]=w.useState({x:0,y:0,width:0,height:0}),p=Ce(["react-flow__edge-textwrapper",l]);return w.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:p,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=w.memo(mf);const Ir=e=>({width:e.offsetWidth,height:e.offsetHeight}),Lt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Tr=(e={x:0,y:0},t)=>({x:Lt(e.x,t[0][0],t[1][0]),y:Lt(e.y,t[0][1],t[1][1])}),xs=(e,t,n)=>en?-Lt(Math.abs(e-n),1,50)/50:0,to=(e,t)=>{const n=xs(e.x,35,t.width-35)*20,r=xs(e.y,35,t.height-35)*20;return[n,r]},no=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},ro=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Qt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),so=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),ws=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>so(ro(Qt(e),Qt(t))),yr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Le(e.width)&&Le(e.height)&&Le(e.x)&&Le(e.y),Le=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),io=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function xr(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const oo=e=>"clientX"in e,ft=(e,t)=>{var i,o;const n=oo(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Cn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},rn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Le(n)&&Le(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);rn.displayName="BaseEdge";function Ht(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function ao({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[b,g,E]=lo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(rn,{path:b,labelX:g,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:y})});Or.displayName="SimpleBezierEdge";const vs={[U.Left]:{x:-1,y:0},[U.Right]:{x:1,y:0},[U.Top]:{x:0,y:-1},[U.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=U.Bottom,target:n})=>t===U.Left||t===U.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=U.Bottom,target:n,targetPosition:r=U.Top,center:s,offset:i}){const o=vs[t],a=vs[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],p,y;const b={x:0,y:0},g={x:0,y:0},[E,C,v,M]=ao({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){p=s.x??E,y=s.y??C;const _=[{x:p,y:c.y},{x:p,y:l.y}],I=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:I:f=d==="x"?I:_}else{const _=[{x:c.x,y:l.y}],I=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?I:_:f=o.y===m?_:I,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const x=Math.min(i-1,i-H);o[d]===m?b[d]=(c[d]>e[d]?-1:1)*x:g[d]=(l[d]>n[d]?-1:1)*x}}if(t!==r){const H=d==="x"?"y":"x",x=o[d]===a[H],$=c[H]>l[H],S=c[H]=V?(p=(N.x+R.x)/2,y=f[0].y):(p=f[0].x,y=(N.y+R.y)/2)}return[[e,{x:c.x+b.x,y:c.y+b.y},...f,{x:l.x+g.x,y:l.y+g.y},n],p,y,v,M]}function _f(e,t,n,r){const s=Math.min(_s(e,t)/2,_s(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let C="";return E>0&&E{const[g,E,C]=Mn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(rn,{path:g,labelX:E,labelY:C,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:p,interactionWidth:b})});Fn.displayName="SmoothStepEdge";const Lr=w.memo(e=>{var t;return A.createElement(Fn,{...e,pathOptions:w.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Lr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=ao({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const Dr=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[p,y,b]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(rn,{path:p,labelX:y,labelY:b,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});Dr.displayName="StraightEdge";function hn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Es({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case U.Left:return[t-hn(t-r,i),n];case U.Right:return[t+hn(r-t,i),n];case U.Top:return[t,n-hn(n-s,i)];case U.Bottom:return[t,n+hn(s-n,i)]}}function uo({sourceX:e,sourceY:t,sourcePosition:n=U.Bottom,targetX:r,targetY:s,targetPosition:i=U.Top,curvature:o=.25}){const[a,c]=Es({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Es({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,p]=co({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,p]}const An=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=U.Bottom,targetPosition:i=U.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,pathOptions:y,interactionWidth:b})=>{const[g,E,C]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(rn,{path:g,labelX:E,labelY:C,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:b})});An.displayName="BezierEdge";const Pr=w.createContext(null),Nf=Pr.Provider;Pr.Consumer;const Sf=()=>w.useContext(Pr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,wr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},br=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},fo=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},sn=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return ro(r,Qt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return so(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),sn(e,t)),ho=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:p=!1}=u;if(o&&!f||p)return!1;const{positionAbsolute:y}=xt(u,a),b={x:y.x,y:y.y,width:d||0,height:m||0},g=yr(c,b),E=typeof d>"u"||typeof m>"u"||d===null||m===null,C=i&&g>0,v=(d||0)*(m||0);(E||C||g>=v||u.dragging)&&l.push(u)}),l},mo=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},po=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Lt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function Ns(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=ft(e),l=t.elementsFromPoint(o,a).find(p=>p.classList.contains("react-flow__handle"));if(l){const p=l.getAttribute("data-nodeid");if(p){const y=zr(void 0,l),b=l.getAttribute("data-handleid"),g=i({nodeId:p,id:b,type:y});if(g){const E=s.find(C=>C.nodeId===p&&C.type===y&&C.id===b);return{handle:{id:b,type:y,nodeId:p,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:g}}}}let u=[],d=1/0;if(s.forEach(p=>{const y=Math.sqrt((p.x-n.x)**2+(p.y-n.y)**2);if(y<=r){const b=i(p);y<=d&&(yp.isValid),f=u.some(({handle:p})=>p.type==="target");return u.find(({handle:p,validHandleResult:y})=>f?p.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},go=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function yo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...go(),handleDomNode:c};if(c){const u=zr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),p=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&p&&(t===bt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=Ns(i,o,"source",`${t}-${n}-${r}`),c=Ns(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function zr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Kn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function xo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=no(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:p,onConnectStart:y,panBy:b,getNodes:g,cancelConnection:E}=i();let C=0,v;const{x:M,y:j}=ft(e),_=u==null?void 0:u.elementFromPoint(M,j),I=zr(c,_),N=m==null?void 0:m.getBoundingClientRect();if(!N||!I)return;let R,P=ft(e,N),V=!1,H=null,x=!1,$=null;const S=If({nodes:g(),nodeId:n,handleId:t,handleType:I}),O=()=>{if(!f)return;const[T,L]=to(P,N);b({x:T,y:L}),C=requestAnimationFrame(O)};o({connectionPosition:P,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:I,connectionStartHandle:{nodeId:n,handleId:t,type:I},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:I});function D(T){const{transform:L}=i();P=ft(T,N);const{handle:z,validHandleResult:W}=Af(T,u,br(P,L,!1,[1,1]),p,S,G=>yo(G,d,n,t,s?"target":"source",a,u));if(v=z,V||(O(),V=!0),$=W.handleDomNode,H=W.connection,x=W.isValid,o({connectionPosition:v&&x?fo({x:v.x,y:v.y},L):P,connectionStatus:Tf(!!v,x),connectionEndHandle:W.endHandle}),!v&&!x&&!$)return Kn(R);H.source!==H.target&&$&&(Kn(R),R=$,$.classList.add("connecting","react-flow__handle-connecting"),$.classList.toggle("valid",x),$.classList.toggle("react-flow__handle-valid",x))}function k(T){var L,z;(v||$)&&H&&x&&(r==null||r(H)),(z=(L=i()).onConnectEnd)==null||z.call(L,T),c&&(l==null||l(T)),Kn(R),E(),cancelAnimationFrame(C),V=!1,x=!1,H=null,$=null,u.removeEventListener("mousemove",D),u.removeEventListener("mouseup",k),u.removeEventListener("touchmove",D),u.removeEventListener("touchend",k)}u.addEventListener("mousemove",D),u.addEventListener("mouseup",k),u.addEventListener("touchmove",D),u.addEventListener("touchend",k)}const Ss=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},wo=w.forwardRef(({type:e="source",position:t=U.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var N,R;const p=o||null,y=e==="target",b=Se(),g=Sf(),{connectOnClick:E,noPanClassName:C}=he(Of,ke),{connecting:v,clickConnecting:M}=he(Lf(g,p,e),ke);g||(R=(N=b.getState()).onError)==null||R.call(N,"010",st.error010());const j=P=>{const{defaultEdgeOptions:V,onConnect:H,hasDefaultEdges:x}=b.getState(),$={...V,...P};if(x){const{edges:S,setEdges:O}=b.getState();O($f($,S))}H==null||H($),a==null||a($)},_=P=>{if(!g)return;const V=oo(P);s&&(V&&P.button===0||!V)&&xo({event:P,handleId:p,nodeId:g,onConnect:j,isTarget:y,getState:b.getState,setState:b.setState,isValidConnection:n||b.getState().isValidConnection||Ss}),V?u==null||u(P):d==null||d(P)},I=P=>{const{onClickConnectStart:V,onClickConnectEnd:H,connectionClickStartHandle:x,connectionMode:$,isValidConnection:S}=b.getState();if(!g||!x&&!s)return;if(!x){V==null||V(P,{nodeId:g,handleId:p,handleType:e}),b.setState({connectionClickStartHandle:{nodeId:g,type:e,handleId:p}});return}const O=no(P.target),D=n||S||Ss,{connection:k,isValid:T}=yo({nodeId:g,id:p,type:e},$,x.nodeId,x.handleId||null,x.type,D,O);T&&j(k),H==null||H(P),b.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":p,"data-nodeid":g,"data-handlepos":t,"data-id":`${g}-${p}-${e}`,className:Ce(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",C,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!v||i&&v)}]),onMouseDown:_,onTouchStart:_,onClick:E?I:void 0,ref:f,...m},c)});wo.displayName="Handle";var ut=w.memo(wo);const bo=({data:e,isConnectable:t,targetPosition:n=U.Top,sourcePosition:r=U.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ut,{type:"source",position:r,isConnectable:t}));bo.displayName="DefaultNode";var vr=w.memo(bo);const vo=({data:e,isConnectable:t,sourcePosition:n=U.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ut,{type:"source",position:n,isConnectable:t}));vo.displayName="InputNode";var _o=w.memo(vo);const Eo=({data:e,isConnectable:t,targetPosition:n=U.Top})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);Eo.displayName="OutputNode";var No=w.memo(Eo);const Hr=()=>null;Hr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),mn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(mn),t.selectedNodes.map(mn))&&ke(e.selectedEdges.map(mn),t.selectedEdges.map(mn))}const So=w.memo(({onSelectionChange:e})=>{const t=Se(),{selectedNodes:n,selectedEdges:r}=he(Df,Pf);return w.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});So.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=he(zf);return e||t?A.createElement(So,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Nt(e,t){w.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function oe(e,t,n){w.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:p,minZoom:y,maxZoom:b,nodeExtent:g,onNodesChange:E,onEdgesChange:C,elementsSelectable:v,connectionMode:M,snapGrid:j,snapToGrid:_,translateExtent:I,connectOnClick:N,defaultEdgeOptions:R,fitView:P,fitViewOptions:V,onNodesDelete:H,onEdgesDelete:x,onNodeDrag:$,onNodeDragStart:S,onNodeDragStop:O,onSelectionDrag:D,onSelectionDragStart:k,onSelectionDragStop:T,noPanClassName:L,nodeOrigin:z,rfId:W,autoPanOnConnect:G,autoPanOnNodeDrag:K,onError:Z,connectionRadius:ne,isValidConnection:ie,nodeDragThreshold:re})=>{const{setNodes:ae,setEdges:ye,setDefaultNodesAndEdges:te,setMinZoom:me,setMaxZoom:ve,setTranslateExtent:de,setNodeExtent:pe,reset:le}=he(Ff,ke),X=Se();return w.useEffect(()=>{const _e=r==null?void 0:r.map(je=>({...je,...R}));return te(n,_e),()=>{le()}},[]),oe("defaultEdgeOptions",R,X.setState),oe("connectionMode",M,X.setState),oe("onConnect",s,X.setState),oe("onConnectStart",i,X.setState),oe("onConnectEnd",o,X.setState),oe("onClickConnectStart",a,X.setState),oe("onClickConnectEnd",c,X.setState),oe("nodesDraggable",l,X.setState),oe("nodesConnectable",u,X.setState),oe("nodesFocusable",d,X.setState),oe("edgesFocusable",m,X.setState),oe("edgesUpdatable",f,X.setState),oe("elementsSelectable",v,X.setState),oe("elevateNodesOnSelect",p,X.setState),oe("snapToGrid",_,X.setState),oe("snapGrid",j,X.setState),oe("onNodesChange",E,X.setState),oe("onEdgesChange",C,X.setState),oe("connectOnClick",N,X.setState),oe("fitViewOnInit",P,X.setState),oe("fitViewOnInitOptions",V,X.setState),oe("onNodesDelete",H,X.setState),oe("onEdgesDelete",x,X.setState),oe("onNodeDrag",$,X.setState),oe("onNodeDragStart",S,X.setState),oe("onNodeDragStop",O,X.setState),oe("onSelectionDrag",D,X.setState),oe("onSelectionDragStart",k,X.setState),oe("onSelectionDragStop",T,X.setState),oe("noPanClassName",L,X.setState),oe("nodeOrigin",z,X.setState),oe("rfId",W,X.setState),oe("autoPanOnConnect",G,X.setState),oe("autoPanOnNodeDrag",K,X.setState),oe("onError",Z,X.setState),oe("connectionRadius",ne,X.setState),oe("isValidConnection",ie,X.setState),oe("nodeDragThreshold",re,X.setState),Nt(e,ae),Nt(t,ye),Nt(y,me),Nt(b,ve),Nt(I,de),Nt(g,pe),null},ks={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},ko="react-flow__node-desc",jo="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Wf({rfId:e}){const t=he(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Uf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${ko}-${e}`,style:ks},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${jo}-${e}`,style:ks},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Wf,{rfId:e}))}var en=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=w.useState(!1),s=w.useRef(!1),i=w.useRef(new Set([])),[o,a]=w.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return w.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&xr(f))return!1;const y=Cs(f.code,a);i.current.add(f[y]),js(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&xr(f))return!1;const y=Cs(f.code,a);js(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function js(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Cs(e,t){return t.includes(e)?"code":"key"}function Co(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return Co(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function $o(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=Co(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Zn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Le(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),$o(s,n,i),s}function Mo(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const p=n().filter(b=>{var E;const g=t.includeHiddenNodes?b.width&&b.height:!b.hidden;return(E=t.nodes)!=null&&E.length?g&&t.nodes.some(C=>C.id===b.id):g}),y=p.every(b=>b.width&&b.height);if(p.length>0&&y){const b=sn(p,d),{x:g,y:E,zoom:C}=po(b,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),v=nt.translate(g,E).scale(C);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),v):a.transform(c,v),!0}}return!1}function Xf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function pn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Xf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const St=()=>{},Kf={zoomIn:St,zoomOut:St,zoomTo:St,getZoom:()=>1,setViewport:St,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:St,fitBounds:St,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Se(),{d3Zoom:t,d3Selection:n}=he(Zf,ke);return w.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=nt.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Mo(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=nt.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=po(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=nt.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),br(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return br(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=fo(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function on(){const e=Qf(),t=Se(),n=w.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=w.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=w.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(b=>({...b}))},[]),i=w.useCallback(y=>{const{edges:b=[]}=t.getState();return b.find(g=>g.id===y)},[]),o=w.useCallback(y=>{const{getNodes:b,setNodes:g,hasDefaultNodes:E,onNodesChange:C}=t.getState(),v=b(),M=typeof y=="function"?y(v):y;if(E)g(M);else if(C){const j=M.length===0?v.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));C(j)}},[]),a=w.useCallback(y=>{const{edges:b=[],setEdges:g,hasDefaultEdges:E,onEdgesChange:C}=t.getState(),v=typeof y=="function"?y(b):y;if(E)g(v);else if(C){const M=v.length===0?b.map(j=>({type:"remove",id:j.id})):v.map(j=>({item:j,type:"reset"}));C(M)}},[]),c=w.useCallback(y=>{const b=Array.isArray(y)?y:[y],{getNodes:g,setNodes:E,hasDefaultNodes:C,onNodesChange:v}=t.getState();if(C){const j=[...g(),...b];E(j)}else if(v){const M=b.map(j=>({item:j,type:"add"}));v(M)}},[]),l=w.useCallback(y=>{const b=Array.isArray(y)?y:[y],{edges:g=[],setEdges:E,hasDefaultEdges:C,onEdgesChange:v}=t.getState();if(C)E([...g,...b]);else if(v){const M=b.map(j=>({item:j,type:"add"}));v(M)}},[]),u=w.useCallback(()=>{const{getNodes:y,edges:b=[],transform:g}=t.getState(),[E,C,v]=g;return{nodes:y().map(M=>({...M})),edges:b.map(M=>({...M})),viewport:{x:E,y:C,zoom:v}}},[]),d=w.useCallback(({nodes:y,edges:b})=>{const{nodeInternals:g,getNodes:E,edges:C,hasDefaultNodes:v,hasDefaultEdges:M,onNodesDelete:j,onEdgesDelete:_,onNodesChange:I,onEdgesChange:N}=t.getState(),R=(y||[]).map($=>$.id),P=(b||[]).map($=>$.id),V=E().reduce(($,S)=>{const O=S.parentNode||S.parentId,D=!R.includes(S.id)&&O&&$.find(T=>T.id===O);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(R.includes(S.id)||D)&&$.push(S),$},[]),H=C.filter($=>typeof $.deletable=="boolean"?$.deletable:!0),x=H.filter($=>P.includes($.id));if(V||x){const $=mo(V,H),S=[...x,...$],O=S.reduce((D,k)=>(D.includes(k.id)||D.push(k.id),D),[]);if((M||v)&&(M&&t.setState({edges:C.filter(D=>!O.includes(D.id))}),v&&(V.forEach(D=>{g.delete(D.id)}),t.setState({nodeInternals:new Map(g)}))),O.length>0&&(_==null||_(S),N&&N(O.map(D=>({id:D,type:"remove"})))),V.length>0&&(j==null||j(V),I)){const D=V.map(k=>({id:k.id,type:"remove"}));I(D)}}},[]),m=w.useCallback(y=>{const b=yf(y),g=b?null:t.getState().nodeInternals.get(y.id);return!b&&!g?[null,null,b]:[b?y:ws(g),g,b]},[]),f=w.useCallback((y,b=!0,g)=>{const[E,C,v]=m(y);return E?(g||t.getState().getNodes()).filter(M=>{if(!v&&(M.id===C.id||!M.positionAbsolute))return!1;const j=ws(M),_=yr(j,E);return b&&_>0||_>=E.width*E.height}):[]},[]),p=w.useCallback((y,b,g=!0)=>{const[E]=m(y);if(!E)return!1;const C=yr(E,b);return g&&C>0||C>=E.width*E.height},[]);return w.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:p}),[e,n,r,s,i,o,a,c,l,u,d,f,p])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Se(),{deleteElements:r}=on(),s=en(e,Jf),i=en(t);w.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),w.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Se();w.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Ir(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",st.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Fr={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,gn=e=>({x:e.x,y:e.y,zoom:e.k}),kt=(e,t)=>e.target.closest(`.${t}`),$s=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Ms=e=>{const t=e.ctrlKey&&Cn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:p,maxZoom:y,zoomActivationKeyCode:b,preventScrolling:g=!0,children:E,noWheelClassName:C,noPanClassName:v})=>{const M=w.useRef(),j=Se(),_=w.useRef(!1),I=w.useRef(!1),N=w.useRef(null),R=w.useRef({x:0,y:0,zoom:0}),{d3Zoom:P,d3Selection:V,d3ZoomHandler:H,userSelectionActive:x}=he(rh,ke),$=en(b),S=w.useRef(0),O=w.useRef(!1),D=w.useRef();return th(N),w.useEffect(()=>{if(N.current){const k=N.current.getBoundingClientRect(),T=Ji().scaleExtent([p,y]).translateExtent(f),L=Oe(N.current).call(T),z=nt.translate(m.x,m.y).scale(Lt(m.zoom,p,y)),W=[[0,0],[k.width,k.height]],G=T.constrain()(z,W,f);T.transform(L,G),T.wheelDelta(Ms),j.setState({d3Zoom:T,d3Selection:L,d3ZoomHandler:L.on("wheel.zoom"),transform:[G.x,G.y,G.k],domNode:N.current.closest(".react-flow")})}},[]),w.useEffect(()=>{V&&P&&(o&&!$&&!x?V.on("wheel.zoom",k=>{if(kt(k,C))return!1;k.preventDefault(),k.stopImmediatePropagation();const T=V.property("__zoom").k||1;if(k.ctrlKey&&i){const ie=Fe(k),re=Ms(k),ae=T*Math.pow(2,re);P.scaleTo(V,ae,ie,k);return}const L=k.deltaMode===1?20:1;let z=c===gt.Vertical?0:k.deltaX*L,W=c===gt.Horizontal?0:k.deltaY*L;!Cn()&&k.shiftKey&&c!==gt.Vertical&&(z=k.deltaY*L,W=0),P.translateBy(V,-(z/T)*a,-(W/T)*a,{internal:!0});const G=gn(V.property("__zoom")),{onViewportChangeStart:K,onViewportChange:Z,onViewportChangeEnd:ne}=j.getState();clearTimeout(D.current),O.current||(O.current=!0,t==null||t(k,G),K==null||K(G)),O.current&&(e==null||e(k,G),Z==null||Z(G),D.current=setTimeout(()=>{n==null||n(k,G),ne==null||ne(G),O.current=!1},150))},{passive:!1}):typeof H<"u"&&V.on("wheel.zoom",function(k,T){if(!g&&k.type==="wheel"&&!k.ctrlKey||kt(k,C))return null;k.preventDefault(),H.call(this,k,T)},{passive:!1}))},[x,o,c,V,P,H,$,i,g,C,t,e,n]),w.useEffect(()=>{P&&P.on("start",k=>{var z,W;if(!k.sourceEvent||k.sourceEvent.internal)return null;S.current=(z=k.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=j.getState(),L=gn(k.transform);_.current=!0,R.current=L,((W=k.sourceEvent)==null?void 0:W.type)==="mousedown"&&j.setState({paneDragging:!0}),T==null||T(L),t==null||t(k.sourceEvent,L)})},[P,t]),w.useEffect(()=>{P&&(x&&!_.current?P.on("zoom",null):x||P.on("zoom",k=>{var L;const{onViewportChange:T}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),I.current=!!(r&&$s(d,S.current??0)),(e||T)&&!((L=k.sourceEvent)!=null&&L.internal)){const z=gn(k.transform);T==null||T(z),e==null||e(k.sourceEvent,z)}}))},[x,P,e,d,r]),w.useEffect(()=>{P&&P.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=j.getState();if(_.current=!1,j.setState({paneDragging:!1}),r&&$s(d,S.current??0)&&!I.current&&r(k.sourceEvent),I.current=!1,(n||T)&&nh(R.current,k.transform)){const L=gn(k.transform);R.current=L,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(L),n==null||n(k.sourceEvent,L)},o?150:0)}})},[P,o,d,n,r]),w.useEffect(()=>{P&&P.filter(k=>{const T=$||s,L=i&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(kt(k,"react-flow__node")||kt(k,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||x||!l&&k.type==="dblclick"||kt(k,C)&&k.type==="wheel"||kt(k,v)&&(k.type!=="wheel"||o&&k.type==="wheel"&&!$)||!i&&k.ctrlKey&&k.type==="wheel"||!T&&!o&&!L&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&z})},[x,P,s,i,o,l,d,u,$]),A.createElement("div",{className:"react-flow__renderer",ref:N,style:Fr},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=he(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function As(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&As(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&As(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ct=(e,t)=>({id:e,type:"select",selected:t});function Ct(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ct(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ct(r.id,!1))),n},[])}const Qn=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ao=w.memo(({isSelecting:e,selectionMode:t=Jt.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=w.useRef(null),f=Se(),p=w.useRef(0),y=w.useRef(0),b=w.useRef(),{userSelectionActive:g,elementsSelectable:E,dragging:C}=he(lh,ke),v=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),p.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,I=H=>{const{resetSelectedElements:x,domNode:$}=f.getState();if(b.current=$==null?void 0:$.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!b.current)return;const{x:S,y:O}=ft(H,b.current);x(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:O,x:S,y:O}}),r==null||r(H)},N=H=>{const{userSelectionRect:x,nodeInternals:$,edges:S,transform:O,onNodesChange:D,onEdgesChange:k,nodeOrigin:T,getNodes:L}=f.getState();if(!e||!b.current||!x)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=ft(H,b.current),W=x.startX??0,G=x.startY??0,K={...x,x:z.xae.id),re=ne.map(ae=>ae.id);if(p.current!==re.length){p.current=re.length;const ae=Ct(Z,re);ae.length&&(D==null||D(ae))}if(y.current!==ie.length){y.current=ie.length;const ae=Ct(S,ie);ae.length&&(k==null||k(ae))}f.setState({userSelectionRect:K})},R=H=>{if(H.button!==0)return;const{userSelectionRect:x}=f.getState();!g&&x&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:p.current>0}),v(),s==null||s(H)},P=H=>{g&&(f.setState({nodesSelectionActive:p.current>0}),s==null||s(H)),v()},V=E&&(e||g);return A.createElement("div",{className:Ce(["react-flow__pane",{dragging:C,selection:e}]),onClick:V?void 0:Qn(M,m),onContextMenu:Qn(j,m),onWheel:Qn(_,m),onMouseEnter:V?void 0:c,onMouseDown:V?I:void 0,onMouseMove:V?N:l,onMouseUp:V?R:void 0,onMouseLeave:V?P:u,ref:m,style:Fr},d,A.createElement(oh,null))});Ao.displayName="Pane";function Ro(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Ro(r,t):!1}function Rs(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Ro(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function Io(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Le(m)&&Le(f)&&Le(d.width)&&Le(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",st.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Tr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function Jn({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Is=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Ir(c)}})};function Ft(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function _r({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",st.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Se();return w.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function er(e){return(t,n,r)=>e==null?void 0:e(t,r)}function To({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Se(),[c,l]=w.useState(!1),u=w.useRef([]),d=w.useRef({x:null,y:null}),m=w.useRef(0),f=w.useRef(null),p=w.useRef({x:0,y:0}),y=w.useRef(null),b=w.useRef(!1),g=w.useRef(!1),E=w.useRef(!1),C=fh();return w.useEffect(()=>{if(e!=null&&e.current){const v=Oe(e.current),M=({x:I,y:N})=>{const{nodeInternals:R,onNodeDrag:P,onSelectionDrag:V,updateNodePositions:H,nodeExtent:x,snapGrid:$,snapToGrid:S,nodeOrigin:O,onError:D}=a.getState();d.current={x:I,y:N};let k=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&x){const z=sn(u.current,O);T=Qt(z)}if(u.current=u.current.map(z=>{const W={x:I-z.distance.x,y:N-z.distance.y};S&&(W.x=$[0]*Math.round(W.x/$[0]),W.y=$[1]*Math.round(W.y/$[1]));const G=[[x[0][0],x[0][1]],[x[1][0],x[1][1]]];u.current.length>1&&x&&!z.extent&&(G[0][0]=z.positionAbsolute.x-T.x+x[0][0],G[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+x[1][0],G[0][1]=z.positionAbsolute.y-T.y+x[0][1],G[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+x[1][1]);const K=Io(z,W,R,G,O,D);return k=k||z.position.x!==K.position.x||z.position.y!==K.position.y,z.position=K.position,z.positionAbsolute=K.positionAbsolute,z}),!k)return;H(u.current,!0,!0),l(!0);const L=s?P:er(V);if(L&&y.current){const[z,W]=Jn({nodeId:s,dragItems:u.current,nodeInternals:R});L(y.current,z,W)}},j=()=>{if(!f.current)return;const[I,N]=to(p.current,f.current);if(I!==0||N!==0){const{transform:R,panBy:P}=a.getState();d.current.x=(d.current.x??0)-I/R[2],d.current.y=(d.current.y??0)-N/R[2],P({x:I,y:N})&&M(d.current)}m.current=requestAnimationFrame(j)},_=I=>{var O;const{nodeInternals:N,multiSelectionActive:R,nodesDraggable:P,unselectNodesAndEdges:V,onNodeDragStart:H,onSelectionDragStart:x}=a.getState();g.current=!0;const $=s?H:er(x);(!o||!i)&&!R&&s&&((O=N.get(s))!=null&&O.selected||V()),s&&i&&o&&_r({id:s,store:a,nodeRef:e});const S=C(I);if(d.current=S,u.current=uh(N,P,S,s),$&&u.current){const[D,k]=Jn({nodeId:s,dragItems:u.current,nodeInternals:N});$(I.sourceEvent,D,k)}};if(t)v.on(".drag",null);else{const I=bu().on("start",N=>{const{domNode:R,nodeDragThreshold:P}=a.getState();P===0&&_(N),E.current=!1;const V=C(N);d.current=V,f.current=(R==null?void 0:R.getBoundingClientRect())||null,p.current=ft(N.sourceEvent,f.current)}).on("drag",N=>{var H,x;const R=C(N),{autoPanOnNodeDrag:P,nodeDragThreshold:V}=a.getState();if(N.sourceEvent.type==="touchmove"&&N.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!b.current&&g.current&&P&&(b.current=!0,j()),!g.current){const $=R.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=R.ySnapped-(((x=d==null?void 0:d.current)==null?void 0:x.y)??0);Math.sqrt($*$+S*S)>V&&_(N)}(d.current.x!==R.xSnapped||d.current.y!==R.ySnapped)&&u.current&&g.current&&(y.current=N.sourceEvent,p.current=ft(N.sourceEvent,f.current),M(R))}}).on("end",N=>{if(!(!g.current||E.current)&&(l(!1),b.current=!1,g.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:R,nodeInternals:P,onNodeDragStop:V,onSelectionDragStop:H}=a.getState(),x=s?V:er(H);if(R(u.current,!1,!1),x){const[$,S]=Jn({nodeId:s,dragItems:u.current,nodeInternals:P});x(N.sourceEvent,$,S)}}}).filter(N=>{const R=N.target;return!N.button&&(!n||!Rs(R,`.${n}`,e))&&(!r||Rs(R,r,e))});return v.call(I),()=>{v.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,C]),c}function Oo(){const e=Se();return w.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,p=n.isShiftPressed?4:1,y=n.x*m*p,b=n.y*f*p,g=d.map(E=>{if(E.positionAbsolute){const C={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+b};a&&(C.x=c[0]*Math.round(C.x/c[0]),C.y=c[1]*Math.round(C.y/c[1]));const{positionAbsolute:v,position:M}=Io(E,C,r,s,void 0,l);E.position=M,E.positionAbsolute=v}return E});i(g,!0,!1)},[])}const Rt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Vt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:p,onDoubleClick:y,style:b,className:g,isDraggable:E,isSelectable:C,isConnectable:v,isFocusable:M,selectNodesOnDrag:j,sourcePosition:_,targetPosition:I,hidden:N,resizeObserver:R,dragHandle:P,zIndex:V,isParent:H,noDragClassName:x,noPanClassName:$,initialized:S,disableKeyboardA11y:O,ariaLabel:D,rfId:k,hasHandleBounds:T})=>{const L=Se(),z=w.useRef(null),W=w.useRef(null),G=w.useRef(_),K=w.useRef(I),Z=w.useRef(r),ne=C||E||u||d||m||f,ie=Oo(),re=Ft(n,L.getState,d),ae=Ft(n,L.getState,m),ye=Ft(n,L.getState,f),te=Ft(n,L.getState,p),me=Ft(n,L.getState,y),ve=le=>{const{nodeDragThreshold:X}=L.getState();if(C&&(!j||!E||X>0)&&_r({id:n,store:L,nodeRef:z}),u){const _e=L.getState().nodeInternals.get(n);_e&&u(le,{..._e})}},de=le=>{if(!xr(le)&&!O)if(io.includes(le.key)&&C){const X=le.key==="Escape";_r({id:n,store:L,unselect:X,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Rt,le.key)&&(L.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),ie({x:Rt[le.key].x,y:Rt[le.key].y,isShiftPressed:le.shiftKey}))};w.useEffect(()=>()=>{W.current&&(R==null||R.unobserve(W.current),W.current=null)},[]),w.useEffect(()=>{if(z.current&&!N){const le=z.current;(!S||!T||W.current!==le)&&(W.current&&(R==null||R.unobserve(W.current)),R==null||R.observe(le),W.current=le)}},[N,S,T]),w.useEffect(()=>{const le=Z.current!==r,X=G.current!==_,_e=K.current!==I;z.current&&(le||X||_e)&&(le&&(Z.current=r),X&&(G.current=_),_e&&(K.current=I),L.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,I]);const pe=To({nodeRef:z,disabled:N||!E,noDragClassName:x,handleSelector:P,nodeId:n,isSelectable:C,selectNodesOnDrag:j});return N?null:A.createElement("div",{className:Ce(["react-flow__node",`react-flow__node-${r}`,{[$]:E},g,{selected:l,selectable:C,parent:H,dragging:pe}]),ref:z,style:{zIndex:V,transform:`translate(${a}px,${c}px)`,pointerEvents:ne?"all":"none",visibility:S?"visible":"hidden",...b},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:re,onMouseMove:ae,onMouseLeave:ye,onContextMenu:te,onClick:ve,onDoubleClick:me,onKeyDown:M?de:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":O?void 0:`${ko}-${k}`,"aria-label":D},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:v,sourcePosition:_,targetPosition:I,dragging:pe,dragHandle:P,zIndex:V})))};return t.displayName="NodeWrapper",w.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...sn(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Se(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=he(hh,ke),u=Oo(),d=w.useRef(null);if(w.useEffect(()=>{var p;n||(p=d.current)==null||p.focus({preventScroll:!0})},[n]),To({nodeRef:d}),l||!s||!i)return null;const m=e?p=>{const y=r.getState().getNodes().filter(b=>b.selected);e(p,y)}:void 0,f=p=>{Object.prototype.hasOwnProperty.call(Rt,p.key)&&u({x:Rt[p.key].x,y:Rt[p.key].y,isShiftPressed:p.shiftKey})};return A.createElement("div",{className:Ce(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=w.memo(mh);const gh=e=>e.nodesSelectionActive,Lo=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:p,onSelectionEnd:y,multiSelectionKeyCode:b,panActivationKeyCode:g,zoomActivationKeyCode:E,elementsSelectable:C,zoomOnScroll:v,zoomOnPinch:M,panOnScroll:j,panOnScrollSpeed:_,panOnScrollMode:I,zoomOnDoubleClick:N,panOnDrag:R,defaultViewport:P,translateExtent:V,minZoom:H,maxZoom:x,preventScrolling:$,onSelectionContextMenu:S,noWheelClassName:O,noPanClassName:D,disableKeyboardA11y:k})=>{const T=he(gh),L=en(d),z=en(g),W=z||R,G=z||j,K=L||m&&W!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:b}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:C,zoomOnScroll:v,zoomOnPinch:M,panOnScroll:G,panOnScrollSpeed:_,panOnScrollMode:I,zoomOnDoubleClick:N,panOnDrag:!L&&W,defaultViewport:P,translateExtent:V,minZoom:H,maxZoom:x,zoomActivationKeyCode:E,preventScrolling:$,noWheelClassName:O,noPanClassName:D},A.createElement(Ao,{onSelectionStart:p,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:W,isSelecting:!!K,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:D,disableKeyboardA11y:k})))};Lo.displayName="FlowRenderer";var yh=w.memo(Lo);function xh(e){return he(w.useCallback(n=>e?ho(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Vt(e.input||_o),default:Vt(e.default||vr),output:Vt(e.output||No),group:Vt(e.group||Hr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Vt(e[i]||vr),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Do=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=he(vh,ke),a=xh(e.onlyRenderVisibleElements),c=w.useRef(),l=w.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return w.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Fr},a.map(u=>{var M,j,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",st.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),p=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),b=!!(u.focusable||r&&typeof u.focusable>"u"),g=e.nodeExtent?Tr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(g==null?void 0:g.x)??0,C=(g==null?void 0:g.y)??0,v=bh({x:E,y:C,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||U.Bottom,targetPosition:u.targetPosition||U.Top,hidden:u.hidden,xPos:E,yPos:C,xPosOrigin:v.x,yPosOrigin:v.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:p,isConnectable:y,isFocusable:b,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((j=u[we])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Do.displayName="NodeRenderer";var _h=w.memo(Do);const Eh=(e,t,n)=>n===U.Left?e-t:n===U.Right?e+t:e,Nh=(e,t,n)=>n===U.Top?e-t:n===U.Bottom?e+t:e,Ts="react-flow__edgeupdater",Os=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:Ce([Ts,`${Ts}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var jt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:y,style:b,source:g,target:E,sourceX:C,sourceY:v,targetX:M,targetY:j,sourcePosition:_,targetPosition:I,elementsSelectable:N,hidden:R,sourceHandleId:P,targetHandleId:V,onContextMenu:H,onMouseEnter:x,onMouseMove:$,onMouseLeave:S,reconnectRadius:O,onReconnect:D,onReconnectStart:k,onReconnectEnd:T,markerEnd:L,markerStart:z,rfId:W,ariaLabel:G,isFocusable:K,isReconnectable:Z,pathOptions:ne,interactionWidth:ie,disableKeyboardA11y:re})=>{const ae=w.useRef(null),[ye,te]=w.useState(!1),[me,ve]=w.useState(!1),de=Se(),pe=w.useMemo(()=>`url('#${wr(z,W)}')`,[z,W]),le=w.useMemo(()=>`url('#${wr(L,W)}')`,[L,W]);if(R)return null;const X=se=>{var Me;const{edges:ge,addSelectedEdges:J,unselectNodesAndEdges:fe,multiSelectionActive:ce}=de.getState(),xe=ge.find(Ye=>Ye.id===n);xe&&(N&&(de.setState({nodesSelectionActive:!1}),xe.selected&&ce?(fe({nodes:[],edges:[xe]}),(Me=ae.current)==null||Me.blur()):J([n])),o&&o(se,xe))},_e=Ht(n,de.getState,a),je=Ht(n,de.getState,H),ze=Ht(n,de.getState,x),$e=Ht(n,de.getState,$),qe=Ht(n,de.getState,S),Ie=(se,ge)=>{if(se.button!==0)return;const{edges:J,isValidConnection:fe}=de.getState(),ce=ge?E:g,xe=(ge?V:P)||null,Me=ge?"target":"source",Ye=fe||Sh,Ke=ge,Te=J.find(He=>He.id===n);ve(!0),k==null||k(se,Te,Me);const _t=He=>{ve(!1),T==null||T(He,Te,Me)};xo({event:se,handleId:xe,nodeId:ce,onConnect:He=>D==null?void 0:D(Te,He),isTarget:Ke,getState:de.getState,setState:de.setState,isValidConnection:Ye,edgeUpdaterType:Me,onReconnectEnd:_t})},F=se=>Ie(se,!0),Y=se=>Ie(se,!1),B=()=>te(!0),Q=()=>te(!1),q=!N&&!o,ee=se=>{var ge;if(!re&&io.includes(se.key)&&N){const{unselectNodesAndEdges:J,addSelectedEdges:fe,edges:ce}=de.getState();se.key==="Escape"?((ge=ae.current)==null||ge.blur(),J({edges:[ce.find(Me=>Me.id===n)]})):fe([n])}};return A.createElement("g",{className:Ce(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:q,updating:ye}]),onClick:X,onDoubleClick:_e,onContextMenu:je,onMouseEnter:ze,onMouseMove:$e,onMouseLeave:qe,onKeyDown:K?ee:void 0,tabIndex:K?0:void 0,role:K?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":G===null?void 0:G||`Edge from ${g} to ${E}`,"aria-describedby":K?`${jo}-${W}`:void 0,ref:ae},!me&&A.createElement(e,{id:n,source:g,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:y,data:i,style:b,sourceX:C,sourceY:v,targetX:M,targetY:j,sourcePosition:_,targetPosition:I,sourceHandleId:P,targetHandleId:V,markerStart:pe,markerEnd:le,pathOptions:ne,interactionWidth:ie}),Z&&A.createElement(A.Fragment,null,(Z==="source"||Z===!0)&&A.createElement(Os,{position:_,centerX:C,centerY:v,radius:O,onMouseDown:F,onMouseEnter:B,onMouseOut:Q,type:"source"}),(Z==="target"||Z===!0)&&A.createElement(Os,{position:I,centerX:M,centerY:j,radius:O,onMouseDown:Y,onMouseEnter:B,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",w.memo(t)};function kh(e){const t={default:jt(e.default||An),straight:jt(e.bezier||Dr),step:jt(e.step||Lr),smoothstep:jt(e.step||Fn),simplebezier:jt(e.simplebezier||Or)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=jt(e[i]||An),s),n);return{...t,...r}}function Ls(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case U.Top:return{x:r+i/2,y:s};case U.Right:return{x:r+i,y:s+o/2};case U.Bottom:return{x:r+i/2,y:s+o};case U.Left:return{x:r,y:s+o/2}}}function Ds(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ls(n,e,t),a=Ls(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Qt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Ps(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Le(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),p=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(p?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=he(w.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),zs={[$n.Arrow]:Rh,[$n.ArrowClosed]:Ih};function Th(e){const t=Se();return w.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(zs,e)?zs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",st.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=wr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},Po=({defaultColor:e,rfId:t})=>{const n=he(w.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};Po.displayName="MarkerDefinitions";var Dh=w.memo(Po);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),zo=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:y,children:b,disableKeyboardA11y:g})=>{const{edgesFocusable:E,edgesUpdatable:C,elementsSelectable:v,width:M,height:j,connectionMode:_,nodeInternals:I,onError:N}=he(Ph,ke),R=Ah(t,I,n);return M?A.createElement(A.Fragment,null,R.map(({level:P,edges:V,isMaxLevel:H})=>A.createElement("svg",{key:P,style:{zIndex:P},width:M,height:j,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,V.map(x=>{const[$,S,O]=Ps(I.get(x.source)),[D,k,T]=Ps(I.get(x.target));if(!O||!T)return null;let L=x.type||"default";s[L]||(N==null||N("011",st.error011(L)),L="default");const z=s[L]||s.default,W=_===bt.Strict?k.target:(k.target??[]).concat(k.source??[]),G=Ds(S.source,x.sourceHandle),K=Ds(W,x.targetHandle),Z=(G==null?void 0:G.position)||U.Bottom,ne=(K==null?void 0:K.position)||U.Top,ie=!!(x.focusable||E&&typeof x.focusable>"u"),re=x.reconnectable||x.updatable,ae=typeof m<"u"&&(re||C&&typeof re>"u");if(!G||!K)return N==null||N("008",st.error008(G,x)),null;const{sourceX:ye,sourceY:te,targetX:me,targetY:ve}=jh($,G,Z,D,K,ne);return A.createElement(z,{key:x.id,id:x.id,className:Ce([x.className,i]),type:L,data:x.data,selected:!!x.selected,animated:!!x.animated,hidden:!!x.hidden,label:x.label,labelStyle:x.labelStyle,labelShowBg:x.labelShowBg,labelBgStyle:x.labelBgStyle,labelBgPadding:x.labelBgPadding,labelBgBorderRadius:x.labelBgBorderRadius,style:x.style,source:x.source,target:x.target,sourceHandleId:x.sourceHandle,targetHandleId:x.targetHandle,markerEnd:x.markerEnd,markerStart:x.markerStart,sourceX:ye,sourceY:te,targetX:me,targetY:ve,sourcePosition:Z,targetPosition:ne,elementsSelectable:v,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:y,rfId:r,ariaLabel:x.ariaLabel,isFocusable:ie,isReconnectable:ae,pathOptions:"pathOptions"in x?x.pathOptions:void 0,interactionWidth:x.interactionWidth,disableKeyboardA11y:g})})))),b):null};zo.displayName="EdgeRenderer";var zh=w.memo(zo);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=he(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=on(),n=w.useRef(!1);w.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[U.Left]:U.Right,[U.Right]:U.Left,[U.Top]:U.Bottom,[U.Bottom]:U.Top},Ho=({nodeId:e,handleType:t,style:n,type:r=lt.Bezier,CustomComponent:s,connectionStatus:i})=>{var j,_,I;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=he(w.useCallback(N=>({fromNode:N.nodeInternals.get(e),handleId:N.connectionHandleId,toX:(N.connectionPosition.x-N.transform[0])/N.transform[2],toY:(N.connectionPosition.y-N.transform[1])/N.transform[2],connectionMode:N.connectionMode}),[e]),ke),d=(j=o==null?void 0:o[we])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(u===bt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(N=>N.id===a):m[0],p=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,b=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+p,g=(((I=o.positionAbsolute)==null?void 0:I.y)??0)+y,E=f==null?void 0:f.position,C=E?Bh[E]:null;if(!E||!C)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:b,fromY:g,toX:c,toY:l,fromPosition:E,toPosition:C,connectionStatus:i});let v="";const M={sourceX:b,sourceY:g,sourcePosition:E,targetX:c,targetY:l,targetPosition:C};return r===lt.Bezier?[v]=uo(M):r===lt.Step?[v]=Mn({...M,borderRadius:0}):r===lt.SmoothStep?[v]=Mn(M):r===lt.SimpleBezier?[v]=lo(M):v=`M${b},${g} ${c},${l}`,A.createElement("path",{d:v,fill:"none",className:"react-flow__connection-path",style:n})};Ho.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=he(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:Ce(["react-flow__connection",l])},A.createElement(Ho,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Hs(e,t){return w.useRef(null),Se(),w.useMemo(()=>t(e),[e])}const Fo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:p,onSelectionStart:y,onSelectionEnd:b,connectionLineType:g,connectionLineStyle:E,connectionLineComponent:C,connectionLineContainerStyle:v,selectionKeyCode:M,selectionOnDrag:j,selectionMode:_,multiSelectionKeyCode:I,panActivationKeyCode:N,zoomActivationKeyCode:R,deleteKeyCode:P,onlyRenderVisibleElements:V,elementsSelectable:H,selectNodesOnDrag:x,defaultViewport:$,translateExtent:S,minZoom:O,maxZoom:D,preventScrolling:k,defaultMarkerColor:T,zoomOnScroll:L,zoomOnPinch:z,panOnScroll:W,panOnScrollSpeed:G,panOnScrollMode:K,zoomOnDoubleClick:Z,panOnDrag:ne,onPaneClick:ie,onPaneMouseEnter:re,onPaneMouseMove:ae,onPaneMouseLeave:ye,onPaneScroll:te,onPaneContextMenu:me,onEdgeContextMenu:ve,onEdgeMouseEnter:de,onEdgeMouseMove:pe,onEdgeMouseLeave:le,onReconnect:X,onReconnectStart:_e,onReconnectEnd:je,reconnectRadius:ze,noDragClassName:$e,noWheelClassName:qe,noPanClassName:Ie,elevateEdgesOnSelect:F,disableKeyboardA11y:Y,nodeOrigin:B,nodeExtent:Q,rfId:q})=>{const ee=Hs(e,wh),se=Hs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:ie,onPaneMouseEnter:re,onPaneMouseMove:ae,onPaneMouseLeave:ye,onPaneContextMenu:me,onPaneScroll:te,deleteKeyCode:P,selectionKeyCode:M,selectionOnDrag:j,selectionMode:_,onSelectionStart:y,onSelectionEnd:b,multiSelectionKeyCode:I,panActivationKeyCode:N,zoomActivationKeyCode:R,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:L,zoomOnPinch:z,zoomOnDoubleClick:Z,panOnScroll:W,panOnScrollSpeed:G,panOnScrollMode:K,panOnDrag:ne,defaultViewport:$,translateExtent:S,minZoom:O,maxZoom:D,onSelectionContextMenu:p,preventScrolling:k,noDragClassName:$e,noWheelClassName:qe,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:V,onEdgeContextMenu:ve,onEdgeMouseEnter:de,onEdgeMouseMove:pe,onEdgeMouseLeave:le,onReconnect:X,onReconnectStart:_e,onReconnectEnd:je,reconnectRadius:ze,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!F,disableKeyboardA11y:Y,rfId:q},A.createElement(Yh,{style:E,type:g,component:C,containerStyle:v})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:ee,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:x,onlyRenderVisibleElements:V,noPanClassName:Ie,noDragClassName:$e,disableKeyboardA11y:Y,nodeOrigin:B,nodeExtent:Q,rfId:q})))};Fo.displayName="GraphView";var Wh=w.memo(Fo);const Er=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ot={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Er,nodeExtent:Er,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:bt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Uh=()=>Rc((e,t)=>({...ot,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Zn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Zn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,b)=>{const g=s.get(b.id);if(g!=null&&g.hidden)s.set(g.id,{...g,[we]:{...g[we],handleBounds:void 0}});else if(g){const E=Ir(b.nodeElement);!!(E.width&&E.height&&(g.width!==E.width||g.height!==E.height||b.forceUpdate))&&(s.set(g.id,{...g,[we]:{...g[we],handleBounds:{source:Is(".source",b.nodeElement,m,l),target:Is(".target",b.nodeElement,m,l)}},...E}),y.push({id:g.id,type:"dimensions",dimensions:E}))}return y},[]);$o(s,l);const p=o||i&&!o&&Mo(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:p}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Zn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(i(),n),a=Ct(s,[])),pn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(s,n),a=Ct(i(),[])),pn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ct(u.id,!1))),l=a.map(u=>ct(u.id,!1));pn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ct(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ct(a.id,!1));pn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Tr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=nt.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:ot.connectionNodeId,connectionHandleId:ot.connectionHandleId,connectionHandleType:ot.connectionHandleType,connectionStatus:ot.connectionStatus,connectionStartHandle:ot.connectionStartHandle,connectionEndHandle:ot.connectionEndHandle}),reset:()=>e({...ot})}),Object.is),Vo=({children:e})=>{const t=w.useRef(null);return t.current||(t.current=Uh()),A.createElement(df,{value:t.current},e)};Vo.displayName="ReactFlowProvider";const Bo=({children:e})=>w.useContext(Hn)?A.createElement(A.Fragment,null,e):A.createElement(Vo,null,e);Bo.displayName="ReactFlowWrapper";const Xh={input:_o,default:vr,output:No,group:Hr},qh={default:An,straight:Dr,step:Lr,smoothstep:Fn,simplebezier:Or},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Go=w.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Xh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:p,onConnectEnd:y,onClickConnectStart:b,onClickConnectEnd:g,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:v,onNodeContextMenu:M,onNodeDoubleClick:j,onNodeDragStart:_,onNodeDrag:I,onNodeDragStop:N,onNodesDelete:R,onEdgesDelete:P,onSelectionChange:V,onSelectionDragStart:H,onSelectionDrag:x,onSelectionDragStop:$,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,connectionMode:k=bt.Strict,connectionLineType:T=lt.Bezier,connectionLineStyle:L,connectionLineComponent:z,connectionLineContainerStyle:W,deleteKeyCode:G="Backspace",selectionKeyCode:K="Shift",selectionOnDrag:Z=!1,selectionMode:ne=Jt.Full,panActivationKeyCode:ie="Space",multiSelectionKeyCode:re=Cn()?"Meta":"Control",zoomActivationKeyCode:ae=Cn()?"Meta":"Control",snapToGrid:ye=!1,snapGrid:te=Zh,onlyRenderVisibleElements:me=!1,selectNodesOnDrag:ve=!0,nodesDraggable:de,nodesConnectable:pe,nodesFocusable:le,nodeOrigin:X=Kh,edgesFocusable:_e,edgesUpdatable:je,elementsSelectable:ze,defaultViewport:$e=Qh,minZoom:qe=.5,maxZoom:Ie=2,translateExtent:F=Er,preventScrolling:Y=!0,nodeExtent:B,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:q=!0,zoomOnPinch:ee=!0,panOnScroll:se=!1,panOnScrollSpeed:ge=.5,panOnScrollMode:J=gt.Free,zoomOnDoubleClick:fe=!0,panOnDrag:ce=!0,onPaneClick:xe,onPaneMouseEnter:Me,onPaneMouseMove:Ye,onPaneMouseLeave:Ke,onPaneScroll:Te,onPaneContextMenu:_t,children:Et,onEdgeContextMenu:He,onEdgeDoubleClick:ue,onEdgeMouseEnter:Ze,onEdgeMouseMove:Dt,onEdgeMouseLeave:$a,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:qr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Wa,defaultEdgeOptions:Ua,elevateNodesOnSelect:Xa=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Kr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Zr,nodeDragThreshold:nc,...rc},sc)=>{const Gn=Zr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:Ce(["react-flow",s]),"data-testid":"rf__wrapper",id:Zr},A.createElement(Bo,null,A.createElement(Wh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:v,onNodeContextMenu:M,onNodeDoubleClick:j,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:L,connectionLineComponent:z,connectionLineContainerStyle:W,selectionKeyCode:K,selectionOnDrag:Z,selectionMode:ne,deleteKeyCode:G,multiSelectionKeyCode:re,panActivationKeyCode:ie,zoomActivationKeyCode:ae,onlyRenderVisibleElements:me,selectNodesOnDrag:ve,defaultViewport:$e,translateExtent:F,minZoom:qe,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:q,zoomOnPinch:ee,zoomOnDoubleClick:fe,panOnScroll:se,panOnScrollSpeed:ge,panOnScrollMode:J,panOnDrag:ce,onPaneClick:xe,onPaneMouseEnter:Me,onPaneMouseMove:Ye,onPaneMouseLeave:Ke,onPaneScroll:Te,onPaneContextMenu:_t,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,onEdgeContextMenu:He,onEdgeDoubleClick:ue,onEdgeMouseEnter:Ze,onEdgeMouseMove:Dt,onEdgeMouseLeave:$a,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:qr,elevateEdgesOnSelect:qa,rfId:Gn,disableKeyboardA11y:Kr,nodeOrigin:X,nodeExtent:B}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:p,onConnectEnd:y,onClickConnectStart:b,onClickConnectEnd:g,nodesDraggable:de,nodesConnectable:pe,nodesFocusable:le,edgesFocusable:_e,edgesUpdatable:je,elementsSelectable:ze,elevateNodesOnSelect:Xa,minZoom:qe,maxZoom:Ie,nodeExtent:B,onNodesChange:Pa,onEdgesChange:za,snapToGrid:ye,snapGrid:te,connectionMode:k,translateExtent:F,connectOnClick:Ga,defaultEdgeOptions:Ua,fitView:Va,fitViewOptions:Ba,onNodesDelete:R,onEdgesDelete:P,onNodeDragStart:_,onNodeDrag:I,onNodeDragStop:N,onSelectionDrag:x,onSelectionDragStart:H,onSelectionDragStop:$,noPanClassName:qr,nodeOrigin:X,rfId:Gn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:V}),Et,A.createElement(hf,{proOptions:Wa,position:Ya}),A.createElement(Uf,{rfId:Gn,disableKeyboardA11y:Kr})))});Go.displayName="ReactFlow";const Yo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:p,backgroundColor:y}=i||{},b=o||p||y;return A.createElement("rect",{className:Ce(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:b,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?g=>m(g,e):void 0})};Yo.displayName="MiniMapNode";var em=w.memo(Yo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),tr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=he(nm,ke),c=he(tm),l=tr(t),u=tr(e),d=tr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:p,y}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:p,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=w.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(sn(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:p=!1,zoomable:y=!1,ariaLabel:b="React Flow mini map",inversePan:g=!1,zoomStep:E=10,offsetScale:C=5}){const v=Se(),M=w.useRef(null),{boundingRect:j,viewBB:_,rfId:I}=he(am,ke),N=(e==null?void 0:e.width)??im,R=(e==null?void 0:e.height)??om,P=j.width/N,V=j.height/R,H=Math.max(P,V),x=H*N,$=H*R,S=C*H,O=j.x-(x-j.width)/2-S,D=j.y-($-j.height)/2-S,k=x+S*2,T=$+S*2,L=`${cm}-${I}`,z=w.useRef(0);z.current=H,w.useEffect(()=>{if(M.current){const K=Oe(M.current),Z=re=>{const{transform:ae,d3Selection:ye,d3Zoom:te}=v.getState();if(re.sourceEvent.type!=="wheel"||!ye||!te)return;const me=-re.sourceEvent.deltaY*(re.sourceEvent.deltaMode===1?.05:re.sourceEvent.deltaMode?1:.002)*E,ve=ae[2]*Math.pow(2,me);te.scaleTo(ye,ve)},ne=re=>{const{transform:ae,d3Selection:ye,d3Zoom:te,translateExtent:me,width:ve,height:de}=v.getState();if(re.sourceEvent.type!=="mousemove"||!ye||!te)return;const pe=z.current*Math.max(1,ae[2])*(g?-1:1),le={x:ae[0]-re.sourceEvent.movementX*pe,y:ae[1]-re.sourceEvent.movementY*pe},X=[[0,0],[ve,de]],_e=nt.translate(le.x,le.y).scale(ae[2]),je=te.constrain()(_e,X,me);te.transform(ye,je)},ie=Ji().on("zoom",p?ne:null).on("zoom.wheel",y?Z:null);return K.call(ie),()=>{K.on("zoom",null)}}},[p,y,g,E]);const W=m?K=>{const Z=Fe(K);m(K,{x:Z[0],y:Z[1]})}:void 0,G=f?(K,Z)=>{const ne=v.getState().nodeInternals.get(Z);f(K,ne)}:void 0;return A.createElement(Rr,{position:d,style:e,className:Ce(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:N,height:R,viewBox:`${O} ${D} ${k} ${T}`,role:"img","aria-labelledby":L,ref:M,onClick:W},b&&A.createElement("title",{id:L},b),A.createElement(sm,{onClick:G,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${O-S},${D-S}h${k+S*2}v${T+S*2}h${-k-S*2}z + M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Wo.displayName="MiniMap";var lm=w.memo(Wo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Yt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:Ce(["react-flow__controls-button",t]),...n},e);Yt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Se(),[f,p]=w.useState(!1),{isInteractive:y,minZoomReached:b,maxZoomReached:g}=he(pm,ke),{zoomIn:E,zoomOut:C,fitView:v}=on();if(w.useEffect(()=>{p(!0)},[]),!f)return null;const M=()=>{E(),i==null||i()},j=()=>{C(),o==null||o()},_=()=>{v(s),a==null||a()},I=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c==null||c(!y)};return A.createElement(Rr,{className:Ce(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Yt,{onClick:M,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:g},A.createElement(um,null)),A.createElement(Yt,{onClick:j,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:b},A.createElement(dm,null))),n&&A.createElement(Yt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Yt,{className:"react-flow__controls-interactive",onClick:I,title:"toggle interactivity","aria-label":"toggle interactivity"},y?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=w.memo(Uo),De;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(De||(De={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[De.Dots]:"#91919a",[De.Lines]:"#eee",[De.Cross]:"#e2e2e2"},bm={[De.Dots]:1,[De.Lines]:1,[De.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Xo({id:e,variant:t=De.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=w.useRef(null),{transform:u,patternId:d}=he(vm,ke),m=o||wm[t],f=r||bm[t],p=t===De.Dots,y=t===De.Cross,b=Array.isArray(n)?n:[n,n],g=[b[0]*u[2]||1,b[1]*u[2]||1],E=f*u[2],C=y?[E,E]:g,v=p?[E/i,E/i]:[C[0]/i,C[1]/i];return A.createElement("svg",{className:Ce(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%g[0],y:u[1]%g[1],width:g[0],height:g[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${v[0]},-${v[1]})`},p?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:C,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}Xo.displayName="Background";var _m=w.memo(Xo);const Vr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Rn(e){return Vr+e}async function be(e){const t=await fetch(Rn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function it(e,t){const n=await fetch(Rn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new qo(r.error??`${e}: ${n.status}`,n.status);return r}class qo extends Error{constructor(n,r){super(n);Ee(this,"status");this.status=r}}const Rx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),Ix=()=>be("/api/diagnostics"),Ko=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Zo=()=>be("/api/ontology/ontologies"),Em=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>be("/api/ontology/stack"),Sm=()=>be("/api/ontology/coverage"),km=(e,t,n)=>it("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>be("/api/git/status"),Cm=()=>be("/api/git/diff"),$m=e=>it("/api/git/commit",{message:e}),Mm=()=>it("/api/git/discard",{}),Am=()=>be("/api/decisions"),Fs=(e,t)=>it(`/api/decisions/${e}/verdict`,{verdict:t}),Tx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Ox=()=>be("/api/glossary/config"),Lx=e=>it("/api/git/propose",e),Dx=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Px=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),zx=e=>it("/api/git/classify",{changes:e}),Hx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Fx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Vx=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>be("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Vr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>it("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>it("/api/import/preview",{format:e,content:t}),Bx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Gx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Yx=(e,t,n)=>fetch(`${Vr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new qo(await r.text(),r.status);return await r.json()}),Wx=()=>be("/api/glossary/subject-areas"),Ux=e=>be(`/api/glossary/subject-area/${e}`),Xx=(e,t)=>it(`/api/glossary/subject-area/${e}/expand`,t);function qx(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Rn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Rn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Br="__entity_source",Gr="__entity_target",Pm=w.memo(function({data:t,selected:n}){var j;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:p}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,b=[...r.attributes].map((_,I)=>({a:_,i:I})).sort((_,I)=>y(_.a)-y(I.a)||_.i-I.i).map(_=>_.a),g=b.filter(_=>_.role==="business_key");let E=b.filter(_=>_.role!=="business_key");const C=!!c&&!l;let v=0;if(C){const _=E.filter(I=>d==null?void 0:d.has(I.id));v=E.length-_.length,E=_}const M=(_,I)=>{const N="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:N,onMouseEnter:p?()=>p(_.id):void 0,onMouseLeave:p?()=>p(null):void 0,children:[h.jsx(ut,{id:_.id,type:"target",position:U.Left,className:"port attr-port"}),h.jsx(ut,{id:_.id,type:"source",position:U.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(I?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ut,{id:Gr,type:"target",position:U.Left,className:"port"}),h.jsx(ut,{id:Br,type:"source",position:U.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((j=r.conceptual)==null?void 0:j.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var N;const _=(((N=r.conceptual)==null?void 0:N.ontology_refs)??[]).filter(R=>R.uri);if(_.length===0)return null;const I=_.map(R=>R.uri).join(` +`);return h.jsxs("span",{className:"badge ontology",title:I,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),g.length>0&&h.jsx("div",{className:"attr-section keys",children:g.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),v>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${v} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,p,y,b,g,E,C,v,M,j,_,I;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(N=>N.from.entity===e.id||N.to.entity===e.id),d=N=>{var R;return((R=t.entities.find(P=>P.id===N))==null?void 0:R.name)??N};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Je,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,name:N})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Je,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,physical_name:N})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Je,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:N=>r("set_definition",{id:e.id,definition:N})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((p=l==null?void 0:l.ontology_refs)==null?void 0:p.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(b=e.term_map)!=null&&b.class_iri?"Edit mapping…":"Map…"}),(((g=e.term_map)==null?void 0:g.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),(C=e.term_map)!=null&&C.subject_template||(v=e.term_map)!=null&&v.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Je,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:N=>{var R;return r("set_stewardship",{id:e.id,owner:N,steward:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Je,{value:((I=l==null?void 0:l.stewardship)==null?void 0:I.steward)??"",placeholder:"—",readOnly:c,onCommit:N=>{var R;return r("set_stewardship",{id:e.id,owner:((R=l==null?void 0:l.stewardship)==null?void 0:R.owner)??null,steward:N})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(N=>h.jsx(Wm,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(Um,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(N=>{const R=N.members.map(P=>{var V;return((V=e.attributes.find(H=>H.id===P))==null?void 0:V.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+N.type,children:N.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:N.name}),h.jsx("span",{className:"key-cols",children:R})]},N.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([N,R])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:N}),h.jsx("td",{className:"udp-val",children:String(R)})]},N))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(N=>{const R=N.from.entity===e.id?N.to.entity:N.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(R),children:[h.jsx("span",{className:"rel-card",children:Xm(N,e.id)}),d(R)]}),(N.verb_phrase||N.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Je,{value:N.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,verb_phrase:P})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Je,{value:N.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,inverse_verb_phrase:P})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${N.name}`,onClick:()=>r("delete_relationship",{id:N.id}),children:"✕"})]},N.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var N;return(N=navigator.clipboard)==null?void 0:N.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Je({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=w.useState(e);w.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Wm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Je,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Je,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Um({entity:e,exec:t}){const[n,r]=w.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Xm(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Vs="";let Km=class{constructor(t){Ee(this,"_isDirected",!0);Ee(this,"_isMultigraph",!1);Ee(this,"_isCompound",!1);Ee(this,"_label");Ee(this,"_defaultNodeLabelFn",()=>{});Ee(this,"_defaultEdgeLabelFn",()=>{});Ee(this,"_nodes",{});Ee(this,"_in",{});Ee(this,"_preds",{});Ee(this,"_out",{});Ee(this,"_sucs",{});Ee(this,"_edgeObjs",{});Ee(this,"_edgeLabels",{});Ee(this,"_nodeCount",0);Ee(this,"_edgeCount",0);Ee(this,"_parent");Ee(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Bs(this._preds[n],t),Bs(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Gs(this._preds[n],t),Gs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Bs(e,t){e[t]?e[t]++:e[t]=1}function Gs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Vs+i+Vs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function nr(e,t){return Wt(e,t.v,t.w,t.name)}var Yr=Km,Qm="2.2.4",Jm={Graph:Yr,version:Qm},ep=Yr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){Ee(this,"_arr",[]);Ee(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=Jo,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ea=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ea,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),sa(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),sa(t(i),o=>s.push(o)))}}function sa(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=ra,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=ra,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Yr,Lp=Qo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:Jo,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ea,topsort:na},Ws=Jm,Ge={Graph:Ws.Graph,json:tp,alg:zp,version:Ws.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Us(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Us(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function Us(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ge.Graph,Gp=Vp;var Yp=Up;let Wp=()=>1;function Up(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Wp);return Xp(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Xp(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)rr(e,t,n,o);for(;o=s.dequeue();)rr(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(rr(e,t,n,o,!0));break}}}return r}function rr(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,Sr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,Sr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{Sr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function Sr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new ia({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Wr(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Wr(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=ua(ca(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Vn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Vn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),oa(e,"border",s,t)}function og(e,t=aa){const n=[];for(let r=0;raa){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function ca(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Vn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function la(e){var t=++ug;return e+(""+t)}function ua(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Wr(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=Ne.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=Ne;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=Ne;var Bn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ge.Graph,In=Bn.slack,da=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!In(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=In(t,s)),it.node(r).rank+=n)}var Rg=da,Xs=Bn.slack,Ig=Bn.longestPath,Tg=Ge.alg.preorder,Og=Ge.alg.postorder,Lg=Ne.simplify,Dg=vt;vt.initLowLimValues=Xr;vt.initCutValues=Ur;vt.calcCutValue=fa;vt.leaveEdge=ma;vt.enterEdge=pa;vt.exchangeEdges=ga;function vt(e){e=Lg(e),Ig(e);var t=Rg(e);Xr(t),Ur(t,e);for(var n,r;n=ma(t);)r=pa(t,e,n),ga(t,e,n,r)}function Ur(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=fa(e,t,n)}function fa(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Xr(e,t){arguments.length<2&&(t=e.nodes()[0]),ha(e,{},1,t)}function ha(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ha(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function ma(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function pa(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===qs(e,e.node(u.v),a)&&c!==qs(e,e.node(u.w),a));return l.reduce((u,d)=>Xs(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function qs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Bn,ya=Fg.longestPath,Vg=da,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Ks(e);break;case"tight-tree":Ug(e);break;case"longest-path":Wg(e);break;case"none":break;default:Ks(e)}}var Wg=ya;function Ug(e){ya(e),Vg(e)}function Ks(e){Bg(e)}var Xg=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Tn=Ne;var Qg={run:Jg,cleanup:ny};function Jg(e){let t=Tn.addDummyNode(e,"root",{},"_root"),n=ey(e),r=Object.values(n),s=Tn.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=ty(e)+1;e.children().forEach(a=>xa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function xa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Tn.addBorderNode(e,"_bt"),l=Tn.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{xa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,p=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,b=f!==p?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:b,nestingEdge:!0}),e.setEdge(p,l,{weight:y,minlen:b,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function ey(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function ty(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function ny(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let ry=Ne;var sy=iy;function iy(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iQs(e.node(t))),e.edges().forEach(t=>Qs(e.edge(t)))}function Qs(e){let t=e.width;e.width=e.height,e.height=t}function ly(e){e.nodes().forEach(t=>sr(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(sr),Object.hasOwn(n,"y")&&sr(n)})}function sr(e){e.y=-e.y}function uy(e){e.nodes().forEach(t=>ir(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ir),Object.hasOwn(n,"x")&&ir(n)})}function ir(e){let t=e.x;e.x=e.y,e.y=t}let Js=Ne;var dy=fy;function fy(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=Js.applyWithChunking(Math.max,r),i=Js.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let hy=Ne.zipObject;var my=py;function py(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var yy=xy;function xy(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let wy=Ne;var by=vy;function vy(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _y(r)}function _y(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&Ey(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>wy.pick(s,["vs","i","barycenter","weight"]))}function Ey(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let Ny=Ne;var Sy=ky;function ky(e,t){let n=Ny.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(jy(!!t)),c=ei(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ei(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ei(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function jy(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Cy=yy,$y=by,My=Sy;var Ay=ba;function ba(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=Cy(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=ba(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&Iy(m,f)}});let u=$y(l,n);Ry(u,c);let d=My(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function Ry(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function Iy(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let Ty=Ge.Graph,Oy=Ne;var Ly=Dy;function Dy(e,t,n,r){r||(r=e.nodes());let s=Py(e),i=new Ty({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function Py(e){for(var t;e.hasNode(t=Oy.uniqueId("_root")););return t}var zy=Hy;function Hy(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let Fy=dy,Vy=my,By=Ay,Gy=Ly,Yy=zy,Wy=Ge.Graph,yn=Ne;var Uy=va;function va(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,va);return}let n=yn.maxRank(e),r=ti(e,yn.range(1,n+1),"inEdges"),s=ti(e,yn.range(n-1,-1,-1),"outEdges"),i=Fy(e);if(ni(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){Xy(c%2?r:s,c%4>=2),i=yn.buildLayerMatrix(e);let u=Vy(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return Gy(e,i,n,r.get(i)||[])})}function Xy(e,t){let n=new Wy;e.forEach(function(r){let s=r.graph().root,i=By(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Yy(r,n,i.vs)})}function ni(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let qy=Ge.Graph,et=Ne;var Ky={positionX:a0};function Zy(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=Jy(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(p=>{e.predecessors(p).forEach(y=>{let b=e.node(y),g=b.order;(g{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&_a(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function Jy(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function _a(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function e0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function t0(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let p=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((p,y)=>Math.min(p,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function r0(e,t,n,r){let s=new qy,i=e.graph(),o=c0(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function s0(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=l0(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-et.applyWithChunking(Math.min,l);o!=="l"&&(u=s-et.applyWithChunking(Math.max,l)),u&&(e[a]=et.mapValues(c,d=>d+u))})})}function o0(e,t){return et.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function a0(e){let t=et.buildLayerMatrix(e),n=Object.assign(Zy(e,t),Qy(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=t0(e,s,n,c),u=n0(e,s,l.root,l.align,a==="r");a==="r"&&(u=et.mapValues(u,d=>-d)),r[o+a]=u})});let i=s0(e,r);return i0(r,i),o0(r,e.graph().align)}function c0(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function l0(e,t){return e.node(t).width}let Ea=Ne,u0=Ky.positionX;var d0=f0;function f0(e){e=Ea.asNonCompoundGraph(e),h0(e),Object.entries(u0(e)).forEach(([t,n])=>e.node(t).x=n)}function h0(e){let t=Ea.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ri=pg,si=bg,m0=Gg,p0=Ne.normalizeRanks,g0=Xg,y0=Ne.removeEmptyRanks,ii=Qg,x0=sy,oi=oy,w0=Uy,b0=d0,Pe=Ne,v0=Ge.Graph;var _0=E0;function E0(e,t){let n=t&&t.debugTiming?Pe.time:Pe.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>I0(e));n(" runLayout",()=>N0(r,n,t)),n(" updateInputGraph",()=>S0(e,r))})}function N0(e,t,n){t(" makeSpaceForEdgeLabels",()=>T0(e)),t(" removeSelfEdges",()=>B0(e)),t(" acyclic",()=>ri.run(e)),t(" nestingGraph.run",()=>ii.run(e)),t(" rank",()=>m0(Pe.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>O0(e)),t(" removeEmptyRanks",()=>y0(e)),t(" nestingGraph.cleanup",()=>ii.cleanup(e)),t(" normalizeRanks",()=>p0(e)),t(" assignRankMinMax",()=>L0(e)),t(" removeEdgeLabelProxies",()=>D0(e)),t(" normalize.run",()=>si.run(e)),t(" parentDummyChains",()=>g0(e)),t(" addBorderSegments",()=>x0(e)),t(" order",()=>w0(e,n)),t(" insertSelfEdges",()=>G0(e)),t(" adjustCoordinateSystem",()=>oi.adjust(e)),t(" position",()=>b0(e)),t(" positionSelfEdges",()=>Y0(e)),t(" removeBorderNodes",()=>V0(e)),t(" normalize.undo",()=>si.undo(e)),t(" fixupEdgeLabelCoords",()=>H0(e)),t(" undoCoordinateSystem",()=>oi.undo(e)),t(" translateGraph",()=>P0(e)),t(" assignNodeIntersects",()=>z0(e)),t(" reversePoints",()=>F0(e)),t(" acyclic.undo",()=>ri.undo(e))}function S0(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let k0=["nodesep","edgesep","ranksep","marginx","marginy"],j0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},C0=["acyclicer","ranker","rankdir","align"],$0=["width","height","rank"],ai={width:0,height:0},M0=["minlen","weight","width","height","labeloffset"],A0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},R0=["labelpos"];function I0(e){let t=new v0({multigraph:!0,compound:!0}),n=ar(e.graph());return t.setGraph(Object.assign({},j0,or(n,k0),Pe.pick(n,C0))),e.nodes().forEach(r=>{let s=ar(e.node(r));const i=or(s,$0);Object.keys(ai).forEach(o=>{i[o]===void 0&&(i[o]=ai[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=ar(e.edge(r));t.setEdge(r,Object.assign({},A0,or(s,M0),Pe.pick(s,R0)))}),t}function T0(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function O0(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};Pe.addDummyNode(e,"edge-proxy",i,"_ep")}})}function L0(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function D0(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function P0(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function z0(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(Pe.intersectRect(r,i)),n.points.push(Pe.intersectRect(s,o))})}function H0(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function F0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function V0(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function B0(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function G0(e){var t=Pe.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{Pe.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Y0(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function or(e,t){return Pe.mapValues(Pe.pick(e,t),Number)}function ar(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let W0=Ne,U0=Ge.Graph;var X0={debugOrdering:q0};function q0(e){let t=W0.buildLayerMatrix(e),n=new U0({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var K0="1.1.8",Z0={graphlib:Ge,layout:_0,debug:X0,util:{time:Ne.time,notime:Ne.notime},version:K0};const ci=bi(Z0),Ue=264,Q0=44,J0=26,ex=14;function dt(e){const t=Math.max(e.attributes.length,1);return Q0+t*J0+ex}const tx=40;function cr(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?fi(e,n,o):r==="clustered"?di(e,t,n,o,i):r==="hierarchical"||e.length<=tx?li(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?di(e,t,n,o,i):fi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Na(e,t,n,r=!1,s="LR"){const i=new ci.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Ue,height:d?dt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ci.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?dt(m):120,p=d.x-Ue/2,y=d.y-f/2;return a=Math.max(a,p+Ue),c=Math.max(c,y+f),{...u,position:{x:p,y}}}),width:a,height:c}}function li(e,t,n,r="LR"){return Na(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?dt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Ue+Sa);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Ue)}),i+=Math.max(...c.map(l=>n(l.id)))+ka}return{nodes:s,width:o,height:i}}const ui=120;function di(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),p=new Set(f.map(E=>E.id));let y=0;for(const E of t)p.has(E.source)&&p.has(E.target)&&y++;const g=f.length<=8&&y>=f.length-1?Na(f,t,n,!0,s):rx(f,n);return{name:m,...g}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const Sa=40,ka=40;function fi(e,t,n){const r=l=>{const u=t.get(l);return u?dt(u):120},s=[...e].sort((l,u)=>{var y,b;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,p=((b=t.get(u.id))==null?void 0:b.name)??u.id;return f.localeCompare(p)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Ue+Sa)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ka}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function an({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],ja=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var v,M;const[r,s]=w.useState(((v=e.conceptual)==null?void 0:v.name)??e.name),[i,o]=w.useState([]),[a,c]=w.useState(null),[l,u]=w.useState(null),[d,m]=w.useState("skos:exactMatch"),[f,p]=w.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,b]=w.useState([]),[g,E]=w.useState("");w.useEffect(()=>{Zo().then(j=>b(j.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return o([]);Ko(r,g||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(j)},[r,g]);const C=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(an,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(g===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(j=>h.jsx("button",{className:"src-chip"+(g===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:g?`Search within ${g}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(j=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===j.iri?" picked":""),onClick:()=>u(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:sx.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>p(j.target.value),children:ja.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:C,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var v,M,j;const[s,i]=w.useState(((v=e.term_map)==null?void 0:v.subject_template)??""),[o,a]=w.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},p=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${p}:`,b=(j=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:j.members.map(_=>{var I;return(I=e.attributes.find(N=>N.id===_))==null?void 0:I.name}).filter(Boolean),g=b&&b.length?`${y}${e.id}/${b.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,C=s.trim()||g;return h.jsxs(an,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",C]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((b==null?void 0:b[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=w.useState(""),[o,a]=w.useState(""),[c,l]=w.useState(""),[u,d]=w.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const p=f==null?void 0:f.created_id;n(),p&&r(p)})};return h.jsxs(an,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),ja.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const Ca=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(v=>v.id===t),c=e.entities.find(v=>v.id===n),l=w.useMemo(()=>c==null?void 0:c.attributes.find(v=>v.role==="business_key"),[c]),[u,d]=w.useState(r??""),[m,f]=w.useState(s??(l==null?void 0:l.id)??""),[p,y]=w.useState("many_to_one"),[b,g]=w.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",C=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:p,optionality:b}).then(o);return h.jsxs(an,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:p,onChange:v=>y(v.target.value),children:Ca.map(v=>h.jsx("option",{children:v},v))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:v=>d(v.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(v=>h.jsx("option",{value:v.id,children:v.name},v.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:v=>f(v.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(v=>h.jsxs("option",{value:v.id,children:[v.name,v.role==="business_key"?" 🔑":""]},v.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:b,onChange:v=>g(v.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:C,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=g=>{var E;return((E=t.entities.find(C=>C.id===g))==null?void 0:E.name)??"?"},[i,o]=w.useState(e.name),[a,c]=w.useState(e.cardinality),[l,u]=w.useState(e.optionality),[d,m]=w.useState(e.identifying),[f,p]=w.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},b=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(an,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:g=>o(g.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:g=>c(g.target.value),children:Ca.map(g=>h.jsx("option",{children:g},g))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:g=>u(g.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:g=>m(g.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:b,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>p(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const hi=10,ux=6,$t=24;function dx(e,t){return t?e:Math.round(e/hi)*hi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-$t,o.right+$t);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eo.left&&ni.left&&nte.transform[2]),[m,f]=w.useState(null),p=w.useRef(!1),y=w.useRef(0),b=c==null?void 0:c.onRouteChange,g=!!b,E=m??(c==null?void 0:c.routeX),[C,v,M]=Mn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),j=c==null?void 0:c.sourceCard,_=c==null?void 0:c.targetCard,I=E!=null&&j&&_?xx({x:n,y:r},{x:s,y:i},E,o===U.Left?-1:1,a===U.Left?-1:1,j,_):null,N=I?I.path:C,R=c==null?void 0:c.relationship,P=(c==null?void 0:c.dimmed)??!1,V=(R==null?void 0:R.cardinality)??"many_to_one",H=(R==null?void 0:R.optionality)==="optional",x=(R==null?void 0:R.identifying)??!1,$=V==="many_to_one"||V==="many_to_many",S=V==="one_to_many"||V==="many_to_many",O="rel-edge"+(l?" selected":"")+(P?" dimmed":""),D=((c==null?void 0:c.memberCount)??0)>1,k=c==null?void 0:c.onHoverEdge,T=E??v,L=M,z=T,W=L,G=I?I.sourceOut:{ox:o===U.Left?-1:1,oy:0},K=I?I.targetOut:{ox:a===U.Left?-1:1,oy:0},Z={x:n,y:r},ne=I&&K.oy!==0&&_?{x:E,y:K.oy<0?_.top:_.bottom}:{x:s,y:i},ie=w.useCallback(te=>b&&R&&b(R.id,te),[b,R]),re=w.useCallback(te=>{var _e,je;if(!g||te.button!==0)return;te.stopPropagation(),(je=(_e=te.target).setPointerCapture)==null||je.call(_e,te.pointerId),p.current=!0,y.current=0;const ve=u({x:te.clientX,y:te.clientY}).x;let de=0,pe=E??T;const le=ze=>{const $e=u({x:ze.clientX,y:ze.clientY});y.current=Math.max(y.current,Math.abs($e.x-ve)),pe=mx($e.x,{shift:ze.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),de||(de=requestAnimationFrame(()=>{de=0,f(pe)}))},X=()=>{window.removeEventListener("pointermove",le),window.removeEventListener("pointerup",X),de&&cancelAnimationFrame(de),p.current=!1,f(null),y.current>=pi&&ie(pe)};window.addEventListener("pointermove",le),window.addEventListener("pointerup",X)},[g,u,E,T,c,n,s,ie]),ae=w.useCallback(te=>{y.current>=pi&&(te.stopPropagation(),y.current=0)},[]),ye=w.useCallback(te=>{g&&(te.stopPropagation(),ie(null))},[g,ie]);return h.jsxs("g",{className:O,onMouseEnter:k?()=>k(R.id):void 0,onMouseLeave:k?()=>k(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:N,fill:"none",strokeDasharray:x?void 0:"6 4"}),h.jsx("path",{d:N,fill:"none",strokeWidth:16/d,stroke:"transparent"}),h.jsx(gi,{x:Z.x,y:Z.y,out:G,many:$,optional:H}),h.jsx(gi,{x:ne.x,y:ne.y,out:K,many:S,optional:!1}),g&&((c==null?void 0:c.hovered)||l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:re,onClickCapture:ae,onDoubleClick:ye,children:[h.jsx("rect",{x:T-20/d,y:Math.min(r,i),width:40/d,height:Math.max(Math.abs(i-r),24/d),fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:T-5.5/d,y:L-11/d,width:11/d,height:22/d,rx:5/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L-4.5/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L+4.5/d,r:1.1/d})]}),(l||D)&&R&&h.jsxs("text",{className:"rel-label",x:z,y:W-8,children:[l?R.verb_phrase||R.name:"",D?`${l?" ":""}(${c.memberCount})`:""]})]})});function gi({x:e,y:t,out:n,many:r,optional:s}){const{ox:a,oy:c}=n,l=-c,u=a,d=p=>({x:e+a*p,y:t+c*p}),m=(p,y)=>({x:e+a*p+l*y,y:t+c*p+u*y}),f=[];if(r){const p=d(12),y=m(0,-7),b=d(0),g=m(0,7);f.push(h.jsx("path",{className:"rel-glyph",d:`M ${p.x} ${p.y} L ${y.x} ${y.y} M ${p.x} ${p.y} L ${b.x} ${b.y} M ${p.x} ${p.y} L ${g.x} ${g.y}`,fill:"none"},"foot"))}else{const p=m(9,-7),y=m(9,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:y.x,y2:y.y},"one"))}if(s){const p=d(18);f.push(h.jsx("circle",{className:"rel-glyph ring",cx:p.x,cy:p.y,r:4},"opt"))}else{const p=m(17,-7),y=m(17,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:y.x,y2:y.y},"mand"))}return h.jsx(h.Fragment,{children:f})}const bx={entity:Pm},vx={relationship:wx},yi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],xi="#8a7d6a";function _x(e,t,n){const s=Ue;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function Ex(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Br,targetHandle:n(e.to.entity,s)?s:Gr}}function Jx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:p,fitBounds:y,getNodes:b}=on(),[g,E]=w.useState([]),[C,v]=w.useState([]),M=w.useRef(!1),j=w.useMemo(()=>{const F=u&&u.size>0?[...u].sort():null;return F?"sa:"+F.join("+"):"__all__"},[u]),_=w.useRef(null),[I,N]=w.useState(0),R=w.useRef(new Map),P=w.useRef(null);w.useEffect(()=>{if(!f){_.current=null;return}const F=R.current.get(j);if(F){_.current=F,M.current=!1,N(B=>B+1);return}let Y=!1;return f.load(j).then(B=>{Y||(R.current.set(j,B),_.current=B,M.current=!1,N(Q=>Q+1))}),()=>{Y=!0}},[f,j]);const[V,H]=w.useState(null),[x,$]=w.useState(null),[S,O]=w.useState(!1),[D,k]=w.useState(null),[T,L]=w.useState(null),[z,W]=w.useState(null),[G,K]=w.useState(null),Z=w.useRef({}),ne=!t.canEdit,ie=w.useRef(null),re=w.useCallback(()=>{f&&(ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>{const F={};for(const Q of b())Q.hidden||(F[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,q]of Object.entries(Z.current))Y[Q]={routeX:Math.round(q)};const B={nodes:F,edges:Y};R.current.set(j,B),_.current=B,f.save(j,B)},800))},[f,b,j]),ae=w.useCallback((F,Y)=>{Y==null?delete Z.current[F]:Z.current[F]=Y,v(B=>B.map(Q=>Q.id===F?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),re()},[re]),ye=w.useMemo(()=>{const F=new Map;return e.subject_areas.forEach((Y,B)=>F.set(Y.id,yi[B%yi.length])),F},[e]),te=w.useMemo(()=>{const F=new Map;return e.entities.forEach(Y=>F.set(Y.id,Y)),F},[e]),me=w.useMemo(()=>{const F=new Map,Y=new Map;return e.subject_areas.forEach(B=>{(B.members??[]).forEach(Q=>Y.set(Q,{id:B.id,name:B.name}))}),e.entities.forEach(B=>{var se,ge;const Q=(se=B.conceptual)!=null&&se.id?Y.get(B.conceptual.id):void 0,q=(ge=B.conceptual)==null?void 0:ge.subject_area,ee=Q??(q?{id:q.id,name:q.name??q.id}:void 0);ee&&F.set(B.id,ee)}),F},[e]),ve=w.useCallback(F=>{var B;if(!u||u.size===0)return!1;const Y=(B=me.get(F))==null?void 0:B.id;return!(Y&&u.has(Y))},[u,me]),de=w.useMemo(()=>{const F=new Map,Y=(B,Q)=>{if(!Q.length)return;const q=F.get(B)??new Set;Q.forEach(ee=>q.add(ee)),F.set(B,q)};for(const B of e.relationships)Y(B.from.entity,B.from.attributes),Y(B.to.entity,B.to.attributes);return F},[e]);w.useEffect(()=>{var ge;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const J of e.entities)(J.name.toLowerCase()+" "+(((ge=J.conceptual)==null?void 0:ge.name.toLowerCase())??"")+" "+J.attributes.map(ce=>ce.name.toLowerCase()).join(" ")).includes(F)&&Y.add(J.id);const B=new Set;if(r){B.add(r);for(const J of e.relationships)J.from.entity===r&&B.add(J.to.entity),J.to.entity===r&&B.add(J.from.entity)}const Q=e.entities.map(J=>{const fe=F!==""&&!Y.has(J.id),ce=r!==null&&!B.has(J.id);return{id:J.id,type:"entity",position:{x:0,y:0},hidden:ve(J.id),data:{entity:J,color:(()=>{const xe=me.get(J.id);return xe?ye.get(xe.id)??xi:xi})(),dimmed:fe||ce,highlighted:F!==""&&Y.has(J.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(J.id))??!1,onToggleExpand:l,endpointAttrs:de.get(J.id),highlightAttrs:void 0,onHoverAttr:W}}}),q=e.relationships.filter(J=>te.has(J.from.entity)&&te.has(J.to.entity)).map(J=>{const{sourceHandle:fe,targetHandle:ce}=Ex(J,te),xe=r!==null&&J.from.entity!==r&&J.to.entity!==r;return{id:J.id,source:J.from.entity,target:J.to.entity,sourceHandle:fe,targetHandle:ce,type:"relationship",data:{relationship:J,dimmed:xe,memberCount:Math.max(J.from.attributes.length,J.to.attributes.length),onHoverEdge:K}}}),ee=_.current;if(Z.current={},ee)for(const[J,fe]of Object.entries(ee.edges))Z.current[J]=fe.routeX;const se=J=>{const fe=new Map;for(const ce of J)fe.set(ce.id,{left:ce.position.x,right:ce.position.x+Ue,top:ce.position.y,bottom:ce.position.y+dt(ce.data.entity)});v(q.map(ce=>({...ce,data:{...ce.data,routeX:Z.current[ce.id],onRouteChange:f?ae:void 0,sourceCard:fe.get(ce.source),targetCard:fe.get(ce.target)}})))};E(J=>{const fe=new Map(J.map(ue=>[ue.id,ue.position])),ce=Q.every(ue=>fe.has(ue.id)),xe=((u==null?void 0:u.size)??0)>0;if(M.current&&ce&&J.length>=Q.length&&!xe){const ue=Q.map(Ze=>({...Ze,position:fe.get(Ze.id)??Ze.position}));return se(ue),ue}const Me=xe?Q.filter(ue=>!ue.hidden):Q,Ye=cr(Me,q,te,"auto",me),Ke=new Map(Ye.map(ue=>[ue.id,ue.position])),Te=(ee==null?void 0:ee.nodes)??{},_t=Object.keys(Te).length>0,Et=[],He=Q.map(ue=>{const Ze=Te[ue.id];if(Ze){const Dt={x:Ze.x,y:Ze.y};return Et.push({x:Dt.x,y:Dt.y,w:Ue,h:dt(ue.data.entity)}),{...ue,position:Dt}}return Ke.has(ue.id)?{...ue,position:Ke.get(ue.id)}:fe.has(ue.id)&&M.current?{...ue,position:fe.get(ue.id)}:ue});if(_t)for(const ue of He)Te[ue.id]||ue.hidden||(ue.position=_x(ue.position,dt(ue.data.entity),Et),Et.push({x:ue.position.x,y:ue.position.y,w:Ue,h:dt(ue.data.entity)}));return M.current=!0,_t||requestAnimationFrame(()=>p({padding:.15,duration:300})),se(He),He})},[e,i,r,o,a,c,l,ye,te,me,ve,u,de,p,f,ae,I]);const pe=w.useMemo(()=>{const F=new Set,Y=new Set,B=new Map,Q=(q,ee)=>{if(!ee.length)return;const se=B.get(q)??new Set;ee.forEach(ge=>se.add(ge)),B.set(q,se)};if(z)for(const q of e.relationships)(q.from.attributes.includes(z)||q.to.attributes.includes(z))&&(F.add(q.id),Y.add(q.from.entity),Y.add(q.to.entity),Q(q.from.entity,q.from.attributes),Q(q.to.entity,q.to.attributes));if(G){const q=e.relationships.find(ee=>ee.id===G);q&&(Q(q.from.entity,q.from.attributes),Q(q.to.entity,q.to.attributes))}return{active:z!==null,relsForAttr:F,entsForAttr:Y,hitAttrsByEntity:B}},[e,z,G]);w.useEffect(()=>{var Q;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const q of e.entities)(q.name.toLowerCase()+" "+(((Q=q.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+q.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(q.id);const B=new Set;if(r){B.add(r);for(const q of e.relationships)q.from.entity===r&&B.add(q.to.entity),q.to.entity===r&&B.add(q.from.entity)}E(q=>q.map(ee=>{const se=F!==""&&!Y.has(ee.id),ge=r!==null&&!B.has(ee.id),J=pe.active&&!pe.entsForAttr.has(ee.id),fe=se||ge||J,ce=F!==""&&Y.has(ee.id)||pe.active&&pe.entsForAttr.has(ee.id),xe=pe.hitAttrsByEntity.get(ee.id);return ee.data.dimmed===fe&&ee.data.highlighted===ce&&ee.data.highlightAttrs===xe?ee:{...ee,data:{...ee.data,dimmed:fe,highlighted:ce,highlightAttrs:xe}}})),v(q=>q.map(ee=>{var Ye,Ke,Te;const se=(Ye=ee.data)==null?void 0:Ye.relationship,ge=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,J=pe.active&&!pe.relsForAttr.has(ee.id),fe=ge||J,ce=G===ee.id,xe=r!==null&&se!==void 0&&(se.from.entity===r||se.to.entity===r),Me=ce||xe?1e3:0;return((Ke=ee.data)==null?void 0:Ke.dimmed)===fe&&((Te=ee.data)==null?void 0:Te.hovered)===ce&&ee.zIndex===Me?ee:{...ee,zIndex:Me,data:{...ee.data,dimmed:fe,hovered:ce}}}))},[pe,G,i,r,e]),w.useEffect(()=>{var Q;const F=i.trim().toLowerCase();if(!F)return;const Y=new Set;for(const q of e.entities)(q.name.toLowerCase()+" "+(((Q=q.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+q.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(q.id);if(!Y.size)return;const B=requestAnimationFrame(()=>{const q=b().filter(se=>Y.has(se.id));if(!q.length)return;const ee=Mf(q);y(ee,{padding:.35,duration:400})});return()=>cancelAnimationFrame(B)},[i,e,b,y]);const le=w.useCallback((F="auto",Y="LR")=>{P.current=Object.fromEntries(b().map(B=>[B.id,{x:B.position.x,y:B.position.y}])),E(B=>cr(B,C,te,F,me,Y)),requestAnimationFrame(()=>p({padding:.15,duration:300})),re()},[C,te,me,p,b,re]),X=w.useCallback(()=>{const F=P.current;F&&(E(Y=>Y.map(B=>F[B.id]?{...B,position:F[B.id]}:B)),P.current=null,re())},[re]),_e=w.useCallback(()=>{f==null||f.reset(j),R.current.delete(j),_.current=null,Z.current={},M.current=!1,v(F=>F.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(F=>{const Y=cr(F,C,te,"auto",me);return requestAnimationFrame(()=>p({padding:.15,duration:300})),Y})},[f,j,C,te,me,p]),je=w.useCallback(F=>{s(F),E(Y=>(Y.find(Q=>Q.id===F)&&requestAnimationFrame(()=>p({nodes:[{id:F}],padding:.4,duration:400})),Y))},[p,s]);w.useImperativeHandle(m,()=>({relayout:le,fitView:()=>p({padding:.15,duration:300}),focusEntity:je,newEntity:()=>O(!0),resetLayout:_e,undoRelayout:X}),[le,p,je,_e,X]);const ze=w.useCallback(F=>{if(ne||!F.source||!F.target||F.source===F.target)return;const Y=F.sourceHandle&&F.sourceHandle!==Br?F.sourceHandle:void 0,B=F.targetHandle&&F.targetHandle!==Gr?F.targetHandle:void 0;k({from:F.source,to:F.target,fromAttr:Y,toAttr:B})},[ne]),$e=w.useCallback(async(F,Y)=>{try{return await n(F,Y)}catch(B){throw d==null||d(B instanceof Error?B.message:String(B)),B}},[n,d]),qe=r?te.get(r)??null:null,Ie=e.relationships.find(F=>F.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Go,{nodes:g,edges:C,nodeTypes:bx,edgeTypes:vx,onNodeClick:(F,Y)=>s(Y.id),onEdgeDoubleClick:(F,Y)=>!ne&&L(Y.id),onPaneClick:()=>{s(null),L(null)},onNodeDragStop:(F,Y)=>{E(B=>B.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),re()},onConnect:ze,nodesConnectable:!ne,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:De.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:F=>{var Y;return((Y=F.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),qe&&h.jsx(Hm,{entity:qe,doc:e,caps:t,exec:$e,onClose:()=>s(null),onFocusEntity:je,onAlign:H,onEditMapping:$}),V&&h.jsx(ix,{entity:V,exec:$e,onClose:()=>H(null)}),x&&h.jsx(ox,{entity:x,doc:e,exec:$e,onClose:()=>$(null)}),S&&h.jsx(ax,{doc:e,exec:$e,onClose:()=>O(!1),onCreated:je}),D&&h.jsx(cx,{doc:e,fromId:D.from,toId:D.to,initialFromAttr:D.fromAttr,initialToAttr:D.toAttr,exec:$e,onClose:()=>k(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:$e,onClose:()=>L(null)})]})}function ew({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(Nx,{}),e==="layers"&&h.jsx(kx,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(jx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Cx,{readOnly:n})]})}function Nx(){const[e,t]=w.useState(""),[n,r]=w.useState([]),[s,i]=w.useState({loaded:0,vocabs:[]}),[o,a]=w.useState(null),[c,l]=w.useState([]),[u,d]=w.useState("");w.useEffect(()=>{Zo().then(f=>l(f.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const f=setTimeout(()=>{Ko(e||"a",u||void 0).then(p=>{r(e?p.results:[]),i({loaded:p.loaded_terms,vocabs:p.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=w.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const Sx=["industry","core","domain","specialised"];function kx({refreshKey:e,onFocusEntity:t}){const[n,r]=w.useState(null),[s,i]=w.useState(null);if(w.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),Sx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function jx({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=w.useState(null),[i,o]=w.useState(""),[a,c]=w.useState(""),[l,u]=w.useState(!1),d=w.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` + +`))).catch(()=>o(""))},[]);return w.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:i.split(` +`).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` +`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:l,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(u(!0),Mm().then(()=>{u(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:l||!a.trim(),onClick:()=>{u(!0),$m(a).then(()=>{u(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Cx({readOnly:e}){const[t,n]=w.useState([]),r=w.useCallback(()=>{Am().then(i=>n(i.decisions)).catch(()=>n([]))},[]);if(w.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(i=>h.jsxs("div",{className:"decision "+i.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[i.verdict]}),h.jsx("span",{className:"chip",children:i.confidence}),h.jsx("span",{className:"chip",children:i.signal})]}),h.jsx("p",{className:"decision-subject",children:i.subject}),!e&&i.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Fs(i.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Fs(i.signal_key,"rejected").then(r),children:"Reject"})]})]},i.signal_key))})}function tw({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:i,openImport:o=!1,prefillImport:a="",onPreview:c}){const[l,u]=w.useState(o&&t?"import":null),[d,m]=w.useState([]),[f,p]=w.useState("postgres"),y=w.useRef(null);w.useEffect(()=>{Rm().then(g=>m(g.formats)).catch(()=>m([]))},[]),w.useEffect(()=>{if(!l)return;const g=E=>{y.current&&!y.current.contains(E.target)&&u(null)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[l]);const b=d.find(g=>g.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:y,children:[h.jsxs("button",{className:s+(l==="export"?" on":""),onClick:()=>u(l==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(l==="import"?" on":""),onClick:()=>u(l==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),l==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(b==null?void 0:b.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:g=>p(g.target.value),children:b.dialects.map(g=>h.jsx("option",{value:g,children:g},g))})]}),d.map(g=>h.jsx("a",{className:"ie-item",href:Im(g.id,g.id==="sql"?f:void 0),download:!0,onClick:()=>u(null),children:g.label},g.id))]}),l==="import"&&h.jsx($x,{exec:e,submitLabel:r,buttonClass:s,applyBatch:i,onClose:()=>u(null),onImported:g=>{u(null),n==null||n(g)},onPreview:c,prefillImport:a})]})}const wi=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function $x({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:i,onPreview:o,prefillImport:a}){var j;const[c,l]=w.useState(o?"erwin":"sql"),[u,d]=w.useState("postgres"),[m,f]=w.useState(a??""),[p,y]=w.useState(!1),[b,g]=w.useState(null),[E,C]=w.useState([]);w.useEffect(()=>{a&&f(a)},[a]);const v=_=>{_&&_.text().then(f).catch(()=>g("could not read that file"))},M=async()=>{y(!0),g(null),C([]);try{if(o&&c==="erwin"){const I=await Om(c,m);if(!I.changes.length){g(I.warnings[0]??"nothing to import from that document"),y(!1);return}s(),o(I),y(!1);return}const _=await Tm(c,m,c==="sql"?u:void 0);if(!_.changes.length){g(_.warnings[0]??"nothing to import from that document"),y(!1);return}if(r)await r(_.changes);else for(const I of _.changes)await e(I.op,I.payload);C(_.warnings),i(_.tables)}catch(_){g(_ instanceof Error?_.message:String(_))}finally{y(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:wi.map(_=>h.jsx("button",{className:"ie-tab"+(c===_.id?" active":""),onClick:()=>l(_.id),children:_.label},_.id))}),h.jsx("p",{className:"ie-hint",children:(j=wi.find(_=>_.id===c))==null?void 0:j.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:u,onChange:_=>d(_.target.value),children:["postgres","snowflake","mysql","duckdb"].map(_=>h.jsx("option",{children:_},_))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:_=>f(_.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:_=>{var I;return v(((I=_.target.files)==null?void 0:I[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((_,I)=>h.jsx("p",{className:"ie-warn",children:_},I)),b&&h.jsx("p",{className:"ie-error",children:b}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:p||!m.trim(),onClick:M,children:p?"Importing…":t})]})]})}export{qo as A,_m as B,gm as C,Pm as E,tw as I,kx as L,Jx as M,Nx as O,yi as P,Vo as R,ew as S,Ix as a,Gx as b,Fx as c,Wx as d,Ux as e,Rx as f,jm as g,qx as h,Xx as i,Vx as j,Lx as k,Dx as l,Px as m,Hx as n,Ko as o,Yx as p,Bx as q,zx as r,km as s,Tx as t,Ox as u,cr as v,Go as w,wx as x,lm as y}; diff --git a/packages/server/src/mdl_server/static/assets/styles-BpoQ4C-h.css b/packages/server/src/mdl_server/static/assets/styles-CK604yls.css similarity index 59% rename from packages/server/src/mdl_server/static/assets/styles-BpoQ4C-h.css rename to packages/server/src/mdl_server/static/assets/styles-CK604yls.css index 206133b..ca5dda2 100644 --- a/packages/server/src/mdl_server/static/assets/styles-BpoQ4C-h.css +++ b/packages/server/src/mdl_server/static/assets/styles-CK604yls.css @@ -1 +1 @@ -.react-flow{direction:ltr}.react-flow__container{position:absolute;width:100%;height:100%;top:0;left:0}.react-flow__pane{z-index:1;cursor:-webkit-grab;cursor:grab}.react-flow__pane.selection{cursor:pointer}.react-flow__pane.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__viewport{transform-origin:0 0;z-index:2;pointer-events:none}.react-flow__renderer{z-index:4}.react-flow__selection{z-index:6}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible{outline:none}.react-flow .react-flow__edges{pointer-events:none;overflow:visible}.react-flow__edge-path,.react-flow__connection-path{stroke:#b1b1b7;stroke-width:1;fill:none}.react-flow__edge{pointer-events:visibleStroke;cursor:pointer}.react-flow__edge.animated path{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__edge.animated path.react-flow__edge-interaction{stroke-dasharray:none;-webkit-animation:none;animation:none}.react-flow__edge.inactive{pointer-events:none}.react-flow__edge.selected,.react-flow__edge:focus,.react-flow__edge:focus-visible{outline:none}.react-flow__edge.selected .react-flow__edge-path,.react-flow__edge:focus .react-flow__edge-path,.react-flow__edge:focus-visible .react-flow__edge-path{stroke:#555}.react-flow__edge-textwrapper{pointer-events:all}.react-flow__edge-textbg{fill:#fff}.react-flow__edge .react-flow__edge-text{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__connection{pointer-events:none}.react-flow__connection .animated{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__connectionline{z-index:1001}.react-flow__nodes{pointer-events:none;transform-origin:0 0}.react-flow__node{position:absolute;-webkit-user-select:none;-moz-user-select:none;user-select:none;pointer-events:all;transform-origin:0 0;box-sizing:border-box;cursor:-webkit-grab;cursor:grab}.react-flow__node.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__nodesselection{z-index:3;transform-origin:left top;pointer-events:none}.react-flow__nodesselection-rect{position:absolute;pointer-events:all;cursor:-webkit-grab;cursor:grab}.react-flow__handle{position:absolute;pointer-events:none;min-width:5px;min-height:5px;width:6px;height:6px;background:#1a192b;border:1px solid white;border-radius:100%}.react-flow__handle.connectionindicator{pointer-events:all;cursor:crosshair}.react-flow__handle-bottom{top:auto;left:50%;bottom:-4px;transform:translate(-50%)}.react-flow__handle-top{left:50%;top:-4px;transform:translate(-50%)}.react-flow__handle-left{top:50%;left:-4px;transform:translateY(-50%)}.react-flow__handle-right{right:-4px;top:50%;transform:translateY(-50%)}.react-flow__edgeupdater{cursor:move;pointer-events:all}.react-flow__panel{position:absolute;z-index:5;margin:15px}.react-flow__panel.top{top:0}.react-flow__panel.bottom{bottom:0}.react-flow__panel.left{left:0}.react-flow__panel.right{right:0}.react-flow__panel.center{left:50%;transform:translate(-50%)}.react-flow__attribution{font-size:10px;background:#ffffff80;padding:2px 3px;margin:0}.react-flow__attribution a{text-decoration:none;color:#999}@-webkit-keyframes dashdraw{0%{stroke-dashoffset:10}}@keyframes dashdraw{0%{stroke-dashoffset:10}}.react-flow__edgelabel-renderer{position:absolute;width:100%;height:100%;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__edge.updating .react-flow__edge-path{stroke:#777}.react-flow__edge-text{font-size:10px}.react-flow__node.selectable:focus,.react-flow__node.selectable:focus-visible{outline:none}.react-flow__node-default,.react-flow__node-input,.react-flow__node-output,.react-flow__node-group{padding:10px;border-radius:3px;width:150px;font-size:12px;color:#222;text-align:center;border-width:1px;border-style:solid;border-color:#1a192b;background-color:#fff}.react-flow__node-default.selectable:hover,.react-flow__node-input.selectable:hover,.react-flow__node-output.selectable:hover,.react-flow__node-group.selectable:hover{box-shadow:0 1px 4px 1px #00000014}.react-flow__node-default.selectable.selected,.react-flow__node-default.selectable:focus,.react-flow__node-default.selectable:focus-visible,.react-flow__node-input.selectable.selected,.react-flow__node-input.selectable:focus,.react-flow__node-input.selectable:focus-visible,.react-flow__node-output.selectable.selected,.react-flow__node-output.selectable:focus,.react-flow__node-output.selectable:focus-visible,.react-flow__node-group.selectable.selected,.react-flow__node-group.selectable:focus,.react-flow__node-group.selectable:focus-visible{box-shadow:0 0 0 .5px #1a192b}.react-flow__node-group{background-color:#f0f0f040}.react-flow__nodesselection-rect,.react-flow__selection{background:#0059dc14;border:1px dotted rgba(0,89,220,.8)}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible,.react-flow__selection:focus,.react-flow__selection:focus-visible{outline:none}.react-flow__controls{box-shadow:0 0 2px 1px #00000014}.react-flow__controls-button{border:none;background:#fefefe;border-bottom:1px solid #eee;box-sizing:content-box;display:flex;justify-content:center;align-items:center;width:16px;height:16px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;padding:5px}.react-flow__controls-button:hover{background:#f4f4f4}.react-flow__controls-button svg{width:100%;max-width:12px;max-height:12px}.react-flow__controls-button:disabled{pointer-events:none}.react-flow__controls-button:disabled svg{fill-opacity:.4}.react-flow__minimap{background-color:#fff}.react-flow__minimap svg{display:block}.react-flow__resize-control{position:absolute}.react-flow__resize-control.left,.react-flow__resize-control.right{cursor:ew-resize}.react-flow__resize-control.top,.react-flow__resize-control.bottom{cursor:ns-resize}.react-flow__resize-control.top.left,.react-flow__resize-control.bottom.right{cursor:nwse-resize}.react-flow__resize-control.bottom.left,.react-flow__resize-control.top.right{cursor:nesw-resize}.react-flow__resize-control.handle{width:4px;height:4px;border:1px solid #fff;border-radius:1px;background-color:#3367d9;transform:translate(-50%,-50%)}.react-flow__resize-control.handle.left{left:0;top:50%}.react-flow__resize-control.handle.right{left:100%;top:50%}.react-flow__resize-control.handle.top{left:50%;top:0}.react-flow__resize-control.handle.bottom{left:50%;top:100%}.react-flow__resize-control.handle.top.left,.react-flow__resize-control.handle.bottom.left{left:0}.react-flow__resize-control.handle.top.right,.react-flow__resize-control.handle.bottom.right{left:100%}.react-flow__resize-control.line{border-color:#3367d9;border-width:0;border-style:solid}.react-flow__resize-control.line.left,.react-flow__resize-control.line.right{width:1px;transform:translate(-50%);top:0;height:100%}.react-flow__resize-control.line.left{left:0;border-left-width:1px}.react-flow__resize-control.line.right{left:100%;border-right-width:1px}.react-flow__resize-control.line.top,.react-flow__resize-control.line.bottom{height:1px;transform:translateY(-50%);left:0;width:100%}.react-flow__resize-control.line.top{top:0;border-top-width:1px}.react-flow__resize-control.line.bottom{border-bottom-width:1px;top:100%}.ie-wrap{position:relative;display:inline-flex;gap:6px}.erd-ico{font-size:13px;line-height:1;opacity:.85;margin-right:1px}.ie-wrap button:hover .erd-ico,.ie-wrap button.on .erd-ico,.ie-wrap button.active .erd-ico{opacity:1}.erd-caret{opacity:.55;margin-left:1px}.ie-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:30;min-width:220px;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:6px;box-shadow:0 12px 32px #00000073;display:flex;flex-direction:column;gap:2px}.ie-item{display:block;padding:8px 10px;border-radius:6px;color:var(--text);text-decoration:none;font-size:13px;cursor:pointer}.ie-item:hover{background:#5eead424;color:var(--accent)}.ie-dialect{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 10px 8px;margin-bottom:4px;border-bottom:1px solid var(--border);font-size:12px;color:var(--text-dim)}.ie-dialect select{background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;padding:3px 6px;font-size:12px}.ie-import{width:380px;padding:12px;gap:8px}.ie-tabs{display:flex;gap:4px}.ie-tab{flex:1;padding:6px 8px;border-radius:6px;font-size:12px;cursor:pointer;background:none;border:1px solid var(--border);color:var(--text-dim)}.ie-tab.active{border-color:var(--accent);color:var(--accent);background:#5eead41a}.ie-hint{font-size:11px;color:var(--text-dim);margin:0}.ie-textarea{width:100%;font-family:var(--mono);font-size:12px;resize:vertical;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:8px;padding:8px;box-sizing:border-box}.ie-textarea:focus{border-color:var(--accent);outline:none}.ie-file{font-size:11px;color:var(--text-dim)}.ie-warn{font-size:11px;color:var(--pk);margin:0}.ie-error{font-size:12px;color:var(--err);margin:0}.ie-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:4px}:root{--bg: #14110f;--bg-raised: #1c1815;--bg-card: #221d19;--border: #33291f;--border-strong: #4a3c2c;--text: #ece6dd;--text-dim: #a89a86;--accent: #e0a63a;--accent-soft: rgba(224, 166, 58, .15);--accent-ink: #241a08;--pk: #f2c14e;--err: #f0857a;--warn: #e6a94a;--ok: #6cbf73;--font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;--mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace}*{box-sizing:border-box}html,body,#root{height:100%;margin:0}body{font-family:var(--font);background:var(--bg);color:var(--text)}.app{display:flex;flex-direction:column;height:100%}.canvas-wrap{flex:1;position:relative;min-height:0}.react-flow{background:var(--bg)}.topbar{display:flex;flex-direction:column;padding:8px 16px 0;background:var(--bg-raised);border-bottom:1px solid var(--border);z-index:10}.topbar-row{display:flex;align-items:center;gap:14px}.topbar-row.context{padding-bottom:8px}.topbar-row.actions{gap:10px;padding-bottom:8px;flex-wrap:wrap}.brand{display:flex;align-items:baseline;gap:8px;white-space:nowrap}.logo{color:var(--accent);font-size:18px}.brand-name{font-weight:700;letter-spacing:.02em}.project-name{color:var(--text-dim);font-size:13px}.search{flex:0 1 300px;margin-left:auto;padding:7px 12px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-size:13px;outline:none}.search:focus{border-color:var(--accent)}.stats{display:flex;align-items:center;gap:12px;font-size:12px;color:var(--text-dim)}.stat-item{display:inline-flex;align-items:center;gap:5px}.stat-item svg{color:var(--text-dim)}.diag-chip{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:99px;font-weight:600}.diag-chip.ok{background:#34d39926;color:var(--ok)}.diag-chip.warn{background:#fbbf2426;color:var(--warn)}.diag-chip.err{background:#f8717126;color:var(--err)}.hamburger{position:relative;display:inline-flex;align-items:center;justify-content:center;padding:6px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer}.hamburger:hover{color:var(--text);border-color:var(--border-strong)}.hamburger.active{color:var(--accent);border-color:var(--accent)}.hamburger-badge{position:absolute;top:-6px;right:-6px;min-width:15px;height:15px;padding:0 3px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-size:10px;font-weight:700;line-height:15px;text-align:center}.btn-group{display:inline-flex;align-items:center;gap:2px;background:var(--bg-card);border:1px solid var(--border);border-radius:9px;padding:2px}.grp-tag{font-size:10px;color:var(--text-dim);opacity:.75;padding:0 6px 0 4px;letter-spacing:.03em;text-transform:none;white-space:nowrap}.grp-btn{display:inline-flex;align-items:center;gap:5px;padding:5px 9px;border-radius:6px;border:none;background:transparent;color:var(--text-dim);cursor:pointer;font-size:12px;white-space:nowrap}.grp-btn.icon-only{padding:5px 7px}.grp-btn:hover{color:var(--text);background:#ffffff0d}.grp-btn.active{color:var(--accent)}.grp-btn.active svg{color:var(--accent)}.grp-badge{width:6px;height:6px;border-radius:50%;background:var(--warn);display:inline-block;margin-left:1px}.dir-arrow{display:inline-flex;transition:transform .15s ease}.tool-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 11px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.tool-btn:hover{color:var(--text);border-color:var(--border-strong)}.tool-btn.active{color:var(--accent);border-color:var(--accent)}.tool-btn.primary{color:var(--accent);border-color:#e0a63a66;font-weight:600}.layout-picker{position:relative;display:inline-flex;gap:2px}.layout-picker .caret{font-size:10px}.layout-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:20;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:8px;padding:4px;min-width:150px;box-shadow:0 8px 24px #0006}.layout-menu button{display:block;width:100%;text-align:left;padding:7px 10px;border:0;border-radius:6px;background:transparent;color:var(--text-dim);cursor:pointer;font-size:13px}.layout-menu button:hover{background:var(--bg-card);color:var(--text)}.canvas-drawer{position:absolute;top:12px;left:12px;bottom:12px;width:300px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:16px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080;display:flex;flex-direction:column;gap:10px;transform:translate(calc(-100% - 16px));opacity:0;pointer-events:none;transition:transform .2s ease,opacity .2s ease}.canvas-drawer.open{transform:translate(0);opacity:1;pointer-events:auto}.drawer-header{display:flex;align-items:center;justify-content:space-between}.drawer-header h2{margin:0;font-size:15px;display:inline-flex;align-items:center;gap:7px}.drawer-header h2 svg{color:var(--accent)}.drawer-hint{font-size:11px;color:var(--text-dim);line-height:1.4}.sa-all{align-self:flex-start;padding:4px 10px;border-radius:7px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.sa-all:hover:not(:disabled){color:var(--text);border-color:var(--border-strong)}.sa-all.active{color:var(--accent);border-color:var(--accent)}.sa-all:disabled{opacity:.5;cursor:default}.sa-list{display:flex;flex-direction:column;gap:3px;margin-top:2px}.sa-row{display:flex;align-items:center;gap:9px;padding:7px 8px;border-radius:8px;cursor:pointer;border:1px solid transparent;-webkit-user-select:none;user-select:none}.sa-row:hover{background:var(--bg-card)}.sa-row.active{background:var(--accent-soft);border-color:#e0a63a66}.sa-row.muted{cursor:default;opacity:.7}.sa-row.muted:hover{background:transparent}.sa-row input[type=checkbox]{accent-color:var(--accent);cursor:pointer}.sa-chip{width:12px;height:12px;border-radius:3px;flex:0 0 auto}.sa-chip.none{background:repeating-linear-gradient(45deg,#4a3c2c,#4a3c2c 2px,transparent 2px,transparent 4px)}.sa-name{flex:1;font-size:13px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.sa-row.muted .sa-name{color:var(--text-dim)}.sa-count{font-size:11px;color:var(--text-dim);background:var(--bg-card);padding:1px 7px;border-radius:99px;flex:0 0 auto}.entity-node{width:264px;background:var(--bg-card);border:1px solid var(--border);border-top:3px solid var(--accent);border-radius:10px;overflow:hidden;box-shadow:0 4px 18px #00000059;font-size:12px;transition:opacity .15s,box-shadow .15s,border-color .15s}.entity-node.selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent),0 8px 24px #00000080}.entity-node.highlighted{box-shadow:0 0 0 2px var(--pk),0 8px 24px #00000080}.entity-node.dimmed{opacity:.18}.entity-header{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#ffffff08;border-bottom:1px solid var(--border)}.entity-name{font-weight:700;font-size:13px;letter-spacing:.01em}.entity-badges{display:flex;gap:4px}.badge{font-size:10px;padding:1px 6px;border-radius:99px;background:var(--accent-soft);color:var(--accent);text-transform:uppercase;letter-spacing:.05em}.badge.ontology{background:#93c5fd1f;color:#93c5fd}.attr-section{padding:4px 0}.attr-section.keys{border-bottom:1px solid var(--border);background:#fcd34d0a}.attr-row{display:flex;align-items:center;gap:6px;padding:3px 12px;height:26px;line-height:20px;position:relative}.attr-row.empty{color:var(--text-dim);font-style:italic}.attr-row.more{color:var(--text-dim);font-style:italic;cursor:pointer;justify-content:center;height:22px;font-size:11px}.attr-row.more:hover{color:var(--accent);background:var(--accent-soft)}.attr-row.rel-hit{background:var(--accent-soft);box-shadow:inset 2px 0 0 var(--accent)}.attr-row.rel-hit .attr-name{color:var(--accent);font-weight:600}.attr-row.rel-dim{opacity:.35}.attr-row.endpoint .attr-name{font-style:normal}.attr-port{width:8px!important;height:8px!important;opacity:0;top:50%!important}.attr-port.react-flow__handle-left{left:-5px!important}.attr-port.react-flow__handle-right{right:-5px!important}.entity-node:hover .attr-port{opacity:.5}.attr-row:hover .attr-port{opacity:1!important;background:var(--accent)!important}.attr-icon{width:14px;text-align:center;font-size:10px;flex:none}.attr-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attr-name.pk{color:var(--pk);font-weight:600}.attr-type{color:var(--text-dim);font-family:var(--mono);font-size:10px;flex:none}.attr-notnull{color:var(--text-dim);font-size:8px;flex:none}.port{width:11px!important;height:11px!important;background:var(--border-strong)!important;border:2px solid var(--bg)!important;opacity:.55;transition:transform .12s ease,background .12s ease,opacity .12s ease}.entity-node:hover .port{opacity:1;background:var(--accent)!important;transform:scale(1.25);box-shadow:0 0 0 4px var(--accent-soft);cursor:crosshair}.port:hover{transform:scale(1.6)!important;cursor:crosshair}.entity-node:hover{border-color:var(--accent);box-shadow:0 0 0 1px #e0a63a40}.react-flow__connectionline .react-flow__edge-path,.react-flow__connection-path{stroke:var(--accent)!important;stroke-width:2!important}.rel-path{stroke:var(--border-strong);stroke-width:1.6}.rel-edge{cursor:pointer}.rel-glyph{stroke:var(--border-strong);stroke-width:1.6;fill:none}.rel-glyph.ring{fill:var(--bg)}.rel-edge:hover .rel-path,.rel-edge.selected .rel-path,.rel-edge:hover .rel-glyph,.rel-edge.selected .rel-glyph{stroke:var(--accent)}.rel-edge.dimmed{opacity:.12}.rel-label{fill:var(--text);font-size:11px;text-anchor:middle;paint-order:stroke;stroke:var(--bg);stroke-width:4px}.rel-handle .rel-grip{fill:var(--accent);stroke:var(--bg);opacity:.95}.rel-handle .rel-grip-dot{fill:var(--bg)}.rel-handle:hover .rel-grip{fill:var(--accent);filter:brightness(1.15)}.layout-menu-sep{height:1px;margin:4px 0;background:var(--border)}.detail-panel{position:absolute;top:12px;right:12px;bottom:12px;width:340px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.detail-header{display:flex;justify-content:space-between;align-items:flex-start}.detail-header h2{margin:0 0 6px;font-size:18px}.icon-btn{background:none;border:none;color:var(--text-dim);cursor:pointer;font-size:14px}.icon-btn:hover{color:var(--text)}.definition{color:var(--text-dim);font-size:13px;line-height:1.5}.detail-panel section{margin-top:18px}.detail-panel h3{margin:0 0 8px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.kv{display:flex;gap:8px;margin:4px 0;font-size:12px;align-items:baseline}.kv .k{color:var(--text-dim);min-width:72px}.kv .v{word-break:break-all}.chip{display:inline-block;font-size:11px;padding:2px 8px;margin:2px 4px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim)}.chip.pattern{background:var(--accent-soft);color:var(--accent)}.chip.layer-industry{background:#93c5fd26;color:#93c5fd}.chip.layer-core{background:var(--accent-soft);color:var(--accent)}.chip.layer-domain{background:#f0abfc26;color:#f0abfc}.chip.layer-specialised{background:#fcd34d26;color:var(--pk)}.cat-badge{font-size:10px;font-weight:700;margin-left:6px;padding:2px 8px;border-radius:5px;cursor:help}.cat-badge.supertype{background:#a78bfa2e;color:#a78bfa}.cat-badge.subtype{background:var(--accent-soft);color:var(--accent)}.udp-row td{padding:3px 6px;border-bottom:1px solid var(--border);font-size:12px}.udp-key{color:var(--text-dim);font-family:var(--mono);font-size:11px}.udp-val{color:var(--text)}.enum-badge{font-size:8px;font-weight:700;margin-left:6px;padding:1px 5px;border-radius:4px;background:#a78bfa2e;color:#a78bfa;vertical-align:middle;cursor:help}.key-row{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:12px}.key-badge{font-size:9px;font-weight:700;padding:2px 6px;border-radius:5px;background:#94a3b826;color:var(--text-dim);flex:none}.key-badge.pk{background:#fcd34d2e;color:var(--pk)}.key-badge.unique,.key-badge.alternate{background:var(--accent-soft);color:var(--accent)}.key-name{font-weight:600}.key-cols{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}.attr-table td{padding:4px 6px;border-bottom:1px solid var(--border)}.attr-table td:first-child{width:100%}.attr-table td:first-child .edit-input{min-width:120px}.attr-table td.pk{color:var(--pk);font-weight:600}.attr-table td.type{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table td.null{color:var(--text-dim);font-size:10px;text-align:right}.rel-link{display:flex;gap:8px;align-items:center;width:100%;background:var(--bg-card);border:1px solid var(--border);border-radius:8px;color:var(--text);padding:7px 10px;margin:4px 0;cursor:pointer;font-size:12px;text-align:left}.rel-link:hover{border-color:var(--accent)}.rel-card{color:var(--text-dim);font-family:var(--mono);font-size:11px}.ulid{font-family:var(--mono);font-size:11px;color:var(--text-dim);cursor:copy;word-break:break-all}.ulid:hover{color:var(--accent)}.splash{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--text-dim)}.splash.error pre{background:var(--bg-card);padding:12px 16px;border-radius:8px;max-width:640px;overflow:auto;color:var(--err);font-size:12px}.react-flow__minimap{background:var(--bg-raised)!important;border-radius:10px}.react-flow__controls{border-radius:10px;overflow:hidden;box-shadow:none!important}.react-flow__controls-button{background:var(--bg-raised)!important;border-bottom:1px solid var(--border)!important;fill:var(--text-dim)!important}.react-flow__controls-button:hover{fill:var(--text)!important}.edit-input{width:100%;padding:6px 9px;border-radius:7px;font-size:12px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-family:var(--font);outline:none}.edit-input:focus{border-color:var(--accent)}.entity-title-input{font-size:17px;font-weight:700;background:transparent;border-color:transparent;padding-left:0}.entity-title-input:hover,.entity-title-input:focus{border-color:var(--border);background:var(--bg-card);padding-left:9px}.definition-input{color:var(--text-dim);line-height:1.5;resize:vertical}.chip-select,.cell-select{font-size:11px;padding:2px 6px;margin:2px 6px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim);border:1px solid transparent;outline:none}.chip-select:hover,.cell-select:hover{border-color:var(--border-strong);color:var(--text)}.cell-select{border-radius:6px;background:transparent;max-width:110px}.mini-btn{font-size:11px;padding:3px 9px;border-radius:7px;cursor:pointer;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim)}.mini-btn:hover{color:var(--accent);border-color:var(--accent)}.mini-btn.danger:hover{color:var(--err);border-color:var(--err)}.h3-actions{float:right;display:inline-flex;gap:6px}.empty-hint{color:var(--text-dim);font-size:12px;font-style:italic}.add-attr{display:flex;gap:6px;margin-top:8px}.rel-row{display:flex;gap:6px;align-items:flex-start}.rel-row .rel-main{flex:1}.verb-phrases{display:flex;align-items:center;gap:4px;margin-top:2px;padding-left:4px}.verb-phrases .verb-input{font-size:11px;font-style:italic;color:var(--text-dim);min-width:40px}.verb-phrases .verb-sep{color:var(--text-dim);font-size:11px}.physical-name-row{display:flex;align-items:center;gap:6px;margin-top:2px}.physical-name-row .physical-label{font-size:9px;text-transform:uppercase;color:var(--text-dim);letter-spacing:.04em}.physical-name-input{font-size:12px;color:var(--text-dim)}.physical-col{display:block;font-size:10px;color:var(--text-dim);font-family:var(--mono, monospace)}.physical-col-input{display:block;font-size:10px;color:var(--text-dim)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#05080db3;z-index:50;display:flex;align-items:center;justify-content:center}.modal{width:440px;max-height:80vh;overflow-y:auto;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:14px;padding:20px;box-shadow:0 24px 80px #0009}.modal.wide{width:600px}.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}.modal-header h2{margin:0;font-size:16px}.modal-search{margin-bottom:10px}.modal-footer{display:flex;gap:10px;justify-content:flex-end;align-items:center;margin-top:14px}.modal-footer label{font-size:11px;color:var(--text-dim);display:flex;flex-direction:column;gap:3px}.modal-footer select,.form-row select{background:var(--bg-card);color:var(--text);border:1px solid var(--border);border-radius:7px;padding:5px 8px;font-size:12px}.primary-btn{padding:8px 16px;border-radius:8px;border:none;cursor:pointer;background:var(--accent);color:var(--accent-ink);font-weight:700;font-size:13px}.primary-btn:disabled{opacity:.4;cursor:default}.danger-btn{padding:8px 16px;border-radius:8px;border:1px solid var(--err);cursor:pointer;background:#f8717124;color:var(--err);font-weight:700;font-size:13px}.form-row{display:flex;flex-direction:column;gap:4px;margin-bottom:14px;font-size:12px;color:var(--text-dim)}.form-row>label{font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:10px}.form-error{color:var(--err);font-size:11px}.form-preview{color:var(--text-dim);font-size:11px;word-break:break-all;opacity:.85}.form-preview:before{content:""}.form-hint{color:var(--text-dim);font-size:11px;font-style:italic;opacity:.75;word-break:break-word}.term-results{display:flex;flex-direction:column;gap:8px;max-height:44vh;overflow-y:auto}.term-card{text-align:left;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:10px 12px;cursor:pointer;color:var(--text)}.term-card:hover{border-color:var(--border-strong)}.term-card.picked{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}.term-head{display:flex;justify-content:space-between;align-items:baseline}.term-label{font-weight:600;font-size:13px}.term-source{font-size:10px;color:var(--text-dim);text-transform:uppercase;letter-spacing:.06em}.term-iri{font-size:10px;color:var(--accent);display:block;margin:2px 0;word-break:break-all}.term-def{font-size:11px;color:var(--text-dim);margin:4px 0 0;line-height:1.45}.kind-badge{font-size:8px;padding:1px 5px;margin-right:6px;border-radius:999px;background:#f0abfc26;color:#f0abfc;letter-spacing:.04em}.src-picker{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}.src-chip{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:3px 9px;border-radius:999px;background:var(--bg);border:1px solid var(--border);color:var(--text-dim);cursor:pointer}.src-chip:hover{border-color:var(--border-strong);color:var(--text)}.src-chip.active{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}.src-layer{font-size:8px;padding:0 5px;border-radius:999px;text-transform:uppercase;letter-spacing:.04em}.side-panel{position:absolute;top:12px;right:12px;bottom:12px;width:380px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.side-panel h2{margin:0;font-size:16px}.side-panel h4{margin:10px 0 6px;font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.panel-body{margin-top:12px}.panel-body.ok{color:var(--ok)}.meta-line{font-size:10px;color:var(--text-dim);margin:6px 0 10px}.coverage-banner{font-size:12px;padding:8px 12px;border-radius:9px;margin-bottom:12px;background:#34d3991a;color:var(--ok)}.coverage-banner.warn{background:#fbbf241a;color:var(--warn)}.layer-band{border:1px dashed var(--border);border-radius:10px;padding:8px 12px 10px;margin-bottom:10px}.layer-band.external{border-style:solid;background:#93c5fd0a}.stack-term{display:flex;justify-content:space-between;align-items:baseline;gap:8px;width:100%;background:var(--bg-card);border:1px solid var(--border);color:var(--text);border-radius:7px;padding:5px 10px;margin:4px 0;font-size:12px;cursor:pointer;text-align:left}div.stack-term{cursor:default}.stack-term:hover{border-color:var(--border-strong)}.stack-term.uncovered{border-color:var(--err)}.align-arrow{font-size:10px;color:var(--accent);white-space:nowrap}.align-arrow.unresolved{color:var(--warn)}.align-arrow.missing{color:var(--err);font-style:italic}.align-arrow.proposed{color:var(--warn);font-style:italic}.ref-list{display:flex;flex-direction:column;gap:6px;margin-top:4px}.ref-card{border:1px solid var(--border);border-radius:8px;padding:6px 8px;background:var(--bg)}.ref-card.proposed{border-color:var(--warn)}.ref-head{display:flex;align-items:baseline;gap:8px;justify-content:space-between}.ref-uri{font-family:var(--mono);font-size:12px;word-break:break-all}.ref-status{font-size:9px;text-transform:uppercase;letter-spacing:.04em}.ref-status.accepted{color:var(--accent)}.ref-status.proposed{color:var(--warn)}.ref-meta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:5px}.ref-pill{font-size:10px;padding:1px 6px;border-radius:999px;background:var(--accent-soft);color:var(--accent)}.ref-via{font-size:10px;color:var(--text-dim)}.ref-actions{display:flex;gap:6px;margin-top:6px}.dirty-list{list-style:none;padding:0;margin:0 0 10px;font-size:12px}.dirty-list li{padding:2px 0}.dirty-state{color:var(--warn);margin-right:6px;font-family:var(--mono)}.diff-view{background:var(--bg);border:1px solid var(--border);border-radius:9px;padding:10px;font-size:10.5px;line-height:1.5;overflow:auto;max-height:42vh;font-family:var(--mono);white-space:pre;margin-bottom:10px}.diff-add{color:var(--ok)}.diff-del{color:var(--err)}.diff-hunk{color:#93c5fd}.decision{border:1px solid var(--border);border-radius:9px;padding:8px 12px;margin-bottom:8px}.decision.accepted{opacity:.65}.decision.rejected{opacity:.45}.decision-head{display:flex;gap:6px;align-items:center}.decision-mark{font-weight:700}.decision-subject{font-size:12px;margin:6px 0}.decision-actions{display:flex;gap:6px}.toast{position:absolute;bottom:20px;left:50%;transform:translate(-50%);background:var(--bg-raised);border:1px solid var(--warn);color:var(--text);border-radius:10px;padding:10px 18px;font-size:12px;z-index:60;box-shadow:0 10px 30px #00000080} +.react-flow{direction:ltr}.react-flow__container{position:absolute;width:100%;height:100%;top:0;left:0}.react-flow__pane{z-index:1;cursor:-webkit-grab;cursor:grab}.react-flow__pane.selection{cursor:pointer}.react-flow__pane.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__viewport{transform-origin:0 0;z-index:2;pointer-events:none}.react-flow__renderer{z-index:4}.react-flow__selection{z-index:6}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible{outline:none}.react-flow .react-flow__edges{pointer-events:none;overflow:visible}.react-flow__edge-path,.react-flow__connection-path{stroke:#b1b1b7;stroke-width:1;fill:none}.react-flow__edge{pointer-events:visibleStroke;cursor:pointer}.react-flow__edge.animated path{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__edge.animated path.react-flow__edge-interaction{stroke-dasharray:none;-webkit-animation:none;animation:none}.react-flow__edge.inactive{pointer-events:none}.react-flow__edge.selected,.react-flow__edge:focus,.react-flow__edge:focus-visible{outline:none}.react-flow__edge.selected .react-flow__edge-path,.react-flow__edge:focus .react-flow__edge-path,.react-flow__edge:focus-visible .react-flow__edge-path{stroke:#555}.react-flow__edge-textwrapper{pointer-events:all}.react-flow__edge-textbg{fill:#fff}.react-flow__edge .react-flow__edge-text{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__connection{pointer-events:none}.react-flow__connection .animated{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__connectionline{z-index:1001}.react-flow__nodes{pointer-events:none;transform-origin:0 0}.react-flow__node{position:absolute;-webkit-user-select:none;-moz-user-select:none;user-select:none;pointer-events:all;transform-origin:0 0;box-sizing:border-box;cursor:-webkit-grab;cursor:grab}.react-flow__node.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__nodesselection{z-index:3;transform-origin:left top;pointer-events:none}.react-flow__nodesselection-rect{position:absolute;pointer-events:all;cursor:-webkit-grab;cursor:grab}.react-flow__handle{position:absolute;pointer-events:none;min-width:5px;min-height:5px;width:6px;height:6px;background:#1a192b;border:1px solid white;border-radius:100%}.react-flow__handle.connectionindicator{pointer-events:all;cursor:crosshair}.react-flow__handle-bottom{top:auto;left:50%;bottom:-4px;transform:translate(-50%)}.react-flow__handle-top{left:50%;top:-4px;transform:translate(-50%)}.react-flow__handle-left{top:50%;left:-4px;transform:translateY(-50%)}.react-flow__handle-right{right:-4px;top:50%;transform:translateY(-50%)}.react-flow__edgeupdater{cursor:move;pointer-events:all}.react-flow__panel{position:absolute;z-index:5;margin:15px}.react-flow__panel.top{top:0}.react-flow__panel.bottom{bottom:0}.react-flow__panel.left{left:0}.react-flow__panel.right{right:0}.react-flow__panel.center{left:50%;transform:translate(-50%)}.react-flow__attribution{font-size:10px;background:#ffffff80;padding:2px 3px;margin:0}.react-flow__attribution a{text-decoration:none;color:#999}@-webkit-keyframes dashdraw{0%{stroke-dashoffset:10}}@keyframes dashdraw{0%{stroke-dashoffset:10}}.react-flow__edgelabel-renderer{position:absolute;width:100%;height:100%;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__edge.updating .react-flow__edge-path{stroke:#777}.react-flow__edge-text{font-size:10px}.react-flow__node.selectable:focus,.react-flow__node.selectable:focus-visible{outline:none}.react-flow__node-default,.react-flow__node-input,.react-flow__node-output,.react-flow__node-group{padding:10px;border-radius:3px;width:150px;font-size:12px;color:#222;text-align:center;border-width:1px;border-style:solid;border-color:#1a192b;background-color:#fff}.react-flow__node-default.selectable:hover,.react-flow__node-input.selectable:hover,.react-flow__node-output.selectable:hover,.react-flow__node-group.selectable:hover{box-shadow:0 1px 4px 1px #00000014}.react-flow__node-default.selectable.selected,.react-flow__node-default.selectable:focus,.react-flow__node-default.selectable:focus-visible,.react-flow__node-input.selectable.selected,.react-flow__node-input.selectable:focus,.react-flow__node-input.selectable:focus-visible,.react-flow__node-output.selectable.selected,.react-flow__node-output.selectable:focus,.react-flow__node-output.selectable:focus-visible,.react-flow__node-group.selectable.selected,.react-flow__node-group.selectable:focus,.react-flow__node-group.selectable:focus-visible{box-shadow:0 0 0 .5px #1a192b}.react-flow__node-group{background-color:#f0f0f040}.react-flow__nodesselection-rect,.react-flow__selection{background:#0059dc14;border:1px dotted rgba(0,89,220,.8)}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible,.react-flow__selection:focus,.react-flow__selection:focus-visible{outline:none}.react-flow__controls{box-shadow:0 0 2px 1px #00000014}.react-flow__controls-button{border:none;background:#fefefe;border-bottom:1px solid #eee;box-sizing:content-box;display:flex;justify-content:center;align-items:center;width:16px;height:16px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;padding:5px}.react-flow__controls-button:hover{background:#f4f4f4}.react-flow__controls-button svg{width:100%;max-width:12px;max-height:12px}.react-flow__controls-button:disabled{pointer-events:none}.react-flow__controls-button:disabled svg{fill-opacity:.4}.react-flow__minimap{background-color:#fff}.react-flow__minimap svg{display:block}.react-flow__resize-control{position:absolute}.react-flow__resize-control.left,.react-flow__resize-control.right{cursor:ew-resize}.react-flow__resize-control.top,.react-flow__resize-control.bottom{cursor:ns-resize}.react-flow__resize-control.top.left,.react-flow__resize-control.bottom.right{cursor:nwse-resize}.react-flow__resize-control.bottom.left,.react-flow__resize-control.top.right{cursor:nesw-resize}.react-flow__resize-control.handle{width:4px;height:4px;border:1px solid #fff;border-radius:1px;background-color:#3367d9;transform:translate(-50%,-50%)}.react-flow__resize-control.handle.left{left:0;top:50%}.react-flow__resize-control.handle.right{left:100%;top:50%}.react-flow__resize-control.handle.top{left:50%;top:0}.react-flow__resize-control.handle.bottom{left:50%;top:100%}.react-flow__resize-control.handle.top.left,.react-flow__resize-control.handle.bottom.left{left:0}.react-flow__resize-control.handle.top.right,.react-flow__resize-control.handle.bottom.right{left:100%}.react-flow__resize-control.line{border-color:#3367d9;border-width:0;border-style:solid}.react-flow__resize-control.line.left,.react-flow__resize-control.line.right{width:1px;transform:translate(-50%);top:0;height:100%}.react-flow__resize-control.line.left{left:0;border-left-width:1px}.react-flow__resize-control.line.right{left:100%;border-right-width:1px}.react-flow__resize-control.line.top,.react-flow__resize-control.line.bottom{height:1px;transform:translateY(-50%);left:0;width:100%}.react-flow__resize-control.line.top{top:0;border-top-width:1px}.react-flow__resize-control.line.bottom{border-bottom-width:1px;top:100%}.ie-wrap{position:relative;display:inline-flex;gap:6px}.erd-ico{font-size:13px;line-height:1;opacity:.85;margin-right:1px}.ie-wrap button:hover .erd-ico,.ie-wrap button.on .erd-ico,.ie-wrap button.active .erd-ico{opacity:1}.erd-caret{opacity:.55;margin-left:1px}.ie-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:30;min-width:220px;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:6px;box-shadow:0 12px 32px #00000073;display:flex;flex-direction:column;gap:2px}.ie-item{display:block;padding:8px 10px;border-radius:6px;color:var(--text);text-decoration:none;font-size:13px;cursor:pointer}.ie-item:hover{background:#5eead424;color:var(--accent)}.ie-dialect{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 10px 8px;margin-bottom:4px;border-bottom:1px solid var(--border);font-size:12px;color:var(--text-dim)}.ie-dialect select{background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;padding:3px 6px;font-size:12px}.ie-import{width:380px;padding:12px;gap:8px}.ie-tabs{display:flex;gap:4px}.ie-tab{flex:1;padding:6px 8px;border-radius:6px;font-size:12px;cursor:pointer;background:none;border:1px solid var(--border);color:var(--text-dim)}.ie-tab.active{border-color:var(--accent);color:var(--accent);background:#5eead41a}.ie-hint{font-size:11px;color:var(--text-dim);margin:0}.ie-textarea{width:100%;font-family:var(--mono);font-size:12px;resize:vertical;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:8px;padding:8px;box-sizing:border-box}.ie-textarea:focus{border-color:var(--accent);outline:none}.ie-file{font-size:11px;color:var(--text-dim)}.ie-warn{font-size:11px;color:var(--pk);margin:0}.ie-error{font-size:12px;color:var(--err);margin:0}.ie-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:4px}:root{--bg: #14110f;--bg-raised: #1c1815;--bg-card: #221d19;--border: #33291f;--border-strong: #4a3c2c;--text: #ece6dd;--text-dim: #a89a86;--accent: #e0a63a;--accent-soft: rgba(224, 166, 58, .15);--accent-ink: #241a08;--pk: #f2c14e;--err: #f0857a;--warn: #e6a94a;--ok: #6cbf73;--font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;--mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace}*{box-sizing:border-box}html,body,#root{height:100%;margin:0}body{font-family:var(--font);background:var(--bg);color:var(--text)}.app{display:flex;flex-direction:column;height:100%}.canvas-wrap{flex:1;position:relative;min-height:0}.react-flow{background:var(--bg)}.topbar{display:flex;flex-direction:column;padding:8px 16px 0;background:var(--bg-raised);border-bottom:1px solid var(--border);z-index:10}.topbar-row{display:flex;align-items:center;gap:14px}.topbar-row.context{padding-bottom:8px}.topbar-row.actions{gap:10px;padding-bottom:8px;flex-wrap:wrap}.brand{display:flex;align-items:baseline;gap:8px;white-space:nowrap}.logo{color:var(--accent);font-size:18px}.brand-name{font-weight:700;letter-spacing:.02em}.project-name{color:var(--text-dim);font-size:13px}.search{flex:0 1 300px;margin-left:auto;padding:7px 12px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-size:13px;outline:none}.search:focus{border-color:var(--accent)}.stats{display:flex;align-items:center;gap:12px;font-size:12px;color:var(--text-dim)}.stat-item{display:inline-flex;align-items:center;gap:5px}.stat-item svg{color:var(--text-dim)}.diag-chip{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:99px;font-weight:600}.diag-chip.ok{background:#34d39926;color:var(--ok)}.diag-chip.warn{background:#fbbf2426;color:var(--warn)}.diag-chip.err{background:#f8717126;color:var(--err)}.hamburger{position:relative;display:inline-flex;align-items:center;justify-content:center;padding:6px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer}.hamburger:hover{color:var(--text);border-color:var(--border-strong)}.hamburger.active{color:var(--accent);border-color:var(--accent)}.hamburger-badge{position:absolute;top:-6px;right:-6px;min-width:15px;height:15px;padding:0 3px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-size:10px;font-weight:700;line-height:15px;text-align:center}.btn-group{display:inline-flex;align-items:center;gap:2px;background:var(--bg-card);border:1px solid var(--border);border-radius:9px;padding:2px}.grp-tag{font-size:10px;color:var(--text-dim);opacity:.75;padding:0 6px 0 4px;letter-spacing:.03em;text-transform:none;white-space:nowrap}.grp-btn{display:inline-flex;align-items:center;gap:5px;padding:5px 9px;border-radius:6px;border:none;background:transparent;color:var(--text-dim);cursor:pointer;font-size:12px;white-space:nowrap}.grp-btn.icon-only{padding:5px 7px}.grp-btn:hover{color:var(--text);background:#ffffff0d}.grp-btn.active{color:var(--accent)}.grp-btn.active svg{color:var(--accent)}.grp-badge{width:6px;height:6px;border-radius:50%;background:var(--warn);display:inline-block;margin-left:1px}.dir-arrow{display:inline-flex;transition:transform .15s ease}.tool-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 11px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.tool-btn:hover{color:var(--text);border-color:var(--border-strong)}.tool-btn.active{color:var(--accent);border-color:var(--accent)}.tool-btn.primary{color:var(--accent);border-color:#e0a63a66;font-weight:600}.layout-picker{position:relative;display:inline-flex;gap:2px}.layout-picker .caret{font-size:10px}.layout-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:20;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:8px;padding:4px;min-width:150px;box-shadow:0 8px 24px #0006}.layout-menu button{display:block;width:100%;text-align:left;padding:7px 10px;border:0;border-radius:6px;background:transparent;color:var(--text-dim);cursor:pointer;font-size:13px}.layout-menu button:hover{background:var(--bg-card);color:var(--text)}.canvas-drawer{position:absolute;top:12px;left:12px;bottom:12px;width:300px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:16px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080;display:flex;flex-direction:column;gap:10px;transform:translate(calc(-100% - 16px));opacity:0;pointer-events:none;transition:transform .2s ease,opacity .2s ease}.canvas-drawer.open{transform:translate(0);opacity:1;pointer-events:auto}.drawer-header{display:flex;align-items:center;justify-content:space-between}.drawer-header h2{margin:0;font-size:15px;display:inline-flex;align-items:center;gap:7px}.drawer-header h2 svg{color:var(--accent)}.drawer-hint{font-size:11px;color:var(--text-dim);line-height:1.4}.sa-all{align-self:flex-start;padding:4px 10px;border-radius:7px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.sa-all:hover:not(:disabled){color:var(--text);border-color:var(--border-strong)}.sa-all.active{color:var(--accent);border-color:var(--accent)}.sa-all:disabled{opacity:.5;cursor:default}.sa-list{display:flex;flex-direction:column;gap:3px;margin-top:2px}.sa-row{display:flex;align-items:center;gap:9px;padding:7px 8px;border-radius:8px;cursor:pointer;border:1px solid transparent;-webkit-user-select:none;user-select:none}.sa-row:hover{background:var(--bg-card)}.sa-row.active{background:var(--accent-soft);border-color:#e0a63a66}.sa-row.muted{cursor:default;opacity:.7}.sa-row.muted:hover{background:transparent}.sa-row input[type=checkbox]{accent-color:var(--accent);cursor:pointer}.sa-chip{width:12px;height:12px;border-radius:3px;flex:0 0 auto}.sa-chip.none{background:repeating-linear-gradient(45deg,#4a3c2c,#4a3c2c 2px,transparent 2px,transparent 4px)}.sa-name{flex:1;font-size:13px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.sa-row.muted .sa-name{color:var(--text-dim)}.sa-count{font-size:11px;color:var(--text-dim);background:var(--bg-card);padding:1px 7px;border-radius:99px;flex:0 0 auto}.entity-node{width:264px;background:var(--bg-card);border:1px solid var(--border);border-top:3px solid var(--accent);border-radius:10px;overflow:hidden;box-shadow:0 4px 18px #00000059;font-size:12px;transition:opacity .15s,box-shadow .15s,border-color .15s}.entity-node.selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent),0 8px 24px #00000080}.entity-node.highlighted{box-shadow:0 0 0 2px var(--pk),0 8px 24px #00000080}.entity-node.dimmed{opacity:.18}.entity-header{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#ffffff08;border-bottom:1px solid var(--border)}.entity-name{font-weight:700;font-size:13px;letter-spacing:.01em}.entity-badges{display:flex;gap:4px}.badge{font-size:10px;padding:1px 6px;border-radius:99px;background:var(--accent-soft);color:var(--accent);text-transform:uppercase;letter-spacing:.05em}.badge.ontology{background:#93c5fd1f;color:#93c5fd}.attr-section{padding:4px 0}.attr-section.keys{border-bottom:1px solid var(--border);background:#fcd34d0a}.attr-row{display:flex;align-items:center;gap:6px;padding:3px 12px;height:26px;line-height:20px;position:relative}.attr-row.empty{color:var(--text-dim);font-style:italic}.attr-row.more{color:var(--text-dim);font-style:italic;cursor:pointer;justify-content:center;height:22px;font-size:11px}.attr-row.more:hover{color:var(--accent);background:var(--accent-soft)}.attr-row.rel-hit{background:var(--accent-soft);box-shadow:inset 2px 0 0 var(--accent)}.attr-row.rel-hit .attr-name{color:var(--accent);font-weight:600}.attr-row.rel-dim{opacity:.35}.attr-row.endpoint .attr-name{font-style:normal}.attr-port{width:8px!important;height:8px!important;opacity:0;top:50%!important}.attr-port.react-flow__handle-left{left:-5px!important}.attr-port.react-flow__handle-right{right:-5px!important}.entity-node:hover .attr-port{opacity:.5}.attr-row:hover .attr-port{opacity:1!important;background:var(--accent)!important}.attr-icon{width:14px;text-align:center;font-size:10px;flex:none}.attr-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attr-name.pk{color:var(--pk);font-weight:600}.attr-type{color:var(--text-dim);font-family:var(--mono);font-size:10px;flex:none}.attr-notnull{color:var(--text-dim);font-size:8px;flex:none}.port{width:11px!important;height:11px!important;background:var(--border-strong)!important;border:2px solid var(--bg)!important;opacity:.55;transition:transform .12s ease,background .12s ease,opacity .12s ease}.entity-node:hover .port{opacity:1;background:var(--accent)!important;transform:scale(1.25);box-shadow:0 0 0 4px var(--accent-soft);cursor:crosshair}.port:hover{transform:scale(1.6)!important;cursor:crosshair}.entity-node:hover{border-color:var(--accent);box-shadow:0 0 0 1px #e0a63a40}.react-flow__connectionline .react-flow__edge-path,.react-flow__connection-path{stroke:var(--accent)!important;stroke-width:2!important}.rel-path{stroke:var(--border-strong);stroke-width:1.6}.rel-edge{cursor:pointer}.rel-glyph{stroke:var(--border-strong);stroke-width:1.6;fill:none}.rel-glyph.ring{fill:var(--bg)}.rel-edge:hover .rel-path,.rel-edge.selected .rel-path,.rel-edge:hover .rel-glyph,.rel-edge.selected .rel-glyph{stroke:var(--accent)}.rel-edge.dimmed{opacity:.12}.rel-label{fill:var(--text);font-size:11px;text-anchor:middle;paint-order:stroke;stroke:var(--bg);stroke-width:4px}.rel-handle{cursor:ew-resize}.rel-handle,.rel-handle *{cursor:ew-resize!important}.rel-handle .rel-grip{fill:var(--accent);stroke:var(--bg);opacity:.95}.rel-handle .rel-grip-dot{fill:var(--bg)}.rel-handle:hover .rel-grip{fill:var(--accent);filter:brightness(1.15)}.layout-menu-sep{height:1px;margin:4px 0;background:var(--border)}.detail-panel{position:absolute;top:12px;right:12px;bottom:12px;width:340px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.detail-header{display:flex;justify-content:space-between;align-items:flex-start}.detail-header h2{margin:0 0 6px;font-size:18px}.icon-btn{background:none;border:none;color:var(--text-dim);cursor:pointer;font-size:14px}.icon-btn:hover{color:var(--text)}.definition{color:var(--text-dim);font-size:13px;line-height:1.5}.detail-panel section{margin-top:18px}.detail-panel h3{margin:0 0 8px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.kv{display:flex;gap:8px;margin:4px 0;font-size:12px;align-items:baseline}.kv .k{color:var(--text-dim);min-width:72px}.kv .v{word-break:break-all}.chip{display:inline-block;font-size:11px;padding:2px 8px;margin:2px 4px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim)}.chip.pattern{background:var(--accent-soft);color:var(--accent)}.chip.layer-industry{background:#93c5fd26;color:#93c5fd}.chip.layer-core{background:var(--accent-soft);color:var(--accent)}.chip.layer-domain{background:#f0abfc26;color:#f0abfc}.chip.layer-specialised{background:#fcd34d26;color:var(--pk)}.cat-badge{font-size:10px;font-weight:700;margin-left:6px;padding:2px 8px;border-radius:5px;cursor:help}.cat-badge.supertype{background:#a78bfa2e;color:#a78bfa}.cat-badge.subtype{background:var(--accent-soft);color:var(--accent)}.udp-row td{padding:3px 6px;border-bottom:1px solid var(--border);font-size:12px}.udp-key{color:var(--text-dim);font-family:var(--mono);font-size:11px}.udp-val{color:var(--text)}.enum-badge{font-size:8px;font-weight:700;margin-left:6px;padding:1px 5px;border-radius:4px;background:#a78bfa2e;color:#a78bfa;vertical-align:middle;cursor:help}.key-row{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:12px}.key-badge{font-size:9px;font-weight:700;padding:2px 6px;border-radius:5px;background:#94a3b826;color:var(--text-dim);flex:none}.key-badge.pk{background:#fcd34d2e;color:var(--pk)}.key-badge.unique,.key-badge.alternate{background:var(--accent-soft);color:var(--accent)}.key-name{font-weight:600}.key-cols{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}.attr-table td{padding:4px 6px;border-bottom:1px solid var(--border)}.attr-table td:first-child{width:100%}.attr-table td:first-child .edit-input{min-width:120px}.attr-table td.pk{color:var(--pk);font-weight:600}.attr-table td.type{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table td.null{color:var(--text-dim);font-size:10px;text-align:right}.rel-link{display:flex;gap:8px;align-items:center;width:100%;background:var(--bg-card);border:1px solid var(--border);border-radius:8px;color:var(--text);padding:7px 10px;margin:4px 0;cursor:pointer;font-size:12px;text-align:left}.rel-link:hover{border-color:var(--accent)}.rel-card{color:var(--text-dim);font-family:var(--mono);font-size:11px}.ulid{font-family:var(--mono);font-size:11px;color:var(--text-dim);cursor:copy;word-break:break-all}.ulid:hover{color:var(--accent)}.splash{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--text-dim)}.splash.error pre{background:var(--bg-card);padding:12px 16px;border-radius:8px;max-width:640px;overflow:auto;color:var(--err);font-size:12px}.react-flow__minimap{background:var(--bg-raised)!important;border-radius:10px}.react-flow__controls{border-radius:10px;overflow:hidden;box-shadow:none!important}.react-flow__controls-button{background:var(--bg-raised)!important;border-bottom:1px solid var(--border)!important;fill:var(--text-dim)!important}.react-flow__controls-button:hover{fill:var(--text)!important}.edit-input{width:100%;padding:6px 9px;border-radius:7px;font-size:12px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-family:var(--font);outline:none}.edit-input:focus{border-color:var(--accent)}.entity-title-input{font-size:17px;font-weight:700;background:transparent;border-color:transparent;padding-left:0}.entity-title-input:hover,.entity-title-input:focus{border-color:var(--border);background:var(--bg-card);padding-left:9px}.definition-input{color:var(--text-dim);line-height:1.5;resize:vertical}.chip-select,.cell-select{font-size:11px;padding:2px 6px;margin:2px 6px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim);border:1px solid transparent;outline:none}.chip-select:hover,.cell-select:hover{border-color:var(--border-strong);color:var(--text)}.cell-select{border-radius:6px;background:transparent;max-width:110px}.mini-btn{font-size:11px;padding:3px 9px;border-radius:7px;cursor:pointer;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim)}.mini-btn:hover{color:var(--accent);border-color:var(--accent)}.mini-btn.danger:hover{color:var(--err);border-color:var(--err)}.h3-actions{float:right;display:inline-flex;gap:6px}.empty-hint{color:var(--text-dim);font-size:12px;font-style:italic}.add-attr{display:flex;gap:6px;margin-top:8px}.rel-row{display:flex;gap:6px;align-items:flex-start}.rel-row .rel-main{flex:1}.verb-phrases{display:flex;align-items:center;gap:4px;margin-top:2px;padding-left:4px}.verb-phrases .verb-input{font-size:11px;font-style:italic;color:var(--text-dim);min-width:40px}.verb-phrases .verb-sep{color:var(--text-dim);font-size:11px}.physical-name-row{display:flex;align-items:center;gap:6px;margin-top:2px}.physical-name-row .physical-label{font-size:9px;text-transform:uppercase;color:var(--text-dim);letter-spacing:.04em}.physical-name-input{font-size:12px;color:var(--text-dim)}.physical-col{display:block;font-size:10px;color:var(--text-dim);font-family:var(--mono, monospace)}.physical-col-input{display:block;font-size:10px;color:var(--text-dim)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#05080db3;z-index:50;display:flex;align-items:center;justify-content:center}.modal{width:440px;max-height:80vh;overflow-y:auto;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:14px;padding:20px;box-shadow:0 24px 80px #0009}.modal.wide{width:600px}.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}.modal-header h2{margin:0;font-size:16px}.modal-search{margin-bottom:10px}.modal-footer{display:flex;gap:10px;justify-content:flex-end;align-items:center;margin-top:14px}.modal-footer label{font-size:11px;color:var(--text-dim);display:flex;flex-direction:column;gap:3px}.modal-footer select,.form-row select{background:var(--bg-card);color:var(--text);border:1px solid var(--border);border-radius:7px;padding:5px 8px;font-size:12px}.primary-btn{padding:8px 16px;border-radius:8px;border:none;cursor:pointer;background:var(--accent);color:var(--accent-ink);font-weight:700;font-size:13px}.primary-btn:disabled{opacity:.4;cursor:default}.danger-btn{padding:8px 16px;border-radius:8px;border:1px solid var(--err);cursor:pointer;background:#f8717124;color:var(--err);font-weight:700;font-size:13px}.form-row{display:flex;flex-direction:column;gap:4px;margin-bottom:14px;font-size:12px;color:var(--text-dim)}.form-row>label{font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:10px}.form-error{color:var(--err);font-size:11px}.form-preview{color:var(--text-dim);font-size:11px;word-break:break-all;opacity:.85}.form-preview:before{content:""}.form-hint{color:var(--text-dim);font-size:11px;font-style:italic;opacity:.75;word-break:break-word}.term-results{display:flex;flex-direction:column;gap:8px;max-height:44vh;overflow-y:auto}.term-card{text-align:left;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:10px 12px;cursor:pointer;color:var(--text)}.term-card:hover{border-color:var(--border-strong)}.term-card.picked{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}.term-head{display:flex;justify-content:space-between;align-items:baseline}.term-label{font-weight:600;font-size:13px}.term-source{font-size:10px;color:var(--text-dim);text-transform:uppercase;letter-spacing:.06em}.term-iri{font-size:10px;color:var(--accent);display:block;margin:2px 0;word-break:break-all}.term-def{font-size:11px;color:var(--text-dim);margin:4px 0 0;line-height:1.45}.kind-badge{font-size:8px;padding:1px 5px;margin-right:6px;border-radius:999px;background:#f0abfc26;color:#f0abfc;letter-spacing:.04em}.src-picker{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}.src-chip{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:3px 9px;border-radius:999px;background:var(--bg);border:1px solid var(--border);color:var(--text-dim);cursor:pointer}.src-chip:hover{border-color:var(--border-strong);color:var(--text)}.src-chip.active{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}.src-layer{font-size:8px;padding:0 5px;border-radius:999px;text-transform:uppercase;letter-spacing:.04em}.side-panel{position:absolute;top:12px;right:12px;bottom:12px;width:380px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.side-panel h2{margin:0;font-size:16px}.side-panel h4{margin:10px 0 6px;font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.panel-body{margin-top:12px}.panel-body.ok{color:var(--ok)}.meta-line{font-size:10px;color:var(--text-dim);margin:6px 0 10px}.coverage-banner{font-size:12px;padding:8px 12px;border-radius:9px;margin-bottom:12px;background:#34d3991a;color:var(--ok)}.coverage-banner.warn{background:#fbbf241a;color:var(--warn)}.layer-band{border:1px dashed var(--border);border-radius:10px;padding:8px 12px 10px;margin-bottom:10px}.layer-band.external{border-style:solid;background:#93c5fd0a}.stack-term{display:flex;justify-content:space-between;align-items:baseline;gap:8px;width:100%;background:var(--bg-card);border:1px solid var(--border);color:var(--text);border-radius:7px;padding:5px 10px;margin:4px 0;font-size:12px;cursor:pointer;text-align:left}div.stack-term{cursor:default}.stack-term:hover{border-color:var(--border-strong)}.stack-term.uncovered{border-color:var(--err)}.align-arrow{font-size:10px;color:var(--accent);white-space:nowrap}.align-arrow.unresolved{color:var(--warn)}.align-arrow.missing{color:var(--err);font-style:italic}.align-arrow.proposed{color:var(--warn);font-style:italic}.ref-list{display:flex;flex-direction:column;gap:6px;margin-top:4px}.ref-card{border:1px solid var(--border);border-radius:8px;padding:6px 8px;background:var(--bg)}.ref-card.proposed{border-color:var(--warn)}.ref-head{display:flex;align-items:baseline;gap:8px;justify-content:space-between}.ref-uri{font-family:var(--mono);font-size:12px;word-break:break-all}.ref-status{font-size:9px;text-transform:uppercase;letter-spacing:.04em}.ref-status.accepted{color:var(--accent)}.ref-status.proposed{color:var(--warn)}.ref-meta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:5px}.ref-pill{font-size:10px;padding:1px 6px;border-radius:999px;background:var(--accent-soft);color:var(--accent)}.ref-via{font-size:10px;color:var(--text-dim)}.ref-actions{display:flex;gap:6px;margin-top:6px}.dirty-list{list-style:none;padding:0;margin:0 0 10px;font-size:12px}.dirty-list li{padding:2px 0}.dirty-state{color:var(--warn);margin-right:6px;font-family:var(--mono)}.diff-view{background:var(--bg);border:1px solid var(--border);border-radius:9px;padding:10px;font-size:10.5px;line-height:1.5;overflow:auto;max-height:42vh;font-family:var(--mono);white-space:pre;margin-bottom:10px}.diff-add{color:var(--ok)}.diff-del{color:var(--err)}.diff-hunk{color:#93c5fd}.decision{border:1px solid var(--border);border-radius:9px;padding:8px 12px;margin-bottom:8px}.decision.accepted{opacity:.65}.decision.rejected{opacity:.45}.decision-head{display:flex;gap:6px;align-items:center}.decision-mark{font-weight:700}.decision-subject{font-size:12px;margin:6px 0}.decision-actions{display:flex;gap:6px}.toast{position:absolute;bottom:20px;left:50%;transform:translate(-50%);background:var(--bg-raised);border:1px solid var(--warn);color:var(--text);border-radius:10px;padding:10px 18px;font-size:12px;z-index:60;box-shadow:0 10px 30px #00000080} diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index 4260232..2f42e84 100644 --- a/packages/server/src/mdl_server/static/index.html +++ b/packages/server/src/mdl_server/static/index.html @@ -4,10 +4,10 @@ Modelith - + - - + +
diff --git a/packages/server/src/mdl_server/static/sme.html b/packages/server/src/mdl_server/static/sme.html index 0cf52f0..165c1b4 100644 --- a/packages/server/src/mdl_server/static/sme.html +++ b/packages/server/src/mdl_server/static/sme.html @@ -4,10 +4,10 @@ Modelith Glossary - + - - + + From f6d0639329b58973f6cad1ae556334432efdc2fa Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Mon, 12 Oct 2026 18:27:15 +1100 Subject: [PATCH 08/14] canvas: edge enters the target from the side the route approaches (not always left) When the route was dragged to the RIGHT of the target, the edge still looped back to the left port, cutting across the card body and through the row label. Pick the target's entry side from where the run actually is: right port when routeX is right of the card, left port when left, top/bottom border when aligned over it. The crow's-foot anchor + direction follow that side, so the marker lands on the border the line crosses and the line never pierces the card or its labels. Tests: orthogonalPath right-port and left-port entry cases. 45 canvas tests pass. Verified live: a route dragged right of dm enters its right edge with the glyph on that edge, clear of the usubjid label. --- canvas/src/RelationshipEdge.tsx | 13 +++++++------ canvas/src/edgeRouting.test.ts | 14 ++++++++++++++ canvas/src/edgeRouting.ts | 19 +++++++++++-------- ...m-nUeQsnnZ.js => ModelDiagram-iv1-Rvhr.js} | 2 +- .../{main-C31opIYt.js => main-CDJWg6AJ.js} | 2 +- .../{sme-EpJn-HtT.js => sme-D5286oaR.js} | 4 ++-- ...{styles-CBRLc9al.js => styles-kEWh7gJm.js} | 4 ++-- .../server/src/mdl_server/static/index.html | 4 ++-- .../server/src/mdl_server/static/sme.html | 4 ++-- 9 files changed, 42 insertions(+), 24 deletions(-) rename packages/server/src/mdl_server/static/assets/{ModelDiagram-nUeQsnnZ.js => ModelDiagram-iv1-Rvhr.js} (97%) rename packages/server/src/mdl_server/static/assets/{main-C31opIYt.js => main-CDJWg6AJ.js} (99%) rename packages/server/src/mdl_server/static/assets/{sme-EpJn-HtT.js => sme-D5286oaR.js} (99%) rename packages/server/src/mdl_server/static/assets/{styles-CBRLc9al.js => styles-kEWh7gJm.js} (89%) diff --git a/canvas/src/RelationshipEdge.tsx b/canvas/src/RelationshipEdge.tsx index 7f96d2d..25dce0a 100644 --- a/canvas/src/RelationshipEdge.tsx +++ b/canvas/src/RelationshipEdge.tsx @@ -127,16 +127,17 @@ export const RelationshipEdge = memo(function RelationshipEdge({ const labelY = handleY; // Crow's-foot orientation + position follow the edge's ACTUAL approach at each end. - // When the orthogonal router sends the line into a node's top/bottom, its out-vector is - // vertical and the target glyph sits on that border at routeX (not the side port). + // The router reports the out-vector; the glyph ANCHOR must move to the border the line + // actually crosses — the right port when entering from the right, the top/bottom border + // when entering vertically — so the marker is never left mid-card. const srcOut = routed ? routed.sourceOut : { ox: sourcePosition === Position.Left ? -1 : 1, oy: 0 }; const tgtOut = routed ? routed.targetOut : { ox: targetPosition === Position.Left ? -1 : 1, oy: 0 }; - // glyph anchor points: the source always leaves its side port; the target glyph moves to - // the top/bottom border point when the router enters vertically. const srcGlyph = { x: sourceX, y: sourceY }; const tgtGlyph = - routed && tgtOut.oy !== 0 && tCard - ? { x: routeX!, y: tgtOut.oy < 0 ? tCard.top : tCard.bottom } + routed && tCard + ? tgtOut.oy !== 0 + ? { x: routeX!, y: tgtOut.oy < 0 ? tCard.top : tCard.bottom } // top/bottom entry + : { x: tgtOut.ox > 0 ? tCard.right : tCard.left, y: targetY } // right/left port : { x: targetX, y: targetY }; const commit = useCallback( diff --git a/canvas/src/edgeRouting.test.ts b/canvas/src/edgeRouting.test.ts index a246c81..d9313ac 100644 --- a/canvas/src/edgeRouting.test.ts +++ b/canvas/src/edgeRouting.test.ts @@ -123,4 +123,18 @@ describe("orthogonalPath", () => { expect(r.targetOut).toEqual({ ox: 0, oy: 1 }); // pointing down (bottom entry) expect(r.path.trimEnd().endsWith("L 700 620")).toBe(true); }); + + it("enters the TARGET from the RIGHT port when routeX is to its right", () => { + // routeX = 950 is to the right of the target(right=864) -> enter the right side, not + // loop back across the card to the left port. + const r = orthogonalPath(s, t, 950, 1, -1, src, tgt); + expect(r.targetOut).toEqual({ ox: 1, oy: 0 }); // points right + expect(r.path.trimEnd().endsWith("L 864 560")).toBe(true); // ends at the RIGHT border + }); + + it("enters the TARGET from the LEFT port when routeX is to its left", () => { + const r = orthogonalPath(s, t, 430, 1, -1, src, tgt); + expect(r.targetOut).toEqual({ ox: -1, oy: 0 }); + expect(r.path.trimEnd().endsWith("L 600 560")).toBe(true); // ends at the LEFT border + }); }) diff --git a/canvas/src/edgeRouting.ts b/canvas/src/edgeRouting.ts index 11a0bd3..e1fb0b0 100644 --- a/canvas/src/edgeRouting.ts +++ b/canvas/src/edgeRouting.ts @@ -196,18 +196,21 @@ export function orthogonalPath( pts.push({ x: s.x, y: s.y }, { x: routeX, y: s.y }); } - // --- TARGET entry --- + // --- TARGET entry: pick the side the route actually approaches from, so the line + // never crosses the card body to reach a far port. --- if (overTarget) { - // The run drops straight onto the target's nearest horizontal border at routeX. - // fromAbove: the vertical run reaches the target from above (source sits higher), so - // it lands on the TOP border and the glyph points up; else the BOTTOM border, pointing - // down. The endpoint moves to (routeX, border) — a true vertical entry. + // Vertical: drop straight onto the nearest horizontal border at routeX. const fromAbove = s.y <= t.y; - const border = fromAbove ? tgtCard.top : tgtCard.bottom; - pts.push({ x: routeX, y: border }); + pts.push({ x: routeX, y: fromAbove ? tgtCard.top : tgtCard.bottom }); targetOut = { ox: 0, oy: fromAbove ? -1 : 1 }; + } else if (routeX >= tgtCard.right) { + // Route is to the RIGHT of the target -> enter the RIGHT port (glyph points right). + pts.push({ x: routeX, y: t.y }, { x: tgtCard.right, y: t.y }); + targetOut = { ox: 1, oy: 0 }; } else { - pts.push({ x: routeX, y: t.y }, { x: t.x, y: t.y }); + // Route is to the LEFT -> enter the LEFT port (glyph points left). + pts.push({ x: routeX, y: t.y }, { x: tgtCard.left, y: t.y }); + targetOut = { ox: -1, oy: 0 }; } return { path: polyline(pts), sourceOut, targetOut }; diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-nUeQsnnZ.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-iv1-Rvhr.js similarity index 97% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-nUeQsnnZ.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-iv1-Rvhr.js index a486e57..dca0648 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-nUeQsnnZ.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-iv1-Rvhr.js @@ -1 +1 @@ -import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-CBRLc9al.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; +import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-kEWh7gJm.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; diff --git a/packages/server/src/mdl_server/static/assets/main-C31opIYt.js b/packages/server/src/mdl_server/static/assets/main-CDJWg6AJ.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-C31opIYt.js rename to packages/server/src/mdl_server/static/assets/main-CDJWg6AJ.js index 3c1eb7d..a824bff 100644 --- a/packages/server/src/mdl_server/static/assets/main-C31opIYt.js +++ b/packages/server/src/mdl_server/static/assets/main-CDJWg6AJ.js @@ -1,2 +1,2 @@ -import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-CBRLc9al.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` +import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-kEWh7gJm.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` `)||"model valid",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),M]}):F?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14}),F]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!u&&e.jsxs("button",{className:"tool-btn primary",onClick:A,title:"New entity (n)",children:[e.jsx(ye,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),E("ontology",e.jsx(be,{size:15}),"Ontology","Ontology browser"),E("layers",e.jsx(we,{size:15}),"Layers","Four-layer stack & coverage"),E("changes",e.jsx(ve,{size:15}),"Changes",k?"Uncommitted changes":"Changes",k),E("decisions",e.jsx(Me,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(w?" active":""),onClick:g,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(m?" active":""),onClick:p,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Ne,{size:15})}),e.jsx(Ke,{onRelayout:f,onReset:v}),e.jsx("button",{className:"grp-btn icon-only",onClick:y,title:"Fit view","aria-label":"Fit view",children:e.jsx(ke,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:r,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Se,{size:15})}),e.jsx(de,{exec:S,canEdit:!u,onImported:I,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:_,openImport:$})]})]})]})}const U=["LR","TB","RL","BT"],$e={LR:0,TB:90,RL:180,BT:270},se={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function Ke({onRelayout:s,onReset:l}){const[j,h]=a.useState(!1),[x,w]=a.useState("LR"),[g,m]=a.useState("auto"),p=a.useRef(null);a.useEffect(()=>{if(!j)return;const r=u=>{p.current&&!p.current.contains(u.target)&&h(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[j]);const y=r=>{m(r),s(r,x)},f=r=>{y(r),h(!1)},v=()=>{const r=U[(U.indexOf(x)+1)%U.length];w(r),s(g,r)};return e.jsxs("div",{className:"layout-picker",ref:p,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>y("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ee,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(j?" active":""),onClick:()=>h(r=>!r),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:v,title:`Flow direction: ${se[x]} (click to rotate)`,"aria-label":`Flow direction: ${se[x]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${$e[x]}deg)`},children:e.jsx(Pe,{size:15})})}),j&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>f("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>f("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>f("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>f("grid"),children:"Grid"}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"layout-menu-sep",role:"separator"}),e.jsx("button",{onClick:()=>{l(),h(!1)},title:"Clear saved positions and routes for this view",children:"Reset layout"})]})]})]})}function He(){const[s,l]=a.useState(null),[j,h]=a.useState(null),[x,w]=a.useState(null),[g,m]=a.useState(null),[p,y]=a.useState(""),[f,v]=a.useState(!0),[r,u]=a.useState(!1),[k,b]=a.useState(()=>new Set),[q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[z,D]=a.useState(()=>new Set),[K,M]=a.useState(!1),[F,E]=a.useState(0),o=a.useRef(null),L=a.useRef(""),B=a.useRef(!1),O=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((c,n)=>t.set(c.id,Y[n%Y.length])),t},[s]),H=a.useMemo(()=>{const t=new Map;if(!s)return t;const c=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(d=>c.set(d,n.id))}),s.entities.forEach(n=>{var N,Q,X;const P=((N=n.conceptual)!=null&&N.id?c.get(n.conceptual.id):void 0)??((X=(Q=n.conceptual)==null?void 0:Q.subject_area)==null?void 0:X.id)??"";t.set(n.id,P)}),t},[s]),te=a.useMemo(()=>{const t=new Map;return H.forEach(c=>t.set(c,(t.get(c)??0)+1)),t},[H]),R=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>ge(R),[R]),ae=a.useMemo(()=>ue(),[]),V=a.useMemo(()=>new URLSearchParams(window.location.search),[]),T=V.get("minimal")==="1";a.useEffect(()=>{T&&u(!0)},[T]);const re=a.useCallback(t=>{b(c=>{const n=new Set(c);return n.has(t)?n.delete(t):n.add(t),n})},[]),ce=V.get("import")==="1",W=a.useRef(!1),C=a.useCallback(()=>{J().then(l).catch(t=>w(String(t))),Z().then(h).catch(()=>h(null)),ee().then(t=>M(!!(t.git&&!t.clean))).catch(()=>M(!1)),E(t=>t+1)},[]);a.useEffect(C,[C]),a.useEffect(()=>{const t=setInterval(()=>{J().then(c=>{l(n=>n&&c.fingerprint===n.fingerprint?n:(B.current||(L.current=c.fingerprint),T||(Z().then(h).catch(()=>h(null)),ee().then(d=>M(!!(d.git&&!d.clean))).catch(()=>M(!1))),E(d=>d+1),c))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[T]),a.useEffect(()=>{s!=null&&s.fingerprint&&(L.current=s.fingerprint)},[s]);const G=a.useCallback(async(t,c)=>{if(s){B.current=!0;try{const n=await xe(t,c,L.current||s.fingerprint);return n!=null&&n.fingerprint&&(L.current=n.fingerprint),C(),n}catch(n){throw n instanceof pe&&n.status===409?(m("Model changed on disk — view refreshed, please retry."),C()):m(n instanceof Error?n.message:String(n)),n}finally{B.current=!1}}},[s,C]);a.useEffect(()=>{if(!g)return;const t=setTimeout(()=>m(null),5e3);return()=>clearTimeout(t)},[g]),a.useEffect(()=>{if(!s||W.current)return;const t=V.get("focus");if(!t)return;const c=s.entities.find(n=>{var d;return n.name===t||((d=n.conceptual)==null?void 0:d.name)===t});c&&(W.current=!0,requestAnimationFrame(()=>{var n;return(n=o.current)==null?void 0:n.focusEntity(c.id)}))},[s,V]);const oe=a.useCallback(()=>{var n;if(!s)return;const t=p.trim().toLowerCase();if(!t)return;const c=s.entities.find(d=>{var N;return(d.name.toLowerCase()+" "+(((N=d.conceptual)==null?void 0:N.name.toLowerCase())??"")+" "+d.attributes.map(Q=>Q.name.toLowerCase()).join(" ")).includes(t)});c&&((n=o.current)==null||n.focusEntity(c.id))},[s,p]);return a.useEffect(()=>{const t=c=>{var d,P,N;const n=(d=document.activeElement)==null?void 0:d.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(c.key==="/"&&(c.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),c.key==="n"&&!R&&((N=o.current)==null||N.newEntity()),c.key==="Escape"&&(A(null),y(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[R]),x?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:x}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!T&&e.jsx(_e,{doc:s,diagnostics:j,query:p,onQuery:y,onSubmitQuery:oe,showTypes:f,onToggleTypes:()=>v(t=>!t),collapseDetail:r,onToggleCollapse:()=>u(t=>!t),onFitView:()=>{var t;return(t=o.current)==null?void 0:t.fitView()},onRelayout:(t,c)=>{var n;return(n=o.current)==null?void 0:n.relayout(t,c)},onResetLayout:()=>{var t;return(t=o.current)==null?void 0:t.resetLayout()},onRefresh:C,readOnly:R,dirty:K,panelTab:S,onPanelTab:t=>I(c=>c===t?null:t),onNewEntity:()=>{var t;return(t=o.current)==null?void 0:t.newEntity()},exec:G,onImported:C,onImportBatch:je,openImport:ce,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:z.size}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(me,{doc:s,caps:ne,exec:G,selectedId:S?null:q,onSelect:A,query:p,showTypes:f,collapseDetail:r,expandedEntities:k,onToggleExpand:re,activeAreas:z,onError:m,handleRef:o,layoutStore:ae}),!T&&e.jsx(Ae,{doc:s,saColors:O,countByArea:te,activeAreas:z,onSetActive:D,open:_,onClose:()=>$(!1)}),S&&e.jsx(fe,{tab:S,onClose:()=>I(null),readOnly:R,refreshKey:F,onModelChanged:C,onFocusEntity:t=>{var c;I(null),(c=o.current)==null||c.focusEntity(t)}}),g&&e.jsx("div",{className:"toast",children:g})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ve(){return e.jsx(he,{children:e.jsx(He,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(le.StrictMode,{children:e.jsx(Ve,{})})); diff --git a/packages/server/src/mdl_server/static/assets/sme-EpJn-HtT.js b/packages/server/src/mdl_server/static/assets/sme-D5286oaR.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-EpJn-HtT.js rename to packages/server/src/mdl_server/static/assets/sme-D5286oaR.js index a101f0c..f8845d4 100644 --- a/packages/server/src/mdl_server/static/assets/sme-EpJn-HtT.js +++ b/packages/server/src/mdl_server/static/assets/sme-D5286oaR.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-nUeQsnnZ.js","assets/client-DOmNpTln.js","assets/styles-CBRLc9al.js","assets/styles-CK604yls.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-CBRLc9al.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-nUeQsnnZ.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-iv1-Rvhr.js","assets/client-DOmNpTln.js","assets/styles-kEWh7gJm.js","assets/styles-CK604yls.css"])))=>i.map(i=>d[i]); +import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-kEWh7gJm.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-iv1-Rvhr.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); diff --git a/packages/server/src/mdl_server/static/assets/styles-CBRLc9al.js b/packages/server/src/mdl_server/static/assets/styles-kEWh7gJm.js similarity index 89% rename from packages/server/src/mdl_server/static/assets/styles-CBRLc9al.js rename to packages/server/src/mdl_server/static/assets/styles-kEWh7gJm.js index 1c9360f..9dac276 100644 --- a/packages/server/src/mdl_server/static/assets/styles-CBRLc9al.js +++ b/packages/server/src/mdl_server/static/assets/styles-kEWh7gJm.js @@ -14,9 +14,9 @@ var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var On=w,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=On.useRef,_c=On.useEffect,Ec=On.useMemo,Nc=On.useDebugValue;_i.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var p=o.value;if(s(p,f))return d=p}return d=f}if(p=d,wc(u,f))return p;var y=r(f);return s!==void 0&&s(p,y)?(u=f,p):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};vi.exports=_i;var Sc=vi.exports;const kc=bi(Sc),jc={},Qr=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(p=>p(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?Qr(e):Qr,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function Si(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const Jr=(e,t)=>{const n=Cc(e),r=(s,i=t)=>Si(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?Jr(e,t):Jr;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Ln(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}xn.prototype=Ln.prototype={constructor:xn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),ts.hasOwnProperty(t)?{space:ts[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===lr&&t.documentElement.namespaceURI===lr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ki(e){var t=Dn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function kr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=kr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=C&&(C=E+1);!(M=b[C])&&++C=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Tt(this.node(),e)}function Tt(e,t){return e.style.getPropertyValue(t)||Ai(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ri(e){return e.trim().split(/^|\s+/)}function jr(e){return e.classList||new Ii(e)}function Ii(e){this._node=e,this._names=Ri(e.getAttribute("class")||"")}Ii.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Ti(e,t){for(var n=jr(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function ur(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}ur.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Ln("start","drag","end"),o=0,a,c,l,u,d=0;function m(v){v.on("mousedown.drag",f).filter(r).on("touchstart.drag",b).on("touchmove.drag",g,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(v,M){if(!(u||!e.call(this,v,M))){var j=C(this,t.call(this,v,M),v,M,"mouse");j&&(Oe(v.view).on("mousemove.drag",p,Ut).on("mouseup.drag",y,Ut),Pi(v.view),Wn(v),l=!1,a=v.clientX,c=v.clientY,j("start",v))}}function p(v){if(Mt(v),!l){var M=v.clientX-a,j=v.clientY-c;l=M*M+j*j>d}s.mouse("drag",v)}function y(v){Oe(v.view).on("mousemove.drag mouseup.drag",null),zi(v.view,l),Mt(v),s.mouse("end",v)}function b(v,M){if(e.call(this,v,M)){var j=v.changedTouches,_=t.call(this,v,M),I=j.length,N,R;for(N=0;N>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?ln(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?ln(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Ae(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Ae(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?ln(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?ln(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?cs(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?cs(t[1],t[2]/100,t[3]/100,t[4]):ns.hasOwnProperty(e)?is(ns[e]):e==="transparent"?new Ae(NaN,NaN,NaN,0):null}function is(e){return new Ae(e>>16&255,e>>8&255,e&255,1)}function ln(e,t,n,r){return r<=0&&(e=t=n=NaN),new Ae(e,t,n,r)}function Mu(e){return e instanceof nn||(e=Kt(e)),e?(e=e.rgb(),new Ae(e.r,e.g,e.b,e.opacity)):new Ae}function dr(e,t,n,r){return arguments.length===1?Mu(e):new Ae(e,t,n,r??1)}function Ae(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Cr(Ae,dr,Hi(nn,{brighter(e){return e=e==null?En:Math.pow(En,e),new Ae(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Xt:Math.pow(Xt,e),new Ae(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Ae(yt(this.r),yt(this.g),yt(this.b),Nn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:os,formatHex:os,formatHex8:Au,formatRgb:as,toString:as}));function os(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function as(){const e=Nn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function Nn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function cs(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ve(e,t,n,r)}function Fi(e){if(e instanceof Ve)return new Ve(e.h,e.s,e.l,e.opacity);if(e instanceof nn||(e=Kt(e)),!e)return new Ve;if(e instanceof Ve)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new Ve(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Fi(e):new Ve(e,t,n,r??1)}function Ve(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Cr(Ve,Ru,Hi(nn,{brighter(e){return e=e==null?En:Math.pow(En,e),new Ve(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Xt:Math.pow(Xt,e),new Ve(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Ae(Un(e>=240?e-240:e+120,s,r),Un(e,s,r),Un(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Ve(ls(this.h),un(this.s),un(this.l),Nn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Nn(this.opacity);return`${e===1?"hsl(":"hsla("}${ls(this.h)}, ${un(this.s)*100}%, ${un(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ls(e){return e=(e||0)%360,e<0?e+360:e}function un(e){return Math.max(0,Math.min(1,e||0))}function Un(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Vi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Bi:function(t,n){return n-t?Tu(t,n,e):Vi(isNaN(t)?n:t)}}function Bi(e,t){var n=t-e;return n?Iu(e,n):Vi(isNaN(e)?t:e)}const us=function e(t){var n=Ou(t);function r(s,i){var o=n((s=dr(s)).r,(i=dr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Bi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function at(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var fr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Xn=new RegExp(fr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=fr.lastIndex=Xn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=fr.exec(e))&&(s=Xn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:at(r,s)})),n=Xn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:at(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:at(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,p){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");p.push({i:y-4,x:at(l,d)},{i:y-2,x:at(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var p=-1,y=m.length,b;++p=0&&e._call.call(void 0,t),e=e._next;--Ot}function hs(){wt=(kn=Zt.now())+Pn,Ot=Bt=0;try{Xu()}finally{Ot=0,Ku(),wt=0}}function qu(){var e=Zt.now(),t=e-kn;t>Wi&&(Pn-=t,kn=e)}function Ku(){for(var e,t=Sn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Sn=n);Gt=e,mr(r)}function mr(e){if(!Ot){Bt&&(Bt=clearTimeout(Bt));var t=e-wt;t>24?(e<1/0&&(Bt=setTimeout(hs,e-Zt.now()-Pn)),Pt&&(Pt=clearInterval(Pt))):(Pt||(kn=Zt.now(),Pt=setInterval(qu,Wi)),Ot=1,Ui(hs))}}function ms(e,t,n){var r=new jn;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Ln("start","end","cancel","interrupt"),Qu=[],qi=0,ps=1,pr=2,wn=3,gs=4,gr=5,bn=6;function zn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:qi})}function Mr(e,t){var n=Be(e,t);if(n.state>qi)throw new Error("too late; already scheduled");return n}function Xe(e,t){var n=Be(e,t);if(n.state>wn)throw new Error("too late; already running");return n}function Be(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=Xi(i,0,n.time);function i(l){n.state=ps,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ps)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===wn)return ms(o);f.state===gs?(f.state=bn,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+upr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Mr:Xe;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Be(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=kr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function tt(e,t,n){this.k=e,this.x=t,this.y=n}tt.prototype={constructor:tt,scale:function(e){return e===1?this:new tt(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new tt(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var nt=new tt(1,0,0);tt.prototype;function qn(e){e.stopImmediatePropagation()}function zt(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ys(){return this.__zoom||nt}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function Ji(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Wu,l=Ln("start","zoom","end"),u,d,m,f=500,p=150,y=0,b=10;function g(x){x.property("__zoom",ys).on("wheel.zoom",I,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",R).filter(s).on("touchstart.zoom",P).on("touchmove.zoom",V).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(x,$,S,O){var D=x.selection?x.selection():x;D.property("__zoom",ys),x!==D?M(x,$,S,O):D.interrupt().each(function(){j(this,arguments).event(O).start().zoom(null,typeof $=="function"?$.apply(this,arguments):$).end()})},g.scaleBy=function(x,$,S,O){g.scaleTo(x,function(){var D=this.__zoom.k,k=typeof $=="function"?$.apply(this,arguments):$;return D*k},S,O)},g.scaleTo=function(x,$,S,O){g.transform(x,function(){var D=t.apply(this,arguments),k=this.__zoom,T=S==null?v(D):typeof S=="function"?S.apply(this,arguments):S,L=k.invert(T),z=typeof $=="function"?$.apply(this,arguments):$;return n(C(E(k,z),T,L),D,o)},S,O)},g.translateBy=function(x,$,S,O){g.transform(x,function(){return n(this.__zoom.translate(typeof $=="function"?$.apply(this,arguments):$,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,O)},g.translateTo=function(x,$,S,O,D){g.transform(x,function(){var k=t.apply(this,arguments),T=this.__zoom,L=O==null?v(k):typeof O=="function"?O.apply(this,arguments):O;return n(nt.translate(L[0],L[1]).scale(T.k).translate(typeof $=="function"?-$.apply(this,arguments):-$,typeof S=="function"?-S.apply(this,arguments):-S),k,o)},O,D)};function E(x,$){return $=Math.max(i[0],Math.min(i[1],$)),$===x.k?x:new tt($,x.x,x.y)}function C(x,$,S){var O=$[0]-S[0]*x.k,D=$[1]-S[1]*x.k;return O===x.x&&D===x.y?x:new tt(x.k,O,D)}function v(x){return[(+x[0][0]+ +x[1][0])/2,(+x[0][1]+ +x[1][1])/2]}function M(x,$,S,O){x.on("start.zoom",function(){j(this,arguments).event(O).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(O).end()}).tween("zoom",function(){var D=this,k=arguments,T=j(D,k).event(O),L=t.apply(D,k),z=S==null?v(L):typeof S=="function"?S.apply(D,k):S,W=Math.max(L[1][0]-L[0][0],L[1][1]-L[0][1]),G=D.__zoom,K=typeof $=="function"?$.apply(D,k):$,Z=c(G.invert(z).concat(W/G.k),K.invert(z).concat(W/K.k));return function(ne){if(ne===1)ne=K;else{var ie=Z(ne),re=W/ie[2];ne=new tt(re,z[0]-ie[0]*re,z[1]-ie[1]*re)}T.zoom(null,ne)}})}function j(x,$,S){return!S&&x.__zooming||new _(x,$)}function _(x,$){this.that=x,this.args=$,this.active=0,this.sourceEvent=null,this.extent=t.apply(x,$),this.taps=0}_.prototype={event:function(x){return x&&(this.sourceEvent=x),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(x,$){return this.mouse&&x!=="mouse"&&(this.mouse[1]=$.invert(this.mouse[0])),this.touch0&&x!=="touch"&&(this.touch0[1]=$.invert(this.touch0[0])),this.touch1&&x!=="touch"&&(this.touch1[1]=$.invert(this.touch1[0])),this.that.__zoom=$,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(x){var $=Oe(this.that).datum();l.call(x,this.that,new sf(x,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:l}),$)}};function I(x,...$){if(!e.apply(this,arguments))return;var S=j(this,$).event(x),O=this.__zoom,D=Math.max(i[0],Math.min(i[1],O.k*Math.pow(2,r.apply(this,arguments)))),k=Fe(x);if(S.wheel)(S.mouse[0][0]!==k[0]||S.mouse[0][1]!==k[1])&&(S.mouse[1]=O.invert(S.mouse[0]=k)),clearTimeout(S.wheel);else{if(O.k===D)return;S.mouse=[k,O.invert(k)],vn(this),S.start()}zt(x),S.wheel=setTimeout(T,p),S.zoom("mouse",n(C(E(O,D),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function N(x,...$){if(m||!e.apply(this,arguments))return;var S=x.currentTarget,O=j(this,$,!0).event(x),D=Oe(x.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",W,!0),k=Fe(x,S),T=x.clientX,L=x.clientY;Pi(x.view),qn(x),O.mouse=[k,this.__zoom.invert(k)],vn(this),O.start();function z(G){if(zt(G),!O.moved){var K=G.clientX-T,Z=G.clientY-L;O.moved=K*K+Z*Z>y}O.event(G).zoom("mouse",n(C(O.that.__zoom,O.mouse[0]=Fe(G,S),O.mouse[1]),O.extent,o))}function W(G){D.on("mousemove.zoom mouseup.zoom",null),zi(G.view,O.moved),zt(G),O.event(G).end()}}function R(x,...$){if(e.apply(this,arguments)){var S=this.__zoom,O=Fe(x.changedTouches?x.changedTouches[0]:x,this),D=S.invert(O),k=S.k*(x.shiftKey?.5:2),T=n(C(E(S,k),O,D),t.apply(this,$),o);zt(x),a>0?Oe(this).transition().duration(a).call(M,T,O,x):Oe(this).call(g.transform,T,O,x)}}function P(x,...$){if(e.apply(this,arguments)){var S=x.touches,O=S.length,D=j(this,$,x.changedTouches.length===O).event(x),k,T,L,z;for(qn(x),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},eo=st.error001();function he(e,t){const n=w.useContext(Hn);if(n===null)throw new Error(eo);return Si(n,e,t)}const Se=()=>{const e=w.useContext(Hn);if(e===null)throw new Error(eo);return w.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Rr({position:e,children:t,className:n,style:r,...s}){const i=he(ff),o=`${e}`.split("-");return A.createElement("div",{className:Ce(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Rr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=w.useRef(null),[m,f]=w.useState({x:0,y:0,width:0,height:0}),p=Ce(["react-flow__edge-textwrapper",l]);return w.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:p,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=w.memo(mf);const Ir=e=>({width:e.offsetWidth,height:e.offsetHeight}),Lt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Tr=(e={x:0,y:0},t)=>({x:Lt(e.x,t[0][0],t[1][0]),y:Lt(e.y,t[0][1],t[1][1])}),xs=(e,t,n)=>en?-Lt(Math.abs(e-n),1,50)/50:0,to=(e,t)=>{const n=xs(e.x,35,t.width-35)*20,r=xs(e.y,35,t.height-35)*20;return[n,r]},no=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},ro=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Qt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),so=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),ws=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>so(ro(Qt(e),Qt(t))),yr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Le(e.width)&&Le(e.height)&&Le(e.x)&&Le(e.y),Le=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),io=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function xr(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const oo=e=>"clientX"in e,ft=(e,t)=>{var i,o;const n=oo(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Cn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},rn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Le(n)&&Le(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);rn.displayName="BaseEdge";function Ht(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function ao({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[b,g,E]=lo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(rn,{path:b,labelX:g,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:y})});Or.displayName="SimpleBezierEdge";const vs={[U.Left]:{x:-1,y:0},[U.Right]:{x:1,y:0},[U.Top]:{x:0,y:-1},[U.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=U.Bottom,target:n})=>t===U.Left||t===U.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=U.Bottom,target:n,targetPosition:r=U.Top,center:s,offset:i}){const o=vs[t],a=vs[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],p,y;const b={x:0,y:0},g={x:0,y:0},[E,C,v,M]=ao({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){p=s.x??E,y=s.y??C;const _=[{x:p,y:c.y},{x:p,y:l.y}],I=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:I:f=d==="x"?I:_}else{const _=[{x:c.x,y:l.y}],I=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?I:_:f=o.y===m?_:I,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const x=Math.min(i-1,i-H);o[d]===m?b[d]=(c[d]>e[d]?-1:1)*x:g[d]=(l[d]>n[d]?-1:1)*x}}if(t!==r){const H=d==="x"?"y":"x",x=o[d]===a[H],$=c[H]>l[H],S=c[H]=V?(p=(N.x+R.x)/2,y=f[0].y):(p=f[0].x,y=(N.y+R.y)/2)}return[[e,{x:c.x+b.x,y:c.y+b.y},...f,{x:l.x+g.x,y:l.y+g.y},n],p,y,v,M]}function _f(e,t,n,r){const s=Math.min(_s(e,t)/2,_s(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let C="";return E>0&&E{const[g,E,C]=Mn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(rn,{path:g,labelX:E,labelY:C,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:p,interactionWidth:b})});Fn.displayName="SmoothStepEdge";const Lr=w.memo(e=>{var t;return A.createElement(Fn,{...e,pathOptions:w.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Lr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=ao({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const Dr=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[p,y,b]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(rn,{path:p,labelX:y,labelY:b,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});Dr.displayName="StraightEdge";function hn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Es({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case U.Left:return[t-hn(t-r,i),n];case U.Right:return[t+hn(r-t,i),n];case U.Top:return[t,n-hn(n-s,i)];case U.Bottom:return[t,n+hn(s-n,i)]}}function uo({sourceX:e,sourceY:t,sourcePosition:n=U.Bottom,targetX:r,targetY:s,targetPosition:i=U.Top,curvature:o=.25}){const[a,c]=Es({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Es({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,p]=co({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,p]}const An=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=U.Bottom,targetPosition:i=U.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,pathOptions:y,interactionWidth:b})=>{const[g,E,C]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(rn,{path:g,labelX:E,labelY:C,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:b})});An.displayName="BezierEdge";const Pr=w.createContext(null),Nf=Pr.Provider;Pr.Consumer;const Sf=()=>w.useContext(Pr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,wr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},br=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},fo=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},sn=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return ro(r,Qt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return so(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),sn(e,t)),ho=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:p=!1}=u;if(o&&!f||p)return!1;const{positionAbsolute:y}=xt(u,a),b={x:y.x,y:y.y,width:d||0,height:m||0},g=yr(c,b),E=typeof d>"u"||typeof m>"u"||d===null||m===null,C=i&&g>0,v=(d||0)*(m||0);(E||C||g>=v||u.dragging)&&l.push(u)}),l},mo=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},po=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Lt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function Ns(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=ft(e),l=t.elementsFromPoint(o,a).find(p=>p.classList.contains("react-flow__handle"));if(l){const p=l.getAttribute("data-nodeid");if(p){const y=zr(void 0,l),b=l.getAttribute("data-handleid"),g=i({nodeId:p,id:b,type:y});if(g){const E=s.find(C=>C.nodeId===p&&C.type===y&&C.id===b);return{handle:{id:b,type:y,nodeId:p,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:g}}}}let u=[],d=1/0;if(s.forEach(p=>{const y=Math.sqrt((p.x-n.x)**2+(p.y-n.y)**2);if(y<=r){const b=i(p);y<=d&&(yp.isValid),f=u.some(({handle:p})=>p.type==="target");return u.find(({handle:p,validHandleResult:y})=>f?p.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},go=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function yo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...go(),handleDomNode:c};if(c){const u=zr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),p=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&p&&(t===bt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=Ns(i,o,"source",`${t}-${n}-${r}`),c=Ns(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function zr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Kn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function xo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=no(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:p,onConnectStart:y,panBy:b,getNodes:g,cancelConnection:E}=i();let C=0,v;const{x:M,y:j}=ft(e),_=u==null?void 0:u.elementFromPoint(M,j),I=zr(c,_),N=m==null?void 0:m.getBoundingClientRect();if(!N||!I)return;let R,P=ft(e,N),V=!1,H=null,x=!1,$=null;const S=If({nodes:g(),nodeId:n,handleId:t,handleType:I}),O=()=>{if(!f)return;const[T,L]=to(P,N);b({x:T,y:L}),C=requestAnimationFrame(O)};o({connectionPosition:P,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:I,connectionStartHandle:{nodeId:n,handleId:t,type:I},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:I});function D(T){const{transform:L}=i();P=ft(T,N);const{handle:z,validHandleResult:W}=Af(T,u,br(P,L,!1,[1,1]),p,S,G=>yo(G,d,n,t,s?"target":"source",a,u));if(v=z,V||(O(),V=!0),$=W.handleDomNode,H=W.connection,x=W.isValid,o({connectionPosition:v&&x?fo({x:v.x,y:v.y},L):P,connectionStatus:Tf(!!v,x),connectionEndHandle:W.endHandle}),!v&&!x&&!$)return Kn(R);H.source!==H.target&&$&&(Kn(R),R=$,$.classList.add("connecting","react-flow__handle-connecting"),$.classList.toggle("valid",x),$.classList.toggle("react-flow__handle-valid",x))}function k(T){var L,z;(v||$)&&H&&x&&(r==null||r(H)),(z=(L=i()).onConnectEnd)==null||z.call(L,T),c&&(l==null||l(T)),Kn(R),E(),cancelAnimationFrame(C),V=!1,x=!1,H=null,$=null,u.removeEventListener("mousemove",D),u.removeEventListener("mouseup",k),u.removeEventListener("touchmove",D),u.removeEventListener("touchend",k)}u.addEventListener("mousemove",D),u.addEventListener("mouseup",k),u.addEventListener("touchmove",D),u.addEventListener("touchend",k)}const Ss=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},wo=w.forwardRef(({type:e="source",position:t=U.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var N,R;const p=o||null,y=e==="target",b=Se(),g=Sf(),{connectOnClick:E,noPanClassName:C}=he(Of,ke),{connecting:v,clickConnecting:M}=he(Lf(g,p,e),ke);g||(R=(N=b.getState()).onError)==null||R.call(N,"010",st.error010());const j=P=>{const{defaultEdgeOptions:V,onConnect:H,hasDefaultEdges:x}=b.getState(),$={...V,...P};if(x){const{edges:S,setEdges:O}=b.getState();O($f($,S))}H==null||H($),a==null||a($)},_=P=>{if(!g)return;const V=oo(P);s&&(V&&P.button===0||!V)&&xo({event:P,handleId:p,nodeId:g,onConnect:j,isTarget:y,getState:b.getState,setState:b.setState,isValidConnection:n||b.getState().isValidConnection||Ss}),V?u==null||u(P):d==null||d(P)},I=P=>{const{onClickConnectStart:V,onClickConnectEnd:H,connectionClickStartHandle:x,connectionMode:$,isValidConnection:S}=b.getState();if(!g||!x&&!s)return;if(!x){V==null||V(P,{nodeId:g,handleId:p,handleType:e}),b.setState({connectionClickStartHandle:{nodeId:g,type:e,handleId:p}});return}const O=no(P.target),D=n||S||Ss,{connection:k,isValid:T}=yo({nodeId:g,id:p,type:e},$,x.nodeId,x.handleId||null,x.type,D,O);T&&j(k),H==null||H(P),b.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":p,"data-nodeid":g,"data-handlepos":t,"data-id":`${g}-${p}-${e}`,className:Ce(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",C,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!v||i&&v)}]),onMouseDown:_,onTouchStart:_,onClick:E?I:void 0,ref:f,...m},c)});wo.displayName="Handle";var ut=w.memo(wo);const bo=({data:e,isConnectable:t,targetPosition:n=U.Top,sourcePosition:r=U.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ut,{type:"source",position:r,isConnectable:t}));bo.displayName="DefaultNode";var vr=w.memo(bo);const vo=({data:e,isConnectable:t,sourcePosition:n=U.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ut,{type:"source",position:n,isConnectable:t}));vo.displayName="InputNode";var _o=w.memo(vo);const Eo=({data:e,isConnectable:t,targetPosition:n=U.Top})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);Eo.displayName="OutputNode";var No=w.memo(Eo);const Hr=()=>null;Hr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),mn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(mn),t.selectedNodes.map(mn))&&ke(e.selectedEdges.map(mn),t.selectedEdges.map(mn))}const So=w.memo(({onSelectionChange:e})=>{const t=Se(),{selectedNodes:n,selectedEdges:r}=he(Df,Pf);return w.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});So.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=he(zf);return e||t?A.createElement(So,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Nt(e,t){w.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function oe(e,t,n){w.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:p,minZoom:y,maxZoom:b,nodeExtent:g,onNodesChange:E,onEdgesChange:C,elementsSelectable:v,connectionMode:M,snapGrid:j,snapToGrid:_,translateExtent:I,connectOnClick:N,defaultEdgeOptions:R,fitView:P,fitViewOptions:V,onNodesDelete:H,onEdgesDelete:x,onNodeDrag:$,onNodeDragStart:S,onNodeDragStop:O,onSelectionDrag:D,onSelectionDragStart:k,onSelectionDragStop:T,noPanClassName:L,nodeOrigin:z,rfId:W,autoPanOnConnect:G,autoPanOnNodeDrag:K,onError:Z,connectionRadius:ne,isValidConnection:ie,nodeDragThreshold:re})=>{const{setNodes:ae,setEdges:ye,setDefaultNodesAndEdges:te,setMinZoom:me,setMaxZoom:ve,setTranslateExtent:de,setNodeExtent:pe,reset:le}=he(Ff,ke),X=Se();return w.useEffect(()=>{const _e=r==null?void 0:r.map(je=>({...je,...R}));return te(n,_e),()=>{le()}},[]),oe("defaultEdgeOptions",R,X.setState),oe("connectionMode",M,X.setState),oe("onConnect",s,X.setState),oe("onConnectStart",i,X.setState),oe("onConnectEnd",o,X.setState),oe("onClickConnectStart",a,X.setState),oe("onClickConnectEnd",c,X.setState),oe("nodesDraggable",l,X.setState),oe("nodesConnectable",u,X.setState),oe("nodesFocusable",d,X.setState),oe("edgesFocusable",m,X.setState),oe("edgesUpdatable",f,X.setState),oe("elementsSelectable",v,X.setState),oe("elevateNodesOnSelect",p,X.setState),oe("snapToGrid",_,X.setState),oe("snapGrid",j,X.setState),oe("onNodesChange",E,X.setState),oe("onEdgesChange",C,X.setState),oe("connectOnClick",N,X.setState),oe("fitViewOnInit",P,X.setState),oe("fitViewOnInitOptions",V,X.setState),oe("onNodesDelete",H,X.setState),oe("onEdgesDelete",x,X.setState),oe("onNodeDrag",$,X.setState),oe("onNodeDragStart",S,X.setState),oe("onNodeDragStop",O,X.setState),oe("onSelectionDrag",D,X.setState),oe("onSelectionDragStart",k,X.setState),oe("onSelectionDragStop",T,X.setState),oe("noPanClassName",L,X.setState),oe("nodeOrigin",z,X.setState),oe("rfId",W,X.setState),oe("autoPanOnConnect",G,X.setState),oe("autoPanOnNodeDrag",K,X.setState),oe("onError",Z,X.setState),oe("connectionRadius",ne,X.setState),oe("isValidConnection",ie,X.setState),oe("nodeDragThreshold",re,X.setState),Nt(e,ae),Nt(t,ye),Nt(y,me),Nt(b,ve),Nt(I,de),Nt(g,pe),null},ks={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},ko="react-flow__node-desc",jo="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Wf({rfId:e}){const t=he(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Uf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${ko}-${e}`,style:ks},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${jo}-${e}`,style:ks},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Wf,{rfId:e}))}var en=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=w.useState(!1),s=w.useRef(!1),i=w.useRef(new Set([])),[o,a]=w.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return w.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&xr(f))return!1;const y=Cs(f.code,a);i.current.add(f[y]),js(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&xr(f))return!1;const y=Cs(f.code,a);js(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function js(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Cs(e,t){return t.includes(e)?"code":"key"}function Co(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return Co(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function $o(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=Co(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Zn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Le(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),$o(s,n,i),s}function Mo(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const p=n().filter(b=>{var E;const g=t.includeHiddenNodes?b.width&&b.height:!b.hidden;return(E=t.nodes)!=null&&E.length?g&&t.nodes.some(C=>C.id===b.id):g}),y=p.every(b=>b.width&&b.height);if(p.length>0&&y){const b=sn(p,d),{x:g,y:E,zoom:C}=po(b,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),v=nt.translate(g,E).scale(C);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),v):a.transform(c,v),!0}}return!1}function Xf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function pn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Xf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const St=()=>{},Kf={zoomIn:St,zoomOut:St,zoomTo:St,getZoom:()=>1,setViewport:St,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:St,fitBounds:St,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Se(),{d3Zoom:t,d3Selection:n}=he(Zf,ke);return w.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=nt.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Mo(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=nt.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=po(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=nt.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),br(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return br(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=fo(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function on(){const e=Qf(),t=Se(),n=w.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=w.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=w.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(b=>({...b}))},[]),i=w.useCallback(y=>{const{edges:b=[]}=t.getState();return b.find(g=>g.id===y)},[]),o=w.useCallback(y=>{const{getNodes:b,setNodes:g,hasDefaultNodes:E,onNodesChange:C}=t.getState(),v=b(),M=typeof y=="function"?y(v):y;if(E)g(M);else if(C){const j=M.length===0?v.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));C(j)}},[]),a=w.useCallback(y=>{const{edges:b=[],setEdges:g,hasDefaultEdges:E,onEdgesChange:C}=t.getState(),v=typeof y=="function"?y(b):y;if(E)g(v);else if(C){const M=v.length===0?b.map(j=>({type:"remove",id:j.id})):v.map(j=>({item:j,type:"reset"}));C(M)}},[]),c=w.useCallback(y=>{const b=Array.isArray(y)?y:[y],{getNodes:g,setNodes:E,hasDefaultNodes:C,onNodesChange:v}=t.getState();if(C){const j=[...g(),...b];E(j)}else if(v){const M=b.map(j=>({item:j,type:"add"}));v(M)}},[]),l=w.useCallback(y=>{const b=Array.isArray(y)?y:[y],{edges:g=[],setEdges:E,hasDefaultEdges:C,onEdgesChange:v}=t.getState();if(C)E([...g,...b]);else if(v){const M=b.map(j=>({item:j,type:"add"}));v(M)}},[]),u=w.useCallback(()=>{const{getNodes:y,edges:b=[],transform:g}=t.getState(),[E,C,v]=g;return{nodes:y().map(M=>({...M})),edges:b.map(M=>({...M})),viewport:{x:E,y:C,zoom:v}}},[]),d=w.useCallback(({nodes:y,edges:b})=>{const{nodeInternals:g,getNodes:E,edges:C,hasDefaultNodes:v,hasDefaultEdges:M,onNodesDelete:j,onEdgesDelete:_,onNodesChange:I,onEdgesChange:N}=t.getState(),R=(y||[]).map($=>$.id),P=(b||[]).map($=>$.id),V=E().reduce(($,S)=>{const O=S.parentNode||S.parentId,D=!R.includes(S.id)&&O&&$.find(T=>T.id===O);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(R.includes(S.id)||D)&&$.push(S),$},[]),H=C.filter($=>typeof $.deletable=="boolean"?$.deletable:!0),x=H.filter($=>P.includes($.id));if(V||x){const $=mo(V,H),S=[...x,...$],O=S.reduce((D,k)=>(D.includes(k.id)||D.push(k.id),D),[]);if((M||v)&&(M&&t.setState({edges:C.filter(D=>!O.includes(D.id))}),v&&(V.forEach(D=>{g.delete(D.id)}),t.setState({nodeInternals:new Map(g)}))),O.length>0&&(_==null||_(S),N&&N(O.map(D=>({id:D,type:"remove"})))),V.length>0&&(j==null||j(V),I)){const D=V.map(k=>({id:k.id,type:"remove"}));I(D)}}},[]),m=w.useCallback(y=>{const b=yf(y),g=b?null:t.getState().nodeInternals.get(y.id);return!b&&!g?[null,null,b]:[b?y:ws(g),g,b]},[]),f=w.useCallback((y,b=!0,g)=>{const[E,C,v]=m(y);return E?(g||t.getState().getNodes()).filter(M=>{if(!v&&(M.id===C.id||!M.positionAbsolute))return!1;const j=ws(M),_=yr(j,E);return b&&_>0||_>=E.width*E.height}):[]},[]),p=w.useCallback((y,b,g=!0)=>{const[E]=m(y);if(!E)return!1;const C=yr(E,b);return g&&C>0||C>=E.width*E.height},[]);return w.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:p}),[e,n,r,s,i,o,a,c,l,u,d,f,p])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Se(),{deleteElements:r}=on(),s=en(e,Jf),i=en(t);w.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),w.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Se();w.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Ir(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",st.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Fr={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,gn=e=>({x:e.x,y:e.y,zoom:e.k}),kt=(e,t)=>e.target.closest(`.${t}`),$s=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Ms=e=>{const t=e.ctrlKey&&Cn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:p,maxZoom:y,zoomActivationKeyCode:b,preventScrolling:g=!0,children:E,noWheelClassName:C,noPanClassName:v})=>{const M=w.useRef(),j=Se(),_=w.useRef(!1),I=w.useRef(!1),N=w.useRef(null),R=w.useRef({x:0,y:0,zoom:0}),{d3Zoom:P,d3Selection:V,d3ZoomHandler:H,userSelectionActive:x}=he(rh,ke),$=en(b),S=w.useRef(0),O=w.useRef(!1),D=w.useRef();return th(N),w.useEffect(()=>{if(N.current){const k=N.current.getBoundingClientRect(),T=Ji().scaleExtent([p,y]).translateExtent(f),L=Oe(N.current).call(T),z=nt.translate(m.x,m.y).scale(Lt(m.zoom,p,y)),W=[[0,0],[k.width,k.height]],G=T.constrain()(z,W,f);T.transform(L,G),T.wheelDelta(Ms),j.setState({d3Zoom:T,d3Selection:L,d3ZoomHandler:L.on("wheel.zoom"),transform:[G.x,G.y,G.k],domNode:N.current.closest(".react-flow")})}},[]),w.useEffect(()=>{V&&P&&(o&&!$&&!x?V.on("wheel.zoom",k=>{if(kt(k,C))return!1;k.preventDefault(),k.stopImmediatePropagation();const T=V.property("__zoom").k||1;if(k.ctrlKey&&i){const ie=Fe(k),re=Ms(k),ae=T*Math.pow(2,re);P.scaleTo(V,ae,ie,k);return}const L=k.deltaMode===1?20:1;let z=c===gt.Vertical?0:k.deltaX*L,W=c===gt.Horizontal?0:k.deltaY*L;!Cn()&&k.shiftKey&&c!==gt.Vertical&&(z=k.deltaY*L,W=0),P.translateBy(V,-(z/T)*a,-(W/T)*a,{internal:!0});const G=gn(V.property("__zoom")),{onViewportChangeStart:K,onViewportChange:Z,onViewportChangeEnd:ne}=j.getState();clearTimeout(D.current),O.current||(O.current=!0,t==null||t(k,G),K==null||K(G)),O.current&&(e==null||e(k,G),Z==null||Z(G),D.current=setTimeout(()=>{n==null||n(k,G),ne==null||ne(G),O.current=!1},150))},{passive:!1}):typeof H<"u"&&V.on("wheel.zoom",function(k,T){if(!g&&k.type==="wheel"&&!k.ctrlKey||kt(k,C))return null;k.preventDefault(),H.call(this,k,T)},{passive:!1}))},[x,o,c,V,P,H,$,i,g,C,t,e,n]),w.useEffect(()=>{P&&P.on("start",k=>{var z,W;if(!k.sourceEvent||k.sourceEvent.internal)return null;S.current=(z=k.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=j.getState(),L=gn(k.transform);_.current=!0,R.current=L,((W=k.sourceEvent)==null?void 0:W.type)==="mousedown"&&j.setState({paneDragging:!0}),T==null||T(L),t==null||t(k.sourceEvent,L)})},[P,t]),w.useEffect(()=>{P&&(x&&!_.current?P.on("zoom",null):x||P.on("zoom",k=>{var L;const{onViewportChange:T}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),I.current=!!(r&&$s(d,S.current??0)),(e||T)&&!((L=k.sourceEvent)!=null&&L.internal)){const z=gn(k.transform);T==null||T(z),e==null||e(k.sourceEvent,z)}}))},[x,P,e,d,r]),w.useEffect(()=>{P&&P.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=j.getState();if(_.current=!1,j.setState({paneDragging:!1}),r&&$s(d,S.current??0)&&!I.current&&r(k.sourceEvent),I.current=!1,(n||T)&&nh(R.current,k.transform)){const L=gn(k.transform);R.current=L,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(L),n==null||n(k.sourceEvent,L)},o?150:0)}})},[P,o,d,n,r]),w.useEffect(()=>{P&&P.filter(k=>{const T=$||s,L=i&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(kt(k,"react-flow__node")||kt(k,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||x||!l&&k.type==="dblclick"||kt(k,C)&&k.type==="wheel"||kt(k,v)&&(k.type!=="wheel"||o&&k.type==="wheel"&&!$)||!i&&k.ctrlKey&&k.type==="wheel"||!T&&!o&&!L&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&z})},[x,P,s,i,o,l,d,u,$]),A.createElement("div",{className:"react-flow__renderer",ref:N,style:Fr},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=he(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function As(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&As(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&As(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ct=(e,t)=>({id:e,type:"select",selected:t});function Ct(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ct(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ct(r.id,!1))),n},[])}const Qn=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ao=w.memo(({isSelecting:e,selectionMode:t=Jt.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=w.useRef(null),f=Se(),p=w.useRef(0),y=w.useRef(0),b=w.useRef(),{userSelectionActive:g,elementsSelectable:E,dragging:C}=he(lh,ke),v=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),p.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,I=H=>{const{resetSelectedElements:x,domNode:$}=f.getState();if(b.current=$==null?void 0:$.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!b.current)return;const{x:S,y:O}=ft(H,b.current);x(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:O,x:S,y:O}}),r==null||r(H)},N=H=>{const{userSelectionRect:x,nodeInternals:$,edges:S,transform:O,onNodesChange:D,onEdgesChange:k,nodeOrigin:T,getNodes:L}=f.getState();if(!e||!b.current||!x)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=ft(H,b.current),W=x.startX??0,G=x.startY??0,K={...x,x:z.xae.id),re=ne.map(ae=>ae.id);if(p.current!==re.length){p.current=re.length;const ae=Ct(Z,re);ae.length&&(D==null||D(ae))}if(y.current!==ie.length){y.current=ie.length;const ae=Ct(S,ie);ae.length&&(k==null||k(ae))}f.setState({userSelectionRect:K})},R=H=>{if(H.button!==0)return;const{userSelectionRect:x}=f.getState();!g&&x&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:p.current>0}),v(),s==null||s(H)},P=H=>{g&&(f.setState({nodesSelectionActive:p.current>0}),s==null||s(H)),v()},V=E&&(e||g);return A.createElement("div",{className:Ce(["react-flow__pane",{dragging:C,selection:e}]),onClick:V?void 0:Qn(M,m),onContextMenu:Qn(j,m),onWheel:Qn(_,m),onMouseEnter:V?void 0:c,onMouseDown:V?I:void 0,onMouseMove:V?N:l,onMouseUp:V?R:void 0,onMouseLeave:V?P:u,ref:m,style:Fr},d,A.createElement(oh,null))});Ao.displayName="Pane";function Ro(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Ro(r,t):!1}function Rs(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Ro(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function Io(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Le(m)&&Le(f)&&Le(d.width)&&Le(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",st.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Tr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function Jn({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Is=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Ir(c)}})};function Ft(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function _r({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",st.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Se();return w.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function er(e){return(t,n,r)=>e==null?void 0:e(t,r)}function To({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Se(),[c,l]=w.useState(!1),u=w.useRef([]),d=w.useRef({x:null,y:null}),m=w.useRef(0),f=w.useRef(null),p=w.useRef({x:0,y:0}),y=w.useRef(null),b=w.useRef(!1),g=w.useRef(!1),E=w.useRef(!1),C=fh();return w.useEffect(()=>{if(e!=null&&e.current){const v=Oe(e.current),M=({x:I,y:N})=>{const{nodeInternals:R,onNodeDrag:P,onSelectionDrag:V,updateNodePositions:H,nodeExtent:x,snapGrid:$,snapToGrid:S,nodeOrigin:O,onError:D}=a.getState();d.current={x:I,y:N};let k=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&x){const z=sn(u.current,O);T=Qt(z)}if(u.current=u.current.map(z=>{const W={x:I-z.distance.x,y:N-z.distance.y};S&&(W.x=$[0]*Math.round(W.x/$[0]),W.y=$[1]*Math.round(W.y/$[1]));const G=[[x[0][0],x[0][1]],[x[1][0],x[1][1]]];u.current.length>1&&x&&!z.extent&&(G[0][0]=z.positionAbsolute.x-T.x+x[0][0],G[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+x[1][0],G[0][1]=z.positionAbsolute.y-T.y+x[0][1],G[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+x[1][1]);const K=Io(z,W,R,G,O,D);return k=k||z.position.x!==K.position.x||z.position.y!==K.position.y,z.position=K.position,z.positionAbsolute=K.positionAbsolute,z}),!k)return;H(u.current,!0,!0),l(!0);const L=s?P:er(V);if(L&&y.current){const[z,W]=Jn({nodeId:s,dragItems:u.current,nodeInternals:R});L(y.current,z,W)}},j=()=>{if(!f.current)return;const[I,N]=to(p.current,f.current);if(I!==0||N!==0){const{transform:R,panBy:P}=a.getState();d.current.x=(d.current.x??0)-I/R[2],d.current.y=(d.current.y??0)-N/R[2],P({x:I,y:N})&&M(d.current)}m.current=requestAnimationFrame(j)},_=I=>{var O;const{nodeInternals:N,multiSelectionActive:R,nodesDraggable:P,unselectNodesAndEdges:V,onNodeDragStart:H,onSelectionDragStart:x}=a.getState();g.current=!0;const $=s?H:er(x);(!o||!i)&&!R&&s&&((O=N.get(s))!=null&&O.selected||V()),s&&i&&o&&_r({id:s,store:a,nodeRef:e});const S=C(I);if(d.current=S,u.current=uh(N,P,S,s),$&&u.current){const[D,k]=Jn({nodeId:s,dragItems:u.current,nodeInternals:N});$(I.sourceEvent,D,k)}};if(t)v.on(".drag",null);else{const I=bu().on("start",N=>{const{domNode:R,nodeDragThreshold:P}=a.getState();P===0&&_(N),E.current=!1;const V=C(N);d.current=V,f.current=(R==null?void 0:R.getBoundingClientRect())||null,p.current=ft(N.sourceEvent,f.current)}).on("drag",N=>{var H,x;const R=C(N),{autoPanOnNodeDrag:P,nodeDragThreshold:V}=a.getState();if(N.sourceEvent.type==="touchmove"&&N.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!b.current&&g.current&&P&&(b.current=!0,j()),!g.current){const $=R.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=R.ySnapped-(((x=d==null?void 0:d.current)==null?void 0:x.y)??0);Math.sqrt($*$+S*S)>V&&_(N)}(d.current.x!==R.xSnapped||d.current.y!==R.ySnapped)&&u.current&&g.current&&(y.current=N.sourceEvent,p.current=ft(N.sourceEvent,f.current),M(R))}}).on("end",N=>{if(!(!g.current||E.current)&&(l(!1),b.current=!1,g.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:R,nodeInternals:P,onNodeDragStop:V,onSelectionDragStop:H}=a.getState(),x=s?V:er(H);if(R(u.current,!1,!1),x){const[$,S]=Jn({nodeId:s,dragItems:u.current,nodeInternals:P});x(N.sourceEvent,$,S)}}}).filter(N=>{const R=N.target;return!N.button&&(!n||!Rs(R,`.${n}`,e))&&(!r||Rs(R,r,e))});return v.call(I),()=>{v.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,C]),c}function Oo(){const e=Se();return w.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,p=n.isShiftPressed?4:1,y=n.x*m*p,b=n.y*f*p,g=d.map(E=>{if(E.positionAbsolute){const C={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+b};a&&(C.x=c[0]*Math.round(C.x/c[0]),C.y=c[1]*Math.round(C.y/c[1]));const{positionAbsolute:v,position:M}=Io(E,C,r,s,void 0,l);E.position=M,E.positionAbsolute=v}return E});i(g,!0,!1)},[])}const Rt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Vt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:p,onDoubleClick:y,style:b,className:g,isDraggable:E,isSelectable:C,isConnectable:v,isFocusable:M,selectNodesOnDrag:j,sourcePosition:_,targetPosition:I,hidden:N,resizeObserver:R,dragHandle:P,zIndex:V,isParent:H,noDragClassName:x,noPanClassName:$,initialized:S,disableKeyboardA11y:O,ariaLabel:D,rfId:k,hasHandleBounds:T})=>{const L=Se(),z=w.useRef(null),W=w.useRef(null),G=w.useRef(_),K=w.useRef(I),Z=w.useRef(r),ne=C||E||u||d||m||f,ie=Oo(),re=Ft(n,L.getState,d),ae=Ft(n,L.getState,m),ye=Ft(n,L.getState,f),te=Ft(n,L.getState,p),me=Ft(n,L.getState,y),ve=le=>{const{nodeDragThreshold:X}=L.getState();if(C&&(!j||!E||X>0)&&_r({id:n,store:L,nodeRef:z}),u){const _e=L.getState().nodeInternals.get(n);_e&&u(le,{..._e})}},de=le=>{if(!xr(le)&&!O)if(io.includes(le.key)&&C){const X=le.key==="Escape";_r({id:n,store:L,unselect:X,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Rt,le.key)&&(L.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),ie({x:Rt[le.key].x,y:Rt[le.key].y,isShiftPressed:le.shiftKey}))};w.useEffect(()=>()=>{W.current&&(R==null||R.unobserve(W.current),W.current=null)},[]),w.useEffect(()=>{if(z.current&&!N){const le=z.current;(!S||!T||W.current!==le)&&(W.current&&(R==null||R.unobserve(W.current)),R==null||R.observe(le),W.current=le)}},[N,S,T]),w.useEffect(()=>{const le=Z.current!==r,X=G.current!==_,_e=K.current!==I;z.current&&(le||X||_e)&&(le&&(Z.current=r),X&&(G.current=_),_e&&(K.current=I),L.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,I]);const pe=To({nodeRef:z,disabled:N||!E,noDragClassName:x,handleSelector:P,nodeId:n,isSelectable:C,selectNodesOnDrag:j});return N?null:A.createElement("div",{className:Ce(["react-flow__node",`react-flow__node-${r}`,{[$]:E},g,{selected:l,selectable:C,parent:H,dragging:pe}]),ref:z,style:{zIndex:V,transform:`translate(${a}px,${c}px)`,pointerEvents:ne?"all":"none",visibility:S?"visible":"hidden",...b},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:re,onMouseMove:ae,onMouseLeave:ye,onContextMenu:te,onClick:ve,onDoubleClick:me,onKeyDown:M?de:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":O?void 0:`${ko}-${k}`,"aria-label":D},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:v,sourcePosition:_,targetPosition:I,dragging:pe,dragHandle:P,zIndex:V})))};return t.displayName="NodeWrapper",w.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...sn(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Se(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=he(hh,ke),u=Oo(),d=w.useRef(null);if(w.useEffect(()=>{var p;n||(p=d.current)==null||p.focus({preventScroll:!0})},[n]),To({nodeRef:d}),l||!s||!i)return null;const m=e?p=>{const y=r.getState().getNodes().filter(b=>b.selected);e(p,y)}:void 0,f=p=>{Object.prototype.hasOwnProperty.call(Rt,p.key)&&u({x:Rt[p.key].x,y:Rt[p.key].y,isShiftPressed:p.shiftKey})};return A.createElement("div",{className:Ce(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=w.memo(mh);const gh=e=>e.nodesSelectionActive,Lo=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:p,onSelectionEnd:y,multiSelectionKeyCode:b,panActivationKeyCode:g,zoomActivationKeyCode:E,elementsSelectable:C,zoomOnScroll:v,zoomOnPinch:M,panOnScroll:j,panOnScrollSpeed:_,panOnScrollMode:I,zoomOnDoubleClick:N,panOnDrag:R,defaultViewport:P,translateExtent:V,minZoom:H,maxZoom:x,preventScrolling:$,onSelectionContextMenu:S,noWheelClassName:O,noPanClassName:D,disableKeyboardA11y:k})=>{const T=he(gh),L=en(d),z=en(g),W=z||R,G=z||j,K=L||m&&W!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:b}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:C,zoomOnScroll:v,zoomOnPinch:M,panOnScroll:G,panOnScrollSpeed:_,panOnScrollMode:I,zoomOnDoubleClick:N,panOnDrag:!L&&W,defaultViewport:P,translateExtent:V,minZoom:H,maxZoom:x,zoomActivationKeyCode:E,preventScrolling:$,noWheelClassName:O,noPanClassName:D},A.createElement(Ao,{onSelectionStart:p,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:W,isSelecting:!!K,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:D,disableKeyboardA11y:k})))};Lo.displayName="FlowRenderer";var yh=w.memo(Lo);function xh(e){return he(w.useCallback(n=>e?ho(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Vt(e.input||_o),default:Vt(e.default||vr),output:Vt(e.output||No),group:Vt(e.group||Hr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Vt(e[i]||vr),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Do=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=he(vh,ke),a=xh(e.onlyRenderVisibleElements),c=w.useRef(),l=w.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return w.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Fr},a.map(u=>{var M,j,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",st.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),p=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),b=!!(u.focusable||r&&typeof u.focusable>"u"),g=e.nodeExtent?Tr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(g==null?void 0:g.x)??0,C=(g==null?void 0:g.y)??0,v=bh({x:E,y:C,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||U.Bottom,targetPosition:u.targetPosition||U.Top,hidden:u.hidden,xPos:E,yPos:C,xPosOrigin:v.x,yPosOrigin:v.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:p,isConnectable:y,isFocusable:b,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((j=u[we])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Do.displayName="NodeRenderer";var _h=w.memo(Do);const Eh=(e,t,n)=>n===U.Left?e-t:n===U.Right?e+t:e,Nh=(e,t,n)=>n===U.Top?e-t:n===U.Bottom?e+t:e,Ts="react-flow__edgeupdater",Os=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:Ce([Ts,`${Ts}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var jt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:y,style:b,source:g,target:E,sourceX:C,sourceY:v,targetX:M,targetY:j,sourcePosition:_,targetPosition:I,elementsSelectable:N,hidden:R,sourceHandleId:P,targetHandleId:V,onContextMenu:H,onMouseEnter:x,onMouseMove:$,onMouseLeave:S,reconnectRadius:O,onReconnect:D,onReconnectStart:k,onReconnectEnd:T,markerEnd:L,markerStart:z,rfId:W,ariaLabel:G,isFocusable:K,isReconnectable:Z,pathOptions:ne,interactionWidth:ie,disableKeyboardA11y:re})=>{const ae=w.useRef(null),[ye,te]=w.useState(!1),[me,ve]=w.useState(!1),de=Se(),pe=w.useMemo(()=>`url('#${wr(z,W)}')`,[z,W]),le=w.useMemo(()=>`url('#${wr(L,W)}')`,[L,W]);if(R)return null;const X=se=>{var Me;const{edges:ge,addSelectedEdges:J,unselectNodesAndEdges:fe,multiSelectionActive:ce}=de.getState(),xe=ge.find(Ye=>Ye.id===n);xe&&(N&&(de.setState({nodesSelectionActive:!1}),xe.selected&&ce?(fe({nodes:[],edges:[xe]}),(Me=ae.current)==null||Me.blur()):J([n])),o&&o(se,xe))},_e=Ht(n,de.getState,a),je=Ht(n,de.getState,H),ze=Ht(n,de.getState,x),$e=Ht(n,de.getState,$),qe=Ht(n,de.getState,S),Ie=(se,ge)=>{if(se.button!==0)return;const{edges:J,isValidConnection:fe}=de.getState(),ce=ge?E:g,xe=(ge?V:P)||null,Me=ge?"target":"source",Ye=fe||Sh,Ke=ge,Te=J.find(He=>He.id===n);ve(!0),k==null||k(se,Te,Me);const _t=He=>{ve(!1),T==null||T(He,Te,Me)};xo({event:se,handleId:xe,nodeId:ce,onConnect:He=>D==null?void 0:D(Te,He),isTarget:Ke,getState:de.getState,setState:de.setState,isValidConnection:Ye,edgeUpdaterType:Me,onReconnectEnd:_t})},F=se=>Ie(se,!0),Y=se=>Ie(se,!1),B=()=>te(!0),Q=()=>te(!1),q=!N&&!o,ee=se=>{var ge;if(!re&&io.includes(se.key)&&N){const{unselectNodesAndEdges:J,addSelectedEdges:fe,edges:ce}=de.getState();se.key==="Escape"?((ge=ae.current)==null||ge.blur(),J({edges:[ce.find(Me=>Me.id===n)]})):fe([n])}};return A.createElement("g",{className:Ce(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:q,updating:ye}]),onClick:X,onDoubleClick:_e,onContextMenu:je,onMouseEnter:ze,onMouseMove:$e,onMouseLeave:qe,onKeyDown:K?ee:void 0,tabIndex:K?0:void 0,role:K?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":G===null?void 0:G||`Edge from ${g} to ${E}`,"aria-describedby":K?`${jo}-${W}`:void 0,ref:ae},!me&&A.createElement(e,{id:n,source:g,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:y,data:i,style:b,sourceX:C,sourceY:v,targetX:M,targetY:j,sourcePosition:_,targetPosition:I,sourceHandleId:P,targetHandleId:V,markerStart:pe,markerEnd:le,pathOptions:ne,interactionWidth:ie}),Z&&A.createElement(A.Fragment,null,(Z==="source"||Z===!0)&&A.createElement(Os,{position:_,centerX:C,centerY:v,radius:O,onMouseDown:F,onMouseEnter:B,onMouseOut:Q,type:"source"}),(Z==="target"||Z===!0)&&A.createElement(Os,{position:I,centerX:M,centerY:j,radius:O,onMouseDown:Y,onMouseEnter:B,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",w.memo(t)};function kh(e){const t={default:jt(e.default||An),straight:jt(e.bezier||Dr),step:jt(e.step||Lr),smoothstep:jt(e.step||Fn),simplebezier:jt(e.simplebezier||Or)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=jt(e[i]||An),s),n);return{...t,...r}}function Ls(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case U.Top:return{x:r+i/2,y:s};case U.Right:return{x:r+i,y:s+o/2};case U.Bottom:return{x:r+i/2,y:s+o};case U.Left:return{x:r,y:s+o/2}}}function Ds(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ls(n,e,t),a=Ls(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Qt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Ps(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Le(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),p=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(p?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=he(w.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),zs={[$n.Arrow]:Rh,[$n.ArrowClosed]:Ih};function Th(e){const t=Se();return w.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(zs,e)?zs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",st.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=wr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},Po=({defaultColor:e,rfId:t})=>{const n=he(w.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};Po.displayName="MarkerDefinitions";var Dh=w.memo(Po);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),zo=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:y,children:b,disableKeyboardA11y:g})=>{const{edgesFocusable:E,edgesUpdatable:C,elementsSelectable:v,width:M,height:j,connectionMode:_,nodeInternals:I,onError:N}=he(Ph,ke),R=Ah(t,I,n);return M?A.createElement(A.Fragment,null,R.map(({level:P,edges:V,isMaxLevel:H})=>A.createElement("svg",{key:P,style:{zIndex:P},width:M,height:j,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,V.map(x=>{const[$,S,O]=Ps(I.get(x.source)),[D,k,T]=Ps(I.get(x.target));if(!O||!T)return null;let L=x.type||"default";s[L]||(N==null||N("011",st.error011(L)),L="default");const z=s[L]||s.default,W=_===bt.Strict?k.target:(k.target??[]).concat(k.source??[]),G=Ds(S.source,x.sourceHandle),K=Ds(W,x.targetHandle),Z=(G==null?void 0:G.position)||U.Bottom,ne=(K==null?void 0:K.position)||U.Top,ie=!!(x.focusable||E&&typeof x.focusable>"u"),re=x.reconnectable||x.updatable,ae=typeof m<"u"&&(re||C&&typeof re>"u");if(!G||!K)return N==null||N("008",st.error008(G,x)),null;const{sourceX:ye,sourceY:te,targetX:me,targetY:ve}=jh($,G,Z,D,K,ne);return A.createElement(z,{key:x.id,id:x.id,className:Ce([x.className,i]),type:L,data:x.data,selected:!!x.selected,animated:!!x.animated,hidden:!!x.hidden,label:x.label,labelStyle:x.labelStyle,labelShowBg:x.labelShowBg,labelBgStyle:x.labelBgStyle,labelBgPadding:x.labelBgPadding,labelBgBorderRadius:x.labelBgBorderRadius,style:x.style,source:x.source,target:x.target,sourceHandleId:x.sourceHandle,targetHandleId:x.targetHandle,markerEnd:x.markerEnd,markerStart:x.markerStart,sourceX:ye,sourceY:te,targetX:me,targetY:ve,sourcePosition:Z,targetPosition:ne,elementsSelectable:v,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:y,rfId:r,ariaLabel:x.ariaLabel,isFocusable:ie,isReconnectable:ae,pathOptions:"pathOptions"in x?x.pathOptions:void 0,interactionWidth:x.interactionWidth,disableKeyboardA11y:g})})))),b):null};zo.displayName="EdgeRenderer";var zh=w.memo(zo);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=he(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=on(),n=w.useRef(!1);w.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[U.Left]:U.Right,[U.Right]:U.Left,[U.Top]:U.Bottom,[U.Bottom]:U.Top},Ho=({nodeId:e,handleType:t,style:n,type:r=lt.Bezier,CustomComponent:s,connectionStatus:i})=>{var j,_,I;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=he(w.useCallback(N=>({fromNode:N.nodeInternals.get(e),handleId:N.connectionHandleId,toX:(N.connectionPosition.x-N.transform[0])/N.transform[2],toY:(N.connectionPosition.y-N.transform[1])/N.transform[2],connectionMode:N.connectionMode}),[e]),ke),d=(j=o==null?void 0:o[we])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(u===bt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(N=>N.id===a):m[0],p=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,b=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+p,g=(((I=o.positionAbsolute)==null?void 0:I.y)??0)+y,E=f==null?void 0:f.position,C=E?Bh[E]:null;if(!E||!C)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:b,fromY:g,toX:c,toY:l,fromPosition:E,toPosition:C,connectionStatus:i});let v="";const M={sourceX:b,sourceY:g,sourcePosition:E,targetX:c,targetY:l,targetPosition:C};return r===lt.Bezier?[v]=uo(M):r===lt.Step?[v]=Mn({...M,borderRadius:0}):r===lt.SmoothStep?[v]=Mn(M):r===lt.SimpleBezier?[v]=lo(M):v=`M${b},${g} ${c},${l}`,A.createElement("path",{d:v,fill:"none",className:"react-flow__connection-path",style:n})};Ho.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=he(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:Ce(["react-flow__connection",l])},A.createElement(Ho,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Hs(e,t){return w.useRef(null),Se(),w.useMemo(()=>t(e),[e])}const Fo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:p,onSelectionStart:y,onSelectionEnd:b,connectionLineType:g,connectionLineStyle:E,connectionLineComponent:C,connectionLineContainerStyle:v,selectionKeyCode:M,selectionOnDrag:j,selectionMode:_,multiSelectionKeyCode:I,panActivationKeyCode:N,zoomActivationKeyCode:R,deleteKeyCode:P,onlyRenderVisibleElements:V,elementsSelectable:H,selectNodesOnDrag:x,defaultViewport:$,translateExtent:S,minZoom:O,maxZoom:D,preventScrolling:k,defaultMarkerColor:T,zoomOnScroll:L,zoomOnPinch:z,panOnScroll:W,panOnScrollSpeed:G,panOnScrollMode:K,zoomOnDoubleClick:Z,panOnDrag:ne,onPaneClick:ie,onPaneMouseEnter:re,onPaneMouseMove:ae,onPaneMouseLeave:ye,onPaneScroll:te,onPaneContextMenu:me,onEdgeContextMenu:ve,onEdgeMouseEnter:de,onEdgeMouseMove:pe,onEdgeMouseLeave:le,onReconnect:X,onReconnectStart:_e,onReconnectEnd:je,reconnectRadius:ze,noDragClassName:$e,noWheelClassName:qe,noPanClassName:Ie,elevateEdgesOnSelect:F,disableKeyboardA11y:Y,nodeOrigin:B,nodeExtent:Q,rfId:q})=>{const ee=Hs(e,wh),se=Hs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:ie,onPaneMouseEnter:re,onPaneMouseMove:ae,onPaneMouseLeave:ye,onPaneContextMenu:me,onPaneScroll:te,deleteKeyCode:P,selectionKeyCode:M,selectionOnDrag:j,selectionMode:_,onSelectionStart:y,onSelectionEnd:b,multiSelectionKeyCode:I,panActivationKeyCode:N,zoomActivationKeyCode:R,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:L,zoomOnPinch:z,zoomOnDoubleClick:Z,panOnScroll:W,panOnScrollSpeed:G,panOnScrollMode:K,panOnDrag:ne,defaultViewport:$,translateExtent:S,minZoom:O,maxZoom:D,onSelectionContextMenu:p,preventScrolling:k,noDragClassName:$e,noWheelClassName:qe,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:V,onEdgeContextMenu:ve,onEdgeMouseEnter:de,onEdgeMouseMove:pe,onEdgeMouseLeave:le,onReconnect:X,onReconnectStart:_e,onReconnectEnd:je,reconnectRadius:ze,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!F,disableKeyboardA11y:Y,rfId:q},A.createElement(Yh,{style:E,type:g,component:C,containerStyle:v})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:ee,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:x,onlyRenderVisibleElements:V,noPanClassName:Ie,noDragClassName:$e,disableKeyboardA11y:Y,nodeOrigin:B,nodeExtent:Q,rfId:q})))};Fo.displayName="GraphView";var Wh=w.memo(Fo);const Er=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ot={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Er,nodeExtent:Er,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:bt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Uh=()=>Rc((e,t)=>({...ot,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Zn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Zn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,b)=>{const g=s.get(b.id);if(g!=null&&g.hidden)s.set(g.id,{...g,[we]:{...g[we],handleBounds:void 0}});else if(g){const E=Ir(b.nodeElement);!!(E.width&&E.height&&(g.width!==E.width||g.height!==E.height||b.forceUpdate))&&(s.set(g.id,{...g,[we]:{...g[we],handleBounds:{source:Is(".source",b.nodeElement,m,l),target:Is(".target",b.nodeElement,m,l)}},...E}),y.push({id:g.id,type:"dimensions",dimensions:E}))}return y},[]);$o(s,l);const p=o||i&&!o&&Mo(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:p}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Zn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(i(),n),a=Ct(s,[])),pn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(s,n),a=Ct(i(),[])),pn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ct(u.id,!1))),l=a.map(u=>ct(u.id,!1));pn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ct(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ct(a.id,!1));pn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Tr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=nt.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:ot.connectionNodeId,connectionHandleId:ot.connectionHandleId,connectionHandleType:ot.connectionHandleType,connectionStatus:ot.connectionStatus,connectionStartHandle:ot.connectionStartHandle,connectionEndHandle:ot.connectionEndHandle}),reset:()=>e({...ot})}),Object.is),Vo=({children:e})=>{const t=w.useRef(null);return t.current||(t.current=Uh()),A.createElement(df,{value:t.current},e)};Vo.displayName="ReactFlowProvider";const Bo=({children:e})=>w.useContext(Hn)?A.createElement(A.Fragment,null,e):A.createElement(Vo,null,e);Bo.displayName="ReactFlowWrapper";const Xh={input:_o,default:vr,output:No,group:Hr},qh={default:An,straight:Dr,step:Lr,smoothstep:Fn,simplebezier:Or},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Go=w.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Xh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:p,onConnectEnd:y,onClickConnectStart:b,onClickConnectEnd:g,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:v,onNodeContextMenu:M,onNodeDoubleClick:j,onNodeDragStart:_,onNodeDrag:I,onNodeDragStop:N,onNodesDelete:R,onEdgesDelete:P,onSelectionChange:V,onSelectionDragStart:H,onSelectionDrag:x,onSelectionDragStop:$,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,connectionMode:k=bt.Strict,connectionLineType:T=lt.Bezier,connectionLineStyle:L,connectionLineComponent:z,connectionLineContainerStyle:W,deleteKeyCode:G="Backspace",selectionKeyCode:K="Shift",selectionOnDrag:Z=!1,selectionMode:ne=Jt.Full,panActivationKeyCode:ie="Space",multiSelectionKeyCode:re=Cn()?"Meta":"Control",zoomActivationKeyCode:ae=Cn()?"Meta":"Control",snapToGrid:ye=!1,snapGrid:te=Zh,onlyRenderVisibleElements:me=!1,selectNodesOnDrag:ve=!0,nodesDraggable:de,nodesConnectable:pe,nodesFocusable:le,nodeOrigin:X=Kh,edgesFocusable:_e,edgesUpdatable:je,elementsSelectable:ze,defaultViewport:$e=Qh,minZoom:qe=.5,maxZoom:Ie=2,translateExtent:F=Er,preventScrolling:Y=!0,nodeExtent:B,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:q=!0,zoomOnPinch:ee=!0,panOnScroll:se=!1,panOnScrollSpeed:ge=.5,panOnScrollMode:J=gt.Free,zoomOnDoubleClick:fe=!0,panOnDrag:ce=!0,onPaneClick:xe,onPaneMouseEnter:Me,onPaneMouseMove:Ye,onPaneMouseLeave:Ke,onPaneScroll:Te,onPaneContextMenu:_t,children:Et,onEdgeContextMenu:He,onEdgeDoubleClick:ue,onEdgeMouseEnter:Ze,onEdgeMouseMove:Dt,onEdgeMouseLeave:$a,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:qr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Wa,defaultEdgeOptions:Ua,elevateNodesOnSelect:Xa=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Kr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Zr,nodeDragThreshold:nc,...rc},sc)=>{const Gn=Zr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:Ce(["react-flow",s]),"data-testid":"rf__wrapper",id:Zr},A.createElement(Bo,null,A.createElement(Wh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:v,onNodeContextMenu:M,onNodeDoubleClick:j,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:L,connectionLineComponent:z,connectionLineContainerStyle:W,selectionKeyCode:K,selectionOnDrag:Z,selectionMode:ne,deleteKeyCode:G,multiSelectionKeyCode:re,panActivationKeyCode:ie,zoomActivationKeyCode:ae,onlyRenderVisibleElements:me,selectNodesOnDrag:ve,defaultViewport:$e,translateExtent:F,minZoom:qe,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:q,zoomOnPinch:ee,zoomOnDoubleClick:fe,panOnScroll:se,panOnScrollSpeed:ge,panOnScrollMode:J,panOnDrag:ce,onPaneClick:xe,onPaneMouseEnter:Me,onPaneMouseMove:Ye,onPaneMouseLeave:Ke,onPaneScroll:Te,onPaneContextMenu:_t,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,onEdgeContextMenu:He,onEdgeDoubleClick:ue,onEdgeMouseEnter:Ze,onEdgeMouseMove:Dt,onEdgeMouseLeave:$a,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:qr,elevateEdgesOnSelect:qa,rfId:Gn,disableKeyboardA11y:Kr,nodeOrigin:X,nodeExtent:B}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:p,onConnectEnd:y,onClickConnectStart:b,onClickConnectEnd:g,nodesDraggable:de,nodesConnectable:pe,nodesFocusable:le,edgesFocusable:_e,edgesUpdatable:je,elementsSelectable:ze,elevateNodesOnSelect:Xa,minZoom:qe,maxZoom:Ie,nodeExtent:B,onNodesChange:Pa,onEdgesChange:za,snapToGrid:ye,snapGrid:te,connectionMode:k,translateExtent:F,connectOnClick:Ga,defaultEdgeOptions:Ua,fitView:Va,fitViewOptions:Ba,onNodesDelete:R,onEdgesDelete:P,onNodeDragStart:_,onNodeDrag:I,onNodeDragStop:N,onSelectionDrag:x,onSelectionDragStart:H,onSelectionDragStop:$,noPanClassName:qr,nodeOrigin:X,rfId:Gn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:V}),Et,A.createElement(hf,{proOptions:Wa,position:Ya}),A.createElement(Uf,{rfId:Gn,disableKeyboardA11y:Kr})))});Go.displayName="ReactFlow";const Yo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:p,backgroundColor:y}=i||{},b=o||p||y;return A.createElement("rect",{className:Ce(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:b,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?g=>m(g,e):void 0})};Yo.displayName="MiniMapNode";var em=w.memo(Yo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),tr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=he(nm,ke),c=he(tm),l=tr(t),u=tr(e),d=tr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:p,y}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:p,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=w.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(sn(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:p=!1,zoomable:y=!1,ariaLabel:b="React Flow mini map",inversePan:g=!1,zoomStep:E=10,offsetScale:C=5}){const v=Se(),M=w.useRef(null),{boundingRect:j,viewBB:_,rfId:I}=he(am,ke),N=(e==null?void 0:e.width)??im,R=(e==null?void 0:e.height)??om,P=j.width/N,V=j.height/R,H=Math.max(P,V),x=H*N,$=H*R,S=C*H,O=j.x-(x-j.width)/2-S,D=j.y-($-j.height)/2-S,k=x+S*2,T=$+S*2,L=`${cm}-${I}`,z=w.useRef(0);z.current=H,w.useEffect(()=>{if(M.current){const K=Oe(M.current),Z=re=>{const{transform:ae,d3Selection:ye,d3Zoom:te}=v.getState();if(re.sourceEvent.type!=="wheel"||!ye||!te)return;const me=-re.sourceEvent.deltaY*(re.sourceEvent.deltaMode===1?.05:re.sourceEvent.deltaMode?1:.002)*E,ve=ae[2]*Math.pow(2,me);te.scaleTo(ye,ve)},ne=re=>{const{transform:ae,d3Selection:ye,d3Zoom:te,translateExtent:me,width:ve,height:de}=v.getState();if(re.sourceEvent.type!=="mousemove"||!ye||!te)return;const pe=z.current*Math.max(1,ae[2])*(g?-1:1),le={x:ae[0]-re.sourceEvent.movementX*pe,y:ae[1]-re.sourceEvent.movementY*pe},X=[[0,0],[ve,de]],_e=nt.translate(le.x,le.y).scale(ae[2]),je=te.constrain()(_e,X,me);te.transform(ye,je)},ie=Ji().on("zoom",p?ne:null).on("zoom.wheel",y?Z:null);return K.call(ie),()=>{K.on("zoom",null)}}},[p,y,g,E]);const W=m?K=>{const Z=Fe(K);m(K,{x:Z[0],y:Z[1]})}:void 0,G=f?(K,Z)=>{const ne=v.getState().nodeInternals.get(Z);f(K,ne)}:void 0;return A.createElement(Rr,{position:d,style:e,className:Ce(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:N,height:R,viewBox:`${O} ${D} ${k} ${T}`,role:"img","aria-labelledby":L,ref:M,onClick:W},b&&A.createElement("title",{id:L},b),A.createElement(sm,{onClick:G,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${O-S},${D-S}h${k+S*2}v${T+S*2}h${-k-S*2}z + */var On=w,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=On.useRef,_c=On.useEffect,Ec=On.useMemo,Nc=On.useDebugValue;_i.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var p=o.value;if(s(p,f))return d=p}return d=f}if(p=d,wc(u,f))return p;var y=r(f);return s!==void 0&&s(p,y)?(u=f,p):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};vi.exports=_i;var Sc=vi.exports;const kc=bi(Sc),jc={},Qr=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(p=>p(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?Qr(e):Qr,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function Si(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const Jr=(e,t)=>{const n=Cc(e),r=(s,i=t)=>Si(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?Jr(e,t):Jr;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Ln(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}xn.prototype=Ln.prototype={constructor:xn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),ts.hasOwnProperty(t)?{space:ts[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===lr&&t.documentElement.namespaceURI===lr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ki(e){var t=Dn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function kr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=kr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=C&&(C=E+1);!(M=b[C])&&++C=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Tt(this.node(),e)}function Tt(e,t){return e.style.getPropertyValue(t)||Ai(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ri(e){return e.trim().split(/^|\s+/)}function jr(e){return e.classList||new Ii(e)}function Ii(e){this._node=e,this._names=Ri(e.getAttribute("class")||"")}Ii.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Ti(e,t){for(var n=jr(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function ur(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}ur.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Ln("start","drag","end"),o=0,a,c,l,u,d=0;function m(v){v.on("mousedown.drag",f).filter(r).on("touchstart.drag",b).on("touchmove.drag",g,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(v,M){if(!(u||!e.call(this,v,M))){var j=C(this,t.call(this,v,M),v,M,"mouse");j&&(Oe(v.view).on("mousemove.drag",p,Ut).on("mouseup.drag",y,Ut),Pi(v.view),Wn(v),l=!1,a=v.clientX,c=v.clientY,j("start",v))}}function p(v){if(Mt(v),!l){var M=v.clientX-a,j=v.clientY-c;l=M*M+j*j>d}s.mouse("drag",v)}function y(v){Oe(v.view).on("mousemove.drag mouseup.drag",null),zi(v.view,l),Mt(v),s.mouse("end",v)}function b(v,M){if(e.call(this,v,M)){var j=v.changedTouches,_=t.call(this,v,M),I=j.length,N,R;for(N=0;N>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?ln(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?ln(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Ae(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Ae(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?ln(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?ln(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?cs(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?cs(t[1],t[2]/100,t[3]/100,t[4]):ns.hasOwnProperty(e)?is(ns[e]):e==="transparent"?new Ae(NaN,NaN,NaN,0):null}function is(e){return new Ae(e>>16&255,e>>8&255,e&255,1)}function ln(e,t,n,r){return r<=0&&(e=t=n=NaN),new Ae(e,t,n,r)}function Mu(e){return e instanceof nn||(e=Kt(e)),e?(e=e.rgb(),new Ae(e.r,e.g,e.b,e.opacity)):new Ae}function dr(e,t,n,r){return arguments.length===1?Mu(e):new Ae(e,t,n,r??1)}function Ae(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Cr(Ae,dr,Hi(nn,{brighter(e){return e=e==null?En:Math.pow(En,e),new Ae(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Xt:Math.pow(Xt,e),new Ae(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Ae(yt(this.r),yt(this.g),yt(this.b),Nn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:os,formatHex:os,formatHex8:Au,formatRgb:as,toString:as}));function os(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function as(){const e=Nn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function Nn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function cs(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ve(e,t,n,r)}function Fi(e){if(e instanceof Ve)return new Ve(e.h,e.s,e.l,e.opacity);if(e instanceof nn||(e=Kt(e)),!e)return new Ve;if(e instanceof Ve)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new Ve(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Fi(e):new Ve(e,t,n,r??1)}function Ve(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Cr(Ve,Ru,Hi(nn,{brighter(e){return e=e==null?En:Math.pow(En,e),new Ve(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Xt:Math.pow(Xt,e),new Ve(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Ae(Un(e>=240?e-240:e+120,s,r),Un(e,s,r),Un(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Ve(ls(this.h),un(this.s),un(this.l),Nn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Nn(this.opacity);return`${e===1?"hsl(":"hsla("}${ls(this.h)}, ${un(this.s)*100}%, ${un(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ls(e){return e=(e||0)%360,e<0?e+360:e}function un(e){return Math.max(0,Math.min(1,e||0))}function Un(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Vi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Bi:function(t,n){return n-t?Tu(t,n,e):Vi(isNaN(t)?n:t)}}function Bi(e,t){var n=t-e;return n?Iu(e,n):Vi(isNaN(e)?t:e)}const us=function e(t){var n=Ou(t);function r(s,i){var o=n((s=dr(s)).r,(i=dr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Bi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function at(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var fr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Xn=new RegExp(fr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=fr.lastIndex=Xn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=fr.exec(e))&&(s=Xn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:at(r,s)})),n=Xn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:at(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:at(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,p){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");p.push({i:y-4,x:at(l,d)},{i:y-2,x:at(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var p=-1,y=m.length,b;++p=0&&e._call.call(void 0,t),e=e._next;--Ot}function hs(){wt=(kn=Zt.now())+Pn,Ot=Bt=0;try{Xu()}finally{Ot=0,Ku(),wt=0}}function qu(){var e=Zt.now(),t=e-kn;t>Wi&&(Pn-=t,kn=e)}function Ku(){for(var e,t=Sn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Sn=n);Gt=e,mr(r)}function mr(e){if(!Ot){Bt&&(Bt=clearTimeout(Bt));var t=e-wt;t>24?(e<1/0&&(Bt=setTimeout(hs,e-Zt.now()-Pn)),Pt&&(Pt=clearInterval(Pt))):(Pt||(kn=Zt.now(),Pt=setInterval(qu,Wi)),Ot=1,Ui(hs))}}function ms(e,t,n){var r=new jn;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Ln("start","end","cancel","interrupt"),Qu=[],qi=0,ps=1,pr=2,wn=3,gs=4,gr=5,bn=6;function zn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:qi})}function Mr(e,t){var n=Be(e,t);if(n.state>qi)throw new Error("too late; already scheduled");return n}function Xe(e,t){var n=Be(e,t);if(n.state>wn)throw new Error("too late; already running");return n}function Be(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=Xi(i,0,n.time);function i(l){n.state=ps,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ps)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===wn)return ms(o);f.state===gs?(f.state=bn,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+upr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Mr:Xe;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Be(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=kr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function tt(e,t,n){this.k=e,this.x=t,this.y=n}tt.prototype={constructor:tt,scale:function(e){return e===1?this:new tt(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new tt(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var nt=new tt(1,0,0);tt.prototype;function qn(e){e.stopImmediatePropagation()}function zt(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ys(){return this.__zoom||nt}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function Ji(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Wu,l=Ln("start","zoom","end"),u,d,m,f=500,p=150,y=0,b=10;function g(x){x.property("__zoom",ys).on("wheel.zoom",I,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",R).filter(s).on("touchstart.zoom",P).on("touchmove.zoom",V).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(x,$,S,O){var D=x.selection?x.selection():x;D.property("__zoom",ys),x!==D?M(x,$,S,O):D.interrupt().each(function(){j(this,arguments).event(O).start().zoom(null,typeof $=="function"?$.apply(this,arguments):$).end()})},g.scaleBy=function(x,$,S,O){g.scaleTo(x,function(){var D=this.__zoom.k,k=typeof $=="function"?$.apply(this,arguments):$;return D*k},S,O)},g.scaleTo=function(x,$,S,O){g.transform(x,function(){var D=t.apply(this,arguments),k=this.__zoom,T=S==null?v(D):typeof S=="function"?S.apply(this,arguments):S,L=k.invert(T),z=typeof $=="function"?$.apply(this,arguments):$;return n(C(E(k,z),T,L),D,o)},S,O)},g.translateBy=function(x,$,S,O){g.transform(x,function(){return n(this.__zoom.translate(typeof $=="function"?$.apply(this,arguments):$,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,O)},g.translateTo=function(x,$,S,O,D){g.transform(x,function(){var k=t.apply(this,arguments),T=this.__zoom,L=O==null?v(k):typeof O=="function"?O.apply(this,arguments):O;return n(nt.translate(L[0],L[1]).scale(T.k).translate(typeof $=="function"?-$.apply(this,arguments):-$,typeof S=="function"?-S.apply(this,arguments):-S),k,o)},O,D)};function E(x,$){return $=Math.max(i[0],Math.min(i[1],$)),$===x.k?x:new tt($,x.x,x.y)}function C(x,$,S){var O=$[0]-S[0]*x.k,D=$[1]-S[1]*x.k;return O===x.x&&D===x.y?x:new tt(x.k,O,D)}function v(x){return[(+x[0][0]+ +x[1][0])/2,(+x[0][1]+ +x[1][1])/2]}function M(x,$,S,O){x.on("start.zoom",function(){j(this,arguments).event(O).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(O).end()}).tween("zoom",function(){var D=this,k=arguments,T=j(D,k).event(O),L=t.apply(D,k),z=S==null?v(L):typeof S=="function"?S.apply(D,k):S,W=Math.max(L[1][0]-L[0][0],L[1][1]-L[0][1]),G=D.__zoom,X=typeof $=="function"?$.apply(D,k):$,Z=c(G.invert(z).concat(W/G.k),X.invert(z).concat(W/X.k));return function(ne){if(ne===1)ne=X;else{var ie=Z(ne),re=W/ie[2];ne=new tt(re,z[0]-ie[0]*re,z[1]-ie[1]*re)}T.zoom(null,ne)}})}function j(x,$,S){return!S&&x.__zooming||new _(x,$)}function _(x,$){this.that=x,this.args=$,this.active=0,this.sourceEvent=null,this.extent=t.apply(x,$),this.taps=0}_.prototype={event:function(x){return x&&(this.sourceEvent=x),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(x,$){return this.mouse&&x!=="mouse"&&(this.mouse[1]=$.invert(this.mouse[0])),this.touch0&&x!=="touch"&&(this.touch0[1]=$.invert(this.touch0[0])),this.touch1&&x!=="touch"&&(this.touch1[1]=$.invert(this.touch1[0])),this.that.__zoom=$,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(x){var $=Oe(this.that).datum();l.call(x,this.that,new sf(x,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:l}),$)}};function I(x,...$){if(!e.apply(this,arguments))return;var S=j(this,$).event(x),O=this.__zoom,D=Math.max(i[0],Math.min(i[1],O.k*Math.pow(2,r.apply(this,arguments)))),k=Fe(x);if(S.wheel)(S.mouse[0][0]!==k[0]||S.mouse[0][1]!==k[1])&&(S.mouse[1]=O.invert(S.mouse[0]=k)),clearTimeout(S.wheel);else{if(O.k===D)return;S.mouse=[k,O.invert(k)],vn(this),S.start()}zt(x),S.wheel=setTimeout(T,p),S.zoom("mouse",n(C(E(O,D),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function N(x,...$){if(m||!e.apply(this,arguments))return;var S=x.currentTarget,O=j(this,$,!0).event(x),D=Oe(x.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",W,!0),k=Fe(x,S),T=x.clientX,L=x.clientY;Pi(x.view),qn(x),O.mouse=[k,this.__zoom.invert(k)],vn(this),O.start();function z(G){if(zt(G),!O.moved){var X=G.clientX-T,Z=G.clientY-L;O.moved=X*X+Z*Z>y}O.event(G).zoom("mouse",n(C(O.that.__zoom,O.mouse[0]=Fe(G,S),O.mouse[1]),O.extent,o))}function W(G){D.on("mousemove.zoom mouseup.zoom",null),zi(G.view,O.moved),zt(G),O.event(G).end()}}function R(x,...$){if(e.apply(this,arguments)){var S=this.__zoom,O=Fe(x.changedTouches?x.changedTouches[0]:x,this),D=S.invert(O),k=S.k*(x.shiftKey?.5:2),T=n(C(E(S,k),O,D),t.apply(this,$),o);zt(x),a>0?Oe(this).transition().duration(a).call(M,T,O,x):Oe(this).call(g.transform,T,O,x)}}function P(x,...$){if(e.apply(this,arguments)){var S=x.touches,O=S.length,D=j(this,$,x.changedTouches.length===O).event(x),k,T,L,z;for(qn(x),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},eo=st.error001();function he(e,t){const n=w.useContext(Hn);if(n===null)throw new Error(eo);return Si(n,e,t)}const Se=()=>{const e=w.useContext(Hn);if(e===null)throw new Error(eo);return w.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Rr({position:e,children:t,className:n,style:r,...s}){const i=he(ff),o=`${e}`.split("-");return A.createElement("div",{className:Ce(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Rr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=w.useRef(null),[m,f]=w.useState({x:0,y:0,width:0,height:0}),p=Ce(["react-flow__edge-textwrapper",l]);return w.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:p,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=w.memo(mf);const Ir=e=>({width:e.offsetWidth,height:e.offsetHeight}),Lt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Tr=(e={x:0,y:0},t)=>({x:Lt(e.x,t[0][0],t[1][0]),y:Lt(e.y,t[0][1],t[1][1])}),xs=(e,t,n)=>en?-Lt(Math.abs(e-n),1,50)/50:0,to=(e,t)=>{const n=xs(e.x,35,t.width-35)*20,r=xs(e.y,35,t.height-35)*20;return[n,r]},no=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},ro=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Qt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),so=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),ws=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>so(ro(Qt(e),Qt(t))),yr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Le(e.width)&&Le(e.height)&&Le(e.x)&&Le(e.y),Le=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),io=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function xr(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const oo=e=>"clientX"in e,ft=(e,t)=>{var i,o;const n=oo(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Cn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},rn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Le(n)&&Le(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);rn.displayName="BaseEdge";function Ht(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function ao({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[b,g,E]=lo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(rn,{path:b,labelX:g,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:y})});Or.displayName="SimpleBezierEdge";const vs={[U.Left]:{x:-1,y:0},[U.Right]:{x:1,y:0},[U.Top]:{x:0,y:-1},[U.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=U.Bottom,target:n})=>t===U.Left||t===U.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=U.Bottom,target:n,targetPosition:r=U.Top,center:s,offset:i}){const o=vs[t],a=vs[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],p,y;const b={x:0,y:0},g={x:0,y:0},[E,C,v,M]=ao({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){p=s.x??E,y=s.y??C;const _=[{x:p,y:c.y},{x:p,y:l.y}],I=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:I:f=d==="x"?I:_}else{const _=[{x:c.x,y:l.y}],I=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?I:_:f=o.y===m?_:I,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const x=Math.min(i-1,i-H);o[d]===m?b[d]=(c[d]>e[d]?-1:1)*x:g[d]=(l[d]>n[d]?-1:1)*x}}if(t!==r){const H=d==="x"?"y":"x",x=o[d]===a[H],$=c[H]>l[H],S=c[H]=V?(p=(N.x+R.x)/2,y=f[0].y):(p=f[0].x,y=(N.y+R.y)/2)}return[[e,{x:c.x+b.x,y:c.y+b.y},...f,{x:l.x+g.x,y:l.y+g.y},n],p,y,v,M]}function _f(e,t,n,r){const s=Math.min(_s(e,t)/2,_s(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let C="";return E>0&&E{const[g,E,C]=Mn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(rn,{path:g,labelX:E,labelY:C,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:p,interactionWidth:b})});Fn.displayName="SmoothStepEdge";const Lr=w.memo(e=>{var t;return A.createElement(Fn,{...e,pathOptions:w.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Lr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=ao({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const Dr=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[p,y,b]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(rn,{path:p,labelX:y,labelY:b,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});Dr.displayName="StraightEdge";function hn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Es({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case U.Left:return[t-hn(t-r,i),n];case U.Right:return[t+hn(r-t,i),n];case U.Top:return[t,n-hn(n-s,i)];case U.Bottom:return[t,n+hn(s-n,i)]}}function uo({sourceX:e,sourceY:t,sourcePosition:n=U.Bottom,targetX:r,targetY:s,targetPosition:i=U.Top,curvature:o=.25}){const[a,c]=Es({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Es({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,p]=co({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,p]}const An=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=U.Bottom,targetPosition:i=U.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,pathOptions:y,interactionWidth:b})=>{const[g,E,C]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(rn,{path:g,labelX:E,labelY:C,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:b})});An.displayName="BezierEdge";const Pr=w.createContext(null),Nf=Pr.Provider;Pr.Consumer;const Sf=()=>w.useContext(Pr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,wr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},br=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},fo=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},sn=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return ro(r,Qt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return so(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),sn(e,t)),ho=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:p=!1}=u;if(o&&!f||p)return!1;const{positionAbsolute:y}=xt(u,a),b={x:y.x,y:y.y,width:d||0,height:m||0},g=yr(c,b),E=typeof d>"u"||typeof m>"u"||d===null||m===null,C=i&&g>0,v=(d||0)*(m||0);(E||C||g>=v||u.dragging)&&l.push(u)}),l},mo=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},po=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Lt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function Ns(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=ft(e),l=t.elementsFromPoint(o,a).find(p=>p.classList.contains("react-flow__handle"));if(l){const p=l.getAttribute("data-nodeid");if(p){const y=zr(void 0,l),b=l.getAttribute("data-handleid"),g=i({nodeId:p,id:b,type:y});if(g){const E=s.find(C=>C.nodeId===p&&C.type===y&&C.id===b);return{handle:{id:b,type:y,nodeId:p,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:g}}}}let u=[],d=1/0;if(s.forEach(p=>{const y=Math.sqrt((p.x-n.x)**2+(p.y-n.y)**2);if(y<=r){const b=i(p);y<=d&&(yp.isValid),f=u.some(({handle:p})=>p.type==="target");return u.find(({handle:p,validHandleResult:y})=>f?p.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},go=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function yo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...go(),handleDomNode:c};if(c){const u=zr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),p=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&p&&(t===bt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=Ns(i,o,"source",`${t}-${n}-${r}`),c=Ns(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function zr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Kn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function xo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=no(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:p,onConnectStart:y,panBy:b,getNodes:g,cancelConnection:E}=i();let C=0,v;const{x:M,y:j}=ft(e),_=u==null?void 0:u.elementFromPoint(M,j),I=zr(c,_),N=m==null?void 0:m.getBoundingClientRect();if(!N||!I)return;let R,P=ft(e,N),V=!1,H=null,x=!1,$=null;const S=If({nodes:g(),nodeId:n,handleId:t,handleType:I}),O=()=>{if(!f)return;const[T,L]=to(P,N);b({x:T,y:L}),C=requestAnimationFrame(O)};o({connectionPosition:P,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:I,connectionStartHandle:{nodeId:n,handleId:t,type:I},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:I});function D(T){const{transform:L}=i();P=ft(T,N);const{handle:z,validHandleResult:W}=Af(T,u,br(P,L,!1,[1,1]),p,S,G=>yo(G,d,n,t,s?"target":"source",a,u));if(v=z,V||(O(),V=!0),$=W.handleDomNode,H=W.connection,x=W.isValid,o({connectionPosition:v&&x?fo({x:v.x,y:v.y},L):P,connectionStatus:Tf(!!v,x),connectionEndHandle:W.endHandle}),!v&&!x&&!$)return Kn(R);H.source!==H.target&&$&&(Kn(R),R=$,$.classList.add("connecting","react-flow__handle-connecting"),$.classList.toggle("valid",x),$.classList.toggle("react-flow__handle-valid",x))}function k(T){var L,z;(v||$)&&H&&x&&(r==null||r(H)),(z=(L=i()).onConnectEnd)==null||z.call(L,T),c&&(l==null||l(T)),Kn(R),E(),cancelAnimationFrame(C),V=!1,x=!1,H=null,$=null,u.removeEventListener("mousemove",D),u.removeEventListener("mouseup",k),u.removeEventListener("touchmove",D),u.removeEventListener("touchend",k)}u.addEventListener("mousemove",D),u.addEventListener("mouseup",k),u.addEventListener("touchmove",D),u.addEventListener("touchend",k)}const Ss=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},wo=w.forwardRef(({type:e="source",position:t=U.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var N,R;const p=o||null,y=e==="target",b=Se(),g=Sf(),{connectOnClick:E,noPanClassName:C}=he(Of,ke),{connecting:v,clickConnecting:M}=he(Lf(g,p,e),ke);g||(R=(N=b.getState()).onError)==null||R.call(N,"010",st.error010());const j=P=>{const{defaultEdgeOptions:V,onConnect:H,hasDefaultEdges:x}=b.getState(),$={...V,...P};if(x){const{edges:S,setEdges:O}=b.getState();O($f($,S))}H==null||H($),a==null||a($)},_=P=>{if(!g)return;const V=oo(P);s&&(V&&P.button===0||!V)&&xo({event:P,handleId:p,nodeId:g,onConnect:j,isTarget:y,getState:b.getState,setState:b.setState,isValidConnection:n||b.getState().isValidConnection||Ss}),V?u==null||u(P):d==null||d(P)},I=P=>{const{onClickConnectStart:V,onClickConnectEnd:H,connectionClickStartHandle:x,connectionMode:$,isValidConnection:S}=b.getState();if(!g||!x&&!s)return;if(!x){V==null||V(P,{nodeId:g,handleId:p,handleType:e}),b.setState({connectionClickStartHandle:{nodeId:g,type:e,handleId:p}});return}const O=no(P.target),D=n||S||Ss,{connection:k,isValid:T}=yo({nodeId:g,id:p,type:e},$,x.nodeId,x.handleId||null,x.type,D,O);T&&j(k),H==null||H(P),b.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":p,"data-nodeid":g,"data-handlepos":t,"data-id":`${g}-${p}-${e}`,className:Ce(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",C,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!v||i&&v)}]),onMouseDown:_,onTouchStart:_,onClick:E?I:void 0,ref:f,...m},c)});wo.displayName="Handle";var ut=w.memo(wo);const bo=({data:e,isConnectable:t,targetPosition:n=U.Top,sourcePosition:r=U.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ut,{type:"source",position:r,isConnectable:t}));bo.displayName="DefaultNode";var vr=w.memo(bo);const vo=({data:e,isConnectable:t,sourcePosition:n=U.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ut,{type:"source",position:n,isConnectable:t}));vo.displayName="InputNode";var _o=w.memo(vo);const Eo=({data:e,isConnectable:t,targetPosition:n=U.Top})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);Eo.displayName="OutputNode";var No=w.memo(Eo);const Hr=()=>null;Hr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),mn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(mn),t.selectedNodes.map(mn))&&ke(e.selectedEdges.map(mn),t.selectedEdges.map(mn))}const So=w.memo(({onSelectionChange:e})=>{const t=Se(),{selectedNodes:n,selectedEdges:r}=he(Df,Pf);return w.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});So.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=he(zf);return e||t?A.createElement(So,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Nt(e,t){w.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function oe(e,t,n){w.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:p,minZoom:y,maxZoom:b,nodeExtent:g,onNodesChange:E,onEdgesChange:C,elementsSelectable:v,connectionMode:M,snapGrid:j,snapToGrid:_,translateExtent:I,connectOnClick:N,defaultEdgeOptions:R,fitView:P,fitViewOptions:V,onNodesDelete:H,onEdgesDelete:x,onNodeDrag:$,onNodeDragStart:S,onNodeDragStop:O,onSelectionDrag:D,onSelectionDragStart:k,onSelectionDragStop:T,noPanClassName:L,nodeOrigin:z,rfId:W,autoPanOnConnect:G,autoPanOnNodeDrag:X,onError:Z,connectionRadius:ne,isValidConnection:ie,nodeDragThreshold:re})=>{const{setNodes:ae,setEdges:ye,setDefaultNodesAndEdges:te,setMinZoom:me,setMaxZoom:ve,setTranslateExtent:de,setNodeExtent:pe,reset:le}=he(Ff,ke),q=Se();return w.useEffect(()=>{const _e=r==null?void 0:r.map(je=>({...je,...R}));return te(n,_e),()=>{le()}},[]),oe("defaultEdgeOptions",R,q.setState),oe("connectionMode",M,q.setState),oe("onConnect",s,q.setState),oe("onConnectStart",i,q.setState),oe("onConnectEnd",o,q.setState),oe("onClickConnectStart",a,q.setState),oe("onClickConnectEnd",c,q.setState),oe("nodesDraggable",l,q.setState),oe("nodesConnectable",u,q.setState),oe("nodesFocusable",d,q.setState),oe("edgesFocusable",m,q.setState),oe("edgesUpdatable",f,q.setState),oe("elementsSelectable",v,q.setState),oe("elevateNodesOnSelect",p,q.setState),oe("snapToGrid",_,q.setState),oe("snapGrid",j,q.setState),oe("onNodesChange",E,q.setState),oe("onEdgesChange",C,q.setState),oe("connectOnClick",N,q.setState),oe("fitViewOnInit",P,q.setState),oe("fitViewOnInitOptions",V,q.setState),oe("onNodesDelete",H,q.setState),oe("onEdgesDelete",x,q.setState),oe("onNodeDrag",$,q.setState),oe("onNodeDragStart",S,q.setState),oe("onNodeDragStop",O,q.setState),oe("onSelectionDrag",D,q.setState),oe("onSelectionDragStart",k,q.setState),oe("onSelectionDragStop",T,q.setState),oe("noPanClassName",L,q.setState),oe("nodeOrigin",z,q.setState),oe("rfId",W,q.setState),oe("autoPanOnConnect",G,q.setState),oe("autoPanOnNodeDrag",X,q.setState),oe("onError",Z,q.setState),oe("connectionRadius",ne,q.setState),oe("isValidConnection",ie,q.setState),oe("nodeDragThreshold",re,q.setState),Nt(e,ae),Nt(t,ye),Nt(y,me),Nt(b,ve),Nt(I,de),Nt(g,pe),null},ks={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},ko="react-flow__node-desc",jo="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Wf({rfId:e}){const t=he(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Uf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${ko}-${e}`,style:ks},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${jo}-${e}`,style:ks},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Wf,{rfId:e}))}var en=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=w.useState(!1),s=w.useRef(!1),i=w.useRef(new Set([])),[o,a]=w.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return w.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&xr(f))return!1;const y=Cs(f.code,a);i.current.add(f[y]),js(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&xr(f))return!1;const y=Cs(f.code,a);js(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function js(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Cs(e,t){return t.includes(e)?"code":"key"}function Co(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return Co(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function $o(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=Co(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Zn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Le(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),$o(s,n,i),s}function Mo(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const p=n().filter(b=>{var E;const g=t.includeHiddenNodes?b.width&&b.height:!b.hidden;return(E=t.nodes)!=null&&E.length?g&&t.nodes.some(C=>C.id===b.id):g}),y=p.every(b=>b.width&&b.height);if(p.length>0&&y){const b=sn(p,d),{x:g,y:E,zoom:C}=po(b,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),v=nt.translate(g,E).scale(C);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),v):a.transform(c,v),!0}}return!1}function Xf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function pn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Xf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const St=()=>{},Kf={zoomIn:St,zoomOut:St,zoomTo:St,getZoom:()=>1,setViewport:St,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:St,fitBounds:St,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Se(),{d3Zoom:t,d3Selection:n}=he(Zf,ke);return w.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=nt.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Mo(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=nt.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=po(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=nt.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),br(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return br(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=fo(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function on(){const e=Qf(),t=Se(),n=w.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=w.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=w.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(b=>({...b}))},[]),i=w.useCallback(y=>{const{edges:b=[]}=t.getState();return b.find(g=>g.id===y)},[]),o=w.useCallback(y=>{const{getNodes:b,setNodes:g,hasDefaultNodes:E,onNodesChange:C}=t.getState(),v=b(),M=typeof y=="function"?y(v):y;if(E)g(M);else if(C){const j=M.length===0?v.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));C(j)}},[]),a=w.useCallback(y=>{const{edges:b=[],setEdges:g,hasDefaultEdges:E,onEdgesChange:C}=t.getState(),v=typeof y=="function"?y(b):y;if(E)g(v);else if(C){const M=v.length===0?b.map(j=>({type:"remove",id:j.id})):v.map(j=>({item:j,type:"reset"}));C(M)}},[]),c=w.useCallback(y=>{const b=Array.isArray(y)?y:[y],{getNodes:g,setNodes:E,hasDefaultNodes:C,onNodesChange:v}=t.getState();if(C){const j=[...g(),...b];E(j)}else if(v){const M=b.map(j=>({item:j,type:"add"}));v(M)}},[]),l=w.useCallback(y=>{const b=Array.isArray(y)?y:[y],{edges:g=[],setEdges:E,hasDefaultEdges:C,onEdgesChange:v}=t.getState();if(C)E([...g,...b]);else if(v){const M=b.map(j=>({item:j,type:"add"}));v(M)}},[]),u=w.useCallback(()=>{const{getNodes:y,edges:b=[],transform:g}=t.getState(),[E,C,v]=g;return{nodes:y().map(M=>({...M})),edges:b.map(M=>({...M})),viewport:{x:E,y:C,zoom:v}}},[]),d=w.useCallback(({nodes:y,edges:b})=>{const{nodeInternals:g,getNodes:E,edges:C,hasDefaultNodes:v,hasDefaultEdges:M,onNodesDelete:j,onEdgesDelete:_,onNodesChange:I,onEdgesChange:N}=t.getState(),R=(y||[]).map($=>$.id),P=(b||[]).map($=>$.id),V=E().reduce(($,S)=>{const O=S.parentNode||S.parentId,D=!R.includes(S.id)&&O&&$.find(T=>T.id===O);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(R.includes(S.id)||D)&&$.push(S),$},[]),H=C.filter($=>typeof $.deletable=="boolean"?$.deletable:!0),x=H.filter($=>P.includes($.id));if(V||x){const $=mo(V,H),S=[...x,...$],O=S.reduce((D,k)=>(D.includes(k.id)||D.push(k.id),D),[]);if((M||v)&&(M&&t.setState({edges:C.filter(D=>!O.includes(D.id))}),v&&(V.forEach(D=>{g.delete(D.id)}),t.setState({nodeInternals:new Map(g)}))),O.length>0&&(_==null||_(S),N&&N(O.map(D=>({id:D,type:"remove"})))),V.length>0&&(j==null||j(V),I)){const D=V.map(k=>({id:k.id,type:"remove"}));I(D)}}},[]),m=w.useCallback(y=>{const b=yf(y),g=b?null:t.getState().nodeInternals.get(y.id);return!b&&!g?[null,null,b]:[b?y:ws(g),g,b]},[]),f=w.useCallback((y,b=!0,g)=>{const[E,C,v]=m(y);return E?(g||t.getState().getNodes()).filter(M=>{if(!v&&(M.id===C.id||!M.positionAbsolute))return!1;const j=ws(M),_=yr(j,E);return b&&_>0||_>=E.width*E.height}):[]},[]),p=w.useCallback((y,b,g=!0)=>{const[E]=m(y);if(!E)return!1;const C=yr(E,b);return g&&C>0||C>=E.width*E.height},[]);return w.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:p}),[e,n,r,s,i,o,a,c,l,u,d,f,p])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Se(),{deleteElements:r}=on(),s=en(e,Jf),i=en(t);w.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),w.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Se();w.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Ir(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",st.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Fr={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,gn=e=>({x:e.x,y:e.y,zoom:e.k}),kt=(e,t)=>e.target.closest(`.${t}`),$s=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Ms=e=>{const t=e.ctrlKey&&Cn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:p,maxZoom:y,zoomActivationKeyCode:b,preventScrolling:g=!0,children:E,noWheelClassName:C,noPanClassName:v})=>{const M=w.useRef(),j=Se(),_=w.useRef(!1),I=w.useRef(!1),N=w.useRef(null),R=w.useRef({x:0,y:0,zoom:0}),{d3Zoom:P,d3Selection:V,d3ZoomHandler:H,userSelectionActive:x}=he(rh,ke),$=en(b),S=w.useRef(0),O=w.useRef(!1),D=w.useRef();return th(N),w.useEffect(()=>{if(N.current){const k=N.current.getBoundingClientRect(),T=Ji().scaleExtent([p,y]).translateExtent(f),L=Oe(N.current).call(T),z=nt.translate(m.x,m.y).scale(Lt(m.zoom,p,y)),W=[[0,0],[k.width,k.height]],G=T.constrain()(z,W,f);T.transform(L,G),T.wheelDelta(Ms),j.setState({d3Zoom:T,d3Selection:L,d3ZoomHandler:L.on("wheel.zoom"),transform:[G.x,G.y,G.k],domNode:N.current.closest(".react-flow")})}},[]),w.useEffect(()=>{V&&P&&(o&&!$&&!x?V.on("wheel.zoom",k=>{if(kt(k,C))return!1;k.preventDefault(),k.stopImmediatePropagation();const T=V.property("__zoom").k||1;if(k.ctrlKey&&i){const ie=Fe(k),re=Ms(k),ae=T*Math.pow(2,re);P.scaleTo(V,ae,ie,k);return}const L=k.deltaMode===1?20:1;let z=c===gt.Vertical?0:k.deltaX*L,W=c===gt.Horizontal?0:k.deltaY*L;!Cn()&&k.shiftKey&&c!==gt.Vertical&&(z=k.deltaY*L,W=0),P.translateBy(V,-(z/T)*a,-(W/T)*a,{internal:!0});const G=gn(V.property("__zoom")),{onViewportChangeStart:X,onViewportChange:Z,onViewportChangeEnd:ne}=j.getState();clearTimeout(D.current),O.current||(O.current=!0,t==null||t(k,G),X==null||X(G)),O.current&&(e==null||e(k,G),Z==null||Z(G),D.current=setTimeout(()=>{n==null||n(k,G),ne==null||ne(G),O.current=!1},150))},{passive:!1}):typeof H<"u"&&V.on("wheel.zoom",function(k,T){if(!g&&k.type==="wheel"&&!k.ctrlKey||kt(k,C))return null;k.preventDefault(),H.call(this,k,T)},{passive:!1}))},[x,o,c,V,P,H,$,i,g,C,t,e,n]),w.useEffect(()=>{P&&P.on("start",k=>{var z,W;if(!k.sourceEvent||k.sourceEvent.internal)return null;S.current=(z=k.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=j.getState(),L=gn(k.transform);_.current=!0,R.current=L,((W=k.sourceEvent)==null?void 0:W.type)==="mousedown"&&j.setState({paneDragging:!0}),T==null||T(L),t==null||t(k.sourceEvent,L)})},[P,t]),w.useEffect(()=>{P&&(x&&!_.current?P.on("zoom",null):x||P.on("zoom",k=>{var L;const{onViewportChange:T}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),I.current=!!(r&&$s(d,S.current??0)),(e||T)&&!((L=k.sourceEvent)!=null&&L.internal)){const z=gn(k.transform);T==null||T(z),e==null||e(k.sourceEvent,z)}}))},[x,P,e,d,r]),w.useEffect(()=>{P&&P.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=j.getState();if(_.current=!1,j.setState({paneDragging:!1}),r&&$s(d,S.current??0)&&!I.current&&r(k.sourceEvent),I.current=!1,(n||T)&&nh(R.current,k.transform)){const L=gn(k.transform);R.current=L,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(L),n==null||n(k.sourceEvent,L)},o?150:0)}})},[P,o,d,n,r]),w.useEffect(()=>{P&&P.filter(k=>{const T=$||s,L=i&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(kt(k,"react-flow__node")||kt(k,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||x||!l&&k.type==="dblclick"||kt(k,C)&&k.type==="wheel"||kt(k,v)&&(k.type!=="wheel"||o&&k.type==="wheel"&&!$)||!i&&k.ctrlKey&&k.type==="wheel"||!T&&!o&&!L&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&z})},[x,P,s,i,o,l,d,u,$]),A.createElement("div",{className:"react-flow__renderer",ref:N,style:Fr},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=he(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function As(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&As(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&As(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ct=(e,t)=>({id:e,type:"select",selected:t});function Ct(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ct(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ct(r.id,!1))),n},[])}const Qn=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ao=w.memo(({isSelecting:e,selectionMode:t=Jt.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=w.useRef(null),f=Se(),p=w.useRef(0),y=w.useRef(0),b=w.useRef(),{userSelectionActive:g,elementsSelectable:E,dragging:C}=he(lh,ke),v=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),p.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,I=H=>{const{resetSelectedElements:x,domNode:$}=f.getState();if(b.current=$==null?void 0:$.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!b.current)return;const{x:S,y:O}=ft(H,b.current);x(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:O,x:S,y:O}}),r==null||r(H)},N=H=>{const{userSelectionRect:x,nodeInternals:$,edges:S,transform:O,onNodesChange:D,onEdgesChange:k,nodeOrigin:T,getNodes:L}=f.getState();if(!e||!b.current||!x)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=ft(H,b.current),W=x.startX??0,G=x.startY??0,X={...x,x:z.xae.id),re=ne.map(ae=>ae.id);if(p.current!==re.length){p.current=re.length;const ae=Ct(Z,re);ae.length&&(D==null||D(ae))}if(y.current!==ie.length){y.current=ie.length;const ae=Ct(S,ie);ae.length&&(k==null||k(ae))}f.setState({userSelectionRect:X})},R=H=>{if(H.button!==0)return;const{userSelectionRect:x}=f.getState();!g&&x&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:p.current>0}),v(),s==null||s(H)},P=H=>{g&&(f.setState({nodesSelectionActive:p.current>0}),s==null||s(H)),v()},V=E&&(e||g);return A.createElement("div",{className:Ce(["react-flow__pane",{dragging:C,selection:e}]),onClick:V?void 0:Qn(M,m),onContextMenu:Qn(j,m),onWheel:Qn(_,m),onMouseEnter:V?void 0:c,onMouseDown:V?I:void 0,onMouseMove:V?N:l,onMouseUp:V?R:void 0,onMouseLeave:V?P:u,ref:m,style:Fr},d,A.createElement(oh,null))});Ao.displayName="Pane";function Ro(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Ro(r,t):!1}function Rs(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Ro(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function Io(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Le(m)&&Le(f)&&Le(d.width)&&Le(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",st.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Tr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function Jn({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Is=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Ir(c)}})};function Ft(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function _r({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",st.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Se();return w.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function er(e){return(t,n,r)=>e==null?void 0:e(t,r)}function To({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Se(),[c,l]=w.useState(!1),u=w.useRef([]),d=w.useRef({x:null,y:null}),m=w.useRef(0),f=w.useRef(null),p=w.useRef({x:0,y:0}),y=w.useRef(null),b=w.useRef(!1),g=w.useRef(!1),E=w.useRef(!1),C=fh();return w.useEffect(()=>{if(e!=null&&e.current){const v=Oe(e.current),M=({x:I,y:N})=>{const{nodeInternals:R,onNodeDrag:P,onSelectionDrag:V,updateNodePositions:H,nodeExtent:x,snapGrid:$,snapToGrid:S,nodeOrigin:O,onError:D}=a.getState();d.current={x:I,y:N};let k=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&x){const z=sn(u.current,O);T=Qt(z)}if(u.current=u.current.map(z=>{const W={x:I-z.distance.x,y:N-z.distance.y};S&&(W.x=$[0]*Math.round(W.x/$[0]),W.y=$[1]*Math.round(W.y/$[1]));const G=[[x[0][0],x[0][1]],[x[1][0],x[1][1]]];u.current.length>1&&x&&!z.extent&&(G[0][0]=z.positionAbsolute.x-T.x+x[0][0],G[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+x[1][0],G[0][1]=z.positionAbsolute.y-T.y+x[0][1],G[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+x[1][1]);const X=Io(z,W,R,G,O,D);return k=k||z.position.x!==X.position.x||z.position.y!==X.position.y,z.position=X.position,z.positionAbsolute=X.positionAbsolute,z}),!k)return;H(u.current,!0,!0),l(!0);const L=s?P:er(V);if(L&&y.current){const[z,W]=Jn({nodeId:s,dragItems:u.current,nodeInternals:R});L(y.current,z,W)}},j=()=>{if(!f.current)return;const[I,N]=to(p.current,f.current);if(I!==0||N!==0){const{transform:R,panBy:P}=a.getState();d.current.x=(d.current.x??0)-I/R[2],d.current.y=(d.current.y??0)-N/R[2],P({x:I,y:N})&&M(d.current)}m.current=requestAnimationFrame(j)},_=I=>{var O;const{nodeInternals:N,multiSelectionActive:R,nodesDraggable:P,unselectNodesAndEdges:V,onNodeDragStart:H,onSelectionDragStart:x}=a.getState();g.current=!0;const $=s?H:er(x);(!o||!i)&&!R&&s&&((O=N.get(s))!=null&&O.selected||V()),s&&i&&o&&_r({id:s,store:a,nodeRef:e});const S=C(I);if(d.current=S,u.current=uh(N,P,S,s),$&&u.current){const[D,k]=Jn({nodeId:s,dragItems:u.current,nodeInternals:N});$(I.sourceEvent,D,k)}};if(t)v.on(".drag",null);else{const I=bu().on("start",N=>{const{domNode:R,nodeDragThreshold:P}=a.getState();P===0&&_(N),E.current=!1;const V=C(N);d.current=V,f.current=(R==null?void 0:R.getBoundingClientRect())||null,p.current=ft(N.sourceEvent,f.current)}).on("drag",N=>{var H,x;const R=C(N),{autoPanOnNodeDrag:P,nodeDragThreshold:V}=a.getState();if(N.sourceEvent.type==="touchmove"&&N.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!b.current&&g.current&&P&&(b.current=!0,j()),!g.current){const $=R.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=R.ySnapped-(((x=d==null?void 0:d.current)==null?void 0:x.y)??0);Math.sqrt($*$+S*S)>V&&_(N)}(d.current.x!==R.xSnapped||d.current.y!==R.ySnapped)&&u.current&&g.current&&(y.current=N.sourceEvent,p.current=ft(N.sourceEvent,f.current),M(R))}}).on("end",N=>{if(!(!g.current||E.current)&&(l(!1),b.current=!1,g.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:R,nodeInternals:P,onNodeDragStop:V,onSelectionDragStop:H}=a.getState(),x=s?V:er(H);if(R(u.current,!1,!1),x){const[$,S]=Jn({nodeId:s,dragItems:u.current,nodeInternals:P});x(N.sourceEvent,$,S)}}}).filter(N=>{const R=N.target;return!N.button&&(!n||!Rs(R,`.${n}`,e))&&(!r||Rs(R,r,e))});return v.call(I),()=>{v.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,C]),c}function Oo(){const e=Se();return w.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,p=n.isShiftPressed?4:1,y=n.x*m*p,b=n.y*f*p,g=d.map(E=>{if(E.positionAbsolute){const C={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+b};a&&(C.x=c[0]*Math.round(C.x/c[0]),C.y=c[1]*Math.round(C.y/c[1]));const{positionAbsolute:v,position:M}=Io(E,C,r,s,void 0,l);E.position=M,E.positionAbsolute=v}return E});i(g,!0,!1)},[])}const Rt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Vt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:p,onDoubleClick:y,style:b,className:g,isDraggable:E,isSelectable:C,isConnectable:v,isFocusable:M,selectNodesOnDrag:j,sourcePosition:_,targetPosition:I,hidden:N,resizeObserver:R,dragHandle:P,zIndex:V,isParent:H,noDragClassName:x,noPanClassName:$,initialized:S,disableKeyboardA11y:O,ariaLabel:D,rfId:k,hasHandleBounds:T})=>{const L=Se(),z=w.useRef(null),W=w.useRef(null),G=w.useRef(_),X=w.useRef(I),Z=w.useRef(r),ne=C||E||u||d||m||f,ie=Oo(),re=Ft(n,L.getState,d),ae=Ft(n,L.getState,m),ye=Ft(n,L.getState,f),te=Ft(n,L.getState,p),me=Ft(n,L.getState,y),ve=le=>{const{nodeDragThreshold:q}=L.getState();if(C&&(!j||!E||q>0)&&_r({id:n,store:L,nodeRef:z}),u){const _e=L.getState().nodeInternals.get(n);_e&&u(le,{..._e})}},de=le=>{if(!xr(le)&&!O)if(io.includes(le.key)&&C){const q=le.key==="Escape";_r({id:n,store:L,unselect:q,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Rt,le.key)&&(L.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),ie({x:Rt[le.key].x,y:Rt[le.key].y,isShiftPressed:le.shiftKey}))};w.useEffect(()=>()=>{W.current&&(R==null||R.unobserve(W.current),W.current=null)},[]),w.useEffect(()=>{if(z.current&&!N){const le=z.current;(!S||!T||W.current!==le)&&(W.current&&(R==null||R.unobserve(W.current)),R==null||R.observe(le),W.current=le)}},[N,S,T]),w.useEffect(()=>{const le=Z.current!==r,q=G.current!==_,_e=X.current!==I;z.current&&(le||q||_e)&&(le&&(Z.current=r),q&&(G.current=_),_e&&(X.current=I),L.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,I]);const pe=To({nodeRef:z,disabled:N||!E,noDragClassName:x,handleSelector:P,nodeId:n,isSelectable:C,selectNodesOnDrag:j});return N?null:A.createElement("div",{className:Ce(["react-flow__node",`react-flow__node-${r}`,{[$]:E},g,{selected:l,selectable:C,parent:H,dragging:pe}]),ref:z,style:{zIndex:V,transform:`translate(${a}px,${c}px)`,pointerEvents:ne?"all":"none",visibility:S?"visible":"hidden",...b},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:re,onMouseMove:ae,onMouseLeave:ye,onContextMenu:te,onClick:ve,onDoubleClick:me,onKeyDown:M?de:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":O?void 0:`${ko}-${k}`,"aria-label":D},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:v,sourcePosition:_,targetPosition:I,dragging:pe,dragHandle:P,zIndex:V})))};return t.displayName="NodeWrapper",w.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...sn(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Se(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=he(hh,ke),u=Oo(),d=w.useRef(null);if(w.useEffect(()=>{var p;n||(p=d.current)==null||p.focus({preventScroll:!0})},[n]),To({nodeRef:d}),l||!s||!i)return null;const m=e?p=>{const y=r.getState().getNodes().filter(b=>b.selected);e(p,y)}:void 0,f=p=>{Object.prototype.hasOwnProperty.call(Rt,p.key)&&u({x:Rt[p.key].x,y:Rt[p.key].y,isShiftPressed:p.shiftKey})};return A.createElement("div",{className:Ce(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=w.memo(mh);const gh=e=>e.nodesSelectionActive,Lo=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:p,onSelectionEnd:y,multiSelectionKeyCode:b,panActivationKeyCode:g,zoomActivationKeyCode:E,elementsSelectable:C,zoomOnScroll:v,zoomOnPinch:M,panOnScroll:j,panOnScrollSpeed:_,panOnScrollMode:I,zoomOnDoubleClick:N,panOnDrag:R,defaultViewport:P,translateExtent:V,minZoom:H,maxZoom:x,preventScrolling:$,onSelectionContextMenu:S,noWheelClassName:O,noPanClassName:D,disableKeyboardA11y:k})=>{const T=he(gh),L=en(d),z=en(g),W=z||R,G=z||j,X=L||m&&W!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:b}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:C,zoomOnScroll:v,zoomOnPinch:M,panOnScroll:G,panOnScrollSpeed:_,panOnScrollMode:I,zoomOnDoubleClick:N,panOnDrag:!L&&W,defaultViewport:P,translateExtent:V,minZoom:H,maxZoom:x,zoomActivationKeyCode:E,preventScrolling:$,noWheelClassName:O,noPanClassName:D},A.createElement(Ao,{onSelectionStart:p,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:W,isSelecting:!!X,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:D,disableKeyboardA11y:k})))};Lo.displayName="FlowRenderer";var yh=w.memo(Lo);function xh(e){return he(w.useCallback(n=>e?ho(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Vt(e.input||_o),default:Vt(e.default||vr),output:Vt(e.output||No),group:Vt(e.group||Hr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Vt(e[i]||vr),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Do=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=he(vh,ke),a=xh(e.onlyRenderVisibleElements),c=w.useRef(),l=w.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return w.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Fr},a.map(u=>{var M,j,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",st.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),p=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),b=!!(u.focusable||r&&typeof u.focusable>"u"),g=e.nodeExtent?Tr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(g==null?void 0:g.x)??0,C=(g==null?void 0:g.y)??0,v=bh({x:E,y:C,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||U.Bottom,targetPosition:u.targetPosition||U.Top,hidden:u.hidden,xPos:E,yPos:C,xPosOrigin:v.x,yPosOrigin:v.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:p,isConnectable:y,isFocusable:b,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((j=u[we])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Do.displayName="NodeRenderer";var _h=w.memo(Do);const Eh=(e,t,n)=>n===U.Left?e-t:n===U.Right?e+t:e,Nh=(e,t,n)=>n===U.Top?e-t:n===U.Bottom?e+t:e,Ts="react-flow__edgeupdater",Os=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:Ce([Ts,`${Ts}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var jt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:y,style:b,source:g,target:E,sourceX:C,sourceY:v,targetX:M,targetY:j,sourcePosition:_,targetPosition:I,elementsSelectable:N,hidden:R,sourceHandleId:P,targetHandleId:V,onContextMenu:H,onMouseEnter:x,onMouseMove:$,onMouseLeave:S,reconnectRadius:O,onReconnect:D,onReconnectStart:k,onReconnectEnd:T,markerEnd:L,markerStart:z,rfId:W,ariaLabel:G,isFocusable:X,isReconnectable:Z,pathOptions:ne,interactionWidth:ie,disableKeyboardA11y:re})=>{const ae=w.useRef(null),[ye,te]=w.useState(!1),[me,ve]=w.useState(!1),de=Se(),pe=w.useMemo(()=>`url('#${wr(z,W)}')`,[z,W]),le=w.useMemo(()=>`url('#${wr(L,W)}')`,[L,W]);if(R)return null;const q=se=>{var Me;const{edges:ge,addSelectedEdges:J,unselectNodesAndEdges:fe,multiSelectionActive:ce}=de.getState(),xe=ge.find(Ye=>Ye.id===n);xe&&(N&&(de.setState({nodesSelectionActive:!1}),xe.selected&&ce?(fe({nodes:[],edges:[xe]}),(Me=ae.current)==null||Me.blur()):J([n])),o&&o(se,xe))},_e=Ht(n,de.getState,a),je=Ht(n,de.getState,H),ze=Ht(n,de.getState,x),$e=Ht(n,de.getState,$),qe=Ht(n,de.getState,S),Ie=(se,ge)=>{if(se.button!==0)return;const{edges:J,isValidConnection:fe}=de.getState(),ce=ge?E:g,xe=(ge?V:P)||null,Me=ge?"target":"source",Ye=fe||Sh,Ke=ge,Te=J.find(He=>He.id===n);ve(!0),k==null||k(se,Te,Me);const _t=He=>{ve(!1),T==null||T(He,Te,Me)};xo({event:se,handleId:xe,nodeId:ce,onConnect:He=>D==null?void 0:D(Te,He),isTarget:Ke,getState:de.getState,setState:de.setState,isValidConnection:Ye,edgeUpdaterType:Me,onReconnectEnd:_t})},F=se=>Ie(se,!0),Y=se=>Ie(se,!1),B=()=>te(!0),Q=()=>te(!1),K=!N&&!o,ee=se=>{var ge;if(!re&&io.includes(se.key)&&N){const{unselectNodesAndEdges:J,addSelectedEdges:fe,edges:ce}=de.getState();se.key==="Escape"?((ge=ae.current)==null||ge.blur(),J({edges:[ce.find(Me=>Me.id===n)]})):fe([n])}};return A.createElement("g",{className:Ce(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:K,updating:ye}]),onClick:q,onDoubleClick:_e,onContextMenu:je,onMouseEnter:ze,onMouseMove:$e,onMouseLeave:qe,onKeyDown:X?ee:void 0,tabIndex:X?0:void 0,role:X?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":G===null?void 0:G||`Edge from ${g} to ${E}`,"aria-describedby":X?`${jo}-${W}`:void 0,ref:ae},!me&&A.createElement(e,{id:n,source:g,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:y,data:i,style:b,sourceX:C,sourceY:v,targetX:M,targetY:j,sourcePosition:_,targetPosition:I,sourceHandleId:P,targetHandleId:V,markerStart:pe,markerEnd:le,pathOptions:ne,interactionWidth:ie}),Z&&A.createElement(A.Fragment,null,(Z==="source"||Z===!0)&&A.createElement(Os,{position:_,centerX:C,centerY:v,radius:O,onMouseDown:F,onMouseEnter:B,onMouseOut:Q,type:"source"}),(Z==="target"||Z===!0)&&A.createElement(Os,{position:I,centerX:M,centerY:j,radius:O,onMouseDown:Y,onMouseEnter:B,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",w.memo(t)};function kh(e){const t={default:jt(e.default||An),straight:jt(e.bezier||Dr),step:jt(e.step||Lr),smoothstep:jt(e.step||Fn),simplebezier:jt(e.simplebezier||Or)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=jt(e[i]||An),s),n);return{...t,...r}}function Ls(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case U.Top:return{x:r+i/2,y:s};case U.Right:return{x:r+i,y:s+o/2};case U.Bottom:return{x:r+i/2,y:s+o};case U.Left:return{x:r,y:s+o/2}}}function Ds(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ls(n,e,t),a=Ls(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Qt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Ps(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Le(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),p=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(p?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=he(w.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),zs={[$n.Arrow]:Rh,[$n.ArrowClosed]:Ih};function Th(e){const t=Se();return w.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(zs,e)?zs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",st.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=wr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},Po=({defaultColor:e,rfId:t})=>{const n=he(w.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};Po.displayName="MarkerDefinitions";var Dh=w.memo(Po);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),zo=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:y,children:b,disableKeyboardA11y:g})=>{const{edgesFocusable:E,edgesUpdatable:C,elementsSelectable:v,width:M,height:j,connectionMode:_,nodeInternals:I,onError:N}=he(Ph,ke),R=Ah(t,I,n);return M?A.createElement(A.Fragment,null,R.map(({level:P,edges:V,isMaxLevel:H})=>A.createElement("svg",{key:P,style:{zIndex:P},width:M,height:j,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,V.map(x=>{const[$,S,O]=Ps(I.get(x.source)),[D,k,T]=Ps(I.get(x.target));if(!O||!T)return null;let L=x.type||"default";s[L]||(N==null||N("011",st.error011(L)),L="default");const z=s[L]||s.default,W=_===bt.Strict?k.target:(k.target??[]).concat(k.source??[]),G=Ds(S.source,x.sourceHandle),X=Ds(W,x.targetHandle),Z=(G==null?void 0:G.position)||U.Bottom,ne=(X==null?void 0:X.position)||U.Top,ie=!!(x.focusable||E&&typeof x.focusable>"u"),re=x.reconnectable||x.updatable,ae=typeof m<"u"&&(re||C&&typeof re>"u");if(!G||!X)return N==null||N("008",st.error008(G,x)),null;const{sourceX:ye,sourceY:te,targetX:me,targetY:ve}=jh($,G,Z,D,X,ne);return A.createElement(z,{key:x.id,id:x.id,className:Ce([x.className,i]),type:L,data:x.data,selected:!!x.selected,animated:!!x.animated,hidden:!!x.hidden,label:x.label,labelStyle:x.labelStyle,labelShowBg:x.labelShowBg,labelBgStyle:x.labelBgStyle,labelBgPadding:x.labelBgPadding,labelBgBorderRadius:x.labelBgBorderRadius,style:x.style,source:x.source,target:x.target,sourceHandleId:x.sourceHandle,targetHandleId:x.targetHandle,markerEnd:x.markerEnd,markerStart:x.markerStart,sourceX:ye,sourceY:te,targetX:me,targetY:ve,sourcePosition:Z,targetPosition:ne,elementsSelectable:v,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:y,rfId:r,ariaLabel:x.ariaLabel,isFocusable:ie,isReconnectable:ae,pathOptions:"pathOptions"in x?x.pathOptions:void 0,interactionWidth:x.interactionWidth,disableKeyboardA11y:g})})))),b):null};zo.displayName="EdgeRenderer";var zh=w.memo(zo);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=he(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=on(),n=w.useRef(!1);w.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[U.Left]:U.Right,[U.Right]:U.Left,[U.Top]:U.Bottom,[U.Bottom]:U.Top},Ho=({nodeId:e,handleType:t,style:n,type:r=lt.Bezier,CustomComponent:s,connectionStatus:i})=>{var j,_,I;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=he(w.useCallback(N=>({fromNode:N.nodeInternals.get(e),handleId:N.connectionHandleId,toX:(N.connectionPosition.x-N.transform[0])/N.transform[2],toY:(N.connectionPosition.y-N.transform[1])/N.transform[2],connectionMode:N.connectionMode}),[e]),ke),d=(j=o==null?void 0:o[we])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(u===bt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(N=>N.id===a):m[0],p=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,b=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+p,g=(((I=o.positionAbsolute)==null?void 0:I.y)??0)+y,E=f==null?void 0:f.position,C=E?Bh[E]:null;if(!E||!C)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:b,fromY:g,toX:c,toY:l,fromPosition:E,toPosition:C,connectionStatus:i});let v="";const M={sourceX:b,sourceY:g,sourcePosition:E,targetX:c,targetY:l,targetPosition:C};return r===lt.Bezier?[v]=uo(M):r===lt.Step?[v]=Mn({...M,borderRadius:0}):r===lt.SmoothStep?[v]=Mn(M):r===lt.SimpleBezier?[v]=lo(M):v=`M${b},${g} ${c},${l}`,A.createElement("path",{d:v,fill:"none",className:"react-flow__connection-path",style:n})};Ho.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=he(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:Ce(["react-flow__connection",l])},A.createElement(Ho,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Hs(e,t){return w.useRef(null),Se(),w.useMemo(()=>t(e),[e])}const Fo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:p,onSelectionStart:y,onSelectionEnd:b,connectionLineType:g,connectionLineStyle:E,connectionLineComponent:C,connectionLineContainerStyle:v,selectionKeyCode:M,selectionOnDrag:j,selectionMode:_,multiSelectionKeyCode:I,panActivationKeyCode:N,zoomActivationKeyCode:R,deleteKeyCode:P,onlyRenderVisibleElements:V,elementsSelectable:H,selectNodesOnDrag:x,defaultViewport:$,translateExtent:S,minZoom:O,maxZoom:D,preventScrolling:k,defaultMarkerColor:T,zoomOnScroll:L,zoomOnPinch:z,panOnScroll:W,panOnScrollSpeed:G,panOnScrollMode:X,zoomOnDoubleClick:Z,panOnDrag:ne,onPaneClick:ie,onPaneMouseEnter:re,onPaneMouseMove:ae,onPaneMouseLeave:ye,onPaneScroll:te,onPaneContextMenu:me,onEdgeContextMenu:ve,onEdgeMouseEnter:de,onEdgeMouseMove:pe,onEdgeMouseLeave:le,onReconnect:q,onReconnectStart:_e,onReconnectEnd:je,reconnectRadius:ze,noDragClassName:$e,noWheelClassName:qe,noPanClassName:Ie,elevateEdgesOnSelect:F,disableKeyboardA11y:Y,nodeOrigin:B,nodeExtent:Q,rfId:K})=>{const ee=Hs(e,wh),se=Hs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:ie,onPaneMouseEnter:re,onPaneMouseMove:ae,onPaneMouseLeave:ye,onPaneContextMenu:me,onPaneScroll:te,deleteKeyCode:P,selectionKeyCode:M,selectionOnDrag:j,selectionMode:_,onSelectionStart:y,onSelectionEnd:b,multiSelectionKeyCode:I,panActivationKeyCode:N,zoomActivationKeyCode:R,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:L,zoomOnPinch:z,zoomOnDoubleClick:Z,panOnScroll:W,panOnScrollSpeed:G,panOnScrollMode:X,panOnDrag:ne,defaultViewport:$,translateExtent:S,minZoom:O,maxZoom:D,onSelectionContextMenu:p,preventScrolling:k,noDragClassName:$e,noWheelClassName:qe,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:V,onEdgeContextMenu:ve,onEdgeMouseEnter:de,onEdgeMouseMove:pe,onEdgeMouseLeave:le,onReconnect:q,onReconnectStart:_e,onReconnectEnd:je,reconnectRadius:ze,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!F,disableKeyboardA11y:Y,rfId:K},A.createElement(Yh,{style:E,type:g,component:C,containerStyle:v})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:ee,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:x,onlyRenderVisibleElements:V,noPanClassName:Ie,noDragClassName:$e,disableKeyboardA11y:Y,nodeOrigin:B,nodeExtent:Q,rfId:K})))};Fo.displayName="GraphView";var Wh=w.memo(Fo);const Er=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ot={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Er,nodeExtent:Er,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:bt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Uh=()=>Rc((e,t)=>({...ot,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Zn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Zn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,b)=>{const g=s.get(b.id);if(g!=null&&g.hidden)s.set(g.id,{...g,[we]:{...g[we],handleBounds:void 0}});else if(g){const E=Ir(b.nodeElement);!!(E.width&&E.height&&(g.width!==E.width||g.height!==E.height||b.forceUpdate))&&(s.set(g.id,{...g,[we]:{...g[we],handleBounds:{source:Is(".source",b.nodeElement,m,l),target:Is(".target",b.nodeElement,m,l)}},...E}),y.push({id:g.id,type:"dimensions",dimensions:E}))}return y},[]);$o(s,l);const p=o||i&&!o&&Mo(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:p}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Zn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(i(),n),a=Ct(s,[])),pn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(s,n),a=Ct(i(),[])),pn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ct(u.id,!1))),l=a.map(u=>ct(u.id,!1));pn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ct(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ct(a.id,!1));pn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Tr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=nt.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:ot.connectionNodeId,connectionHandleId:ot.connectionHandleId,connectionHandleType:ot.connectionHandleType,connectionStatus:ot.connectionStatus,connectionStartHandle:ot.connectionStartHandle,connectionEndHandle:ot.connectionEndHandle}),reset:()=>e({...ot})}),Object.is),Vo=({children:e})=>{const t=w.useRef(null);return t.current||(t.current=Uh()),A.createElement(df,{value:t.current},e)};Vo.displayName="ReactFlowProvider";const Bo=({children:e})=>w.useContext(Hn)?A.createElement(A.Fragment,null,e):A.createElement(Vo,null,e);Bo.displayName="ReactFlowWrapper";const Xh={input:_o,default:vr,output:No,group:Hr},qh={default:An,straight:Dr,step:Lr,smoothstep:Fn,simplebezier:Or},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Go=w.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Xh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:p,onConnectEnd:y,onClickConnectStart:b,onClickConnectEnd:g,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:v,onNodeContextMenu:M,onNodeDoubleClick:j,onNodeDragStart:_,onNodeDrag:I,onNodeDragStop:N,onNodesDelete:R,onEdgesDelete:P,onSelectionChange:V,onSelectionDragStart:H,onSelectionDrag:x,onSelectionDragStop:$,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,connectionMode:k=bt.Strict,connectionLineType:T=lt.Bezier,connectionLineStyle:L,connectionLineComponent:z,connectionLineContainerStyle:W,deleteKeyCode:G="Backspace",selectionKeyCode:X="Shift",selectionOnDrag:Z=!1,selectionMode:ne=Jt.Full,panActivationKeyCode:ie="Space",multiSelectionKeyCode:re=Cn()?"Meta":"Control",zoomActivationKeyCode:ae=Cn()?"Meta":"Control",snapToGrid:ye=!1,snapGrid:te=Zh,onlyRenderVisibleElements:me=!1,selectNodesOnDrag:ve=!0,nodesDraggable:de,nodesConnectable:pe,nodesFocusable:le,nodeOrigin:q=Kh,edgesFocusable:_e,edgesUpdatable:je,elementsSelectable:ze,defaultViewport:$e=Qh,minZoom:qe=.5,maxZoom:Ie=2,translateExtent:F=Er,preventScrolling:Y=!0,nodeExtent:B,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:K=!0,zoomOnPinch:ee=!0,panOnScroll:se=!1,panOnScrollSpeed:ge=.5,panOnScrollMode:J=gt.Free,zoomOnDoubleClick:fe=!0,panOnDrag:ce=!0,onPaneClick:xe,onPaneMouseEnter:Me,onPaneMouseMove:Ye,onPaneMouseLeave:Ke,onPaneScroll:Te,onPaneContextMenu:_t,children:Et,onEdgeContextMenu:He,onEdgeDoubleClick:ue,onEdgeMouseEnter:Ze,onEdgeMouseMove:Dt,onEdgeMouseLeave:$a,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:qr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Wa,defaultEdgeOptions:Ua,elevateNodesOnSelect:Xa=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Kr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Zr,nodeDragThreshold:nc,...rc},sc)=>{const Gn=Zr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:Ce(["react-flow",s]),"data-testid":"rf__wrapper",id:Zr},A.createElement(Bo,null,A.createElement(Wh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:v,onNodeContextMenu:M,onNodeDoubleClick:j,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:L,connectionLineComponent:z,connectionLineContainerStyle:W,selectionKeyCode:X,selectionOnDrag:Z,selectionMode:ne,deleteKeyCode:G,multiSelectionKeyCode:re,panActivationKeyCode:ie,zoomActivationKeyCode:ae,onlyRenderVisibleElements:me,selectNodesOnDrag:ve,defaultViewport:$e,translateExtent:F,minZoom:qe,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:K,zoomOnPinch:ee,zoomOnDoubleClick:fe,panOnScroll:se,panOnScrollSpeed:ge,panOnScrollMode:J,panOnDrag:ce,onPaneClick:xe,onPaneMouseEnter:Me,onPaneMouseMove:Ye,onPaneMouseLeave:Ke,onPaneScroll:Te,onPaneContextMenu:_t,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,onEdgeContextMenu:He,onEdgeDoubleClick:ue,onEdgeMouseEnter:Ze,onEdgeMouseMove:Dt,onEdgeMouseLeave:$a,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:qr,elevateEdgesOnSelect:qa,rfId:Gn,disableKeyboardA11y:Kr,nodeOrigin:q,nodeExtent:B}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:p,onConnectEnd:y,onClickConnectStart:b,onClickConnectEnd:g,nodesDraggable:de,nodesConnectable:pe,nodesFocusable:le,edgesFocusable:_e,edgesUpdatable:je,elementsSelectable:ze,elevateNodesOnSelect:Xa,minZoom:qe,maxZoom:Ie,nodeExtent:B,onNodesChange:Pa,onEdgesChange:za,snapToGrid:ye,snapGrid:te,connectionMode:k,translateExtent:F,connectOnClick:Ga,defaultEdgeOptions:Ua,fitView:Va,fitViewOptions:Ba,onNodesDelete:R,onEdgesDelete:P,onNodeDragStart:_,onNodeDrag:I,onNodeDragStop:N,onSelectionDrag:x,onSelectionDragStart:H,onSelectionDragStop:$,noPanClassName:qr,nodeOrigin:q,rfId:Gn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:V}),Et,A.createElement(hf,{proOptions:Wa,position:Ya}),A.createElement(Uf,{rfId:Gn,disableKeyboardA11y:Kr})))});Go.displayName="ReactFlow";const Yo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:p,backgroundColor:y}=i||{},b=o||p||y;return A.createElement("rect",{className:Ce(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:b,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?g=>m(g,e):void 0})};Yo.displayName="MiniMapNode";var em=w.memo(Yo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),tr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=he(nm,ke),c=he(tm),l=tr(t),u=tr(e),d=tr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:p,y}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:p,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=w.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(sn(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:p=!1,zoomable:y=!1,ariaLabel:b="React Flow mini map",inversePan:g=!1,zoomStep:E=10,offsetScale:C=5}){const v=Se(),M=w.useRef(null),{boundingRect:j,viewBB:_,rfId:I}=he(am,ke),N=(e==null?void 0:e.width)??im,R=(e==null?void 0:e.height)??om,P=j.width/N,V=j.height/R,H=Math.max(P,V),x=H*N,$=H*R,S=C*H,O=j.x-(x-j.width)/2-S,D=j.y-($-j.height)/2-S,k=x+S*2,T=$+S*2,L=`${cm}-${I}`,z=w.useRef(0);z.current=H,w.useEffect(()=>{if(M.current){const X=Oe(M.current),Z=re=>{const{transform:ae,d3Selection:ye,d3Zoom:te}=v.getState();if(re.sourceEvent.type!=="wheel"||!ye||!te)return;const me=-re.sourceEvent.deltaY*(re.sourceEvent.deltaMode===1?.05:re.sourceEvent.deltaMode?1:.002)*E,ve=ae[2]*Math.pow(2,me);te.scaleTo(ye,ve)},ne=re=>{const{transform:ae,d3Selection:ye,d3Zoom:te,translateExtent:me,width:ve,height:de}=v.getState();if(re.sourceEvent.type!=="mousemove"||!ye||!te)return;const pe=z.current*Math.max(1,ae[2])*(g?-1:1),le={x:ae[0]-re.sourceEvent.movementX*pe,y:ae[1]-re.sourceEvent.movementY*pe},q=[[0,0],[ve,de]],_e=nt.translate(le.x,le.y).scale(ae[2]),je=te.constrain()(_e,q,me);te.transform(ye,je)},ie=Ji().on("zoom",p?ne:null).on("zoom.wheel",y?Z:null);return X.call(ie),()=>{X.on("zoom",null)}}},[p,y,g,E]);const W=m?X=>{const Z=Fe(X);m(X,{x:Z[0],y:Z[1]})}:void 0,G=f?(X,Z)=>{const ne=v.getState().nodeInternals.get(Z);f(X,ne)}:void 0;return A.createElement(Rr,{position:d,style:e,className:Ce(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:N,height:R,viewBox:`${O} ${D} ${k} ${T}`,role:"img","aria-labelledby":L,ref:M,onClick:W},b&&A.createElement("title",{id:L},b),A.createElement(sm,{onClick:G,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${O-S},${D-S}h${k+S*2}v${T+S*2}h${-k-S*2}z M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Wo.displayName="MiniMap";var lm=w.memo(Wo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Yt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:Ce(["react-flow__controls-button",t]),...n},e);Yt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Se(),[f,p]=w.useState(!1),{isInteractive:y,minZoomReached:b,maxZoomReached:g}=he(pm,ke),{zoomIn:E,zoomOut:C,fitView:v}=on();if(w.useEffect(()=>{p(!0)},[]),!f)return null;const M=()=>{E(),i==null||i()},j=()=>{C(),o==null||o()},_=()=>{v(s),a==null||a()},I=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c==null||c(!y)};return A.createElement(Rr,{className:Ce(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Yt,{onClick:M,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:g},A.createElement(um,null)),A.createElement(Yt,{onClick:j,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:b},A.createElement(dm,null))),n&&A.createElement(Yt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Yt,{className:"react-flow__controls-interactive",onClick:I,title:"toggle interactivity","aria-label":"toggle interactivity"},y?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=w.memo(Uo),De;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(De||(De={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[De.Dots]:"#91919a",[De.Lines]:"#eee",[De.Cross]:"#e2e2e2"},bm={[De.Dots]:1,[De.Lines]:1,[De.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Xo({id:e,variant:t=De.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=w.useRef(null),{transform:u,patternId:d}=he(vm,ke),m=o||wm[t],f=r||bm[t],p=t===De.Dots,y=t===De.Cross,b=Array.isArray(n)?n:[n,n],g=[b[0]*u[2]||1,b[1]*u[2]||1],E=f*u[2],C=y?[E,E]:g,v=p?[E/i,E/i]:[C[0]/i,C[1]/i];return A.createElement("svg",{className:Ce(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%g[0],y:u[1]%g[1],width:g[0],height:g[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${v[0]},-${v[1]})`},p?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:C,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}Xo.displayName="Background";var _m=w.memo(Xo);const Vr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Rn(e){return Vr+e}async function be(e){const t=await fetch(Rn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function it(e,t){const n=await fetch(Rn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new qo(r.error??`${e}: ${n.status}`,n.status);return r}class qo extends Error{constructor(n,r){super(n);Ee(this,"status");this.status=r}}const Rx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),Ix=()=>be("/api/diagnostics"),Ko=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Zo=()=>be("/api/ontology/ontologies"),Em=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>be("/api/ontology/stack"),Sm=()=>be("/api/ontology/coverage"),km=(e,t,n)=>it("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>be("/api/git/status"),Cm=()=>be("/api/git/diff"),$m=e=>it("/api/git/commit",{message:e}),Mm=()=>it("/api/git/discard",{}),Am=()=>be("/api/decisions"),Fs=(e,t)=>it(`/api/decisions/${e}/verdict`,{verdict:t}),Tx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Ox=()=>be("/api/glossary/config"),Lx=e=>it("/api/git/propose",e),Dx=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Px=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),zx=e=>it("/api/git/classify",{changes:e}),Hx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Fx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Vx=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>be("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Vr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>it("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>it("/api/import/preview",{format:e,content:t}),Bx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Gx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Yx=(e,t,n)=>fetch(`${Vr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new qo(await r.text(),r.status);return await r.json()}),Wx=()=>be("/api/glossary/subject-areas"),Ux=e=>be(`/api/glossary/subject-area/${e}`),Xx=(e,t)=>it(`/api/glossary/subject-area/${e}/expand`,t);function qx(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Rn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Rn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Br="__entity_source",Gr="__entity_target",Pm=w.memo(function({data:t,selected:n}){var j;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:p}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,b=[...r.attributes].map((_,I)=>({a:_,i:I})).sort((_,I)=>y(_.a)-y(I.a)||_.i-I.i).map(_=>_.a),g=b.filter(_=>_.role==="business_key");let E=b.filter(_=>_.role!=="business_key");const C=!!c&&!l;let v=0;if(C){const _=E.filter(I=>d==null?void 0:d.has(I.id));v=E.length-_.length,E=_}const M=(_,I)=>{const N="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:N,onMouseEnter:p?()=>p(_.id):void 0,onMouseLeave:p?()=>p(null):void 0,children:[h.jsx(ut,{id:_.id,type:"target",position:U.Left,className:"port attr-port"}),h.jsx(ut,{id:_.id,type:"source",position:U.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(I?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ut,{id:Gr,type:"target",position:U.Left,className:"port"}),h.jsx(ut,{id:Br,type:"source",position:U.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((j=r.conceptual)==null?void 0:j.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var N;const _=(((N=r.conceptual)==null?void 0:N.ontology_refs)??[]).filter(R=>R.uri);if(_.length===0)return null;const I=_.map(R=>R.uri).join(` -`);return h.jsxs("span",{className:"badge ontology",title:I,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),g.length>0&&h.jsx("div",{className:"attr-section keys",children:g.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),v>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${v} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,p,y,b,g,E,C,v,M,j,_,I;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(N=>N.from.entity===e.id||N.to.entity===e.id),d=N=>{var R;return((R=t.entities.find(P=>P.id===N))==null?void 0:R.name)??N};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Je,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,name:N})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Je,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,physical_name:N})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Je,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:N=>r("set_definition",{id:e.id,definition:N})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((p=l==null?void 0:l.ontology_refs)==null?void 0:p.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(b=e.term_map)!=null&&b.class_iri?"Edit mapping…":"Map…"}),(((g=e.term_map)==null?void 0:g.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),(C=e.term_map)!=null&&C.subject_template||(v=e.term_map)!=null&&v.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Je,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:N=>{var R;return r("set_stewardship",{id:e.id,owner:N,steward:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Je,{value:((I=l==null?void 0:l.stewardship)==null?void 0:I.steward)??"",placeholder:"—",readOnly:c,onCommit:N=>{var R;return r("set_stewardship",{id:e.id,owner:((R=l==null?void 0:l.stewardship)==null?void 0:R.owner)??null,steward:N})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(N=>h.jsx(Wm,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(Um,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(N=>{const R=N.members.map(P=>{var V;return((V=e.attributes.find(H=>H.id===P))==null?void 0:V.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+N.type,children:N.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:N.name}),h.jsx("span",{className:"key-cols",children:R})]},N.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([N,R])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:N}),h.jsx("td",{className:"udp-val",children:String(R)})]},N))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(N=>{const R=N.from.entity===e.id?N.to.entity:N.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(R),children:[h.jsx("span",{className:"rel-card",children:Xm(N,e.id)}),d(R)]}),(N.verb_phrase||N.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Je,{value:N.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,verb_phrase:P})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Je,{value:N.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,inverse_verb_phrase:P})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${N.name}`,onClick:()=>r("delete_relationship",{id:N.id}),children:"✕"})]},N.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var N;return(N=navigator.clipboard)==null?void 0:N.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Je({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=w.useState(e);w.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Wm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Je,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Je,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Um({entity:e,exec:t}){const[n,r]=w.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Xm(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Vs="";let Km=class{constructor(t){Ee(this,"_isDirected",!0);Ee(this,"_isMultigraph",!1);Ee(this,"_isCompound",!1);Ee(this,"_label");Ee(this,"_defaultNodeLabelFn",()=>{});Ee(this,"_defaultEdgeLabelFn",()=>{});Ee(this,"_nodes",{});Ee(this,"_in",{});Ee(this,"_preds",{});Ee(this,"_out",{});Ee(this,"_sucs",{});Ee(this,"_edgeObjs",{});Ee(this,"_edgeLabels",{});Ee(this,"_nodeCount",0);Ee(this,"_edgeCount",0);Ee(this,"_parent");Ee(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Bs(this._preds[n],t),Bs(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Gs(this._preds[n],t),Gs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Bs(e,t){e[t]?e[t]++:e[t]=1}function Gs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Vs+i+Vs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function nr(e,t){return Wt(e,t.v,t.w,t.name)}var Yr=Km,Qm="2.2.4",Jm={Graph:Yr,version:Qm},ep=Yr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){Ee(this,"_arr",[]);Ee(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=Jo,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ea=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ea,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),sa(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),sa(t(i),o=>s.push(o)))}}function sa(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=ra,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=ra,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Yr,Lp=Qo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:Jo,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ea,topsort:na},Ws=Jm,Ge={Graph:Ws.Graph,json:tp,alg:zp,version:Ws.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Us(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Us(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function Us(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ge.Graph,Gp=Vp;var Yp=Up;let Wp=()=>1;function Up(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Wp);return Xp(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Xp(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)rr(e,t,n,o);for(;o=s.dequeue();)rr(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(rr(e,t,n,o,!0));break}}}return r}function rr(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,Sr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,Sr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{Sr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function Sr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new ia({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Wr(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Wr(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=ua(ca(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Vn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Vn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),oa(e,"border",s,t)}function og(e,t=aa){const n=[];for(let r=0;raa){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function ca(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Vn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function la(e){var t=++ug;return e+(""+t)}function ua(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Wr(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=Ne.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=Ne;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=Ne;var Bn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ge.Graph,In=Bn.slack,da=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!In(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=In(t,s)),it.node(r).rank+=n)}var Rg=da,Xs=Bn.slack,Ig=Bn.longestPath,Tg=Ge.alg.preorder,Og=Ge.alg.postorder,Lg=Ne.simplify,Dg=vt;vt.initLowLimValues=Xr;vt.initCutValues=Ur;vt.calcCutValue=fa;vt.leaveEdge=ma;vt.enterEdge=pa;vt.exchangeEdges=ga;function vt(e){e=Lg(e),Ig(e);var t=Rg(e);Xr(t),Ur(t,e);for(var n,r;n=ma(t);)r=pa(t,e,n),ga(t,e,n,r)}function Ur(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=fa(e,t,n)}function fa(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Xr(e,t){arguments.length<2&&(t=e.nodes()[0]),ha(e,{},1,t)}function ha(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ha(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function ma(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function pa(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===qs(e,e.node(u.v),a)&&c!==qs(e,e.node(u.w),a));return l.reduce((u,d)=>Xs(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function qs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Bn,ya=Fg.longestPath,Vg=da,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Ks(e);break;case"tight-tree":Ug(e);break;case"longest-path":Wg(e);break;case"none":break;default:Ks(e)}}var Wg=ya;function Ug(e){ya(e),Vg(e)}function Ks(e){Bg(e)}var Xg=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Tn=Ne;var Qg={run:Jg,cleanup:ny};function Jg(e){let t=Tn.addDummyNode(e,"root",{},"_root"),n=ey(e),r=Object.values(n),s=Tn.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=ty(e)+1;e.children().forEach(a=>xa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function xa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Tn.addBorderNode(e,"_bt"),l=Tn.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{xa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,p=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,b=f!==p?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:b,nestingEdge:!0}),e.setEdge(p,l,{weight:y,minlen:b,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function ey(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function ty(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function ny(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let ry=Ne;var sy=iy;function iy(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iQs(e.node(t))),e.edges().forEach(t=>Qs(e.edge(t)))}function Qs(e){let t=e.width;e.width=e.height,e.height=t}function ly(e){e.nodes().forEach(t=>sr(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(sr),Object.hasOwn(n,"y")&&sr(n)})}function sr(e){e.y=-e.y}function uy(e){e.nodes().forEach(t=>ir(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ir),Object.hasOwn(n,"x")&&ir(n)})}function ir(e){let t=e.x;e.x=e.y,e.y=t}let Js=Ne;var dy=fy;function fy(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=Js.applyWithChunking(Math.max,r),i=Js.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let hy=Ne.zipObject;var my=py;function py(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var yy=xy;function xy(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let wy=Ne;var by=vy;function vy(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _y(r)}function _y(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&Ey(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>wy.pick(s,["vs","i","barycenter","weight"]))}function Ey(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let Ny=Ne;var Sy=ky;function ky(e,t){let n=Ny.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(jy(!!t)),c=ei(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ei(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ei(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function jy(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Cy=yy,$y=by,My=Sy;var Ay=ba;function ba(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=Cy(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=ba(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&Iy(m,f)}});let u=$y(l,n);Ry(u,c);let d=My(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function Ry(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function Iy(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let Ty=Ge.Graph,Oy=Ne;var Ly=Dy;function Dy(e,t,n,r){r||(r=e.nodes());let s=Py(e),i=new Ty({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function Py(e){for(var t;e.hasNode(t=Oy.uniqueId("_root")););return t}var zy=Hy;function Hy(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let Fy=dy,Vy=my,By=Ay,Gy=Ly,Yy=zy,Wy=Ge.Graph,yn=Ne;var Uy=va;function va(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,va);return}let n=yn.maxRank(e),r=ti(e,yn.range(1,n+1),"inEdges"),s=ti(e,yn.range(n-1,-1,-1),"outEdges"),i=Fy(e);if(ni(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){Xy(c%2?r:s,c%4>=2),i=yn.buildLayerMatrix(e);let u=Vy(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return Gy(e,i,n,r.get(i)||[])})}function Xy(e,t){let n=new Wy;e.forEach(function(r){let s=r.graph().root,i=By(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Yy(r,n,i.vs)})}function ni(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let qy=Ge.Graph,et=Ne;var Ky={positionX:a0};function Zy(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=Jy(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(p=>{e.predecessors(p).forEach(y=>{let b=e.node(y),g=b.order;(g{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&_a(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function Jy(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function _a(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function e0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function t0(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let p=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((p,y)=>Math.min(p,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function r0(e,t,n,r){let s=new qy,i=e.graph(),o=c0(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function s0(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=l0(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-et.applyWithChunking(Math.min,l);o!=="l"&&(u=s-et.applyWithChunking(Math.max,l)),u&&(e[a]=et.mapValues(c,d=>d+u))})})}function o0(e,t){return et.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function a0(e){let t=et.buildLayerMatrix(e),n=Object.assign(Zy(e,t),Qy(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=t0(e,s,n,c),u=n0(e,s,l.root,l.align,a==="r");a==="r"&&(u=et.mapValues(u,d=>-d)),r[o+a]=u})});let i=s0(e,r);return i0(r,i),o0(r,e.graph().align)}function c0(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function l0(e,t){return e.node(t).width}let Ea=Ne,u0=Ky.positionX;var d0=f0;function f0(e){e=Ea.asNonCompoundGraph(e),h0(e),Object.entries(u0(e)).forEach(([t,n])=>e.node(t).x=n)}function h0(e){let t=Ea.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ri=pg,si=bg,m0=Gg,p0=Ne.normalizeRanks,g0=Xg,y0=Ne.removeEmptyRanks,ii=Qg,x0=sy,oi=oy,w0=Uy,b0=d0,Pe=Ne,v0=Ge.Graph;var _0=E0;function E0(e,t){let n=t&&t.debugTiming?Pe.time:Pe.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>I0(e));n(" runLayout",()=>N0(r,n,t)),n(" updateInputGraph",()=>S0(e,r))})}function N0(e,t,n){t(" makeSpaceForEdgeLabels",()=>T0(e)),t(" removeSelfEdges",()=>B0(e)),t(" acyclic",()=>ri.run(e)),t(" nestingGraph.run",()=>ii.run(e)),t(" rank",()=>m0(Pe.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>O0(e)),t(" removeEmptyRanks",()=>y0(e)),t(" nestingGraph.cleanup",()=>ii.cleanup(e)),t(" normalizeRanks",()=>p0(e)),t(" assignRankMinMax",()=>L0(e)),t(" removeEdgeLabelProxies",()=>D0(e)),t(" normalize.run",()=>si.run(e)),t(" parentDummyChains",()=>g0(e)),t(" addBorderSegments",()=>x0(e)),t(" order",()=>w0(e,n)),t(" insertSelfEdges",()=>G0(e)),t(" adjustCoordinateSystem",()=>oi.adjust(e)),t(" position",()=>b0(e)),t(" positionSelfEdges",()=>Y0(e)),t(" removeBorderNodes",()=>V0(e)),t(" normalize.undo",()=>si.undo(e)),t(" fixupEdgeLabelCoords",()=>H0(e)),t(" undoCoordinateSystem",()=>oi.undo(e)),t(" translateGraph",()=>P0(e)),t(" assignNodeIntersects",()=>z0(e)),t(" reversePoints",()=>F0(e)),t(" acyclic.undo",()=>ri.undo(e))}function S0(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let k0=["nodesep","edgesep","ranksep","marginx","marginy"],j0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},C0=["acyclicer","ranker","rankdir","align"],$0=["width","height","rank"],ai={width:0,height:0},M0=["minlen","weight","width","height","labeloffset"],A0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},R0=["labelpos"];function I0(e){let t=new v0({multigraph:!0,compound:!0}),n=ar(e.graph());return t.setGraph(Object.assign({},j0,or(n,k0),Pe.pick(n,C0))),e.nodes().forEach(r=>{let s=ar(e.node(r));const i=or(s,$0);Object.keys(ai).forEach(o=>{i[o]===void 0&&(i[o]=ai[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=ar(e.edge(r));t.setEdge(r,Object.assign({},A0,or(s,M0),Pe.pick(s,R0)))}),t}function T0(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function O0(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};Pe.addDummyNode(e,"edge-proxy",i,"_ep")}})}function L0(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function D0(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function P0(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function z0(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(Pe.intersectRect(r,i)),n.points.push(Pe.intersectRect(s,o))})}function H0(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function F0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function V0(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function B0(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function G0(e){var t=Pe.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{Pe.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Y0(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function or(e,t){return Pe.mapValues(Pe.pick(e,t),Number)}function ar(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let W0=Ne,U0=Ge.Graph;var X0={debugOrdering:q0};function q0(e){let t=W0.buildLayerMatrix(e),n=new U0({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var K0="1.1.8",Z0={graphlib:Ge,layout:_0,debug:X0,util:{time:Ne.time,notime:Ne.notime},version:K0};const ci=bi(Z0),Ue=264,Q0=44,J0=26,ex=14;function dt(e){const t=Math.max(e.attributes.length,1);return Q0+t*J0+ex}const tx=40;function cr(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?fi(e,n,o):r==="clustered"?di(e,t,n,o,i):r==="hierarchical"||e.length<=tx?li(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?di(e,t,n,o,i):fi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Na(e,t,n,r=!1,s="LR"){const i=new ci.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Ue,height:d?dt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ci.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?dt(m):120,p=d.x-Ue/2,y=d.y-f/2;return a=Math.max(a,p+Ue),c=Math.max(c,y+f),{...u,position:{x:p,y}}}),width:a,height:c}}function li(e,t,n,r="LR"){return Na(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?dt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Ue+Sa);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Ue)}),i+=Math.max(...c.map(l=>n(l.id)))+ka}return{nodes:s,width:o,height:i}}const ui=120;function di(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),p=new Set(f.map(E=>E.id));let y=0;for(const E of t)p.has(E.source)&&p.has(E.target)&&y++;const g=f.length<=8&&y>=f.length-1?Na(f,t,n,!0,s):rx(f,n);return{name:m,...g}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const Sa=40,ka=40;function fi(e,t,n){const r=l=>{const u=t.get(l);return u?dt(u):120},s=[...e].sort((l,u)=>{var y,b;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,p=((b=t.get(u.id))==null?void 0:b.name)??u.id;return f.localeCompare(p)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Ue+Sa)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ka}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function an({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],ja=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var v,M;const[r,s]=w.useState(((v=e.conceptual)==null?void 0:v.name)??e.name),[i,o]=w.useState([]),[a,c]=w.useState(null),[l,u]=w.useState(null),[d,m]=w.useState("skos:exactMatch"),[f,p]=w.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,b]=w.useState([]),[g,E]=w.useState("");w.useEffect(()=>{Zo().then(j=>b(j.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return o([]);Ko(r,g||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(j)},[r,g]);const C=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(an,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(g===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(j=>h.jsx("button",{className:"src-chip"+(g===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:g?`Search within ${g}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(j=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===j.iri?" picked":""),onClick:()=>u(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:sx.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>p(j.target.value),children:ja.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:C,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var v,M,j;const[s,i]=w.useState(((v=e.term_map)==null?void 0:v.subject_template)??""),[o,a]=w.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},p=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${p}:`,b=(j=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:j.members.map(_=>{var I;return(I=e.attributes.find(N=>N.id===_))==null?void 0:I.name}).filter(Boolean),g=b&&b.length?`${y}${e.id}/${b.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,C=s.trim()||g;return h.jsxs(an,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",C]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((b==null?void 0:b[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=w.useState(""),[o,a]=w.useState(""),[c,l]=w.useState(""),[u,d]=w.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const p=f==null?void 0:f.created_id;n(),p&&r(p)})};return h.jsxs(an,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),ja.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const Ca=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(v=>v.id===t),c=e.entities.find(v=>v.id===n),l=w.useMemo(()=>c==null?void 0:c.attributes.find(v=>v.role==="business_key"),[c]),[u,d]=w.useState(r??""),[m,f]=w.useState(s??(l==null?void 0:l.id)??""),[p,y]=w.useState("many_to_one"),[b,g]=w.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",C=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:p,optionality:b}).then(o);return h.jsxs(an,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:p,onChange:v=>y(v.target.value),children:Ca.map(v=>h.jsx("option",{children:v},v))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:v=>d(v.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(v=>h.jsx("option",{value:v.id,children:v.name},v.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:v=>f(v.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(v=>h.jsxs("option",{value:v.id,children:[v.name,v.role==="business_key"?" 🔑":""]},v.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:b,onChange:v=>g(v.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:C,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=g=>{var E;return((E=t.entities.find(C=>C.id===g))==null?void 0:E.name)??"?"},[i,o]=w.useState(e.name),[a,c]=w.useState(e.cardinality),[l,u]=w.useState(e.optionality),[d,m]=w.useState(e.identifying),[f,p]=w.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},b=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(an,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:g=>o(g.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:g=>c(g.target.value),children:Ca.map(g=>h.jsx("option",{children:g},g))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:g=>u(g.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:g=>m(g.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:b,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>p(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const hi=10,ux=6,$t=24;function dx(e,t){return t?e:Math.round(e/hi)*hi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-$t,o.right+$t);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eo.left&&ni.left&&nte.transform[2]),[m,f]=w.useState(null),p=w.useRef(!1),y=w.useRef(0),b=c==null?void 0:c.onRouteChange,g=!!b,E=m??(c==null?void 0:c.routeX),[C,v,M]=Mn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),j=c==null?void 0:c.sourceCard,_=c==null?void 0:c.targetCard,I=E!=null&&j&&_?xx({x:n,y:r},{x:s,y:i},E,o===U.Left?-1:1,a===U.Left?-1:1,j,_):null,N=I?I.path:C,R=c==null?void 0:c.relationship,P=(c==null?void 0:c.dimmed)??!1,V=(R==null?void 0:R.cardinality)??"many_to_one",H=(R==null?void 0:R.optionality)==="optional",x=(R==null?void 0:R.identifying)??!1,$=V==="many_to_one"||V==="many_to_many",S=V==="one_to_many"||V==="many_to_many",O="rel-edge"+(l?" selected":"")+(P?" dimmed":""),D=((c==null?void 0:c.memberCount)??0)>1,k=c==null?void 0:c.onHoverEdge,T=E??v,L=M,z=T,W=L,G=I?I.sourceOut:{ox:o===U.Left?-1:1,oy:0},K=I?I.targetOut:{ox:a===U.Left?-1:1,oy:0},Z={x:n,y:r},ne=I&&K.oy!==0&&_?{x:E,y:K.oy<0?_.top:_.bottom}:{x:s,y:i},ie=w.useCallback(te=>b&&R&&b(R.id,te),[b,R]),re=w.useCallback(te=>{var _e,je;if(!g||te.button!==0)return;te.stopPropagation(),(je=(_e=te.target).setPointerCapture)==null||je.call(_e,te.pointerId),p.current=!0,y.current=0;const ve=u({x:te.clientX,y:te.clientY}).x;let de=0,pe=E??T;const le=ze=>{const $e=u({x:ze.clientX,y:ze.clientY});y.current=Math.max(y.current,Math.abs($e.x-ve)),pe=mx($e.x,{shift:ze.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),de||(de=requestAnimationFrame(()=>{de=0,f(pe)}))},X=()=>{window.removeEventListener("pointermove",le),window.removeEventListener("pointerup",X),de&&cancelAnimationFrame(de),p.current=!1,f(null),y.current>=pi&&ie(pe)};window.addEventListener("pointermove",le),window.addEventListener("pointerup",X)},[g,u,E,T,c,n,s,ie]),ae=w.useCallback(te=>{y.current>=pi&&(te.stopPropagation(),y.current=0)},[]),ye=w.useCallback(te=>{g&&(te.stopPropagation(),ie(null))},[g,ie]);return h.jsxs("g",{className:O,onMouseEnter:k?()=>k(R.id):void 0,onMouseLeave:k?()=>k(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:N,fill:"none",strokeDasharray:x?void 0:"6 4"}),h.jsx("path",{d:N,fill:"none",strokeWidth:16/d,stroke:"transparent"}),h.jsx(gi,{x:Z.x,y:Z.y,out:G,many:$,optional:H}),h.jsx(gi,{x:ne.x,y:ne.y,out:K,many:S,optional:!1}),g&&((c==null?void 0:c.hovered)||l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:re,onClickCapture:ae,onDoubleClick:ye,children:[h.jsx("rect",{x:T-20/d,y:Math.min(r,i),width:40/d,height:Math.max(Math.abs(i-r),24/d),fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:T-5.5/d,y:L-11/d,width:11/d,height:22/d,rx:5/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L-4.5/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L+4.5/d,r:1.1/d})]}),(l||D)&&R&&h.jsxs("text",{className:"rel-label",x:z,y:W-8,children:[l?R.verb_phrase||R.name:"",D?`${l?" ":""}(${c.memberCount})`:""]})]})});function gi({x:e,y:t,out:n,many:r,optional:s}){const{ox:a,oy:c}=n,l=-c,u=a,d=p=>({x:e+a*p,y:t+c*p}),m=(p,y)=>({x:e+a*p+l*y,y:t+c*p+u*y}),f=[];if(r){const p=d(12),y=m(0,-7),b=d(0),g=m(0,7);f.push(h.jsx("path",{className:"rel-glyph",d:`M ${p.x} ${p.y} L ${y.x} ${y.y} M ${p.x} ${p.y} L ${b.x} ${b.y} M ${p.x} ${p.y} L ${g.x} ${g.y}`,fill:"none"},"foot"))}else{const p=m(9,-7),y=m(9,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:y.x,y2:y.y},"one"))}if(s){const p=d(18);f.push(h.jsx("circle",{className:"rel-glyph ring",cx:p.x,cy:p.y,r:4},"opt"))}else{const p=m(17,-7),y=m(17,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:y.x,y2:y.y},"mand"))}return h.jsx(h.Fragment,{children:f})}const bx={entity:Pm},vx={relationship:wx},yi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],xi="#8a7d6a";function _x(e,t,n){const s=Ue;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function Ex(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Br,targetHandle:n(e.to.entity,s)?s:Gr}}function Jx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:p,fitBounds:y,getNodes:b}=on(),[g,E]=w.useState([]),[C,v]=w.useState([]),M=w.useRef(!1),j=w.useMemo(()=>{const F=u&&u.size>0?[...u].sort():null;return F?"sa:"+F.join("+"):"__all__"},[u]),_=w.useRef(null),[I,N]=w.useState(0),R=w.useRef(new Map),P=w.useRef(null);w.useEffect(()=>{if(!f){_.current=null;return}const F=R.current.get(j);if(F){_.current=F,M.current=!1,N(B=>B+1);return}let Y=!1;return f.load(j).then(B=>{Y||(R.current.set(j,B),_.current=B,M.current=!1,N(Q=>Q+1))}),()=>{Y=!0}},[f,j]);const[V,H]=w.useState(null),[x,$]=w.useState(null),[S,O]=w.useState(!1),[D,k]=w.useState(null),[T,L]=w.useState(null),[z,W]=w.useState(null),[G,K]=w.useState(null),Z=w.useRef({}),ne=!t.canEdit,ie=w.useRef(null),re=w.useCallback(()=>{f&&(ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>{const F={};for(const Q of b())Q.hidden||(F[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,q]of Object.entries(Z.current))Y[Q]={routeX:Math.round(q)};const B={nodes:F,edges:Y};R.current.set(j,B),_.current=B,f.save(j,B)},800))},[f,b,j]),ae=w.useCallback((F,Y)=>{Y==null?delete Z.current[F]:Z.current[F]=Y,v(B=>B.map(Q=>Q.id===F?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),re()},[re]),ye=w.useMemo(()=>{const F=new Map;return e.subject_areas.forEach((Y,B)=>F.set(Y.id,yi[B%yi.length])),F},[e]),te=w.useMemo(()=>{const F=new Map;return e.entities.forEach(Y=>F.set(Y.id,Y)),F},[e]),me=w.useMemo(()=>{const F=new Map,Y=new Map;return e.subject_areas.forEach(B=>{(B.members??[]).forEach(Q=>Y.set(Q,{id:B.id,name:B.name}))}),e.entities.forEach(B=>{var se,ge;const Q=(se=B.conceptual)!=null&&se.id?Y.get(B.conceptual.id):void 0,q=(ge=B.conceptual)==null?void 0:ge.subject_area,ee=Q??(q?{id:q.id,name:q.name??q.id}:void 0);ee&&F.set(B.id,ee)}),F},[e]),ve=w.useCallback(F=>{var B;if(!u||u.size===0)return!1;const Y=(B=me.get(F))==null?void 0:B.id;return!(Y&&u.has(Y))},[u,me]),de=w.useMemo(()=>{const F=new Map,Y=(B,Q)=>{if(!Q.length)return;const q=F.get(B)??new Set;Q.forEach(ee=>q.add(ee)),F.set(B,q)};for(const B of e.relationships)Y(B.from.entity,B.from.attributes),Y(B.to.entity,B.to.attributes);return F},[e]);w.useEffect(()=>{var ge;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const J of e.entities)(J.name.toLowerCase()+" "+(((ge=J.conceptual)==null?void 0:ge.name.toLowerCase())??"")+" "+J.attributes.map(ce=>ce.name.toLowerCase()).join(" ")).includes(F)&&Y.add(J.id);const B=new Set;if(r){B.add(r);for(const J of e.relationships)J.from.entity===r&&B.add(J.to.entity),J.to.entity===r&&B.add(J.from.entity)}const Q=e.entities.map(J=>{const fe=F!==""&&!Y.has(J.id),ce=r!==null&&!B.has(J.id);return{id:J.id,type:"entity",position:{x:0,y:0},hidden:ve(J.id),data:{entity:J,color:(()=>{const xe=me.get(J.id);return xe?ye.get(xe.id)??xi:xi})(),dimmed:fe||ce,highlighted:F!==""&&Y.has(J.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(J.id))??!1,onToggleExpand:l,endpointAttrs:de.get(J.id),highlightAttrs:void 0,onHoverAttr:W}}}),q=e.relationships.filter(J=>te.has(J.from.entity)&&te.has(J.to.entity)).map(J=>{const{sourceHandle:fe,targetHandle:ce}=Ex(J,te),xe=r!==null&&J.from.entity!==r&&J.to.entity!==r;return{id:J.id,source:J.from.entity,target:J.to.entity,sourceHandle:fe,targetHandle:ce,type:"relationship",data:{relationship:J,dimmed:xe,memberCount:Math.max(J.from.attributes.length,J.to.attributes.length),onHoverEdge:K}}}),ee=_.current;if(Z.current={},ee)for(const[J,fe]of Object.entries(ee.edges))Z.current[J]=fe.routeX;const se=J=>{const fe=new Map;for(const ce of J)fe.set(ce.id,{left:ce.position.x,right:ce.position.x+Ue,top:ce.position.y,bottom:ce.position.y+dt(ce.data.entity)});v(q.map(ce=>({...ce,data:{...ce.data,routeX:Z.current[ce.id],onRouteChange:f?ae:void 0,sourceCard:fe.get(ce.source),targetCard:fe.get(ce.target)}})))};E(J=>{const fe=new Map(J.map(ue=>[ue.id,ue.position])),ce=Q.every(ue=>fe.has(ue.id)),xe=((u==null?void 0:u.size)??0)>0;if(M.current&&ce&&J.length>=Q.length&&!xe){const ue=Q.map(Ze=>({...Ze,position:fe.get(Ze.id)??Ze.position}));return se(ue),ue}const Me=xe?Q.filter(ue=>!ue.hidden):Q,Ye=cr(Me,q,te,"auto",me),Ke=new Map(Ye.map(ue=>[ue.id,ue.position])),Te=(ee==null?void 0:ee.nodes)??{},_t=Object.keys(Te).length>0,Et=[],He=Q.map(ue=>{const Ze=Te[ue.id];if(Ze){const Dt={x:Ze.x,y:Ze.y};return Et.push({x:Dt.x,y:Dt.y,w:Ue,h:dt(ue.data.entity)}),{...ue,position:Dt}}return Ke.has(ue.id)?{...ue,position:Ke.get(ue.id)}:fe.has(ue.id)&&M.current?{...ue,position:fe.get(ue.id)}:ue});if(_t)for(const ue of He)Te[ue.id]||ue.hidden||(ue.position=_x(ue.position,dt(ue.data.entity),Et),Et.push({x:ue.position.x,y:ue.position.y,w:Ue,h:dt(ue.data.entity)}));return M.current=!0,_t||requestAnimationFrame(()=>p({padding:.15,duration:300})),se(He),He})},[e,i,r,o,a,c,l,ye,te,me,ve,u,de,p,f,ae,I]);const pe=w.useMemo(()=>{const F=new Set,Y=new Set,B=new Map,Q=(q,ee)=>{if(!ee.length)return;const se=B.get(q)??new Set;ee.forEach(ge=>se.add(ge)),B.set(q,se)};if(z)for(const q of e.relationships)(q.from.attributes.includes(z)||q.to.attributes.includes(z))&&(F.add(q.id),Y.add(q.from.entity),Y.add(q.to.entity),Q(q.from.entity,q.from.attributes),Q(q.to.entity,q.to.attributes));if(G){const q=e.relationships.find(ee=>ee.id===G);q&&(Q(q.from.entity,q.from.attributes),Q(q.to.entity,q.to.attributes))}return{active:z!==null,relsForAttr:F,entsForAttr:Y,hitAttrsByEntity:B}},[e,z,G]);w.useEffect(()=>{var Q;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const q of e.entities)(q.name.toLowerCase()+" "+(((Q=q.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+q.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(q.id);const B=new Set;if(r){B.add(r);for(const q of e.relationships)q.from.entity===r&&B.add(q.to.entity),q.to.entity===r&&B.add(q.from.entity)}E(q=>q.map(ee=>{const se=F!==""&&!Y.has(ee.id),ge=r!==null&&!B.has(ee.id),J=pe.active&&!pe.entsForAttr.has(ee.id),fe=se||ge||J,ce=F!==""&&Y.has(ee.id)||pe.active&&pe.entsForAttr.has(ee.id),xe=pe.hitAttrsByEntity.get(ee.id);return ee.data.dimmed===fe&&ee.data.highlighted===ce&&ee.data.highlightAttrs===xe?ee:{...ee,data:{...ee.data,dimmed:fe,highlighted:ce,highlightAttrs:xe}}})),v(q=>q.map(ee=>{var Ye,Ke,Te;const se=(Ye=ee.data)==null?void 0:Ye.relationship,ge=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,J=pe.active&&!pe.relsForAttr.has(ee.id),fe=ge||J,ce=G===ee.id,xe=r!==null&&se!==void 0&&(se.from.entity===r||se.to.entity===r),Me=ce||xe?1e3:0;return((Ke=ee.data)==null?void 0:Ke.dimmed)===fe&&((Te=ee.data)==null?void 0:Te.hovered)===ce&&ee.zIndex===Me?ee:{...ee,zIndex:Me,data:{...ee.data,dimmed:fe,hovered:ce}}}))},[pe,G,i,r,e]),w.useEffect(()=>{var Q;const F=i.trim().toLowerCase();if(!F)return;const Y=new Set;for(const q of e.entities)(q.name.toLowerCase()+" "+(((Q=q.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+q.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(q.id);if(!Y.size)return;const B=requestAnimationFrame(()=>{const q=b().filter(se=>Y.has(se.id));if(!q.length)return;const ee=Mf(q);y(ee,{padding:.35,duration:400})});return()=>cancelAnimationFrame(B)},[i,e,b,y]);const le=w.useCallback((F="auto",Y="LR")=>{P.current=Object.fromEntries(b().map(B=>[B.id,{x:B.position.x,y:B.position.y}])),E(B=>cr(B,C,te,F,me,Y)),requestAnimationFrame(()=>p({padding:.15,duration:300})),re()},[C,te,me,p,b,re]),X=w.useCallback(()=>{const F=P.current;F&&(E(Y=>Y.map(B=>F[B.id]?{...B,position:F[B.id]}:B)),P.current=null,re())},[re]),_e=w.useCallback(()=>{f==null||f.reset(j),R.current.delete(j),_.current=null,Z.current={},M.current=!1,v(F=>F.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(F=>{const Y=cr(F,C,te,"auto",me);return requestAnimationFrame(()=>p({padding:.15,duration:300})),Y})},[f,j,C,te,me,p]),je=w.useCallback(F=>{s(F),E(Y=>(Y.find(Q=>Q.id===F)&&requestAnimationFrame(()=>p({nodes:[{id:F}],padding:.4,duration:400})),Y))},[p,s]);w.useImperativeHandle(m,()=>({relayout:le,fitView:()=>p({padding:.15,duration:300}),focusEntity:je,newEntity:()=>O(!0),resetLayout:_e,undoRelayout:X}),[le,p,je,_e,X]);const ze=w.useCallback(F=>{if(ne||!F.source||!F.target||F.source===F.target)return;const Y=F.sourceHandle&&F.sourceHandle!==Br?F.sourceHandle:void 0,B=F.targetHandle&&F.targetHandle!==Gr?F.targetHandle:void 0;k({from:F.source,to:F.target,fromAttr:Y,toAttr:B})},[ne]),$e=w.useCallback(async(F,Y)=>{try{return await n(F,Y)}catch(B){throw d==null||d(B instanceof Error?B.message:String(B)),B}},[n,d]),qe=r?te.get(r)??null:null,Ie=e.relationships.find(F=>F.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Go,{nodes:g,edges:C,nodeTypes:bx,edgeTypes:vx,onNodeClick:(F,Y)=>s(Y.id),onEdgeDoubleClick:(F,Y)=>!ne&&L(Y.id),onPaneClick:()=>{s(null),L(null)},onNodeDragStop:(F,Y)=>{E(B=>B.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),re()},onConnect:ze,nodesConnectable:!ne,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:De.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:F=>{var Y;return((Y=F.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),qe&&h.jsx(Hm,{entity:qe,doc:e,caps:t,exec:$e,onClose:()=>s(null),onFocusEntity:je,onAlign:H,onEditMapping:$}),V&&h.jsx(ix,{entity:V,exec:$e,onClose:()=>H(null)}),x&&h.jsx(ox,{entity:x,doc:e,exec:$e,onClose:()=>$(null)}),S&&h.jsx(ax,{doc:e,exec:$e,onClose:()=>O(!1),onCreated:je}),D&&h.jsx(cx,{doc:e,fromId:D.from,toId:D.to,initialFromAttr:D.fromAttr,initialToAttr:D.toAttr,exec:$e,onClose:()=>k(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:$e,onClose:()=>L(null)})]})}function ew({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(Nx,{}),e==="layers"&&h.jsx(kx,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(jx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Cx,{readOnly:n})]})}function Nx(){const[e,t]=w.useState(""),[n,r]=w.useState([]),[s,i]=w.useState({loaded:0,vocabs:[]}),[o,a]=w.useState(null),[c,l]=w.useState([]),[u,d]=w.useState("");w.useEffect(()=>{Zo().then(f=>l(f.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const f=setTimeout(()=>{Ko(e||"a",u||void 0).then(p=>{r(e?p.results:[]),i({loaded:p.loaded_terms,vocabs:p.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=w.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const Sx=["industry","core","domain","specialised"];function kx({refreshKey:e,onFocusEntity:t}){const[n,r]=w.useState(null),[s,i]=w.useState(null);if(w.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),Sx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function jx({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=w.useState(null),[i,o]=w.useState(""),[a,c]=w.useState(""),[l,u]=w.useState(!1),d=w.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` +`);return h.jsxs("span",{className:"badge ontology",title:I,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),g.length>0&&h.jsx("div",{className:"attr-section keys",children:g.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),v>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${v} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,p,y,b,g,E,C,v,M,j,_,I;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(N=>N.from.entity===e.id||N.to.entity===e.id),d=N=>{var R;return((R=t.entities.find(P=>P.id===N))==null?void 0:R.name)??N};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Je,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,name:N})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Je,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,physical_name:N})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Je,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:N=>r("set_definition",{id:e.id,definition:N})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((p=l==null?void 0:l.ontology_refs)==null?void 0:p.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(b=e.term_map)!=null&&b.class_iri?"Edit mapping…":"Map…"}),(((g=e.term_map)==null?void 0:g.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),(C=e.term_map)!=null&&C.subject_template||(v=e.term_map)!=null&&v.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Je,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:N=>{var R;return r("set_stewardship",{id:e.id,owner:N,steward:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Je,{value:((I=l==null?void 0:l.stewardship)==null?void 0:I.steward)??"",placeholder:"—",readOnly:c,onCommit:N=>{var R;return r("set_stewardship",{id:e.id,owner:((R=l==null?void 0:l.stewardship)==null?void 0:R.owner)??null,steward:N})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(N=>h.jsx(Wm,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(Um,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(N=>{const R=N.members.map(P=>{var V;return((V=e.attributes.find(H=>H.id===P))==null?void 0:V.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+N.type,children:N.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:N.name}),h.jsx("span",{className:"key-cols",children:R})]},N.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([N,R])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:N}),h.jsx("td",{className:"udp-val",children:String(R)})]},N))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(N=>{const R=N.from.entity===e.id?N.to.entity:N.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(R),children:[h.jsx("span",{className:"rel-card",children:Xm(N,e.id)}),d(R)]}),(N.verb_phrase||N.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Je,{value:N.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,verb_phrase:P})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Je,{value:N.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,inverse_verb_phrase:P})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${N.name}`,onClick:()=>r("delete_relationship",{id:N.id}),children:"✕"})]},N.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var N;return(N=navigator.clipboard)==null?void 0:N.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Je({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=w.useState(e);w.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Wm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Je,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Je,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Um({entity:e,exec:t}){const[n,r]=w.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Xm(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Vs="";let Km=class{constructor(t){Ee(this,"_isDirected",!0);Ee(this,"_isMultigraph",!1);Ee(this,"_isCompound",!1);Ee(this,"_label");Ee(this,"_defaultNodeLabelFn",()=>{});Ee(this,"_defaultEdgeLabelFn",()=>{});Ee(this,"_nodes",{});Ee(this,"_in",{});Ee(this,"_preds",{});Ee(this,"_out",{});Ee(this,"_sucs",{});Ee(this,"_edgeObjs",{});Ee(this,"_edgeLabels",{});Ee(this,"_nodeCount",0);Ee(this,"_edgeCount",0);Ee(this,"_parent");Ee(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Bs(this._preds[n],t),Bs(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Gs(this._preds[n],t),Gs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Bs(e,t){e[t]?e[t]++:e[t]=1}function Gs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Vs+i+Vs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function nr(e,t){return Wt(e,t.v,t.w,t.name)}var Yr=Km,Qm="2.2.4",Jm={Graph:Yr,version:Qm},ep=Yr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){Ee(this,"_arr",[]);Ee(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=Jo,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ea=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ea,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),sa(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),sa(t(i),o=>s.push(o)))}}function sa(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=ra,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=ra,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Yr,Lp=Qo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:Jo,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ea,topsort:na},Ws=Jm,Ge={Graph:Ws.Graph,json:tp,alg:zp,version:Ws.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Us(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Us(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function Us(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ge.Graph,Gp=Vp;var Yp=Up;let Wp=()=>1;function Up(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Wp);return Xp(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Xp(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)rr(e,t,n,o);for(;o=s.dequeue();)rr(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(rr(e,t,n,o,!0));break}}}return r}function rr(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,Sr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,Sr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{Sr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function Sr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new ia({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Wr(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Wr(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=ua(ca(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Vn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Vn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),oa(e,"border",s,t)}function og(e,t=aa){const n=[];for(let r=0;raa){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function ca(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Vn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function la(e){var t=++ug;return e+(""+t)}function ua(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Wr(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=Ne.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=Ne;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=Ne;var Bn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ge.Graph,In=Bn.slack,da=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!In(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=In(t,s)),it.node(r).rank+=n)}var Rg=da,Xs=Bn.slack,Ig=Bn.longestPath,Tg=Ge.alg.preorder,Og=Ge.alg.postorder,Lg=Ne.simplify,Dg=vt;vt.initLowLimValues=Xr;vt.initCutValues=Ur;vt.calcCutValue=fa;vt.leaveEdge=ma;vt.enterEdge=pa;vt.exchangeEdges=ga;function vt(e){e=Lg(e),Ig(e);var t=Rg(e);Xr(t),Ur(t,e);for(var n,r;n=ma(t);)r=pa(t,e,n),ga(t,e,n,r)}function Ur(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=fa(e,t,n)}function fa(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Xr(e,t){arguments.length<2&&(t=e.nodes()[0]),ha(e,{},1,t)}function ha(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ha(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function ma(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function pa(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===qs(e,e.node(u.v),a)&&c!==qs(e,e.node(u.w),a));return l.reduce((u,d)=>Xs(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function qs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Bn,ya=Fg.longestPath,Vg=da,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Ks(e);break;case"tight-tree":Ug(e);break;case"longest-path":Wg(e);break;case"none":break;default:Ks(e)}}var Wg=ya;function Ug(e){ya(e),Vg(e)}function Ks(e){Bg(e)}var Xg=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Tn=Ne;var Qg={run:Jg,cleanup:ny};function Jg(e){let t=Tn.addDummyNode(e,"root",{},"_root"),n=ey(e),r=Object.values(n),s=Tn.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=ty(e)+1;e.children().forEach(a=>xa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function xa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Tn.addBorderNode(e,"_bt"),l=Tn.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{xa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,p=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,b=f!==p?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:b,nestingEdge:!0}),e.setEdge(p,l,{weight:y,minlen:b,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function ey(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function ty(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function ny(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let ry=Ne;var sy=iy;function iy(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iQs(e.node(t))),e.edges().forEach(t=>Qs(e.edge(t)))}function Qs(e){let t=e.width;e.width=e.height,e.height=t}function ly(e){e.nodes().forEach(t=>sr(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(sr),Object.hasOwn(n,"y")&&sr(n)})}function sr(e){e.y=-e.y}function uy(e){e.nodes().forEach(t=>ir(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ir),Object.hasOwn(n,"x")&&ir(n)})}function ir(e){let t=e.x;e.x=e.y,e.y=t}let Js=Ne;var dy=fy;function fy(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=Js.applyWithChunking(Math.max,r),i=Js.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let hy=Ne.zipObject;var my=py;function py(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var yy=xy;function xy(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let wy=Ne;var by=vy;function vy(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _y(r)}function _y(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&Ey(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>wy.pick(s,["vs","i","barycenter","weight"]))}function Ey(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let Ny=Ne;var Sy=ky;function ky(e,t){let n=Ny.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(jy(!!t)),c=ei(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ei(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ei(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function jy(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Cy=yy,$y=by,My=Sy;var Ay=ba;function ba(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=Cy(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=ba(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&Iy(m,f)}});let u=$y(l,n);Ry(u,c);let d=My(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function Ry(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function Iy(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let Ty=Ge.Graph,Oy=Ne;var Ly=Dy;function Dy(e,t,n,r){r||(r=e.nodes());let s=Py(e),i=new Ty({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function Py(e){for(var t;e.hasNode(t=Oy.uniqueId("_root")););return t}var zy=Hy;function Hy(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let Fy=dy,Vy=my,By=Ay,Gy=Ly,Yy=zy,Wy=Ge.Graph,yn=Ne;var Uy=va;function va(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,va);return}let n=yn.maxRank(e),r=ti(e,yn.range(1,n+1),"inEdges"),s=ti(e,yn.range(n-1,-1,-1),"outEdges"),i=Fy(e);if(ni(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){Xy(c%2?r:s,c%4>=2),i=yn.buildLayerMatrix(e);let u=Vy(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return Gy(e,i,n,r.get(i)||[])})}function Xy(e,t){let n=new Wy;e.forEach(function(r){let s=r.graph().root,i=By(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Yy(r,n,i.vs)})}function ni(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let qy=Ge.Graph,et=Ne;var Ky={positionX:a0};function Zy(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=Jy(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(p=>{e.predecessors(p).forEach(y=>{let b=e.node(y),g=b.order;(g{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&_a(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function Jy(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function _a(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function e0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function t0(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let p=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((p,y)=>Math.min(p,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function r0(e,t,n,r){let s=new qy,i=e.graph(),o=c0(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function s0(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=l0(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-et.applyWithChunking(Math.min,l);o!=="l"&&(u=s-et.applyWithChunking(Math.max,l)),u&&(e[a]=et.mapValues(c,d=>d+u))})})}function o0(e,t){return et.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function a0(e){let t=et.buildLayerMatrix(e),n=Object.assign(Zy(e,t),Qy(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=t0(e,s,n,c),u=n0(e,s,l.root,l.align,a==="r");a==="r"&&(u=et.mapValues(u,d=>-d)),r[o+a]=u})});let i=s0(e,r);return i0(r,i),o0(r,e.graph().align)}function c0(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function l0(e,t){return e.node(t).width}let Ea=Ne,u0=Ky.positionX;var d0=f0;function f0(e){e=Ea.asNonCompoundGraph(e),h0(e),Object.entries(u0(e)).forEach(([t,n])=>e.node(t).x=n)}function h0(e){let t=Ea.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ri=pg,si=bg,m0=Gg,p0=Ne.normalizeRanks,g0=Xg,y0=Ne.removeEmptyRanks,ii=Qg,x0=sy,oi=oy,w0=Uy,b0=d0,Pe=Ne,v0=Ge.Graph;var _0=E0;function E0(e,t){let n=t&&t.debugTiming?Pe.time:Pe.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>I0(e));n(" runLayout",()=>N0(r,n,t)),n(" updateInputGraph",()=>S0(e,r))})}function N0(e,t,n){t(" makeSpaceForEdgeLabels",()=>T0(e)),t(" removeSelfEdges",()=>B0(e)),t(" acyclic",()=>ri.run(e)),t(" nestingGraph.run",()=>ii.run(e)),t(" rank",()=>m0(Pe.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>O0(e)),t(" removeEmptyRanks",()=>y0(e)),t(" nestingGraph.cleanup",()=>ii.cleanup(e)),t(" normalizeRanks",()=>p0(e)),t(" assignRankMinMax",()=>L0(e)),t(" removeEdgeLabelProxies",()=>D0(e)),t(" normalize.run",()=>si.run(e)),t(" parentDummyChains",()=>g0(e)),t(" addBorderSegments",()=>x0(e)),t(" order",()=>w0(e,n)),t(" insertSelfEdges",()=>G0(e)),t(" adjustCoordinateSystem",()=>oi.adjust(e)),t(" position",()=>b0(e)),t(" positionSelfEdges",()=>Y0(e)),t(" removeBorderNodes",()=>V0(e)),t(" normalize.undo",()=>si.undo(e)),t(" fixupEdgeLabelCoords",()=>H0(e)),t(" undoCoordinateSystem",()=>oi.undo(e)),t(" translateGraph",()=>P0(e)),t(" assignNodeIntersects",()=>z0(e)),t(" reversePoints",()=>F0(e)),t(" acyclic.undo",()=>ri.undo(e))}function S0(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let k0=["nodesep","edgesep","ranksep","marginx","marginy"],j0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},C0=["acyclicer","ranker","rankdir","align"],$0=["width","height","rank"],ai={width:0,height:0},M0=["minlen","weight","width","height","labeloffset"],A0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},R0=["labelpos"];function I0(e){let t=new v0({multigraph:!0,compound:!0}),n=ar(e.graph());return t.setGraph(Object.assign({},j0,or(n,k0),Pe.pick(n,C0))),e.nodes().forEach(r=>{let s=ar(e.node(r));const i=or(s,$0);Object.keys(ai).forEach(o=>{i[o]===void 0&&(i[o]=ai[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=ar(e.edge(r));t.setEdge(r,Object.assign({},A0,or(s,M0),Pe.pick(s,R0)))}),t}function T0(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function O0(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};Pe.addDummyNode(e,"edge-proxy",i,"_ep")}})}function L0(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function D0(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function P0(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function z0(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(Pe.intersectRect(r,i)),n.points.push(Pe.intersectRect(s,o))})}function H0(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function F0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function V0(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function B0(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function G0(e){var t=Pe.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{Pe.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Y0(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function or(e,t){return Pe.mapValues(Pe.pick(e,t),Number)}function ar(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let W0=Ne,U0=Ge.Graph;var X0={debugOrdering:q0};function q0(e){let t=W0.buildLayerMatrix(e),n=new U0({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var K0="1.1.8",Z0={graphlib:Ge,layout:_0,debug:X0,util:{time:Ne.time,notime:Ne.notime},version:K0};const ci=bi(Z0),Ue=264,Q0=44,J0=26,ex=14;function dt(e){const t=Math.max(e.attributes.length,1);return Q0+t*J0+ex}const tx=40;function cr(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?fi(e,n,o):r==="clustered"?di(e,t,n,o,i):r==="hierarchical"||e.length<=tx?li(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?di(e,t,n,o,i):fi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Na(e,t,n,r=!1,s="LR"){const i=new ci.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Ue,height:d?dt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ci.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?dt(m):120,p=d.x-Ue/2,y=d.y-f/2;return a=Math.max(a,p+Ue),c=Math.max(c,y+f),{...u,position:{x:p,y}}}),width:a,height:c}}function li(e,t,n,r="LR"){return Na(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?dt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Ue+Sa);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Ue)}),i+=Math.max(...c.map(l=>n(l.id)))+ka}return{nodes:s,width:o,height:i}}const ui=120;function di(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),p=new Set(f.map(E=>E.id));let y=0;for(const E of t)p.has(E.source)&&p.has(E.target)&&y++;const g=f.length<=8&&y>=f.length-1?Na(f,t,n,!0,s):rx(f,n);return{name:m,...g}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const Sa=40,ka=40;function fi(e,t,n){const r=l=>{const u=t.get(l);return u?dt(u):120},s=[...e].sort((l,u)=>{var y,b;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,p=((b=t.get(u.id))==null?void 0:b.name)??u.id;return f.localeCompare(p)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Ue+Sa)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ka}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function an({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],ja=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var v,M;const[r,s]=w.useState(((v=e.conceptual)==null?void 0:v.name)??e.name),[i,o]=w.useState([]),[a,c]=w.useState(null),[l,u]=w.useState(null),[d,m]=w.useState("skos:exactMatch"),[f,p]=w.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,b]=w.useState([]),[g,E]=w.useState("");w.useEffect(()=>{Zo().then(j=>b(j.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return o([]);Ko(r,g||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(j)},[r,g]);const C=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(an,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(g===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(j=>h.jsx("button",{className:"src-chip"+(g===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:g?`Search within ${g}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(j=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===j.iri?" picked":""),onClick:()=>u(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:sx.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>p(j.target.value),children:ja.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:C,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var v,M,j;const[s,i]=w.useState(((v=e.term_map)==null?void 0:v.subject_template)??""),[o,a]=w.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},p=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${p}:`,b=(j=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:j.members.map(_=>{var I;return(I=e.attributes.find(N=>N.id===_))==null?void 0:I.name}).filter(Boolean),g=b&&b.length?`${y}${e.id}/${b.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,C=s.trim()||g;return h.jsxs(an,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",C]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((b==null?void 0:b[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=w.useState(""),[o,a]=w.useState(""),[c,l]=w.useState(""),[u,d]=w.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const p=f==null?void 0:f.created_id;n(),p&&r(p)})};return h.jsxs(an,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),ja.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const Ca=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(v=>v.id===t),c=e.entities.find(v=>v.id===n),l=w.useMemo(()=>c==null?void 0:c.attributes.find(v=>v.role==="business_key"),[c]),[u,d]=w.useState(r??""),[m,f]=w.useState(s??(l==null?void 0:l.id)??""),[p,y]=w.useState("many_to_one"),[b,g]=w.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",C=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:p,optionality:b}).then(o);return h.jsxs(an,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:p,onChange:v=>y(v.target.value),children:Ca.map(v=>h.jsx("option",{children:v},v))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:v=>d(v.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(v=>h.jsx("option",{value:v.id,children:v.name},v.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:v=>f(v.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(v=>h.jsxs("option",{value:v.id,children:[v.name,v.role==="business_key"?" 🔑":""]},v.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:b,onChange:v=>g(v.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:C,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=g=>{var E;return((E=t.entities.find(C=>C.id===g))==null?void 0:E.name)??"?"},[i,o]=w.useState(e.name),[a,c]=w.useState(e.cardinality),[l,u]=w.useState(e.optionality),[d,m]=w.useState(e.identifying),[f,p]=w.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},b=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(an,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:g=>o(g.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:g=>c(g.target.value),children:Ca.map(g=>h.jsx("option",{children:g},g))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:g=>u(g.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:g=>m(g.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:b,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>p(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const hi=10,ux=6,$t=24;function dx(e,t){return t?e:Math.round(e/hi)*hi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-$t,o.right+$t);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eo.left&&ni.left&&n=o.right?(u.push({x:n,y:t.y},{x:o.right,y:t.y}),m={ox:1,oy:0}):(u.push({x:n,y:t.y},{x:o.left,y:t.y}),m={ox:-1,oy:0});return{path:yx(u),sourceOut:d,targetOut:m}}const pi=3,wx=w.memo(function({id:t,sourceX:n,sourceY:r,targetX:s,targetY:i,sourcePosition:o,targetPosition:a,data:c,selected:l}){const{screenToFlowPosition:u}=on(),d=he(te=>te.transform[2]),[m,f]=w.useState(null),p=w.useRef(!1),y=w.useRef(0),b=c==null?void 0:c.onRouteChange,g=!!b,E=m??(c==null?void 0:c.routeX),[C,v,M]=Mn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),j=c==null?void 0:c.sourceCard,_=c==null?void 0:c.targetCard,I=E!=null&&j&&_?xx({x:n,y:r},{y:i},E,o===U.Left?-1:1,a===U.Left?-1:1,j,_):null,N=I?I.path:C,R=c==null?void 0:c.relationship,P=(c==null?void 0:c.dimmed)??!1,V=(R==null?void 0:R.cardinality)??"many_to_one",H=(R==null?void 0:R.optionality)==="optional",x=(R==null?void 0:R.identifying)??!1,$=V==="many_to_one"||V==="many_to_many",S=V==="one_to_many"||V==="many_to_many",O="rel-edge"+(l?" selected":"")+(P?" dimmed":""),D=((c==null?void 0:c.memberCount)??0)>1,k=c==null?void 0:c.onHoverEdge,T=E??v,L=M,z=T,W=L,G=I?I.sourceOut:{ox:o===U.Left?-1:1,oy:0},X=I?I.targetOut:{ox:a===U.Left?-1:1,oy:0},Z={x:n,y:r},ne=I&&_?X.oy!==0?{x:E,y:X.oy<0?_.top:_.bottom}:{x:X.ox>0?_.right:_.left,y:i}:{x:s,y:i},ie=w.useCallback(te=>b&&R&&b(R.id,te),[b,R]),re=w.useCallback(te=>{var _e,je;if(!g||te.button!==0)return;te.stopPropagation(),(je=(_e=te.target).setPointerCapture)==null||je.call(_e,te.pointerId),p.current=!0,y.current=0;const ve=u({x:te.clientX,y:te.clientY}).x;let de=0,pe=E??T;const le=ze=>{const $e=u({x:ze.clientX,y:ze.clientY});y.current=Math.max(y.current,Math.abs($e.x-ve)),pe=mx($e.x,{shift:ze.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),de||(de=requestAnimationFrame(()=>{de=0,f(pe)}))},q=()=>{window.removeEventListener("pointermove",le),window.removeEventListener("pointerup",q),de&&cancelAnimationFrame(de),p.current=!1,f(null),y.current>=pi&&ie(pe)};window.addEventListener("pointermove",le),window.addEventListener("pointerup",q)},[g,u,E,T,c,n,s,ie]),ae=w.useCallback(te=>{y.current>=pi&&(te.stopPropagation(),y.current=0)},[]),ye=w.useCallback(te=>{g&&(te.stopPropagation(),ie(null))},[g,ie]);return h.jsxs("g",{className:O,onMouseEnter:k?()=>k(R.id):void 0,onMouseLeave:k?()=>k(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:N,fill:"none",strokeDasharray:x?void 0:"6 4"}),h.jsx("path",{d:N,fill:"none",strokeWidth:16/d,stroke:"transparent"}),h.jsx(gi,{x:Z.x,y:Z.y,out:G,many:$,optional:H}),h.jsx(gi,{x:ne.x,y:ne.y,out:X,many:S,optional:!1}),g&&((c==null?void 0:c.hovered)||l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:re,onClickCapture:ae,onDoubleClick:ye,children:[h.jsx("rect",{x:T-20/d,y:Math.min(r,i),width:40/d,height:Math.max(Math.abs(i-r),24/d),fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:T-5.5/d,y:L-11/d,width:11/d,height:22/d,rx:5/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L-4.5/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L+4.5/d,r:1.1/d})]}),(l||D)&&R&&h.jsxs("text",{className:"rel-label",x:z,y:W-8,children:[l?R.verb_phrase||R.name:"",D?`${l?" ":""}(${c.memberCount})`:""]})]})});function gi({x:e,y:t,out:n,many:r,optional:s}){const{ox:a,oy:c}=n,l=-c,u=a,d=p=>({x:e+a*p,y:t+c*p}),m=(p,y)=>({x:e+a*p+l*y,y:t+c*p+u*y}),f=[];if(r){const p=d(12),y=m(0,-7),b=d(0),g=m(0,7);f.push(h.jsx("path",{className:"rel-glyph",d:`M ${p.x} ${p.y} L ${y.x} ${y.y} M ${p.x} ${p.y} L ${b.x} ${b.y} M ${p.x} ${p.y} L ${g.x} ${g.y}`,fill:"none"},"foot"))}else{const p=m(9,-7),y=m(9,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:y.x,y2:y.y},"one"))}if(s){const p=d(18);f.push(h.jsx("circle",{className:"rel-glyph ring",cx:p.x,cy:p.y,r:4},"opt"))}else{const p=m(17,-7),y=m(17,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:y.x,y2:y.y},"mand"))}return h.jsx(h.Fragment,{children:f})}const bx={entity:Pm},vx={relationship:wx},yi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],xi="#8a7d6a";function _x(e,t,n){const s=Ue;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function Ex(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Br,targetHandle:n(e.to.entity,s)?s:Gr}}function Jx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:p,fitBounds:y,getNodes:b}=on(),[g,E]=w.useState([]),[C,v]=w.useState([]),M=w.useRef(!1),j=w.useMemo(()=>{const F=u&&u.size>0?[...u].sort():null;return F?"sa:"+F.join("+"):"__all__"},[u]),_=w.useRef(null),[I,N]=w.useState(0),R=w.useRef(new Map),P=w.useRef(null);w.useEffect(()=>{if(!f){_.current=null;return}const F=R.current.get(j);if(F){_.current=F,M.current=!1,N(B=>B+1);return}let Y=!1;return f.load(j).then(B=>{Y||(R.current.set(j,B),_.current=B,M.current=!1,N(Q=>Q+1))}),()=>{Y=!0}},[f,j]);const[V,H]=w.useState(null),[x,$]=w.useState(null),[S,O]=w.useState(!1),[D,k]=w.useState(null),[T,L]=w.useState(null),[z,W]=w.useState(null),[G,X]=w.useState(null),Z=w.useRef({}),ne=!t.canEdit,ie=w.useRef(null),re=w.useCallback(()=>{f&&(ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>{const F={};for(const Q of b())Q.hidden||(F[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,K]of Object.entries(Z.current))Y[Q]={routeX:Math.round(K)};const B={nodes:F,edges:Y};R.current.set(j,B),_.current=B,f.save(j,B)},800))},[f,b,j]),ae=w.useCallback((F,Y)=>{Y==null?delete Z.current[F]:Z.current[F]=Y,v(B=>B.map(Q=>Q.id===F?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),re()},[re]),ye=w.useMemo(()=>{const F=new Map;return e.subject_areas.forEach((Y,B)=>F.set(Y.id,yi[B%yi.length])),F},[e]),te=w.useMemo(()=>{const F=new Map;return e.entities.forEach(Y=>F.set(Y.id,Y)),F},[e]),me=w.useMemo(()=>{const F=new Map,Y=new Map;return e.subject_areas.forEach(B=>{(B.members??[]).forEach(Q=>Y.set(Q,{id:B.id,name:B.name}))}),e.entities.forEach(B=>{var se,ge;const Q=(se=B.conceptual)!=null&&se.id?Y.get(B.conceptual.id):void 0,K=(ge=B.conceptual)==null?void 0:ge.subject_area,ee=Q??(K?{id:K.id,name:K.name??K.id}:void 0);ee&&F.set(B.id,ee)}),F},[e]),ve=w.useCallback(F=>{var B;if(!u||u.size===0)return!1;const Y=(B=me.get(F))==null?void 0:B.id;return!(Y&&u.has(Y))},[u,me]),de=w.useMemo(()=>{const F=new Map,Y=(B,Q)=>{if(!Q.length)return;const K=F.get(B)??new Set;Q.forEach(ee=>K.add(ee)),F.set(B,K)};for(const B of e.relationships)Y(B.from.entity,B.from.attributes),Y(B.to.entity,B.to.attributes);return F},[e]);w.useEffect(()=>{var ge;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const J of e.entities)(J.name.toLowerCase()+" "+(((ge=J.conceptual)==null?void 0:ge.name.toLowerCase())??"")+" "+J.attributes.map(ce=>ce.name.toLowerCase()).join(" ")).includes(F)&&Y.add(J.id);const B=new Set;if(r){B.add(r);for(const J of e.relationships)J.from.entity===r&&B.add(J.to.entity),J.to.entity===r&&B.add(J.from.entity)}const Q=e.entities.map(J=>{const fe=F!==""&&!Y.has(J.id),ce=r!==null&&!B.has(J.id);return{id:J.id,type:"entity",position:{x:0,y:0},hidden:ve(J.id),data:{entity:J,color:(()=>{const xe=me.get(J.id);return xe?ye.get(xe.id)??xi:xi})(),dimmed:fe||ce,highlighted:F!==""&&Y.has(J.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(J.id))??!1,onToggleExpand:l,endpointAttrs:de.get(J.id),highlightAttrs:void 0,onHoverAttr:W}}}),K=e.relationships.filter(J=>te.has(J.from.entity)&&te.has(J.to.entity)).map(J=>{const{sourceHandle:fe,targetHandle:ce}=Ex(J,te),xe=r!==null&&J.from.entity!==r&&J.to.entity!==r;return{id:J.id,source:J.from.entity,target:J.to.entity,sourceHandle:fe,targetHandle:ce,type:"relationship",data:{relationship:J,dimmed:xe,memberCount:Math.max(J.from.attributes.length,J.to.attributes.length),onHoverEdge:X}}}),ee=_.current;if(Z.current={},ee)for(const[J,fe]of Object.entries(ee.edges))Z.current[J]=fe.routeX;const se=J=>{const fe=new Map;for(const ce of J)fe.set(ce.id,{left:ce.position.x,right:ce.position.x+Ue,top:ce.position.y,bottom:ce.position.y+dt(ce.data.entity)});v(K.map(ce=>({...ce,data:{...ce.data,routeX:Z.current[ce.id],onRouteChange:f?ae:void 0,sourceCard:fe.get(ce.source),targetCard:fe.get(ce.target)}})))};E(J=>{const fe=new Map(J.map(ue=>[ue.id,ue.position])),ce=Q.every(ue=>fe.has(ue.id)),xe=((u==null?void 0:u.size)??0)>0;if(M.current&&ce&&J.length>=Q.length&&!xe){const ue=Q.map(Ze=>({...Ze,position:fe.get(Ze.id)??Ze.position}));return se(ue),ue}const Me=xe?Q.filter(ue=>!ue.hidden):Q,Ye=cr(Me,K,te,"auto",me),Ke=new Map(Ye.map(ue=>[ue.id,ue.position])),Te=(ee==null?void 0:ee.nodes)??{},_t=Object.keys(Te).length>0,Et=[],He=Q.map(ue=>{const Ze=Te[ue.id];if(Ze){const Dt={x:Ze.x,y:Ze.y};return Et.push({x:Dt.x,y:Dt.y,w:Ue,h:dt(ue.data.entity)}),{...ue,position:Dt}}return Ke.has(ue.id)?{...ue,position:Ke.get(ue.id)}:fe.has(ue.id)&&M.current?{...ue,position:fe.get(ue.id)}:ue});if(_t)for(const ue of He)Te[ue.id]||ue.hidden||(ue.position=_x(ue.position,dt(ue.data.entity),Et),Et.push({x:ue.position.x,y:ue.position.y,w:Ue,h:dt(ue.data.entity)}));return M.current=!0,_t||requestAnimationFrame(()=>p({padding:.15,duration:300})),se(He),He})},[e,i,r,o,a,c,l,ye,te,me,ve,u,de,p,f,ae,I]);const pe=w.useMemo(()=>{const F=new Set,Y=new Set,B=new Map,Q=(K,ee)=>{if(!ee.length)return;const se=B.get(K)??new Set;ee.forEach(ge=>se.add(ge)),B.set(K,se)};if(z)for(const K of e.relationships)(K.from.attributes.includes(z)||K.to.attributes.includes(z))&&(F.add(K.id),Y.add(K.from.entity),Y.add(K.to.entity),Q(K.from.entity,K.from.attributes),Q(K.to.entity,K.to.attributes));if(G){const K=e.relationships.find(ee=>ee.id===G);K&&(Q(K.from.entity,K.from.attributes),Q(K.to.entity,K.to.attributes))}return{active:z!==null,relsForAttr:F,entsForAttr:Y,hitAttrsByEntity:B}},[e,z,G]);w.useEffect(()=>{var Q;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const K of e.entities)(K.name.toLowerCase()+" "+(((Q=K.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+K.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(K.id);const B=new Set;if(r){B.add(r);for(const K of e.relationships)K.from.entity===r&&B.add(K.to.entity),K.to.entity===r&&B.add(K.from.entity)}E(K=>K.map(ee=>{const se=F!==""&&!Y.has(ee.id),ge=r!==null&&!B.has(ee.id),J=pe.active&&!pe.entsForAttr.has(ee.id),fe=se||ge||J,ce=F!==""&&Y.has(ee.id)||pe.active&&pe.entsForAttr.has(ee.id),xe=pe.hitAttrsByEntity.get(ee.id);return ee.data.dimmed===fe&&ee.data.highlighted===ce&&ee.data.highlightAttrs===xe?ee:{...ee,data:{...ee.data,dimmed:fe,highlighted:ce,highlightAttrs:xe}}})),v(K=>K.map(ee=>{var Ye,Ke,Te;const se=(Ye=ee.data)==null?void 0:Ye.relationship,ge=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,J=pe.active&&!pe.relsForAttr.has(ee.id),fe=ge||J,ce=G===ee.id,xe=r!==null&&se!==void 0&&(se.from.entity===r||se.to.entity===r),Me=ce||xe?1e3:0;return((Ke=ee.data)==null?void 0:Ke.dimmed)===fe&&((Te=ee.data)==null?void 0:Te.hovered)===ce&&ee.zIndex===Me?ee:{...ee,zIndex:Me,data:{...ee.data,dimmed:fe,hovered:ce}}}))},[pe,G,i,r,e]),w.useEffect(()=>{var Q;const F=i.trim().toLowerCase();if(!F)return;const Y=new Set;for(const K of e.entities)(K.name.toLowerCase()+" "+(((Q=K.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+K.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(K.id);if(!Y.size)return;const B=requestAnimationFrame(()=>{const K=b().filter(se=>Y.has(se.id));if(!K.length)return;const ee=Mf(K);y(ee,{padding:.35,duration:400})});return()=>cancelAnimationFrame(B)},[i,e,b,y]);const le=w.useCallback((F="auto",Y="LR")=>{P.current=Object.fromEntries(b().map(B=>[B.id,{x:B.position.x,y:B.position.y}])),E(B=>cr(B,C,te,F,me,Y)),requestAnimationFrame(()=>p({padding:.15,duration:300})),re()},[C,te,me,p,b,re]),q=w.useCallback(()=>{const F=P.current;F&&(E(Y=>Y.map(B=>F[B.id]?{...B,position:F[B.id]}:B)),P.current=null,re())},[re]),_e=w.useCallback(()=>{f==null||f.reset(j),R.current.delete(j),_.current=null,Z.current={},M.current=!1,v(F=>F.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(F=>{const Y=cr(F,C,te,"auto",me);return requestAnimationFrame(()=>p({padding:.15,duration:300})),Y})},[f,j,C,te,me,p]),je=w.useCallback(F=>{s(F),E(Y=>(Y.find(Q=>Q.id===F)&&requestAnimationFrame(()=>p({nodes:[{id:F}],padding:.4,duration:400})),Y))},[p,s]);w.useImperativeHandle(m,()=>({relayout:le,fitView:()=>p({padding:.15,duration:300}),focusEntity:je,newEntity:()=>O(!0),resetLayout:_e,undoRelayout:q}),[le,p,je,_e,q]);const ze=w.useCallback(F=>{if(ne||!F.source||!F.target||F.source===F.target)return;const Y=F.sourceHandle&&F.sourceHandle!==Br?F.sourceHandle:void 0,B=F.targetHandle&&F.targetHandle!==Gr?F.targetHandle:void 0;k({from:F.source,to:F.target,fromAttr:Y,toAttr:B})},[ne]),$e=w.useCallback(async(F,Y)=>{try{return await n(F,Y)}catch(B){throw d==null||d(B instanceof Error?B.message:String(B)),B}},[n,d]),qe=r?te.get(r)??null:null,Ie=e.relationships.find(F=>F.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Go,{nodes:g,edges:C,nodeTypes:bx,edgeTypes:vx,onNodeClick:(F,Y)=>s(Y.id),onEdgeDoubleClick:(F,Y)=>!ne&&L(Y.id),onPaneClick:()=>{s(null),L(null)},onNodeDragStop:(F,Y)=>{E(B=>B.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),re()},onConnect:ze,nodesConnectable:!ne,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:De.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:F=>{var Y;return((Y=F.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),qe&&h.jsx(Hm,{entity:qe,doc:e,caps:t,exec:$e,onClose:()=>s(null),onFocusEntity:je,onAlign:H,onEditMapping:$}),V&&h.jsx(ix,{entity:V,exec:$e,onClose:()=>H(null)}),x&&h.jsx(ox,{entity:x,doc:e,exec:$e,onClose:()=>$(null)}),S&&h.jsx(ax,{doc:e,exec:$e,onClose:()=>O(!1),onCreated:je}),D&&h.jsx(cx,{doc:e,fromId:D.from,toId:D.to,initialFromAttr:D.fromAttr,initialToAttr:D.toAttr,exec:$e,onClose:()=>k(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:$e,onClose:()=>L(null)})]})}function ew({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(Nx,{}),e==="layers"&&h.jsx(kx,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(jx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Cx,{readOnly:n})]})}function Nx(){const[e,t]=w.useState(""),[n,r]=w.useState([]),[s,i]=w.useState({loaded:0,vocabs:[]}),[o,a]=w.useState(null),[c,l]=w.useState([]),[u,d]=w.useState("");w.useEffect(()=>{Zo().then(f=>l(f.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const f=setTimeout(()=>{Ko(e||"a",u||void 0).then(p=>{r(e?p.results:[]),i({loaded:p.loaded_terms,vocabs:p.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=w.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const Sx=["industry","core","domain","specialised"];function kx({refreshKey:e,onFocusEntity:t}){const[n,r]=w.useState(null),[s,i]=w.useState(null);if(w.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),Sx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function jx({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=w.useState(null),[i,o]=w.useState(""),[a,c]=w.useState(""),[l,u]=w.useState(!1),d=w.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` `))).catch(()=>o(""))},[]);return w.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:i.split(` `).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index 2f42e84..4377003 100644 --- a/packages/server/src/mdl_server/static/index.html +++ b/packages/server/src/mdl_server/static/index.html @@ -4,9 +4,9 @@ Modelith - + - + diff --git a/packages/server/src/mdl_server/static/sme.html b/packages/server/src/mdl_server/static/sme.html index 165c1b4..79e0d53 100644 --- a/packages/server/src/mdl_server/static/sme.html +++ b/packages/server/src/mdl_server/static/sme.html @@ -4,9 +4,9 @@ Modelith Glossary - + - + From 34bc8b48151546653de68d43cf01f4bf8e90a27d Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Mon, 12 Oct 2026 18:51:40 +1100 Subject: [PATCH 09/14] canvas: draggable edge ENDPOINTS that slide along the entity border MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Beyond dragging the vertical segment (routeX), each edge end can now be dragged ALONG its entity's border, with the crow's-foot following smoothly — the Eclipse Sirius "adjust the extremity, never reconnect" pattern. Visual only: the model still links the real attribute rows; this is only where the line meets the box. - edgeRouting: anchorOnBorder (resolve a drop point to the nearest border + clamp) and resolveAnchor (border point + outward vector, re-clamped to the current card). Unit-tested. - RelationshipEdge: a draggable grip at each endpoint (hover/select reveals it, move cursor); the effective source/target point overrides the attribute-row port so the path + glyph follow the anchor; double-click an endpoint resets it. - Persistence: EdgeRoute gains optional sourceAnchor/targetAnchor {side,y,x?}; saved/loaded via the same layout store and debounced save. Server layout_store validates + rounds anchors (422 on a bad side/non-finite). Both ends draggable. Verified live: endpoint grips appear on hover, dragging one slides the connection point down the border (e.g. dm's left edge) with the glyph tracking, and it persists. 49 canvas + 16 server layout tests pass; ruff clean. --- canvas/src/ModelCanvas.tsx | 83 +++++++-- canvas/src/RelationshipEdge.tsx | 175 ++++++++++++++++-- canvas/src/edgeRouting.test.ts | 35 ++++ canvas/src/edgeRouting.ts | 63 +++++++ canvas/src/styles.css | 4 + canvas/src/types.ts | 16 +- .../server/src/mdl_server/layout_store.py | 41 +++- ...m-iv1-Rvhr.js => ModelDiagram-BKkR2OJE.js} | 2 +- .../{main-CDJWg6AJ.js => main-B_vfjY00.js} | 2 +- .../{sme-D5286oaR.js => sme-D4FCzUN8.js} | 4 +- ...tyles-CK604yls.css => styles-BzOwieT6.css} | 2 +- .../static/assets/styles-Dfh1I8li.js | 23 +++ .../static/assets/styles-kEWh7gJm.js | 23 --- .../server/src/mdl_server/static/index.html | 6 +- .../server/src/mdl_server/static/sme.html | 6 +- packages/server/tests/test_layout_api.py | 29 +++ 16 files changed, 436 insertions(+), 78 deletions(-) rename packages/server/src/mdl_server/static/assets/{ModelDiagram-iv1-Rvhr.js => ModelDiagram-BKkR2OJE.js} (97%) rename packages/server/src/mdl_server/static/assets/{main-CDJWg6AJ.js => main-B_vfjY00.js} (99%) rename packages/server/src/mdl_server/static/assets/{sme-D5286oaR.js => sme-D4FCzUN8.js} (99%) rename packages/server/src/mdl_server/static/assets/{styles-CK604yls.css => styles-BzOwieT6.css} (60%) create mode 100644 packages/server/src/mdl_server/static/assets/styles-Dfh1I8li.js delete mode 100644 packages/server/src/mdl_server/static/assets/styles-kEWh7gJm.js diff --git a/canvas/src/ModelCanvas.tsx b/canvas/src/ModelCanvas.tsx index 3dd901b..fa85d6e 100644 --- a/canvas/src/ModelCanvas.tsx +++ b/canvas/src/ModelCanvas.tsx @@ -28,7 +28,7 @@ import { type LayoutDir, type LayoutMode, NODE_WIDTH, layoutGraph, nodeHeight } import type { LayoutStore } from "./layoutStore"; import { AlignModal, NewEntityModal, RelEditModal, RelModal, TermMapModal } from "./modals"; import { RelationshipEdge, type RelationshipEdgeData } from "./RelationshipEdge"; -import type { Entity, ModelDoc, ViewLayout } from "./types"; +import type { EdgeAnchor, EdgeRoute, Entity, ModelDoc, ViewLayout } from "./types"; const nodeTypes: NodeTypes = { entity: EntityNode }; const edgeTypes: EdgeTypes = { relationship: RelationshipEdge }; @@ -41,6 +41,11 @@ export const NO_SA_COLOR = "#8a7d6a"; /** Nudge a card down until it no longer overlaps any occupied rectangle, so a * newly-auto-placed entity (e.g. one Copilot just created) does not land on top * of a restored card. Simple vertical push; good enough for the rare new node. */ +/** Round an anchor's coordinates for a stable, small saved diff. */ +function roundAnchor(a: EdgeAnchor): EdgeAnchor { + return { side: a.side, y: Math.round(a.y), ...(a.x != null ? { x: Math.round(a.x) } : {}) }; +} + function nudgeOffOverlaps( pos: { x: number; y: number }, h: number, @@ -214,9 +219,10 @@ export function ModelCanvas({ // and canvas-local; it feeds the existing dimmed/highlighted computation. const [hoveredAttr, setHoveredAttr] = useState(null); const [hoveredEdge, setHoveredEdge] = useState(null); - // committed edge routes for the current view (relId -> routeX). The live drag - // is kept inside the edge component; this holds only committed values. - const routesRef = useRef>({}); + // committed edge routes for the current view (relId -> {routeX?, sourceAnchor?, + // targetAnchor?}). The live drag is kept inside the edge component; this holds only + // committed values. + const routesRef = useRef>({}); const readOnly = !caps.canEdit; @@ -231,8 +237,12 @@ export function ModelCanvas({ if (!n.hidden) posNodes[n.id] = { x: Math.round(n.position.x), y: Math.round(n.position.y) }; } const edgeRoutes: ViewLayout["edges"] = {}; - for (const [relId, routeX] of Object.entries(routesRef.current)) { - edgeRoutes[relId] = { routeX: Math.round(routeX) }; + for (const [relId, r] of Object.entries(routesRef.current)) { + const out: EdgeRoute = {}; + if (r.routeX != null) out.routeX = Math.round(r.routeX); + if (r.sourceAnchor) out.sourceAnchor = roundAnchor(r.sourceAnchor); + if (r.targetAnchor) out.targetAnchor = roundAnchor(r.targetAnchor); + if (out.routeX != null || out.sourceAnchor || out.targetAnchor) edgeRoutes[relId] = out; } const layout: ViewLayout = { nodes: posNodes, edges: edgeRoutes }; loadedViews.current.set(viewKey, layout); @@ -245,8 +255,10 @@ export function ModelCanvas({ // data in place (identity-preserving, so only that one edge re-renders) and saves. const onRouteCommit = useCallback( (relId: string, routeX: number | null) => { - if (routeX == null) delete routesRef.current[relId]; - else routesRef.current[relId] = routeX; + const cur = routesRef.current[relId] ?? {}; + if (routeX == null) delete cur.routeX; + else cur.routeX = routeX; + routesRef.current[relId] = cur; setEdges((prev) => prev.map((e) => e.id === relId ? { ...e, data: { ...e.data!, routeX: routeX ?? undefined } } : e, @@ -257,6 +269,26 @@ export function ModelCanvas({ [saveLayout], ); + // Commit a dragged endpoint anchor (or null to reset that end to its attribute-row port). + const onAnchorCommit = useCallback( + (relId: string, end: "source" | "target", anchor: EdgeAnchor | null) => { + const cur = routesRef.current[relId] ?? {}; + const key = end === "source" ? "sourceAnchor" : "targetAnchor"; + if (anchor == null) delete cur[key]; + else cur[key] = anchor; + routesRef.current[relId] = cur; + setEdges((prev) => + prev.map((e) => + e.id === relId + ? { ...e, data: { ...e.data!, [key]: anchor ?? undefined } } + : e, + ), + ); + saveLayout(); + }, + [saveLayout], + ); + const saColors = useMemo(() => { const m = new Map(); doc.subject_areas.forEach((sa, i) => m.set(sa.id, PALETTE[i % PALETTE.length])); @@ -402,7 +434,13 @@ export function ModelCanvas({ const saved = savedRef.current; routesRef.current = {}; if (saved) { - for (const [relId, r] of Object.entries(saved.edges)) routesRef.current[relId] = r.routeX; + for (const [relId, r] of Object.entries(saved.edges)) { + routesRef.current[relId] = { + ...(r.routeX != null ? { routeX: r.routeX } : {}), + ...(r.sourceAnchor ? { sourceAnchor: r.sourceAnchor } : {}), + ...(r.targetAnchor ? { targetAnchor: r.targetAnchor } : {}), + }; + } } // Build the edges from the FINAL node positions. We do this inside the setNodes @@ -420,16 +458,22 @@ export function ModelCanvas({ }); } setEdges( - newEdges.map((e) => ({ - ...e, - data: { - ...e.data!, - routeX: routesRef.current[e.id], - onRouteChange: layoutStore ? onRouteCommit : undefined, - sourceCard: cardById.get(e.source), - targetCard: cardById.get(e.target), - }, - })), + newEdges.map((e) => { + const r = routesRef.current[e.id] ?? {}; + return { + ...e, + data: { + ...e.data!, + routeX: r.routeX, + sourceAnchor: r.sourceAnchor, + targetAnchor: r.targetAnchor, + onRouteChange: layoutStore ? onRouteCommit : undefined, + onAnchorChange: layoutStore ? onAnchorCommit : undefined, + sourceCard: cardById.get(e.source), + targetCard: cardById.get(e.target), + }, + }; + }), ); }; setNodes((prev) => { @@ -495,6 +539,7 @@ export function ModelCanvas({ fitView, layoutStore, onRouteCommit, + onAnchorCommit, savedTick, ]); diff --git a/canvas/src/RelationshipEdge.tsx b/canvas/src/RelationshipEdge.tsx index 25dce0a..dabbcd0 100644 --- a/canvas/src/RelationshipEdge.tsx +++ b/canvas/src/RelationshipEdge.tsx @@ -1,6 +1,6 @@ import { memo, useCallback, useRef, useState } from "react"; import { getSmoothStepPath, Position, useReactFlow, useStore, type EdgeProps } from "reactflow"; -import { adjustRouteX, orthogonalPath } from "./edgeRouting"; +import { type Anchor, adjustRouteX, anchorOnBorder, orthogonalPath, resolveAnchor } from "./edgeRouting"; import type { Relationship } from "./types"; export interface RelationshipEdgeData { @@ -21,6 +21,12 @@ export interface RelationshipEdgeData { * side-aware orthogonal routing (top/bottom entry) */ sourceCard?: { left: number; right: number; top: number; bottom: number }; targetCard?: { left: number; right: number; top: number; bottom: number }; + /** endpoints dragged ALONG the entity's border (visual only; the data still links the + * real attribute rows). Undefined = the natural attribute-row port. */ + sourceAnchor?: Anchor; + targetAnchor?: Anchor; + /** commit a dragged endpoint anchor (or null to reset to the attribute-row port). */ + onAnchorChange?: (relId: string, end: "source" | "target", anchor: Anchor | null) => void; } @@ -63,6 +69,8 @@ export const RelationshipEdge = memo(function RelationshipEdge({ // while dragging, the live route is kept here so we do NOT rebuild all edges // per move; the committed value rides in data.routeX. const [dragX, setDragX] = useState(null); + // live endpoint-anchor drag (per end), kept local so a drag does not rebuild all edges. + const [dragAnchor, setDragAnchor] = useState<{ end: "source" | "target"; a: Anchor } | null>(null); const draggingRef = useRef(false); const movedRef = useRef(0); @@ -72,13 +80,43 @@ export const RelationshipEdge = memo(function RelationshipEdge({ // effective vertical-segment x: live drag wins, else the committed route. const routeX = dragX ?? data?.routeX; + // Effective endpoints: a dragged/stored anchor overrides the attribute-row port, so the + // line visually meets the box where the anchor sits (the data still links the real rows). + const srcCardR = data?.sourceCard; + const tgtCardR = data?.targetCard; + const liveSrcAnchor = + dragAnchor?.end === "source" ? dragAnchor.a : data?.sourceAnchor; + const liveTgtAnchor = + dragAnchor?.end === "target" ? dragAnchor.a : data?.targetAnchor; + const srcPt = + liveSrcAnchor && srcCardR + ? resolveAnchor(liveSrcAnchor, srcCardR) + : { x: sourceX, y: sourceY, out: null as null | { ox: number; oy: number } }; + const tgtPt = + liveTgtAnchor && tgtCardR + ? resolveAnchor(liveTgtAnchor, tgtCardR) + : { x: targetX, y: targetY, out: null as null | { ox: number; oy: number } }; + const eSourceX = srcPt.x; + const eSourceY = srcPt.y; + const eTargetX = tgtPt.x; + const eTargetY = tgtPt.y; + // when an endpoint is anchored, its port side follows the anchor's side. + const eSourcePos = + liveSrcAnchor?.side === "right" ? Position.Right + : liveSrcAnchor?.side === "left" ? Position.Left + : sourcePosition; + const eTargetPos = + liveTgtAnchor?.side === "right" ? Position.Right + : liveTgtAnchor?.side === "left" ? Position.Left + : targetPosition; + const [smoothPath, autoLabelX, autoLabelY] = getSmoothStepPath({ - sourceX, - sourceY, - sourcePosition, - targetX, - targetY, - targetPosition, + sourceX: eSourceX, + sourceY: eSourceY, + sourcePosition: eSourcePos, + targetX: eTargetX, + targetY: eTargetY, + targetPosition: eTargetPos, borderRadius: 10, ...(routeX != null ? { centerX: routeX } : {}), }); @@ -91,11 +129,11 @@ export const RelationshipEdge = memo(function RelationshipEdge({ const routed = routeX != null && sCard && tCard ? orthogonalPath( - { x: sourceX, y: sourceY }, - { x: targetX, y: targetY }, + { x: eSourceX, y: eSourceY }, + { x: eTargetX, y: eTargetY }, routeX, - sourcePosition === Position.Left ? -1 : 1, - targetPosition === Position.Left ? -1 : 1, + eSourcePos === Position.Left ? -1 : 1, + eTargetPos === Position.Left ? -1 : 1, sCard, tCard, ) @@ -130,15 +168,21 @@ export const RelationshipEdge = memo(function RelationshipEdge({ // The router reports the out-vector; the glyph ANCHOR must move to the border the line // actually crosses — the right port when entering from the right, the top/bottom border // when entering vertically — so the marker is never left mid-card. - const srcOut = routed ? routed.sourceOut : { ox: sourcePosition === Position.Left ? -1 : 1, oy: 0 }; - const tgtOut = routed ? routed.targetOut : { ox: targetPosition === Position.Left ? -1 : 1, oy: 0 }; - const srcGlyph = { x: sourceX, y: sourceY }; + // out-vectors + glyph anchor points. Priority: the orthogonal router (when a route is + // set) > a dragged endpoint anchor > the natural attribute-row port. + const srcOut = routed + ? routed.sourceOut + : srcPt.out ?? { ox: eSourcePos === Position.Left ? -1 : 1, oy: 0 }; + const tgtOut = routed + ? routed.targetOut + : tgtPt.out ?? { ox: eTargetPos === Position.Left ? -1 : 1, oy: 0 }; + const srcGlyph = { x: eSourceX, y: eSourceY }; const tgtGlyph = routed && tCard ? tgtOut.oy !== 0 ? { x: routeX!, y: tgtOut.oy < 0 ? tCard.top : tCard.bottom } // top/bottom entry - : { x: tgtOut.ox > 0 ? tCard.right : tCard.left, y: targetY } // right/left port - : { x: targetX, y: targetY }; + : { x: tgtOut.ox > 0 ? tCard.right : tCard.left, y: eTargetY } // right/left port + : { x: eTargetX, y: eTargetY }; const commit = useCallback( (x: number | null) => onRouteChange && rel && onRouteChange(rel.id, x), @@ -208,6 +252,52 @@ export const RelationshipEdge = memo(function RelationshipEdge({ [draggable, commit], ); + const onAnchorChange = data?.onAnchorChange; + // Drag an endpoint along its entity's border. `end` picks source/target; the drop point + // resolves to the nearest border via anchorOnBorder. Commits on release; double-click a + // handle resets that end to its attribute-row port. + const onEndpointDown = useCallback( + (end: "source" | "target") => (e: React.PointerEvent) => { + const card = end === "source" ? data?.sourceCard : data?.targetCard; + if (!onAnchorChange || !rel || !card || e.button !== 0) return; + e.stopPropagation(); + (e.target as Element).setPointerCapture?.(e.pointerId); + movedRef.current = 0; + const start = screenToFlowPosition({ x: e.clientX, y: e.clientY }); + let raf = 0; + let latest: Anchor | null = null; + const onMove = (ev: PointerEvent) => { + const p = screenToFlowPosition({ x: ev.clientX, y: ev.clientY }); + movedRef.current = Math.max(movedRef.current, Math.hypot(p.x - start.x, p.y - start.y)); + latest = anchorOnBorder(p.x, p.y, card); + if (!raf) { + raf = requestAnimationFrame(() => { + raf = 0; + setDragAnchor({ end, a: latest! }); + }); + } + }; + const onUp = () => { + window.removeEventListener("pointermove", onMove); + window.removeEventListener("pointerup", onUp); + if (raf) cancelAnimationFrame(raf); + setDragAnchor(null); + if (movedRef.current >= CLICK_SLOP && latest) onAnchorChange(rel.id, end, latest); + }; + window.addEventListener("pointermove", onMove); + window.addEventListener("pointerup", onUp); + }, + [onAnchorChange, rel, data, screenToFlowPosition], + ); + const onEndpointDouble = useCallback( + (end: "source" | "target") => (e: React.MouseEvent) => { + if (!onAnchorChange || !rel) return; + e.stopPropagation(); + onAnchorChange(rel.id, end, null); // reset to the attribute-row port + }, + [onAnchorChange, rel], + ); + return ( // Hover handlers on the whole group so moving from the line onto the grip keeps the // edge "hovered" (and the handle mounted) instead of flickering off between children. @@ -227,6 +317,25 @@ export const RelationshipEdge = memo(function RelationshipEdge({ + {/* endpoint handles — drag an end ALONG its entity's border. Shown on hover/select. */} + {!!onAnchorChange && (data?.hovered || selected || dragAnchor != null) && ( + <> + + + + )} {/* drag handle on the vertical segment — shown while hovered, selected, or mid-drag. Sizes are divided by the zoom so the grip keeps a constant ON-SCREEN size and stays visible + grabbable however far the canvas is zoomed out. */} @@ -244,9 +353,9 @@ export const RelationshipEdge = memo(function RelationshipEdge({ guidance: a generous (20-75px) hit area. */} {/* the visible grip: a rounded pill (~11x22px on screen) */} @@ -276,6 +385,36 @@ export const RelationshipEdge = memo(function RelationshipEdge({ ); }); +/** A small circular grip at an edge endpoint; drag it to slide the endpoint along the + * entity's border. Zoom-invariant, like the route grip. */ +function EndpointHandle({ + x, + y, + zoom, + onPointerDown, + onDoubleClick, +}: { + x: number; + y: number; + zoom: number; + onPointerDown: (e: React.PointerEvent) => void; + onDoubleClick: (e: React.MouseEvent) => void; +}) { + return ( + + {/* fat transparent grab target (~20px on screen) */} + + {/* visible dot (~7px on screen) */} + + + ); +} + function EndGlyph({ x, y, diff --git a/canvas/src/edgeRouting.test.ts b/canvas/src/edgeRouting.test.ts index d9313ac..3a21eb2 100644 --- a/canvas/src/edgeRouting.test.ts +++ b/canvas/src/edgeRouting.test.ts @@ -7,6 +7,8 @@ import { clampRouteX, magnetise, orthogonalPath, + anchorOnBorder, + resolveAnchor, snapRouteX, type CardX, } from "./edgeRouting"; @@ -138,3 +140,36 @@ describe("orthogonalPath", () => { expect(r.path.trimEnd().endsWith("L 600 560")).toBe(true); // ends at the LEFT border }); }) + +describe("anchorOnBorder", () => { + const card = { left: 100, right: 300, top: 50, bottom: 250 }; + it("snaps to the nearest side and clamps along it", () => { + // near the left edge, mid-height -> left side at that y + expect(anchorOnBorder(96, 140, card)).toEqual({ side: "left", x: 100, y: 140 }); + // near the right edge + expect(anchorOnBorder(305, 140, card)).toEqual({ side: "right", x: 300, y: 140 }); + // near the top + expect(anchorOnBorder(200, 45, card)).toEqual({ side: "top", x: 200, y: 50 }); + // near the bottom + expect(anchorOnBorder(200, 255, card)).toEqual({ side: "bottom", x: 200, y: 250 }); + }); + it("clamps away from the corners (inset)", () => { + const a = anchorOnBorder(96, 0, card); // way above -> clamp to top+inset + expect(a.side).toBe("left"); + expect(a.y).toBe(50 + 8); + }); +}); + +describe("resolveAnchor", () => { + const card = { left: 100, right: 300, top: 50, bottom: 250 }; + it("returns the border point + outward vector per side", () => { + expect(resolveAnchor({ side: "left", x: 100, y: 140 }, card)).toEqual({ x: 100, y: 140, out: { ox: -1, oy: 0 } }); + expect(resolveAnchor({ side: "right", x: 300, y: 140 }, card)).toEqual({ x: 300, y: 140, out: { ox: 1, oy: 0 } }); + expect(resolveAnchor({ side: "top", x: 200, y: 50 }, card)).toEqual({ x: 200, y: 50, out: { ox: 0, oy: -1 } }); + expect(resolveAnchor({ side: "bottom", x: 200, y: 250 }, card)).toEqual({ x: 200, y: 250, out: { ox: 0, oy: 1 } }); + }); + it("re-clamps y if the card shrank", () => { + const r = resolveAnchor({ side: "left", x: 100, y: 999 }, card); + expect(r.y).toBe(250); // clamped to bottom + }); +}); diff --git a/canvas/src/edgeRouting.ts b/canvas/src/edgeRouting.ts index e1fb0b0..76712ba 100644 --- a/canvas/src/edgeRouting.ts +++ b/canvas/src/edgeRouting.ts @@ -215,3 +215,66 @@ export function orthogonalPath( return { path: polyline(pts), sourceOut, targetOut }; } + +// --- draggable endpoint anchors (slide the endpoint along an entity's border) --- + +/** A card's full rectangle in flow coordinates. */ +export interface Rect { + left: number; + right: number; + top: number; + bottom: number; +} + +/** Which border a dragged endpoint snaps to, and where on it. The endpoint slides + * freely along a border; `side` is the nearest border to the drop point, `x`/`y` the + * point on it (`x` only matters on top/bottom). Purely visual — the model still links + * the real attribute rows. Matches the stored EdgeAnchor wire type. */ +export interface Anchor { + side: "left" | "right" | "top" | "bottom"; + x?: number; + y: number; +} + +const ANCHOR_INSET = 8; // keep the anchor this far from a corner + +/** + * Resolve a free drag point `(px, py)` to an anchor ON the card's border: pick the + * nearest side, then clamp the point to that side's span (minus a small corner inset). + * This lets the endpoint slide smoothly along whichever edge the cursor is closest to. + */ +export function anchorOnBorder(px: number, py: number, card: Rect): Anchor { + const dLeft = Math.abs(px - card.left); + const dRight = Math.abs(px - card.right); + const dTop = Math.abs(py - card.top); + const dBottom = Math.abs(py - card.bottom); + const min = Math.min(dLeft, dRight, dTop, dBottom); + const clamp = (v: number, lo: number, hi: number) => Math.min(Math.max(v, lo), hi); + if (min === dLeft) { + return { side: "left", x: card.left, y: clamp(py, card.top + ANCHOR_INSET, card.bottom - ANCHOR_INSET) }; + } + if (min === dRight) { + return { side: "right", x: card.right, y: clamp(py, card.top + ANCHOR_INSET, card.bottom - ANCHOR_INSET) }; + } + if (min === dTop) { + return { side: "top", x: clamp(px, card.left + ANCHOR_INSET, card.right - ANCHOR_INSET), y: card.top }; + } + return { side: "bottom", x: clamp(px, card.left + ANCHOR_INSET, card.right - ANCHOR_INSET), y: card.bottom }; +} + +/** Re-resolve a stored anchor against the card's CURRENT rect (the card may have moved + * or resized since the anchor was saved), keeping it on the same side at the same + * relative position. Returns the point + outward unit vector for the glyph. */ +export function resolveAnchor(a: Anchor, card: Rect): { x: number; y: number; out: Out } { + const clamp = (v: number, lo: number, hi: number) => Math.min(Math.max(v, lo), hi); + switch (a.side) { + case "left": + return { x: card.left, y: clamp(a.y, card.top, card.bottom), out: { ox: -1, oy: 0 } }; + case "right": + return { x: card.right, y: clamp(a.y, card.top, card.bottom), out: { ox: 1, oy: 0 } }; + case "top": + return { x: clamp(a.x ?? (card.left + card.right) / 2, card.left, card.right), y: card.top, out: { ox: 0, oy: -1 } }; + default: + return { x: clamp(a.x ?? (card.left + card.right) / 2, card.left, card.right), y: card.bottom, out: { ox: 0, oy: 1 } }; + } +} diff --git a/canvas/src/styles.css b/canvas/src/styles.css index 64dc955..495deb6 100644 --- a/canvas/src/styles.css +++ b/canvas/src/styles.css @@ -265,6 +265,10 @@ body { font-family: var(--font); background: var(--bg); color: var(--text); } .rel-handle .rel-grip { fill: var(--accent); stroke: var(--bg); opacity: 0.95; } .rel-handle .rel-grip-dot { fill: var(--bg); } .rel-handle:hover .rel-grip { fill: var(--accent); filter: brightness(1.15); } +/* draggable endpoint grips (slide an edge end along an entity's border) */ +.rel-endpoint, .rel-endpoint * { cursor: move !important; } +.rel-endpoint .rel-endpoint-dot { fill: var(--accent); stroke: var(--bg); opacity: 0.95; } +.rel-endpoint:hover .rel-endpoint-dot { filter: brightness(1.2); } .layout-menu-sep { height: 1px; margin: 4px 0; background: var(--border); } /* ---------- detail panel ---------- */ diff --git a/canvas/src/types.ts b/canvas/src/types.ts index 00e0543..34c67a6 100644 --- a/canvas/src/types.ts +++ b/canvas/src/types.ts @@ -488,9 +488,21 @@ export interface NodePos { y: number; } -/** One saved edge route: the x of its draggable vertical segment. */ +/** One saved edge route (all optional, visual-only): + * - `routeX`: x of the draggable vertical segment. + * - `sourceAnchor`/`targetAnchor`: the endpoint's position dragged ALONG the entity's + * border, as `{ side, y }` where `side` is which border it sits on and `y` the flow-y + * on that border. The data still links the real attribute rows; this is only where the + * line visually meets the box. */ +export interface EdgeAnchor { + side: "left" | "right" | "top" | "bottom"; + y: number; + x?: number; +} export interface EdgeRoute { - routeX: number; + routeX?: number; + sourceAnchor?: EdgeAnchor; + targetAnchor?: EdgeAnchor; } /** One view's saved arrangement. `__all__` is the unfiltered canvas; a filtered diff --git a/packages/server/src/mdl_server/layout_store.py b/packages/server/src/mdl_server/layout_store.py index bebf089..e905167 100644 --- a/packages/server/src/mdl_server/layout_store.py +++ b/packages/server/src/mdl_server/layout_store.py @@ -102,8 +102,27 @@ def _clean_nodes(nodes: Any, valid_ids: set[str]) -> dict[str, dict[str, int]]: return out -def _clean_edges(edges: Any, valid_ids: set[str]) -> dict[str, dict[str, int]]: - out: dict[str, dict[str, int]] = {} +_SIDES = {"left", "right", "top", "bottom"} + + +def _clean_anchor(a: Any) -> dict[str, Any] | None: + """A dragged-endpoint anchor: {side, y, x?}. None when absent/invalid-shape (dropped, + not fatal); raises only on a present-but-non-finite number.""" + if not isinstance(a, dict): + return None + side = a.get("side") + if side not in _SIDES or not _finite(a.get("y")): + raise LayoutError("anchor: side must be left/right/top/bottom and y finite") + out: dict[str, Any] = {"side": side, "y": round(a["y"])} + if a.get("x") is not None: + if not _finite(a["x"]): + raise LayoutError("anchor x must be finite") + out["x"] = round(a["x"]) + return out + + +def _clean_edges(edges: Any, valid_ids: set[str]) -> dict[str, dict[str, Any]]: + out: dict[str, dict[str, Any]] = {} if not isinstance(edges, dict): return out for eid, route in edges.items(): @@ -111,9 +130,21 @@ def _clean_edges(edges: Any, valid_ids: set[str]) -> dict[str, dict[str, int]]: raise LayoutError(f"edge id too long: {eid[:16]}…") if eid not in valid_ids: continue - if not isinstance(route, dict) or not _finite(route.get("routeX")): - raise LayoutError(f"edge {eid}: routeX must be a finite number") - out[eid] = {"routeX": round(route["routeX"])} + if not isinstance(route, dict): + raise LayoutError(f"edge {eid}: route must be an object") + rec: dict[str, Any] = {} + if route.get("routeX") is not None: + if not _finite(route["routeX"]): + raise LayoutError(f"edge {eid}: routeX must be a finite number") + rec["routeX"] = round(route["routeX"]) + sa = _clean_anchor(route.get("sourceAnchor")) + if sa: + rec["sourceAnchor"] = sa + ta = _clean_anchor(route.get("targetAnchor")) + if ta: + rec["targetAnchor"] = ta + if rec: # drop empty edge records + out[eid] = rec return out diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-iv1-Rvhr.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-BKkR2OJE.js similarity index 97% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-iv1-Rvhr.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-BKkR2OJE.js index dca0648..c8fdaaf 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-iv1-Rvhr.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-BKkR2OJE.js @@ -1 +1 @@ -import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-kEWh7gJm.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; +import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-Dfh1I8li.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; diff --git a/packages/server/src/mdl_server/static/assets/main-CDJWg6AJ.js b/packages/server/src/mdl_server/static/assets/main-B_vfjY00.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-CDJWg6AJ.js rename to packages/server/src/mdl_server/static/assets/main-B_vfjY00.js index a824bff..f13f5d3 100644 --- a/packages/server/src/mdl_server/static/assets/main-CDJWg6AJ.js +++ b/packages/server/src/mdl_server/static/assets/main-B_vfjY00.js @@ -1,2 +1,2 @@ -import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-kEWh7gJm.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` +import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-Dfh1I8li.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` `)||"model valid",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),M]}):F?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14}),F]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!u&&e.jsxs("button",{className:"tool-btn primary",onClick:A,title:"New entity (n)",children:[e.jsx(ye,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),E("ontology",e.jsx(be,{size:15}),"Ontology","Ontology browser"),E("layers",e.jsx(we,{size:15}),"Layers","Four-layer stack & coverage"),E("changes",e.jsx(ve,{size:15}),"Changes",k?"Uncommitted changes":"Changes",k),E("decisions",e.jsx(Me,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(w?" active":""),onClick:g,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(m?" active":""),onClick:p,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Ne,{size:15})}),e.jsx(Ke,{onRelayout:f,onReset:v}),e.jsx("button",{className:"grp-btn icon-only",onClick:y,title:"Fit view","aria-label":"Fit view",children:e.jsx(ke,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:r,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Se,{size:15})}),e.jsx(de,{exec:S,canEdit:!u,onImported:I,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:_,openImport:$})]})]})]})}const U=["LR","TB","RL","BT"],$e={LR:0,TB:90,RL:180,BT:270},se={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function Ke({onRelayout:s,onReset:l}){const[j,h]=a.useState(!1),[x,w]=a.useState("LR"),[g,m]=a.useState("auto"),p=a.useRef(null);a.useEffect(()=>{if(!j)return;const r=u=>{p.current&&!p.current.contains(u.target)&&h(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[j]);const y=r=>{m(r),s(r,x)},f=r=>{y(r),h(!1)},v=()=>{const r=U[(U.indexOf(x)+1)%U.length];w(r),s(g,r)};return e.jsxs("div",{className:"layout-picker",ref:p,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>y("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ee,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(j?" active":""),onClick:()=>h(r=>!r),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:v,title:`Flow direction: ${se[x]} (click to rotate)`,"aria-label":`Flow direction: ${se[x]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${$e[x]}deg)`},children:e.jsx(Pe,{size:15})})}),j&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>f("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>f("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>f("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>f("grid"),children:"Grid"}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"layout-menu-sep",role:"separator"}),e.jsx("button",{onClick:()=>{l(),h(!1)},title:"Clear saved positions and routes for this view",children:"Reset layout"})]})]})]})}function He(){const[s,l]=a.useState(null),[j,h]=a.useState(null),[x,w]=a.useState(null),[g,m]=a.useState(null),[p,y]=a.useState(""),[f,v]=a.useState(!0),[r,u]=a.useState(!1),[k,b]=a.useState(()=>new Set),[q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[z,D]=a.useState(()=>new Set),[K,M]=a.useState(!1),[F,E]=a.useState(0),o=a.useRef(null),L=a.useRef(""),B=a.useRef(!1),O=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((c,n)=>t.set(c.id,Y[n%Y.length])),t},[s]),H=a.useMemo(()=>{const t=new Map;if(!s)return t;const c=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(d=>c.set(d,n.id))}),s.entities.forEach(n=>{var N,Q,X;const P=((N=n.conceptual)!=null&&N.id?c.get(n.conceptual.id):void 0)??((X=(Q=n.conceptual)==null?void 0:Q.subject_area)==null?void 0:X.id)??"";t.set(n.id,P)}),t},[s]),te=a.useMemo(()=>{const t=new Map;return H.forEach(c=>t.set(c,(t.get(c)??0)+1)),t},[H]),R=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>ge(R),[R]),ae=a.useMemo(()=>ue(),[]),V=a.useMemo(()=>new URLSearchParams(window.location.search),[]),T=V.get("minimal")==="1";a.useEffect(()=>{T&&u(!0)},[T]);const re=a.useCallback(t=>{b(c=>{const n=new Set(c);return n.has(t)?n.delete(t):n.add(t),n})},[]),ce=V.get("import")==="1",W=a.useRef(!1),C=a.useCallback(()=>{J().then(l).catch(t=>w(String(t))),Z().then(h).catch(()=>h(null)),ee().then(t=>M(!!(t.git&&!t.clean))).catch(()=>M(!1)),E(t=>t+1)},[]);a.useEffect(C,[C]),a.useEffect(()=>{const t=setInterval(()=>{J().then(c=>{l(n=>n&&c.fingerprint===n.fingerprint?n:(B.current||(L.current=c.fingerprint),T||(Z().then(h).catch(()=>h(null)),ee().then(d=>M(!!(d.git&&!d.clean))).catch(()=>M(!1))),E(d=>d+1),c))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[T]),a.useEffect(()=>{s!=null&&s.fingerprint&&(L.current=s.fingerprint)},[s]);const G=a.useCallback(async(t,c)=>{if(s){B.current=!0;try{const n=await xe(t,c,L.current||s.fingerprint);return n!=null&&n.fingerprint&&(L.current=n.fingerprint),C(),n}catch(n){throw n instanceof pe&&n.status===409?(m("Model changed on disk — view refreshed, please retry."),C()):m(n instanceof Error?n.message:String(n)),n}finally{B.current=!1}}},[s,C]);a.useEffect(()=>{if(!g)return;const t=setTimeout(()=>m(null),5e3);return()=>clearTimeout(t)},[g]),a.useEffect(()=>{if(!s||W.current)return;const t=V.get("focus");if(!t)return;const c=s.entities.find(n=>{var d;return n.name===t||((d=n.conceptual)==null?void 0:d.name)===t});c&&(W.current=!0,requestAnimationFrame(()=>{var n;return(n=o.current)==null?void 0:n.focusEntity(c.id)}))},[s,V]);const oe=a.useCallback(()=>{var n;if(!s)return;const t=p.trim().toLowerCase();if(!t)return;const c=s.entities.find(d=>{var N;return(d.name.toLowerCase()+" "+(((N=d.conceptual)==null?void 0:N.name.toLowerCase())??"")+" "+d.attributes.map(Q=>Q.name.toLowerCase()).join(" ")).includes(t)});c&&((n=o.current)==null||n.focusEntity(c.id))},[s,p]);return a.useEffect(()=>{const t=c=>{var d,P,N;const n=(d=document.activeElement)==null?void 0:d.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(c.key==="/"&&(c.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),c.key==="n"&&!R&&((N=o.current)==null||N.newEntity()),c.key==="Escape"&&(A(null),y(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[R]),x?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:x}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!T&&e.jsx(_e,{doc:s,diagnostics:j,query:p,onQuery:y,onSubmitQuery:oe,showTypes:f,onToggleTypes:()=>v(t=>!t),collapseDetail:r,onToggleCollapse:()=>u(t=>!t),onFitView:()=>{var t;return(t=o.current)==null?void 0:t.fitView()},onRelayout:(t,c)=>{var n;return(n=o.current)==null?void 0:n.relayout(t,c)},onResetLayout:()=>{var t;return(t=o.current)==null?void 0:t.resetLayout()},onRefresh:C,readOnly:R,dirty:K,panelTab:S,onPanelTab:t=>I(c=>c===t?null:t),onNewEntity:()=>{var t;return(t=o.current)==null?void 0:t.newEntity()},exec:G,onImported:C,onImportBatch:je,openImport:ce,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:z.size}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(me,{doc:s,caps:ne,exec:G,selectedId:S?null:q,onSelect:A,query:p,showTypes:f,collapseDetail:r,expandedEntities:k,onToggleExpand:re,activeAreas:z,onError:m,handleRef:o,layoutStore:ae}),!T&&e.jsx(Ae,{doc:s,saColors:O,countByArea:te,activeAreas:z,onSetActive:D,open:_,onClose:()=>$(!1)}),S&&e.jsx(fe,{tab:S,onClose:()=>I(null),readOnly:R,refreshKey:F,onModelChanged:C,onFocusEntity:t=>{var c;I(null),(c=o.current)==null||c.focusEntity(t)}}),g&&e.jsx("div",{className:"toast",children:g})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ve(){return e.jsx(he,{children:e.jsx(He,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(le.StrictMode,{children:e.jsx(Ve,{})})); diff --git a/packages/server/src/mdl_server/static/assets/sme-D5286oaR.js b/packages/server/src/mdl_server/static/assets/sme-D4FCzUN8.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-D5286oaR.js rename to packages/server/src/mdl_server/static/assets/sme-D4FCzUN8.js index f8845d4..4592029 100644 --- a/packages/server/src/mdl_server/static/assets/sme-D5286oaR.js +++ b/packages/server/src/mdl_server/static/assets/sme-D4FCzUN8.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-iv1-Rvhr.js","assets/client-DOmNpTln.js","assets/styles-kEWh7gJm.js","assets/styles-CK604yls.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-kEWh7gJm.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-iv1-Rvhr.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-BKkR2OJE.js","assets/client-DOmNpTln.js","assets/styles-Dfh1I8li.js","assets/styles-BzOwieT6.css"])))=>i.map(i=>d[i]); +import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-Dfh1I8li.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-BKkR2OJE.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); diff --git a/packages/server/src/mdl_server/static/assets/styles-CK604yls.css b/packages/server/src/mdl_server/static/assets/styles-BzOwieT6.css similarity index 60% rename from packages/server/src/mdl_server/static/assets/styles-CK604yls.css rename to packages/server/src/mdl_server/static/assets/styles-BzOwieT6.css index ca5dda2..3786206 100644 --- a/packages/server/src/mdl_server/static/assets/styles-CK604yls.css +++ b/packages/server/src/mdl_server/static/assets/styles-BzOwieT6.css @@ -1 +1 @@ -.react-flow{direction:ltr}.react-flow__container{position:absolute;width:100%;height:100%;top:0;left:0}.react-flow__pane{z-index:1;cursor:-webkit-grab;cursor:grab}.react-flow__pane.selection{cursor:pointer}.react-flow__pane.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__viewport{transform-origin:0 0;z-index:2;pointer-events:none}.react-flow__renderer{z-index:4}.react-flow__selection{z-index:6}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible{outline:none}.react-flow .react-flow__edges{pointer-events:none;overflow:visible}.react-flow__edge-path,.react-flow__connection-path{stroke:#b1b1b7;stroke-width:1;fill:none}.react-flow__edge{pointer-events:visibleStroke;cursor:pointer}.react-flow__edge.animated path{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__edge.animated path.react-flow__edge-interaction{stroke-dasharray:none;-webkit-animation:none;animation:none}.react-flow__edge.inactive{pointer-events:none}.react-flow__edge.selected,.react-flow__edge:focus,.react-flow__edge:focus-visible{outline:none}.react-flow__edge.selected .react-flow__edge-path,.react-flow__edge:focus .react-flow__edge-path,.react-flow__edge:focus-visible .react-flow__edge-path{stroke:#555}.react-flow__edge-textwrapper{pointer-events:all}.react-flow__edge-textbg{fill:#fff}.react-flow__edge .react-flow__edge-text{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__connection{pointer-events:none}.react-flow__connection .animated{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__connectionline{z-index:1001}.react-flow__nodes{pointer-events:none;transform-origin:0 0}.react-flow__node{position:absolute;-webkit-user-select:none;-moz-user-select:none;user-select:none;pointer-events:all;transform-origin:0 0;box-sizing:border-box;cursor:-webkit-grab;cursor:grab}.react-flow__node.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__nodesselection{z-index:3;transform-origin:left top;pointer-events:none}.react-flow__nodesselection-rect{position:absolute;pointer-events:all;cursor:-webkit-grab;cursor:grab}.react-flow__handle{position:absolute;pointer-events:none;min-width:5px;min-height:5px;width:6px;height:6px;background:#1a192b;border:1px solid white;border-radius:100%}.react-flow__handle.connectionindicator{pointer-events:all;cursor:crosshair}.react-flow__handle-bottom{top:auto;left:50%;bottom:-4px;transform:translate(-50%)}.react-flow__handle-top{left:50%;top:-4px;transform:translate(-50%)}.react-flow__handle-left{top:50%;left:-4px;transform:translateY(-50%)}.react-flow__handle-right{right:-4px;top:50%;transform:translateY(-50%)}.react-flow__edgeupdater{cursor:move;pointer-events:all}.react-flow__panel{position:absolute;z-index:5;margin:15px}.react-flow__panel.top{top:0}.react-flow__panel.bottom{bottom:0}.react-flow__panel.left{left:0}.react-flow__panel.right{right:0}.react-flow__panel.center{left:50%;transform:translate(-50%)}.react-flow__attribution{font-size:10px;background:#ffffff80;padding:2px 3px;margin:0}.react-flow__attribution a{text-decoration:none;color:#999}@-webkit-keyframes dashdraw{0%{stroke-dashoffset:10}}@keyframes dashdraw{0%{stroke-dashoffset:10}}.react-flow__edgelabel-renderer{position:absolute;width:100%;height:100%;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__edge.updating .react-flow__edge-path{stroke:#777}.react-flow__edge-text{font-size:10px}.react-flow__node.selectable:focus,.react-flow__node.selectable:focus-visible{outline:none}.react-flow__node-default,.react-flow__node-input,.react-flow__node-output,.react-flow__node-group{padding:10px;border-radius:3px;width:150px;font-size:12px;color:#222;text-align:center;border-width:1px;border-style:solid;border-color:#1a192b;background-color:#fff}.react-flow__node-default.selectable:hover,.react-flow__node-input.selectable:hover,.react-flow__node-output.selectable:hover,.react-flow__node-group.selectable:hover{box-shadow:0 1px 4px 1px #00000014}.react-flow__node-default.selectable.selected,.react-flow__node-default.selectable:focus,.react-flow__node-default.selectable:focus-visible,.react-flow__node-input.selectable.selected,.react-flow__node-input.selectable:focus,.react-flow__node-input.selectable:focus-visible,.react-flow__node-output.selectable.selected,.react-flow__node-output.selectable:focus,.react-flow__node-output.selectable:focus-visible,.react-flow__node-group.selectable.selected,.react-flow__node-group.selectable:focus,.react-flow__node-group.selectable:focus-visible{box-shadow:0 0 0 .5px #1a192b}.react-flow__node-group{background-color:#f0f0f040}.react-flow__nodesselection-rect,.react-flow__selection{background:#0059dc14;border:1px dotted rgba(0,89,220,.8)}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible,.react-flow__selection:focus,.react-flow__selection:focus-visible{outline:none}.react-flow__controls{box-shadow:0 0 2px 1px #00000014}.react-flow__controls-button{border:none;background:#fefefe;border-bottom:1px solid #eee;box-sizing:content-box;display:flex;justify-content:center;align-items:center;width:16px;height:16px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;padding:5px}.react-flow__controls-button:hover{background:#f4f4f4}.react-flow__controls-button svg{width:100%;max-width:12px;max-height:12px}.react-flow__controls-button:disabled{pointer-events:none}.react-flow__controls-button:disabled svg{fill-opacity:.4}.react-flow__minimap{background-color:#fff}.react-flow__minimap svg{display:block}.react-flow__resize-control{position:absolute}.react-flow__resize-control.left,.react-flow__resize-control.right{cursor:ew-resize}.react-flow__resize-control.top,.react-flow__resize-control.bottom{cursor:ns-resize}.react-flow__resize-control.top.left,.react-flow__resize-control.bottom.right{cursor:nwse-resize}.react-flow__resize-control.bottom.left,.react-flow__resize-control.top.right{cursor:nesw-resize}.react-flow__resize-control.handle{width:4px;height:4px;border:1px solid #fff;border-radius:1px;background-color:#3367d9;transform:translate(-50%,-50%)}.react-flow__resize-control.handle.left{left:0;top:50%}.react-flow__resize-control.handle.right{left:100%;top:50%}.react-flow__resize-control.handle.top{left:50%;top:0}.react-flow__resize-control.handle.bottom{left:50%;top:100%}.react-flow__resize-control.handle.top.left,.react-flow__resize-control.handle.bottom.left{left:0}.react-flow__resize-control.handle.top.right,.react-flow__resize-control.handle.bottom.right{left:100%}.react-flow__resize-control.line{border-color:#3367d9;border-width:0;border-style:solid}.react-flow__resize-control.line.left,.react-flow__resize-control.line.right{width:1px;transform:translate(-50%);top:0;height:100%}.react-flow__resize-control.line.left{left:0;border-left-width:1px}.react-flow__resize-control.line.right{left:100%;border-right-width:1px}.react-flow__resize-control.line.top,.react-flow__resize-control.line.bottom{height:1px;transform:translateY(-50%);left:0;width:100%}.react-flow__resize-control.line.top{top:0;border-top-width:1px}.react-flow__resize-control.line.bottom{border-bottom-width:1px;top:100%}.ie-wrap{position:relative;display:inline-flex;gap:6px}.erd-ico{font-size:13px;line-height:1;opacity:.85;margin-right:1px}.ie-wrap button:hover .erd-ico,.ie-wrap button.on .erd-ico,.ie-wrap button.active .erd-ico{opacity:1}.erd-caret{opacity:.55;margin-left:1px}.ie-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:30;min-width:220px;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:6px;box-shadow:0 12px 32px #00000073;display:flex;flex-direction:column;gap:2px}.ie-item{display:block;padding:8px 10px;border-radius:6px;color:var(--text);text-decoration:none;font-size:13px;cursor:pointer}.ie-item:hover{background:#5eead424;color:var(--accent)}.ie-dialect{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 10px 8px;margin-bottom:4px;border-bottom:1px solid var(--border);font-size:12px;color:var(--text-dim)}.ie-dialect select{background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;padding:3px 6px;font-size:12px}.ie-import{width:380px;padding:12px;gap:8px}.ie-tabs{display:flex;gap:4px}.ie-tab{flex:1;padding:6px 8px;border-radius:6px;font-size:12px;cursor:pointer;background:none;border:1px solid var(--border);color:var(--text-dim)}.ie-tab.active{border-color:var(--accent);color:var(--accent);background:#5eead41a}.ie-hint{font-size:11px;color:var(--text-dim);margin:0}.ie-textarea{width:100%;font-family:var(--mono);font-size:12px;resize:vertical;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:8px;padding:8px;box-sizing:border-box}.ie-textarea:focus{border-color:var(--accent);outline:none}.ie-file{font-size:11px;color:var(--text-dim)}.ie-warn{font-size:11px;color:var(--pk);margin:0}.ie-error{font-size:12px;color:var(--err);margin:0}.ie-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:4px}:root{--bg: #14110f;--bg-raised: #1c1815;--bg-card: #221d19;--border: #33291f;--border-strong: #4a3c2c;--text: #ece6dd;--text-dim: #a89a86;--accent: #e0a63a;--accent-soft: rgba(224, 166, 58, .15);--accent-ink: #241a08;--pk: #f2c14e;--err: #f0857a;--warn: #e6a94a;--ok: #6cbf73;--font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;--mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace}*{box-sizing:border-box}html,body,#root{height:100%;margin:0}body{font-family:var(--font);background:var(--bg);color:var(--text)}.app{display:flex;flex-direction:column;height:100%}.canvas-wrap{flex:1;position:relative;min-height:0}.react-flow{background:var(--bg)}.topbar{display:flex;flex-direction:column;padding:8px 16px 0;background:var(--bg-raised);border-bottom:1px solid var(--border);z-index:10}.topbar-row{display:flex;align-items:center;gap:14px}.topbar-row.context{padding-bottom:8px}.topbar-row.actions{gap:10px;padding-bottom:8px;flex-wrap:wrap}.brand{display:flex;align-items:baseline;gap:8px;white-space:nowrap}.logo{color:var(--accent);font-size:18px}.brand-name{font-weight:700;letter-spacing:.02em}.project-name{color:var(--text-dim);font-size:13px}.search{flex:0 1 300px;margin-left:auto;padding:7px 12px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-size:13px;outline:none}.search:focus{border-color:var(--accent)}.stats{display:flex;align-items:center;gap:12px;font-size:12px;color:var(--text-dim)}.stat-item{display:inline-flex;align-items:center;gap:5px}.stat-item svg{color:var(--text-dim)}.diag-chip{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:99px;font-weight:600}.diag-chip.ok{background:#34d39926;color:var(--ok)}.diag-chip.warn{background:#fbbf2426;color:var(--warn)}.diag-chip.err{background:#f8717126;color:var(--err)}.hamburger{position:relative;display:inline-flex;align-items:center;justify-content:center;padding:6px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer}.hamburger:hover{color:var(--text);border-color:var(--border-strong)}.hamburger.active{color:var(--accent);border-color:var(--accent)}.hamburger-badge{position:absolute;top:-6px;right:-6px;min-width:15px;height:15px;padding:0 3px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-size:10px;font-weight:700;line-height:15px;text-align:center}.btn-group{display:inline-flex;align-items:center;gap:2px;background:var(--bg-card);border:1px solid var(--border);border-radius:9px;padding:2px}.grp-tag{font-size:10px;color:var(--text-dim);opacity:.75;padding:0 6px 0 4px;letter-spacing:.03em;text-transform:none;white-space:nowrap}.grp-btn{display:inline-flex;align-items:center;gap:5px;padding:5px 9px;border-radius:6px;border:none;background:transparent;color:var(--text-dim);cursor:pointer;font-size:12px;white-space:nowrap}.grp-btn.icon-only{padding:5px 7px}.grp-btn:hover{color:var(--text);background:#ffffff0d}.grp-btn.active{color:var(--accent)}.grp-btn.active svg{color:var(--accent)}.grp-badge{width:6px;height:6px;border-radius:50%;background:var(--warn);display:inline-block;margin-left:1px}.dir-arrow{display:inline-flex;transition:transform .15s ease}.tool-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 11px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.tool-btn:hover{color:var(--text);border-color:var(--border-strong)}.tool-btn.active{color:var(--accent);border-color:var(--accent)}.tool-btn.primary{color:var(--accent);border-color:#e0a63a66;font-weight:600}.layout-picker{position:relative;display:inline-flex;gap:2px}.layout-picker .caret{font-size:10px}.layout-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:20;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:8px;padding:4px;min-width:150px;box-shadow:0 8px 24px #0006}.layout-menu button{display:block;width:100%;text-align:left;padding:7px 10px;border:0;border-radius:6px;background:transparent;color:var(--text-dim);cursor:pointer;font-size:13px}.layout-menu button:hover{background:var(--bg-card);color:var(--text)}.canvas-drawer{position:absolute;top:12px;left:12px;bottom:12px;width:300px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:16px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080;display:flex;flex-direction:column;gap:10px;transform:translate(calc(-100% - 16px));opacity:0;pointer-events:none;transition:transform .2s ease,opacity .2s ease}.canvas-drawer.open{transform:translate(0);opacity:1;pointer-events:auto}.drawer-header{display:flex;align-items:center;justify-content:space-between}.drawer-header h2{margin:0;font-size:15px;display:inline-flex;align-items:center;gap:7px}.drawer-header h2 svg{color:var(--accent)}.drawer-hint{font-size:11px;color:var(--text-dim);line-height:1.4}.sa-all{align-self:flex-start;padding:4px 10px;border-radius:7px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.sa-all:hover:not(:disabled){color:var(--text);border-color:var(--border-strong)}.sa-all.active{color:var(--accent);border-color:var(--accent)}.sa-all:disabled{opacity:.5;cursor:default}.sa-list{display:flex;flex-direction:column;gap:3px;margin-top:2px}.sa-row{display:flex;align-items:center;gap:9px;padding:7px 8px;border-radius:8px;cursor:pointer;border:1px solid transparent;-webkit-user-select:none;user-select:none}.sa-row:hover{background:var(--bg-card)}.sa-row.active{background:var(--accent-soft);border-color:#e0a63a66}.sa-row.muted{cursor:default;opacity:.7}.sa-row.muted:hover{background:transparent}.sa-row input[type=checkbox]{accent-color:var(--accent);cursor:pointer}.sa-chip{width:12px;height:12px;border-radius:3px;flex:0 0 auto}.sa-chip.none{background:repeating-linear-gradient(45deg,#4a3c2c,#4a3c2c 2px,transparent 2px,transparent 4px)}.sa-name{flex:1;font-size:13px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.sa-row.muted .sa-name{color:var(--text-dim)}.sa-count{font-size:11px;color:var(--text-dim);background:var(--bg-card);padding:1px 7px;border-radius:99px;flex:0 0 auto}.entity-node{width:264px;background:var(--bg-card);border:1px solid var(--border);border-top:3px solid var(--accent);border-radius:10px;overflow:hidden;box-shadow:0 4px 18px #00000059;font-size:12px;transition:opacity .15s,box-shadow .15s,border-color .15s}.entity-node.selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent),0 8px 24px #00000080}.entity-node.highlighted{box-shadow:0 0 0 2px var(--pk),0 8px 24px #00000080}.entity-node.dimmed{opacity:.18}.entity-header{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#ffffff08;border-bottom:1px solid var(--border)}.entity-name{font-weight:700;font-size:13px;letter-spacing:.01em}.entity-badges{display:flex;gap:4px}.badge{font-size:10px;padding:1px 6px;border-radius:99px;background:var(--accent-soft);color:var(--accent);text-transform:uppercase;letter-spacing:.05em}.badge.ontology{background:#93c5fd1f;color:#93c5fd}.attr-section{padding:4px 0}.attr-section.keys{border-bottom:1px solid var(--border);background:#fcd34d0a}.attr-row{display:flex;align-items:center;gap:6px;padding:3px 12px;height:26px;line-height:20px;position:relative}.attr-row.empty{color:var(--text-dim);font-style:italic}.attr-row.more{color:var(--text-dim);font-style:italic;cursor:pointer;justify-content:center;height:22px;font-size:11px}.attr-row.more:hover{color:var(--accent);background:var(--accent-soft)}.attr-row.rel-hit{background:var(--accent-soft);box-shadow:inset 2px 0 0 var(--accent)}.attr-row.rel-hit .attr-name{color:var(--accent);font-weight:600}.attr-row.rel-dim{opacity:.35}.attr-row.endpoint .attr-name{font-style:normal}.attr-port{width:8px!important;height:8px!important;opacity:0;top:50%!important}.attr-port.react-flow__handle-left{left:-5px!important}.attr-port.react-flow__handle-right{right:-5px!important}.entity-node:hover .attr-port{opacity:.5}.attr-row:hover .attr-port{opacity:1!important;background:var(--accent)!important}.attr-icon{width:14px;text-align:center;font-size:10px;flex:none}.attr-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attr-name.pk{color:var(--pk);font-weight:600}.attr-type{color:var(--text-dim);font-family:var(--mono);font-size:10px;flex:none}.attr-notnull{color:var(--text-dim);font-size:8px;flex:none}.port{width:11px!important;height:11px!important;background:var(--border-strong)!important;border:2px solid var(--bg)!important;opacity:.55;transition:transform .12s ease,background .12s ease,opacity .12s ease}.entity-node:hover .port{opacity:1;background:var(--accent)!important;transform:scale(1.25);box-shadow:0 0 0 4px var(--accent-soft);cursor:crosshair}.port:hover{transform:scale(1.6)!important;cursor:crosshair}.entity-node:hover{border-color:var(--accent);box-shadow:0 0 0 1px #e0a63a40}.react-flow__connectionline .react-flow__edge-path,.react-flow__connection-path{stroke:var(--accent)!important;stroke-width:2!important}.rel-path{stroke:var(--border-strong);stroke-width:1.6}.rel-edge{cursor:pointer}.rel-glyph{stroke:var(--border-strong);stroke-width:1.6;fill:none}.rel-glyph.ring{fill:var(--bg)}.rel-edge:hover .rel-path,.rel-edge.selected .rel-path,.rel-edge:hover .rel-glyph,.rel-edge.selected .rel-glyph{stroke:var(--accent)}.rel-edge.dimmed{opacity:.12}.rel-label{fill:var(--text);font-size:11px;text-anchor:middle;paint-order:stroke;stroke:var(--bg);stroke-width:4px}.rel-handle{cursor:ew-resize}.rel-handle,.rel-handle *{cursor:ew-resize!important}.rel-handle .rel-grip{fill:var(--accent);stroke:var(--bg);opacity:.95}.rel-handle .rel-grip-dot{fill:var(--bg)}.rel-handle:hover .rel-grip{fill:var(--accent);filter:brightness(1.15)}.layout-menu-sep{height:1px;margin:4px 0;background:var(--border)}.detail-panel{position:absolute;top:12px;right:12px;bottom:12px;width:340px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.detail-header{display:flex;justify-content:space-between;align-items:flex-start}.detail-header h2{margin:0 0 6px;font-size:18px}.icon-btn{background:none;border:none;color:var(--text-dim);cursor:pointer;font-size:14px}.icon-btn:hover{color:var(--text)}.definition{color:var(--text-dim);font-size:13px;line-height:1.5}.detail-panel section{margin-top:18px}.detail-panel h3{margin:0 0 8px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.kv{display:flex;gap:8px;margin:4px 0;font-size:12px;align-items:baseline}.kv .k{color:var(--text-dim);min-width:72px}.kv .v{word-break:break-all}.chip{display:inline-block;font-size:11px;padding:2px 8px;margin:2px 4px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim)}.chip.pattern{background:var(--accent-soft);color:var(--accent)}.chip.layer-industry{background:#93c5fd26;color:#93c5fd}.chip.layer-core{background:var(--accent-soft);color:var(--accent)}.chip.layer-domain{background:#f0abfc26;color:#f0abfc}.chip.layer-specialised{background:#fcd34d26;color:var(--pk)}.cat-badge{font-size:10px;font-weight:700;margin-left:6px;padding:2px 8px;border-radius:5px;cursor:help}.cat-badge.supertype{background:#a78bfa2e;color:#a78bfa}.cat-badge.subtype{background:var(--accent-soft);color:var(--accent)}.udp-row td{padding:3px 6px;border-bottom:1px solid var(--border);font-size:12px}.udp-key{color:var(--text-dim);font-family:var(--mono);font-size:11px}.udp-val{color:var(--text)}.enum-badge{font-size:8px;font-weight:700;margin-left:6px;padding:1px 5px;border-radius:4px;background:#a78bfa2e;color:#a78bfa;vertical-align:middle;cursor:help}.key-row{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:12px}.key-badge{font-size:9px;font-weight:700;padding:2px 6px;border-radius:5px;background:#94a3b826;color:var(--text-dim);flex:none}.key-badge.pk{background:#fcd34d2e;color:var(--pk)}.key-badge.unique,.key-badge.alternate{background:var(--accent-soft);color:var(--accent)}.key-name{font-weight:600}.key-cols{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}.attr-table td{padding:4px 6px;border-bottom:1px solid var(--border)}.attr-table td:first-child{width:100%}.attr-table td:first-child .edit-input{min-width:120px}.attr-table td.pk{color:var(--pk);font-weight:600}.attr-table td.type{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table td.null{color:var(--text-dim);font-size:10px;text-align:right}.rel-link{display:flex;gap:8px;align-items:center;width:100%;background:var(--bg-card);border:1px solid var(--border);border-radius:8px;color:var(--text);padding:7px 10px;margin:4px 0;cursor:pointer;font-size:12px;text-align:left}.rel-link:hover{border-color:var(--accent)}.rel-card{color:var(--text-dim);font-family:var(--mono);font-size:11px}.ulid{font-family:var(--mono);font-size:11px;color:var(--text-dim);cursor:copy;word-break:break-all}.ulid:hover{color:var(--accent)}.splash{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--text-dim)}.splash.error pre{background:var(--bg-card);padding:12px 16px;border-radius:8px;max-width:640px;overflow:auto;color:var(--err);font-size:12px}.react-flow__minimap{background:var(--bg-raised)!important;border-radius:10px}.react-flow__controls{border-radius:10px;overflow:hidden;box-shadow:none!important}.react-flow__controls-button{background:var(--bg-raised)!important;border-bottom:1px solid var(--border)!important;fill:var(--text-dim)!important}.react-flow__controls-button:hover{fill:var(--text)!important}.edit-input{width:100%;padding:6px 9px;border-radius:7px;font-size:12px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-family:var(--font);outline:none}.edit-input:focus{border-color:var(--accent)}.entity-title-input{font-size:17px;font-weight:700;background:transparent;border-color:transparent;padding-left:0}.entity-title-input:hover,.entity-title-input:focus{border-color:var(--border);background:var(--bg-card);padding-left:9px}.definition-input{color:var(--text-dim);line-height:1.5;resize:vertical}.chip-select,.cell-select{font-size:11px;padding:2px 6px;margin:2px 6px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim);border:1px solid transparent;outline:none}.chip-select:hover,.cell-select:hover{border-color:var(--border-strong);color:var(--text)}.cell-select{border-radius:6px;background:transparent;max-width:110px}.mini-btn{font-size:11px;padding:3px 9px;border-radius:7px;cursor:pointer;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim)}.mini-btn:hover{color:var(--accent);border-color:var(--accent)}.mini-btn.danger:hover{color:var(--err);border-color:var(--err)}.h3-actions{float:right;display:inline-flex;gap:6px}.empty-hint{color:var(--text-dim);font-size:12px;font-style:italic}.add-attr{display:flex;gap:6px;margin-top:8px}.rel-row{display:flex;gap:6px;align-items:flex-start}.rel-row .rel-main{flex:1}.verb-phrases{display:flex;align-items:center;gap:4px;margin-top:2px;padding-left:4px}.verb-phrases .verb-input{font-size:11px;font-style:italic;color:var(--text-dim);min-width:40px}.verb-phrases .verb-sep{color:var(--text-dim);font-size:11px}.physical-name-row{display:flex;align-items:center;gap:6px;margin-top:2px}.physical-name-row .physical-label{font-size:9px;text-transform:uppercase;color:var(--text-dim);letter-spacing:.04em}.physical-name-input{font-size:12px;color:var(--text-dim)}.physical-col{display:block;font-size:10px;color:var(--text-dim);font-family:var(--mono, monospace)}.physical-col-input{display:block;font-size:10px;color:var(--text-dim)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#05080db3;z-index:50;display:flex;align-items:center;justify-content:center}.modal{width:440px;max-height:80vh;overflow-y:auto;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:14px;padding:20px;box-shadow:0 24px 80px #0009}.modal.wide{width:600px}.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}.modal-header h2{margin:0;font-size:16px}.modal-search{margin-bottom:10px}.modal-footer{display:flex;gap:10px;justify-content:flex-end;align-items:center;margin-top:14px}.modal-footer label{font-size:11px;color:var(--text-dim);display:flex;flex-direction:column;gap:3px}.modal-footer select,.form-row select{background:var(--bg-card);color:var(--text);border:1px solid var(--border);border-radius:7px;padding:5px 8px;font-size:12px}.primary-btn{padding:8px 16px;border-radius:8px;border:none;cursor:pointer;background:var(--accent);color:var(--accent-ink);font-weight:700;font-size:13px}.primary-btn:disabled{opacity:.4;cursor:default}.danger-btn{padding:8px 16px;border-radius:8px;border:1px solid var(--err);cursor:pointer;background:#f8717124;color:var(--err);font-weight:700;font-size:13px}.form-row{display:flex;flex-direction:column;gap:4px;margin-bottom:14px;font-size:12px;color:var(--text-dim)}.form-row>label{font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:10px}.form-error{color:var(--err);font-size:11px}.form-preview{color:var(--text-dim);font-size:11px;word-break:break-all;opacity:.85}.form-preview:before{content:""}.form-hint{color:var(--text-dim);font-size:11px;font-style:italic;opacity:.75;word-break:break-word}.term-results{display:flex;flex-direction:column;gap:8px;max-height:44vh;overflow-y:auto}.term-card{text-align:left;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:10px 12px;cursor:pointer;color:var(--text)}.term-card:hover{border-color:var(--border-strong)}.term-card.picked{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}.term-head{display:flex;justify-content:space-between;align-items:baseline}.term-label{font-weight:600;font-size:13px}.term-source{font-size:10px;color:var(--text-dim);text-transform:uppercase;letter-spacing:.06em}.term-iri{font-size:10px;color:var(--accent);display:block;margin:2px 0;word-break:break-all}.term-def{font-size:11px;color:var(--text-dim);margin:4px 0 0;line-height:1.45}.kind-badge{font-size:8px;padding:1px 5px;margin-right:6px;border-radius:999px;background:#f0abfc26;color:#f0abfc;letter-spacing:.04em}.src-picker{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}.src-chip{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:3px 9px;border-radius:999px;background:var(--bg);border:1px solid var(--border);color:var(--text-dim);cursor:pointer}.src-chip:hover{border-color:var(--border-strong);color:var(--text)}.src-chip.active{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}.src-layer{font-size:8px;padding:0 5px;border-radius:999px;text-transform:uppercase;letter-spacing:.04em}.side-panel{position:absolute;top:12px;right:12px;bottom:12px;width:380px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.side-panel h2{margin:0;font-size:16px}.side-panel h4{margin:10px 0 6px;font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.panel-body{margin-top:12px}.panel-body.ok{color:var(--ok)}.meta-line{font-size:10px;color:var(--text-dim);margin:6px 0 10px}.coverage-banner{font-size:12px;padding:8px 12px;border-radius:9px;margin-bottom:12px;background:#34d3991a;color:var(--ok)}.coverage-banner.warn{background:#fbbf241a;color:var(--warn)}.layer-band{border:1px dashed var(--border);border-radius:10px;padding:8px 12px 10px;margin-bottom:10px}.layer-band.external{border-style:solid;background:#93c5fd0a}.stack-term{display:flex;justify-content:space-between;align-items:baseline;gap:8px;width:100%;background:var(--bg-card);border:1px solid var(--border);color:var(--text);border-radius:7px;padding:5px 10px;margin:4px 0;font-size:12px;cursor:pointer;text-align:left}div.stack-term{cursor:default}.stack-term:hover{border-color:var(--border-strong)}.stack-term.uncovered{border-color:var(--err)}.align-arrow{font-size:10px;color:var(--accent);white-space:nowrap}.align-arrow.unresolved{color:var(--warn)}.align-arrow.missing{color:var(--err);font-style:italic}.align-arrow.proposed{color:var(--warn);font-style:italic}.ref-list{display:flex;flex-direction:column;gap:6px;margin-top:4px}.ref-card{border:1px solid var(--border);border-radius:8px;padding:6px 8px;background:var(--bg)}.ref-card.proposed{border-color:var(--warn)}.ref-head{display:flex;align-items:baseline;gap:8px;justify-content:space-between}.ref-uri{font-family:var(--mono);font-size:12px;word-break:break-all}.ref-status{font-size:9px;text-transform:uppercase;letter-spacing:.04em}.ref-status.accepted{color:var(--accent)}.ref-status.proposed{color:var(--warn)}.ref-meta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:5px}.ref-pill{font-size:10px;padding:1px 6px;border-radius:999px;background:var(--accent-soft);color:var(--accent)}.ref-via{font-size:10px;color:var(--text-dim)}.ref-actions{display:flex;gap:6px;margin-top:6px}.dirty-list{list-style:none;padding:0;margin:0 0 10px;font-size:12px}.dirty-list li{padding:2px 0}.dirty-state{color:var(--warn);margin-right:6px;font-family:var(--mono)}.diff-view{background:var(--bg);border:1px solid var(--border);border-radius:9px;padding:10px;font-size:10.5px;line-height:1.5;overflow:auto;max-height:42vh;font-family:var(--mono);white-space:pre;margin-bottom:10px}.diff-add{color:var(--ok)}.diff-del{color:var(--err)}.diff-hunk{color:#93c5fd}.decision{border:1px solid var(--border);border-radius:9px;padding:8px 12px;margin-bottom:8px}.decision.accepted{opacity:.65}.decision.rejected{opacity:.45}.decision-head{display:flex;gap:6px;align-items:center}.decision-mark{font-weight:700}.decision-subject{font-size:12px;margin:6px 0}.decision-actions{display:flex;gap:6px}.toast{position:absolute;bottom:20px;left:50%;transform:translate(-50%);background:var(--bg-raised);border:1px solid var(--warn);color:var(--text);border-radius:10px;padding:10px 18px;font-size:12px;z-index:60;box-shadow:0 10px 30px #00000080} +.react-flow{direction:ltr}.react-flow__container{position:absolute;width:100%;height:100%;top:0;left:0}.react-flow__pane{z-index:1;cursor:-webkit-grab;cursor:grab}.react-flow__pane.selection{cursor:pointer}.react-flow__pane.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__viewport{transform-origin:0 0;z-index:2;pointer-events:none}.react-flow__renderer{z-index:4}.react-flow__selection{z-index:6}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible{outline:none}.react-flow .react-flow__edges{pointer-events:none;overflow:visible}.react-flow__edge-path,.react-flow__connection-path{stroke:#b1b1b7;stroke-width:1;fill:none}.react-flow__edge{pointer-events:visibleStroke;cursor:pointer}.react-flow__edge.animated path{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__edge.animated path.react-flow__edge-interaction{stroke-dasharray:none;-webkit-animation:none;animation:none}.react-flow__edge.inactive{pointer-events:none}.react-flow__edge.selected,.react-flow__edge:focus,.react-flow__edge:focus-visible{outline:none}.react-flow__edge.selected .react-flow__edge-path,.react-flow__edge:focus .react-flow__edge-path,.react-flow__edge:focus-visible .react-flow__edge-path{stroke:#555}.react-flow__edge-textwrapper{pointer-events:all}.react-flow__edge-textbg{fill:#fff}.react-flow__edge .react-flow__edge-text{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__connection{pointer-events:none}.react-flow__connection .animated{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__connectionline{z-index:1001}.react-flow__nodes{pointer-events:none;transform-origin:0 0}.react-flow__node{position:absolute;-webkit-user-select:none;-moz-user-select:none;user-select:none;pointer-events:all;transform-origin:0 0;box-sizing:border-box;cursor:-webkit-grab;cursor:grab}.react-flow__node.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__nodesselection{z-index:3;transform-origin:left top;pointer-events:none}.react-flow__nodesselection-rect{position:absolute;pointer-events:all;cursor:-webkit-grab;cursor:grab}.react-flow__handle{position:absolute;pointer-events:none;min-width:5px;min-height:5px;width:6px;height:6px;background:#1a192b;border:1px solid white;border-radius:100%}.react-flow__handle.connectionindicator{pointer-events:all;cursor:crosshair}.react-flow__handle-bottom{top:auto;left:50%;bottom:-4px;transform:translate(-50%)}.react-flow__handle-top{left:50%;top:-4px;transform:translate(-50%)}.react-flow__handle-left{top:50%;left:-4px;transform:translateY(-50%)}.react-flow__handle-right{right:-4px;top:50%;transform:translateY(-50%)}.react-flow__edgeupdater{cursor:move;pointer-events:all}.react-flow__panel{position:absolute;z-index:5;margin:15px}.react-flow__panel.top{top:0}.react-flow__panel.bottom{bottom:0}.react-flow__panel.left{left:0}.react-flow__panel.right{right:0}.react-flow__panel.center{left:50%;transform:translate(-50%)}.react-flow__attribution{font-size:10px;background:#ffffff80;padding:2px 3px;margin:0}.react-flow__attribution a{text-decoration:none;color:#999}@-webkit-keyframes dashdraw{0%{stroke-dashoffset:10}}@keyframes dashdraw{0%{stroke-dashoffset:10}}.react-flow__edgelabel-renderer{position:absolute;width:100%;height:100%;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__edge.updating .react-flow__edge-path{stroke:#777}.react-flow__edge-text{font-size:10px}.react-flow__node.selectable:focus,.react-flow__node.selectable:focus-visible{outline:none}.react-flow__node-default,.react-flow__node-input,.react-flow__node-output,.react-flow__node-group{padding:10px;border-radius:3px;width:150px;font-size:12px;color:#222;text-align:center;border-width:1px;border-style:solid;border-color:#1a192b;background-color:#fff}.react-flow__node-default.selectable:hover,.react-flow__node-input.selectable:hover,.react-flow__node-output.selectable:hover,.react-flow__node-group.selectable:hover{box-shadow:0 1px 4px 1px #00000014}.react-flow__node-default.selectable.selected,.react-flow__node-default.selectable:focus,.react-flow__node-default.selectable:focus-visible,.react-flow__node-input.selectable.selected,.react-flow__node-input.selectable:focus,.react-flow__node-input.selectable:focus-visible,.react-flow__node-output.selectable.selected,.react-flow__node-output.selectable:focus,.react-flow__node-output.selectable:focus-visible,.react-flow__node-group.selectable.selected,.react-flow__node-group.selectable:focus,.react-flow__node-group.selectable:focus-visible{box-shadow:0 0 0 .5px #1a192b}.react-flow__node-group{background-color:#f0f0f040}.react-flow__nodesselection-rect,.react-flow__selection{background:#0059dc14;border:1px dotted rgba(0,89,220,.8)}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible,.react-flow__selection:focus,.react-flow__selection:focus-visible{outline:none}.react-flow__controls{box-shadow:0 0 2px 1px #00000014}.react-flow__controls-button{border:none;background:#fefefe;border-bottom:1px solid #eee;box-sizing:content-box;display:flex;justify-content:center;align-items:center;width:16px;height:16px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;padding:5px}.react-flow__controls-button:hover{background:#f4f4f4}.react-flow__controls-button svg{width:100%;max-width:12px;max-height:12px}.react-flow__controls-button:disabled{pointer-events:none}.react-flow__controls-button:disabled svg{fill-opacity:.4}.react-flow__minimap{background-color:#fff}.react-flow__minimap svg{display:block}.react-flow__resize-control{position:absolute}.react-flow__resize-control.left,.react-flow__resize-control.right{cursor:ew-resize}.react-flow__resize-control.top,.react-flow__resize-control.bottom{cursor:ns-resize}.react-flow__resize-control.top.left,.react-flow__resize-control.bottom.right{cursor:nwse-resize}.react-flow__resize-control.bottom.left,.react-flow__resize-control.top.right{cursor:nesw-resize}.react-flow__resize-control.handle{width:4px;height:4px;border:1px solid #fff;border-radius:1px;background-color:#3367d9;transform:translate(-50%,-50%)}.react-flow__resize-control.handle.left{left:0;top:50%}.react-flow__resize-control.handle.right{left:100%;top:50%}.react-flow__resize-control.handle.top{left:50%;top:0}.react-flow__resize-control.handle.bottom{left:50%;top:100%}.react-flow__resize-control.handle.top.left,.react-flow__resize-control.handle.bottom.left{left:0}.react-flow__resize-control.handle.top.right,.react-flow__resize-control.handle.bottom.right{left:100%}.react-flow__resize-control.line{border-color:#3367d9;border-width:0;border-style:solid}.react-flow__resize-control.line.left,.react-flow__resize-control.line.right{width:1px;transform:translate(-50%);top:0;height:100%}.react-flow__resize-control.line.left{left:0;border-left-width:1px}.react-flow__resize-control.line.right{left:100%;border-right-width:1px}.react-flow__resize-control.line.top,.react-flow__resize-control.line.bottom{height:1px;transform:translateY(-50%);left:0;width:100%}.react-flow__resize-control.line.top{top:0;border-top-width:1px}.react-flow__resize-control.line.bottom{border-bottom-width:1px;top:100%}.ie-wrap{position:relative;display:inline-flex;gap:6px}.erd-ico{font-size:13px;line-height:1;opacity:.85;margin-right:1px}.ie-wrap button:hover .erd-ico,.ie-wrap button.on .erd-ico,.ie-wrap button.active .erd-ico{opacity:1}.erd-caret{opacity:.55;margin-left:1px}.ie-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:30;min-width:220px;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:6px;box-shadow:0 12px 32px #00000073;display:flex;flex-direction:column;gap:2px}.ie-item{display:block;padding:8px 10px;border-radius:6px;color:var(--text);text-decoration:none;font-size:13px;cursor:pointer}.ie-item:hover{background:#5eead424;color:var(--accent)}.ie-dialect{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 10px 8px;margin-bottom:4px;border-bottom:1px solid var(--border);font-size:12px;color:var(--text-dim)}.ie-dialect select{background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;padding:3px 6px;font-size:12px}.ie-import{width:380px;padding:12px;gap:8px}.ie-tabs{display:flex;gap:4px}.ie-tab{flex:1;padding:6px 8px;border-radius:6px;font-size:12px;cursor:pointer;background:none;border:1px solid var(--border);color:var(--text-dim)}.ie-tab.active{border-color:var(--accent);color:var(--accent);background:#5eead41a}.ie-hint{font-size:11px;color:var(--text-dim);margin:0}.ie-textarea{width:100%;font-family:var(--mono);font-size:12px;resize:vertical;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:8px;padding:8px;box-sizing:border-box}.ie-textarea:focus{border-color:var(--accent);outline:none}.ie-file{font-size:11px;color:var(--text-dim)}.ie-warn{font-size:11px;color:var(--pk);margin:0}.ie-error{font-size:12px;color:var(--err);margin:0}.ie-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:4px}:root{--bg: #14110f;--bg-raised: #1c1815;--bg-card: #221d19;--border: #33291f;--border-strong: #4a3c2c;--text: #ece6dd;--text-dim: #a89a86;--accent: #e0a63a;--accent-soft: rgba(224, 166, 58, .15);--accent-ink: #241a08;--pk: #f2c14e;--err: #f0857a;--warn: #e6a94a;--ok: #6cbf73;--font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;--mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace}*{box-sizing:border-box}html,body,#root{height:100%;margin:0}body{font-family:var(--font);background:var(--bg);color:var(--text)}.app{display:flex;flex-direction:column;height:100%}.canvas-wrap{flex:1;position:relative;min-height:0}.react-flow{background:var(--bg)}.topbar{display:flex;flex-direction:column;padding:8px 16px 0;background:var(--bg-raised);border-bottom:1px solid var(--border);z-index:10}.topbar-row{display:flex;align-items:center;gap:14px}.topbar-row.context{padding-bottom:8px}.topbar-row.actions{gap:10px;padding-bottom:8px;flex-wrap:wrap}.brand{display:flex;align-items:baseline;gap:8px;white-space:nowrap}.logo{color:var(--accent);font-size:18px}.brand-name{font-weight:700;letter-spacing:.02em}.project-name{color:var(--text-dim);font-size:13px}.search{flex:0 1 300px;margin-left:auto;padding:7px 12px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-size:13px;outline:none}.search:focus{border-color:var(--accent)}.stats{display:flex;align-items:center;gap:12px;font-size:12px;color:var(--text-dim)}.stat-item{display:inline-flex;align-items:center;gap:5px}.stat-item svg{color:var(--text-dim)}.diag-chip{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:99px;font-weight:600}.diag-chip.ok{background:#34d39926;color:var(--ok)}.diag-chip.warn{background:#fbbf2426;color:var(--warn)}.diag-chip.err{background:#f8717126;color:var(--err)}.hamburger{position:relative;display:inline-flex;align-items:center;justify-content:center;padding:6px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer}.hamburger:hover{color:var(--text);border-color:var(--border-strong)}.hamburger.active{color:var(--accent);border-color:var(--accent)}.hamburger-badge{position:absolute;top:-6px;right:-6px;min-width:15px;height:15px;padding:0 3px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-size:10px;font-weight:700;line-height:15px;text-align:center}.btn-group{display:inline-flex;align-items:center;gap:2px;background:var(--bg-card);border:1px solid var(--border);border-radius:9px;padding:2px}.grp-tag{font-size:10px;color:var(--text-dim);opacity:.75;padding:0 6px 0 4px;letter-spacing:.03em;text-transform:none;white-space:nowrap}.grp-btn{display:inline-flex;align-items:center;gap:5px;padding:5px 9px;border-radius:6px;border:none;background:transparent;color:var(--text-dim);cursor:pointer;font-size:12px;white-space:nowrap}.grp-btn.icon-only{padding:5px 7px}.grp-btn:hover{color:var(--text);background:#ffffff0d}.grp-btn.active{color:var(--accent)}.grp-btn.active svg{color:var(--accent)}.grp-badge{width:6px;height:6px;border-radius:50%;background:var(--warn);display:inline-block;margin-left:1px}.dir-arrow{display:inline-flex;transition:transform .15s ease}.tool-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 11px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.tool-btn:hover{color:var(--text);border-color:var(--border-strong)}.tool-btn.active{color:var(--accent);border-color:var(--accent)}.tool-btn.primary{color:var(--accent);border-color:#e0a63a66;font-weight:600}.layout-picker{position:relative;display:inline-flex;gap:2px}.layout-picker .caret{font-size:10px}.layout-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:20;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:8px;padding:4px;min-width:150px;box-shadow:0 8px 24px #0006}.layout-menu button{display:block;width:100%;text-align:left;padding:7px 10px;border:0;border-radius:6px;background:transparent;color:var(--text-dim);cursor:pointer;font-size:13px}.layout-menu button:hover{background:var(--bg-card);color:var(--text)}.canvas-drawer{position:absolute;top:12px;left:12px;bottom:12px;width:300px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:16px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080;display:flex;flex-direction:column;gap:10px;transform:translate(calc(-100% - 16px));opacity:0;pointer-events:none;transition:transform .2s ease,opacity .2s ease}.canvas-drawer.open{transform:translate(0);opacity:1;pointer-events:auto}.drawer-header{display:flex;align-items:center;justify-content:space-between}.drawer-header h2{margin:0;font-size:15px;display:inline-flex;align-items:center;gap:7px}.drawer-header h2 svg{color:var(--accent)}.drawer-hint{font-size:11px;color:var(--text-dim);line-height:1.4}.sa-all{align-self:flex-start;padding:4px 10px;border-radius:7px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.sa-all:hover:not(:disabled){color:var(--text);border-color:var(--border-strong)}.sa-all.active{color:var(--accent);border-color:var(--accent)}.sa-all:disabled{opacity:.5;cursor:default}.sa-list{display:flex;flex-direction:column;gap:3px;margin-top:2px}.sa-row{display:flex;align-items:center;gap:9px;padding:7px 8px;border-radius:8px;cursor:pointer;border:1px solid transparent;-webkit-user-select:none;user-select:none}.sa-row:hover{background:var(--bg-card)}.sa-row.active{background:var(--accent-soft);border-color:#e0a63a66}.sa-row.muted{cursor:default;opacity:.7}.sa-row.muted:hover{background:transparent}.sa-row input[type=checkbox]{accent-color:var(--accent);cursor:pointer}.sa-chip{width:12px;height:12px;border-radius:3px;flex:0 0 auto}.sa-chip.none{background:repeating-linear-gradient(45deg,#4a3c2c,#4a3c2c 2px,transparent 2px,transparent 4px)}.sa-name{flex:1;font-size:13px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.sa-row.muted .sa-name{color:var(--text-dim)}.sa-count{font-size:11px;color:var(--text-dim);background:var(--bg-card);padding:1px 7px;border-radius:99px;flex:0 0 auto}.entity-node{width:264px;background:var(--bg-card);border:1px solid var(--border);border-top:3px solid var(--accent);border-radius:10px;overflow:hidden;box-shadow:0 4px 18px #00000059;font-size:12px;transition:opacity .15s,box-shadow .15s,border-color .15s}.entity-node.selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent),0 8px 24px #00000080}.entity-node.highlighted{box-shadow:0 0 0 2px var(--pk),0 8px 24px #00000080}.entity-node.dimmed{opacity:.18}.entity-header{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#ffffff08;border-bottom:1px solid var(--border)}.entity-name{font-weight:700;font-size:13px;letter-spacing:.01em}.entity-badges{display:flex;gap:4px}.badge{font-size:10px;padding:1px 6px;border-radius:99px;background:var(--accent-soft);color:var(--accent);text-transform:uppercase;letter-spacing:.05em}.badge.ontology{background:#93c5fd1f;color:#93c5fd}.attr-section{padding:4px 0}.attr-section.keys{border-bottom:1px solid var(--border);background:#fcd34d0a}.attr-row{display:flex;align-items:center;gap:6px;padding:3px 12px;height:26px;line-height:20px;position:relative}.attr-row.empty{color:var(--text-dim);font-style:italic}.attr-row.more{color:var(--text-dim);font-style:italic;cursor:pointer;justify-content:center;height:22px;font-size:11px}.attr-row.more:hover{color:var(--accent);background:var(--accent-soft)}.attr-row.rel-hit{background:var(--accent-soft);box-shadow:inset 2px 0 0 var(--accent)}.attr-row.rel-hit .attr-name{color:var(--accent);font-weight:600}.attr-row.rel-dim{opacity:.35}.attr-row.endpoint .attr-name{font-style:normal}.attr-port{width:8px!important;height:8px!important;opacity:0;top:50%!important}.attr-port.react-flow__handle-left{left:-5px!important}.attr-port.react-flow__handle-right{right:-5px!important}.entity-node:hover .attr-port{opacity:.5}.attr-row:hover .attr-port{opacity:1!important;background:var(--accent)!important}.attr-icon{width:14px;text-align:center;font-size:10px;flex:none}.attr-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attr-name.pk{color:var(--pk);font-weight:600}.attr-type{color:var(--text-dim);font-family:var(--mono);font-size:10px;flex:none}.attr-notnull{color:var(--text-dim);font-size:8px;flex:none}.port{width:11px!important;height:11px!important;background:var(--border-strong)!important;border:2px solid var(--bg)!important;opacity:.55;transition:transform .12s ease,background .12s ease,opacity .12s ease}.entity-node:hover .port{opacity:1;background:var(--accent)!important;transform:scale(1.25);box-shadow:0 0 0 4px var(--accent-soft);cursor:crosshair}.port:hover{transform:scale(1.6)!important;cursor:crosshair}.entity-node:hover{border-color:var(--accent);box-shadow:0 0 0 1px #e0a63a40}.react-flow__connectionline .react-flow__edge-path,.react-flow__connection-path{stroke:var(--accent)!important;stroke-width:2!important}.rel-path{stroke:var(--border-strong);stroke-width:1.6}.rel-edge{cursor:pointer}.rel-glyph{stroke:var(--border-strong);stroke-width:1.6;fill:none}.rel-glyph.ring{fill:var(--bg)}.rel-edge:hover .rel-path,.rel-edge.selected .rel-path,.rel-edge:hover .rel-glyph,.rel-edge.selected .rel-glyph{stroke:var(--accent)}.rel-edge.dimmed{opacity:.12}.rel-label{fill:var(--text);font-size:11px;text-anchor:middle;paint-order:stroke;stroke:var(--bg);stroke-width:4px}.rel-handle{cursor:ew-resize}.rel-handle,.rel-handle *{cursor:ew-resize!important}.rel-handle .rel-grip{fill:var(--accent);stroke:var(--bg);opacity:.95}.rel-handle .rel-grip-dot{fill:var(--bg)}.rel-handle:hover .rel-grip{fill:var(--accent);filter:brightness(1.15)}.rel-endpoint,.rel-endpoint *{cursor:move!important}.rel-endpoint .rel-endpoint-dot{fill:var(--accent);stroke:var(--bg);opacity:.95}.rel-endpoint:hover .rel-endpoint-dot{filter:brightness(1.2)}.layout-menu-sep{height:1px;margin:4px 0;background:var(--border)}.detail-panel{position:absolute;top:12px;right:12px;bottom:12px;width:340px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.detail-header{display:flex;justify-content:space-between;align-items:flex-start}.detail-header h2{margin:0 0 6px;font-size:18px}.icon-btn{background:none;border:none;color:var(--text-dim);cursor:pointer;font-size:14px}.icon-btn:hover{color:var(--text)}.definition{color:var(--text-dim);font-size:13px;line-height:1.5}.detail-panel section{margin-top:18px}.detail-panel h3{margin:0 0 8px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.kv{display:flex;gap:8px;margin:4px 0;font-size:12px;align-items:baseline}.kv .k{color:var(--text-dim);min-width:72px}.kv .v{word-break:break-all}.chip{display:inline-block;font-size:11px;padding:2px 8px;margin:2px 4px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim)}.chip.pattern{background:var(--accent-soft);color:var(--accent)}.chip.layer-industry{background:#93c5fd26;color:#93c5fd}.chip.layer-core{background:var(--accent-soft);color:var(--accent)}.chip.layer-domain{background:#f0abfc26;color:#f0abfc}.chip.layer-specialised{background:#fcd34d26;color:var(--pk)}.cat-badge{font-size:10px;font-weight:700;margin-left:6px;padding:2px 8px;border-radius:5px;cursor:help}.cat-badge.supertype{background:#a78bfa2e;color:#a78bfa}.cat-badge.subtype{background:var(--accent-soft);color:var(--accent)}.udp-row td{padding:3px 6px;border-bottom:1px solid var(--border);font-size:12px}.udp-key{color:var(--text-dim);font-family:var(--mono);font-size:11px}.udp-val{color:var(--text)}.enum-badge{font-size:8px;font-weight:700;margin-left:6px;padding:1px 5px;border-radius:4px;background:#a78bfa2e;color:#a78bfa;vertical-align:middle;cursor:help}.key-row{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:12px}.key-badge{font-size:9px;font-weight:700;padding:2px 6px;border-radius:5px;background:#94a3b826;color:var(--text-dim);flex:none}.key-badge.pk{background:#fcd34d2e;color:var(--pk)}.key-badge.unique,.key-badge.alternate{background:var(--accent-soft);color:var(--accent)}.key-name{font-weight:600}.key-cols{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}.attr-table td{padding:4px 6px;border-bottom:1px solid var(--border)}.attr-table td:first-child{width:100%}.attr-table td:first-child .edit-input{min-width:120px}.attr-table td.pk{color:var(--pk);font-weight:600}.attr-table td.type{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table td.null{color:var(--text-dim);font-size:10px;text-align:right}.rel-link{display:flex;gap:8px;align-items:center;width:100%;background:var(--bg-card);border:1px solid var(--border);border-radius:8px;color:var(--text);padding:7px 10px;margin:4px 0;cursor:pointer;font-size:12px;text-align:left}.rel-link:hover{border-color:var(--accent)}.rel-card{color:var(--text-dim);font-family:var(--mono);font-size:11px}.ulid{font-family:var(--mono);font-size:11px;color:var(--text-dim);cursor:copy;word-break:break-all}.ulid:hover{color:var(--accent)}.splash{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--text-dim)}.splash.error pre{background:var(--bg-card);padding:12px 16px;border-radius:8px;max-width:640px;overflow:auto;color:var(--err);font-size:12px}.react-flow__minimap{background:var(--bg-raised)!important;border-radius:10px}.react-flow__controls{border-radius:10px;overflow:hidden;box-shadow:none!important}.react-flow__controls-button{background:var(--bg-raised)!important;border-bottom:1px solid var(--border)!important;fill:var(--text-dim)!important}.react-flow__controls-button:hover{fill:var(--text)!important}.edit-input{width:100%;padding:6px 9px;border-radius:7px;font-size:12px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-family:var(--font);outline:none}.edit-input:focus{border-color:var(--accent)}.entity-title-input{font-size:17px;font-weight:700;background:transparent;border-color:transparent;padding-left:0}.entity-title-input:hover,.entity-title-input:focus{border-color:var(--border);background:var(--bg-card);padding-left:9px}.definition-input{color:var(--text-dim);line-height:1.5;resize:vertical}.chip-select,.cell-select{font-size:11px;padding:2px 6px;margin:2px 6px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim);border:1px solid transparent;outline:none}.chip-select:hover,.cell-select:hover{border-color:var(--border-strong);color:var(--text)}.cell-select{border-radius:6px;background:transparent;max-width:110px}.mini-btn{font-size:11px;padding:3px 9px;border-radius:7px;cursor:pointer;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim)}.mini-btn:hover{color:var(--accent);border-color:var(--accent)}.mini-btn.danger:hover{color:var(--err);border-color:var(--err)}.h3-actions{float:right;display:inline-flex;gap:6px}.empty-hint{color:var(--text-dim);font-size:12px;font-style:italic}.add-attr{display:flex;gap:6px;margin-top:8px}.rel-row{display:flex;gap:6px;align-items:flex-start}.rel-row .rel-main{flex:1}.verb-phrases{display:flex;align-items:center;gap:4px;margin-top:2px;padding-left:4px}.verb-phrases .verb-input{font-size:11px;font-style:italic;color:var(--text-dim);min-width:40px}.verb-phrases .verb-sep{color:var(--text-dim);font-size:11px}.physical-name-row{display:flex;align-items:center;gap:6px;margin-top:2px}.physical-name-row .physical-label{font-size:9px;text-transform:uppercase;color:var(--text-dim);letter-spacing:.04em}.physical-name-input{font-size:12px;color:var(--text-dim)}.physical-col{display:block;font-size:10px;color:var(--text-dim);font-family:var(--mono, monospace)}.physical-col-input{display:block;font-size:10px;color:var(--text-dim)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#05080db3;z-index:50;display:flex;align-items:center;justify-content:center}.modal{width:440px;max-height:80vh;overflow-y:auto;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:14px;padding:20px;box-shadow:0 24px 80px #0009}.modal.wide{width:600px}.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}.modal-header h2{margin:0;font-size:16px}.modal-search{margin-bottom:10px}.modal-footer{display:flex;gap:10px;justify-content:flex-end;align-items:center;margin-top:14px}.modal-footer label{font-size:11px;color:var(--text-dim);display:flex;flex-direction:column;gap:3px}.modal-footer select,.form-row select{background:var(--bg-card);color:var(--text);border:1px solid var(--border);border-radius:7px;padding:5px 8px;font-size:12px}.primary-btn{padding:8px 16px;border-radius:8px;border:none;cursor:pointer;background:var(--accent);color:var(--accent-ink);font-weight:700;font-size:13px}.primary-btn:disabled{opacity:.4;cursor:default}.danger-btn{padding:8px 16px;border-radius:8px;border:1px solid var(--err);cursor:pointer;background:#f8717124;color:var(--err);font-weight:700;font-size:13px}.form-row{display:flex;flex-direction:column;gap:4px;margin-bottom:14px;font-size:12px;color:var(--text-dim)}.form-row>label{font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:10px}.form-error{color:var(--err);font-size:11px}.form-preview{color:var(--text-dim);font-size:11px;word-break:break-all;opacity:.85}.form-preview:before{content:""}.form-hint{color:var(--text-dim);font-size:11px;font-style:italic;opacity:.75;word-break:break-word}.term-results{display:flex;flex-direction:column;gap:8px;max-height:44vh;overflow-y:auto}.term-card{text-align:left;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:10px 12px;cursor:pointer;color:var(--text)}.term-card:hover{border-color:var(--border-strong)}.term-card.picked{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}.term-head{display:flex;justify-content:space-between;align-items:baseline}.term-label{font-weight:600;font-size:13px}.term-source{font-size:10px;color:var(--text-dim);text-transform:uppercase;letter-spacing:.06em}.term-iri{font-size:10px;color:var(--accent);display:block;margin:2px 0;word-break:break-all}.term-def{font-size:11px;color:var(--text-dim);margin:4px 0 0;line-height:1.45}.kind-badge{font-size:8px;padding:1px 5px;margin-right:6px;border-radius:999px;background:#f0abfc26;color:#f0abfc;letter-spacing:.04em}.src-picker{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}.src-chip{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:3px 9px;border-radius:999px;background:var(--bg);border:1px solid var(--border);color:var(--text-dim);cursor:pointer}.src-chip:hover{border-color:var(--border-strong);color:var(--text)}.src-chip.active{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}.src-layer{font-size:8px;padding:0 5px;border-radius:999px;text-transform:uppercase;letter-spacing:.04em}.side-panel{position:absolute;top:12px;right:12px;bottom:12px;width:380px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.side-panel h2{margin:0;font-size:16px}.side-panel h4{margin:10px 0 6px;font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.panel-body{margin-top:12px}.panel-body.ok{color:var(--ok)}.meta-line{font-size:10px;color:var(--text-dim);margin:6px 0 10px}.coverage-banner{font-size:12px;padding:8px 12px;border-radius:9px;margin-bottom:12px;background:#34d3991a;color:var(--ok)}.coverage-banner.warn{background:#fbbf241a;color:var(--warn)}.layer-band{border:1px dashed var(--border);border-radius:10px;padding:8px 12px 10px;margin-bottom:10px}.layer-band.external{border-style:solid;background:#93c5fd0a}.stack-term{display:flex;justify-content:space-between;align-items:baseline;gap:8px;width:100%;background:var(--bg-card);border:1px solid var(--border);color:var(--text);border-radius:7px;padding:5px 10px;margin:4px 0;font-size:12px;cursor:pointer;text-align:left}div.stack-term{cursor:default}.stack-term:hover{border-color:var(--border-strong)}.stack-term.uncovered{border-color:var(--err)}.align-arrow{font-size:10px;color:var(--accent);white-space:nowrap}.align-arrow.unresolved{color:var(--warn)}.align-arrow.missing{color:var(--err);font-style:italic}.align-arrow.proposed{color:var(--warn);font-style:italic}.ref-list{display:flex;flex-direction:column;gap:6px;margin-top:4px}.ref-card{border:1px solid var(--border);border-radius:8px;padding:6px 8px;background:var(--bg)}.ref-card.proposed{border-color:var(--warn)}.ref-head{display:flex;align-items:baseline;gap:8px;justify-content:space-between}.ref-uri{font-family:var(--mono);font-size:12px;word-break:break-all}.ref-status{font-size:9px;text-transform:uppercase;letter-spacing:.04em}.ref-status.accepted{color:var(--accent)}.ref-status.proposed{color:var(--warn)}.ref-meta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:5px}.ref-pill{font-size:10px;padding:1px 6px;border-radius:999px;background:var(--accent-soft);color:var(--accent)}.ref-via{font-size:10px;color:var(--text-dim)}.ref-actions{display:flex;gap:6px;margin-top:6px}.dirty-list{list-style:none;padding:0;margin:0 0 10px;font-size:12px}.dirty-list li{padding:2px 0}.dirty-state{color:var(--warn);margin-right:6px;font-family:var(--mono)}.diff-view{background:var(--bg);border:1px solid var(--border);border-radius:9px;padding:10px;font-size:10.5px;line-height:1.5;overflow:auto;max-height:42vh;font-family:var(--mono);white-space:pre;margin-bottom:10px}.diff-add{color:var(--ok)}.diff-del{color:var(--err)}.diff-hunk{color:#93c5fd}.decision{border:1px solid var(--border);border-radius:9px;padding:8px 12px;margin-bottom:8px}.decision.accepted{opacity:.65}.decision.rejected{opacity:.45}.decision-head{display:flex;gap:6px;align-items:center}.decision-mark{font-weight:700}.decision-subject{font-size:12px;margin:6px 0}.decision-actions{display:flex;gap:6px}.toast{position:absolute;bottom:20px;left:50%;transform:translate(-50%);background:var(--bg-raised);border:1px solid var(--warn);color:var(--text);border-radius:10px;padding:10px 18px;font-size:12px;z-index:60;box-shadow:0 10px 30px #00000080} diff --git a/packages/server/src/mdl_server/static/assets/styles-Dfh1I8li.js b/packages/server/src/mdl_server/static/assets/styles-Dfh1I8li.js new file mode 100644 index 0000000..861a234 --- /dev/null +++ b/packages/server/src/mdl_server/static/assets/styles-Dfh1I8li.js @@ -0,0 +1,23 @@ +var lc=Object.defineProperty;var uc=(e,t,n)=>t in e?lc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _e=(e,t,n)=>uc(e,typeof t!="symbol"?t+"":t,n);import{r as w,g as ko,R as A,j as h}from"./client-DOmNpTln.js";function Me(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?xc:yc;$o.useSyncExternalStore=It.useSyncExternalStore!==void 0?It.useSyncExternalStore:wc;Mo.exports=$o;var bc=Mo.exports;/** + * @license React + * use-sync-external-store-shim/with-selector.production.js + * + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var Dn=w,vc=bc;function _c(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var Ec=typeof Object.is=="function"?Object.is:_c,Nc=vc.useSyncExternalStore,Sc=Dn.useRef,kc=Dn.useEffect,jc=Dn.useMemo,Cc=Dn.useDebugValue;Co.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var o=Sc(null);if(o.current===null){var i={hasValue:!1,value:null};o.current=i}else i=o.current;o=jc(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&i.hasValue){var p=i.value;if(s(p,f))return d=p}return d=f}if(p=d,Ec(u,f))return p;var x=r(f);return s!==void 0&&s(p,x)?(u=f,p):(u=f,d=x)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=Nc(e,o[0],o[1]);return kc(function(){i.hasValue=!0,i.value=a},[a]),Cc(a),a};jo.exports=Co;var Mc=jo.exports;const $c=ko(Mc),Ac={},ts=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(p=>p(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(Ac?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Rc=e=>e?ts(e):ts,{useDebugValue:Ic}=A,{useSyncExternalStoreWithSelector:Tc}=$c,Oc=e=>e;function Ao(e,t=Oc,n){const r=Tc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Ic(r),r}const ns=(e,t)=>{const n=Rc(e),r=(s,o=t)=>Ao(n,s,o);return Object.assign(r,n),r},Lc=(e,t)=>e?ns(e,t):ns;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Dc={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Pc(e+"",n),s,o=-1,i=r.length;if(arguments.length<2){for(;++o0)for(var n=new Array(s),r=0,s,o;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),ss.hasOwnProperty(t)?{space:ss[t],local:e}:e}function Hc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===fr&&t.documentElement.namespaceURI===fr?t.createElement(e):t.createElementNS(n,e)}}function Fc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Ro(e){var t=zn(e);return(t.local?Fc:Hc)(t)}function Vc(){}function Mr(e){return e==null?Vc:function(){return this.querySelector(e)}}function Bc(e){typeof e!="function"&&(e=Mr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=C&&(C=E+1);!($=_[C])&&++C=0;)(i=r[s])&&(o&&i.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(i,o),o=i);return this}function ml(e){e||(e=pl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),o=0;ot?1:e>=t?0:NaN}function gl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function yl(){return Array.from(this)}function xl(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Ml:typeof t=="function"?Al:$l)(e,t,n??"")):Tt(this.node(),e)}function Tt(e,t){return e.style.getPropertyValue(t)||Do(e).getComputedStyle(e,null).getPropertyValue(t)}function Il(e){return function(){delete this[e]}}function Tl(e,t){return function(){this[e]=t}}function Ol(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Ll(e,t){return arguments.length>1?this.each((t==null?Il:typeof t=="function"?Ol:Tl)(e,t)):this.node()[e]}function Po(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new zo(e)}function zo(e){this._node=e,this._names=Po(e.getAttribute("class")||"")}zo.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Ho(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function uu(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,o;n()=>e;function hr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:o,x:i,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}hr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function bu(e){return!e.ctrlKey&&!e.button}function vu(){return this.parentNode}function _u(e,t){return t??{x:e.x,y:e.y}}function Eu(){return navigator.maxTouchPoints||"ontouchstart"in this}function Nu(){var e=bu,t=vu,n=_u,r=Eu,s={},o=Pn("start","drag","end"),i=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",_).on("touchmove.drag",g,wu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,$){if(!(u||!e.call(this,b,$))){var j=C(this,t.call(this,b,$),b,$,"mouse");j&&(Pe(b.view).on("mousemove.drag",p,qt).on("mouseup.drag",x,qt),Go(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,j("start",b))}}function p(b){if($t(b),!l){var $=b.clientX-a,j=b.clientY-c;l=$*$+j*j>d}s.mouse("drag",b)}function x(b){Pe(b.view).on("mousemove.drag mouseup.drag",null),Yo(b.view,l),$t(b),s.mouse("end",b)}function _(b,$){if(e.call(this,b,$)){var j=b.changedTouches,v=t.call(this,b,$),R=j.length,N,T;for(N=0;N>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?dn(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?dn(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=ku.exec(e))?new Oe(t[1],t[2],t[3],1):(t=ju.exec(e))?new Oe(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Cu.exec(e))?dn(t[1],t[2],t[3],t[4]):(t=Mu.exec(e))?dn(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=$u.exec(e))?ds(t[1],t[2]/100,t[3]/100,1):(t=Au.exec(e))?ds(t[1],t[2]/100,t[3]/100,t[4]):os.hasOwnProperty(e)?cs(os[e]):e==="transparent"?new Oe(NaN,NaN,NaN,0):null}function cs(e){return new Oe(e>>16&255,e>>8&255,e&255,1)}function dn(e,t,n,r){return r<=0&&(e=t=n=NaN),new Oe(e,t,n,r)}function Tu(e){return e instanceof sn||(e=Qt(e)),e?(e=e.rgb(),new Oe(e.r,e.g,e.b,e.opacity)):new Oe}function mr(e,t,n,r){return arguments.length===1?Tu(e):new Oe(e,t,n,r??1)}function Oe(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Ar(Oe,mr,Xo(sn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Oe(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Kt:Math.pow(Kt,e),new Oe(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Oe(wt(this.r),wt(this.g),wt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:ls,formatHex:ls,formatHex8:Ou,formatRgb:us,toString:us}));function ls(){return`#${yt(this.r)}${yt(this.g)}${yt(this.b)}`}function Ou(){return`#${yt(this.r)}${yt(this.g)}${yt(this.b)}${yt((isNaN(this.opacity)?1:this.opacity)*255)}`}function us(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${wt(this.r)}, ${wt(this.g)}, ${wt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function wt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function yt(e){return e=wt(e),(e<16?"0":"")+e.toString(16)}function ds(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ye(e,t,n,r)}function Wo(e){if(e instanceof Ye)return new Ye(e.h,e.s,e.l,e.opacity);if(e instanceof sn||(e=Qt(e)),!e)return new Ye;if(e instanceof Ye)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),o=Math.max(t,n,r),i=NaN,a=o-s,c=(o+s)/2;return a?(t===o?i=(n-r)/a+(n0&&c<1?0:i,new Ye(i,a,c,e.opacity)}function Lu(e,t,n,r){return arguments.length===1?Wo(e):new Ye(e,t,n,r??1)}function Ye(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Ar(Ye,Lu,Xo(sn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Ye(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Kt:Math.pow(Kt,e),new Ye(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Oe(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Ye(fs(this.h),fn(this.s),fn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${fs(this.h)}, ${fn(this.s)*100}%, ${fn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function fs(e){return e=(e||0)%360,e<0?e+360:e}function fn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Uo=e=>()=>e;function Du(e,t){return function(n){return e+n*t}}function Pu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function zu(e){return(e=+e)==1?qo:function(t,n){return n-t?Pu(t,n,e):Uo(isNaN(t)?n:t)}}function qo(e,t){var n=t-e;return n?Du(e,n):Uo(isNaN(e)?t:e)}const hs=function e(t){var n=zu(t);function r(s,o){var i=n((s=mr(s)).r,(o=mr(o)).r),a=n(s.g,o.g),c=n(s.b,o.b),l=qo(s.opacity,o.opacity);return function(u){return s.r=i(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function lt(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var pr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(pr.source,"g");function Hu(e){return function(){return e}}function Fu(e){return function(t){return e(t)+""}}function Vu(e,t){var n=pr.lastIndex=Kn.lastIndex=0,r,s,o,i=-1,a=[],c=[];for(e=e+"",t=t+"";(r=pr.exec(e))&&(s=Kn.exec(t));)(o=s.index)>n&&(o=t.slice(n,o),a[i]?a[i]+=o:a[++i]=o),(r=r[0])===(s=s[0])?a[i]?a[i]+=s:a[++i]=s:(a[++i]=null,c.push({i,x:lt(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:lt(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:lt(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,p){if(l!==d||u!==m){var x=f.push(s(f)+"scale(",null,",",null,")");p.push({i:x-4,x:lt(l,d)},{i:x-2,x:lt(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),o(l.translateX,l.translateY,u.translateX,u.translateY,d,m),i(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var p=-1,x=m.length,_;++p=0&&e._call.call(void 0,t),e=e._next;--Ot}function gs(){vt=(Cn=Jt.now())+Hn,Ot=Yt=0;try{Qu()}finally{Ot=0,ed(),vt=0}}function Ju(){var e=Jt.now(),t=e-Cn;t>Qo&&(Hn-=t,Cn=e)}function ed(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Xt=e,yr(r)}function yr(e){if(!Ot){Yt&&(Yt=clearTimeout(Yt));var t=e-vt;t>24?(e<1/0&&(Yt=setTimeout(gs,e-Jt.now()-Hn)),Ht&&(Ht=clearInterval(Ht))):(Ht||(Cn=Jt.now(),Ht=setInterval(Ju,Qo)),Ot=1,Jo(gs))}}function ys(e,t,n){var r=new Mn;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var td=Pn("start","end","cancel","interrupt"),nd=[],ti=0,xs=1,xr=2,vn=3,ws=4,wr=5,_n=6;function Fn(e,t,n,r,s,o){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;rd(e,n,{name:t,index:r,group:s,on:td,tween:nd,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:ti})}function Ir(e,t){var n=Xe(e,t);if(n.state>ti)throw new Error("too late; already scheduled");return n}function Ze(e,t){var n=Xe(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Xe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function rd(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=ei(o,0,n.time);function o(l){n.state=xs,n.timer.restart(i,n.delay,n.time),n.delay<=l&&i(l-n.delay)}function i(l){var u,d,m,f;if(n.state!==xs)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return ys(i);f.state===ws?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uxr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function Id(e,t,n){var r,s,o=Rd(t)?Ir:Ze;return function(){var i=o(this,e),a=i.on;a!==r&&(s=(r=a).copy()).on(t,n),i.on=s}}function Td(e,t){var n=this._id;return arguments.length<2?Xe(this.node(),n).on.on(e):this.each(Id(n,e,t))}function Od(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Ld(){return this.on("end.remove",Od(this._id))}function Dd(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Mr(e));for(var r=this._groups,s=r.length,o=new Array(s),i=0;i()=>e;function lf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function nt(e,t,n){this.k=e,this.x=t,this.y=n}nt.prototype={constructor:nt,scale:function(e){return e===1?this:new nt(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new nt(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var rt=new nt(1,0,0);nt.prototype;function Zn(e){e.stopImmediatePropagation()}function Ft(e){e.preventDefault(),e.stopImmediatePropagation()}function uf(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function df(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function bs(){return this.__zoom||rt}function ff(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function hf(){return navigator.maxTouchPoints||"ontouchstart"in this}function mf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),i>o?(o+i)/2:Math.min(0,o)||Math.max(0,i))}function oi(){var e=uf,t=df,n=mf,r=ff,s=hf,o=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Ku,l=Pn("start","zoom","end"),u,d,m,f=500,p=150,x=0,_=10;function g(y){y.property("__zoom",bs).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",T).filter(s).on("touchstart.zoom",P).on("touchmove.zoom",G).on("touchend.zoom touchcancel.zoom",V).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(y,M,S,O){var z=y.selection?y.selection():y;z.property("__zoom",bs),y!==z?$(y,M,S,O):z.interrupt().each(function(){j(this,arguments).event(O).start().zoom(null,typeof M=="function"?M.apply(this,arguments):M).end()})},g.scaleBy=function(y,M,S,O){g.scaleTo(y,function(){var z=this.__zoom.k,k=typeof M=="function"?M.apply(this,arguments):M;return z*k},S,O)},g.scaleTo=function(y,M,S,O){g.transform(y,function(){var z=t.apply(this,arguments),k=this.__zoom,I=S==null?b(z):typeof S=="function"?S.apply(this,arguments):S,L=k.invert(I),D=typeof M=="function"?M.apply(this,arguments):M;return n(C(E(k,D),I,L),z,i)},S,O)},g.translateBy=function(y,M,S,O){g.transform(y,function(){return n(this.__zoom.translate(typeof M=="function"?M.apply(this,arguments):M,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),i)},null,O)},g.translateTo=function(y,M,S,O,z){g.transform(y,function(){var k=t.apply(this,arguments),I=this.__zoom,L=O==null?b(k):typeof O=="function"?O.apply(this,arguments):O;return n(rt.translate(L[0],L[1]).scale(I.k).translate(typeof M=="function"?-M.apply(this,arguments):-M,typeof S=="function"?-S.apply(this,arguments):-S),k,i)},O,z)};function E(y,M){return M=Math.max(o[0],Math.min(o[1],M)),M===y.k?y:new nt(M,y.x,y.y)}function C(y,M,S){var O=M[0]-S[0]*y.k,z=M[1]-S[1]*y.k;return O===y.x&&z===y.y?y:new nt(y.k,O,z)}function b(y){return[(+y[0][0]+ +y[1][0])/2,(+y[0][1]+ +y[1][1])/2]}function $(y,M,S,O){y.on("start.zoom",function(){j(this,arguments).event(O).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(O).end()}).tween("zoom",function(){var z=this,k=arguments,I=j(z,k).event(O),L=t.apply(z,k),D=S==null?b(L):typeof S=="function"?S.apply(z,k):S,q=Math.max(L[1][0]-L[0][0],L[1][1]-L[0][1]),F=z.__zoom,J=typeof M=="function"?M.apply(z,k):M,ee=c(F.invert(D).concat(q/F.k),J.invert(D).concat(q/J.k));return function(se){if(se===1)se=J;else{var le=ee(se),ne=q/le[2];se=new nt(ne,D[0]-le[0]*ne,D[1]-le[1]*ne)}I.zoom(null,se)}})}function j(y,M,S){return!S&&y.__zooming||new v(y,M)}function v(y,M){this.that=y,this.args=M,this.active=0,this.sourceEvent=null,this.extent=t.apply(y,M),this.taps=0}v.prototype={event:function(y){return y&&(this.sourceEvent=y),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(y,M){return this.mouse&&y!=="mouse"&&(this.mouse[1]=M.invert(this.mouse[0])),this.touch0&&y!=="touch"&&(this.touch0[1]=M.invert(this.touch0[0])),this.touch1&&y!=="touch"&&(this.touch1[1]=M.invert(this.touch1[0])),this.that.__zoom=M,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(y){var M=Pe(this.that).datum();l.call(y,this.that,new lf(y,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:l}),M)}};function R(y,...M){if(!e.apply(this,arguments))return;var S=j(this,M).event(y),O=this.__zoom,z=Math.max(o[0],Math.min(o[1],O.k*Math.pow(2,r.apply(this,arguments)))),k=Ge(y);if(S.wheel)(S.mouse[0][0]!==k[0]||S.mouse[0][1]!==k[1])&&(S.mouse[1]=O.invert(S.mouse[0]=k)),clearTimeout(S.wheel);else{if(O.k===z)return;S.mouse=[k,O.invert(k)],En(this),S.start()}Ft(y),S.wheel=setTimeout(I,p),S.zoom("mouse",n(C(E(O,z),S.mouse[0],S.mouse[1]),S.extent,i));function I(){S.wheel=null,S.end()}}function N(y,...M){if(m||!e.apply(this,arguments))return;var S=y.currentTarget,O=j(this,M,!0).event(y),z=Pe(y.view).on("mousemove.zoom",D,!0).on("mouseup.zoom",q,!0),k=Ge(y,S),I=y.clientX,L=y.clientY;Go(y.view),Zn(y),O.mouse=[k,this.__zoom.invert(k)],En(this),O.start();function D(F){if(Ft(F),!O.moved){var J=F.clientX-I,ee=F.clientY-L;O.moved=J*J+ee*ee>x}O.event(F).zoom("mouse",n(C(O.that.__zoom,O.mouse[0]=Ge(F,S),O.mouse[1]),O.extent,i))}function q(F){z.on("mousemove.zoom mouseup.zoom",null),Yo(F.view,O.moved),Ft(F),O.event(F).end()}}function T(y,...M){if(e.apply(this,arguments)){var S=this.__zoom,O=Ge(y.changedTouches?y.changedTouches[0]:y,this),z=S.invert(O),k=S.k*(y.shiftKey?.5:2),I=n(C(E(S,k),O,z),t.apply(this,M),i);Ft(y),a>0?Pe(this).transition().duration(a).call($,I,O,y):Pe(this).call(g.transform,I,O,y)}}function P(y,...M){if(e.apply(this,arguments)){var S=y.touches,O=S.length,z=j(this,M,y.changedTouches.length===O).event(y),k,I,L,D;for(Zn(y),I=0;I"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},ii=ot.error001();function ge(e,t){const n=w.useContext(Vn);if(n===null)throw new Error(ii);return Ao(n,e,t)}const Ne=()=>{const e=w.useContext(Vn);if(e===null)throw new Error(ii);return w.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},gf=e=>e.userSelectionActive?"none":"all";function Or({position:e,children:t,className:n,style:r,...s}){const o=ge(gf),i=`${e}`.split("-");return A.createElement("div",{className:Me(["react-flow__panel",n,...i]),style:{...r,pointerEvents:o},...s},t)}function yf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Or,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const xf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:o={},labelBgPadding:i=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=w.useRef(null),[m,f]=w.useState({x:0,y:0,width:0,height:0}),p=Me(["react-flow__edge-textwrapper",l]);return w.useEffect(()=>{if(d.current){const x=d.current.getBBox();f({x:x.x,y:x.y,width:x.width,height:x.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:p,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*i[0],x:-i[0],y:-i[1],height:m.height+2*i[1],className:"react-flow__edge-textbg",style:o,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var wf=w.memo(xf);const Lr=e=>({width:e.offsetWidth,height:e.offsetHeight}),Lt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Dr=(e={x:0,y:0},t)=>({x:Lt(e.x,t[0][0],t[1][0]),y:Lt(e.y,t[0][1],t[1][1])}),vs=(e,t,n)=>en?-Lt(Math.abs(e-n),1,50)/50:0,ai=(e,t)=>{const n=vs(e.x,35,t.width-35)*20,r=vs(e.y,35,t.height-35)*20;return[n,r]},ci=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},li=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),en=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),ui=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),_s=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),bf=(e,t)=>ui(li(en(e),en(t))),br=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},vf=e=>ze(e.width)&&ze(e.height)&&ze(e.x)&&ze(e.y),ze=e=>!isNaN(e)&&isFinite(e),be=Symbol.for("internals"),di=["Enter"," ","Escape"],_f=(e,t)=>{},Ef=e=>"nativeEvent"in e;function vr(e){var s,o;const t=Ef(e)?e.nativeEvent:e,n=((o=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:o[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const fi=e=>"clientX"in e,mt=(e,t)=>{var o,i;const n=fi(e),r=n?e.clientX:(o=e.touches)==null?void 0:o[0].clientX,s=n?e.clientY:(i=e.touches)==null?void 0:i[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},$n=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},on=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&ze(n)&&ze(r)?A.createElement(wf,{x:n,y:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);on.displayName="BaseEdge";function Vt(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(o=>o.id===e);s&&n(r,{...s})}}function hi({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,o=n{const[_,g,E]=pi({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:o});return A.createElement(on,{path:_,labelX:g,labelY:E,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:x})});Pr.displayName="SimpleBezierEdge";const Ns={[K.Left]:{x:-1,y:0},[K.Right]:{x:1,y:0},[K.Top]:{x:0,y:-1},[K.Bottom]:{x:0,y:1}},Nf=({source:e,sourcePosition:t=K.Bottom,target:n})=>t===K.Left||t===K.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function Sf({source:e,sourcePosition:t=K.Bottom,target:n,targetPosition:r=K.Top,center:s,offset:o}){const i=Ns[t],a=Ns[r],c={x:e.x+i.x*o,y:e.y+i.y*o},l={x:n.x+a.x*o,y:n.y+a.y*o},u=Nf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],p,x;const _={x:0,y:0},g={x:0,y:0},[E,C,b,$]=hi({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(i[d]*a[d]===-1){p=s.x??E,x=s.y??C;const v=[{x:p,y:c.y},{x:p,y:l.y}],R=[{x:c.x,y:x},{x:l.x,y:x}];i[d]===m?f=d==="x"?v:R:f=d==="x"?R:v}else{const v=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=i.x===m?R:v:f=i.y===m?v:R,t===r){const V=Math.abs(e[d]-n[d]);if(V<=o){const y=Math.min(o-1,o-V);i[d]===m?_[d]=(c[d]>e[d]?-1:1)*y:g[d]=(l[d]>n[d]?-1:1)*y}}if(t!==r){const V=d==="x"?"y":"x",y=i[d]===a[V],M=c[V]>l[V],S=c[V]=G?(p=(N.x+T.x)/2,x=f[0].y):(p=f[0].x,x=(N.y+T.y)/2)}return[[e,{x:c.x+_.x,y:c.y+_.y},...f,{x:l.x+g.x,y:l.y+g.y},n],p,x,b,$]}function kf(e,t,n,r){const s=Math.min(Ss(e,t)/2,Ss(t,n)/2,r),{x:o,y:i}=t;if(e.x===o&&o===n.x||e.y===i&&i===n.y)return`L${o} ${i}`;if(e.y===i){const l=e.x{let C="";return E>0&&E{const[g,E,C]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:x==null?void 0:x.borderRadius,offset:x==null?void 0:x.offset});return A.createElement(on,{path:g,labelX:E,labelY:C,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:p,interactionWidth:_})});Bn.displayName="SmoothStepEdge";const zr=w.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:w.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});zr.displayName="StepEdge";function jf({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,o,i,a]=hi({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,o,i,a]}const Hr=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[p,x,_]=jf({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(on,{path:p,labelX:x,labelY:_,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});Hr.displayName="StraightEdge";function pn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function ks({pos:e,x1:t,y1:n,x2:r,y2:s,c:o}){switch(e){case K.Left:return[t-pn(t-r,o),n];case K.Right:return[t+pn(r-t,o),n];case K.Top:return[t,n-pn(n-s,o)];case K.Bottom:return[t,n+pn(s-n,o)]}}function gi({sourceX:e,sourceY:t,sourcePosition:n=K.Bottom,targetX:r,targetY:s,targetPosition:o=K.Top,curvature:i=.25}){const[a,c]=ks({pos:n,x1:e,y1:t,x2:r,y2:s,c:i}),[l,u]=ks({pos:o,x1:r,y1:s,x2:e,y2:t,c:i}),[d,m,f,p]=mi({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,p]}const In=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=K.Bottom,targetPosition:o=K.Top,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,pathOptions:x,interactionWidth:_})=>{const[g,E,C]=gi({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:o,curvature:x==null?void 0:x.curvature});return A.createElement(on,{path:g,labelX:E,labelY:C,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:_})});In.displayName="BezierEdge";const Fr=w.createContext(null),Cf=Fr.Provider;Fr.Consumer;const Mf=()=>w.useContext(Fr),$f=e=>"id"in e&&"source"in e&&"target"in e,Af=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,_r=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Rf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),If=(e,t)=>{if(!e.source||!e.target)return t;let n;return $f(e)?n={...e}:n={...e,id:Af(e)},Rf(n,t)?t:t.concat(n)},Er=({x:e,y:t},[n,r,s],o,[i,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return o?{x:i*Math.round(c.x/i),y:a*Math.round(c.y/a)}:c},yi=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),bt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},an=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:o,y:i}=bt(s,t).positionAbsolute;return li(r,en({x:o,y:i,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return ui(n)},Tf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),an(e,t)),xi=(e,t,[n,r,s]=[0,0,1],o=!1,i=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:p=!1}=u;if(i&&!f||p)return!1;const{positionAbsolute:x}=bt(u,a),_={x:x.x,y:x.y,width:d||0,height:m||0},g=br(c,_),E=typeof d>"u"||typeof m>"u"||d===null||m===null,C=o&&g>0,b=(d||0)*(m||0);(E||C||g>=b||u.dragging)&&l.push(u)}),l},wi=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},bi=(e,t,n,r,s,o=.1)=>{const i=t/(e.width*(1+o)),a=n/(e.height*(1+o)),c=Math.min(i,a),l=Lt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},gt=(e,t=0)=>e.transition().duration(t);function js(e,t,n,r){return(t[n]||[]).reduce((s,o)=>{var i,a;return`${e.id}-${o.id}-${n}`!==r&&s.push({id:o.id||null,type:n,nodeId:e.id,x:(((i=e.positionAbsolute)==null?void 0:i.x)??0)+o.x+o.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+o.y+o.height/2}),s},[])}function Of(e,t,n,r,s,o){const{x:i,y:a}=mt(e),l=t.elementsFromPoint(i,a).find(p=>p.classList.contains("react-flow__handle"));if(l){const p=l.getAttribute("data-nodeid");if(p){const x=Vr(void 0,l),_=l.getAttribute("data-handleid"),g=o({nodeId:p,id:_,type:x});if(g){const E=s.find(C=>C.nodeId===p&&C.type===x&&C.id===_);return{handle:{id:_,type:x,nodeId:p,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:g}}}}let u=[],d=1/0;if(s.forEach(p=>{const x=Math.sqrt((p.x-n.x)**2+(p.y-n.y)**2);if(x<=r){const _=o(p);x<=d&&(xp.isValid),f=u.some(({handle:p})=>p.type==="target");return u.find(({handle:p,validHandleResult:x})=>f?p.type==="target":m?x.isValid:!0)||u[0]}const Lf={source:null,target:null,sourceHandle:null,targetHandle:null},vi=()=>({handleDomNode:null,isValid:!1,connection:Lf,endHandle:null});function _i(e,t,n,r,s,o,i){const a=s==="target",c=i.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...vi(),handleDomNode:c};if(c){const u=Vr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),p=c.classList.contains("connectableend"),x={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=x,f&&p&&(t===_t.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=o(x))}return l}function Df({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,o)=>{if(o[be]){const{handleBounds:i}=o[be];let a=[],c=[];i&&(a=js(o,i,"source",`${t}-${n}-${r}`),c=js(o,i,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Vr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Pf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function Ei({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:o,setState:i,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ci(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:p,onConnectStart:x,panBy:_,getNodes:g,cancelConnection:E}=o();let C=0,b;const{x:$,y:j}=mt(e),v=u==null?void 0:u.elementFromPoint($,j),R=Vr(c,v),N=m==null?void 0:m.getBoundingClientRect();if(!N||!R)return;let T,P=mt(e,N),G=!1,V=null,y=!1,M=null;const S=Df({nodes:g(),nodeId:n,handleId:t,handleType:R}),O=()=>{if(!f)return;const[I,L]=ai(P,N);_({x:I,y:L}),C=requestAnimationFrame(O)};i({connectionPosition:P,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),x==null||x(e,{nodeId:n,handleId:t,handleType:R});function z(I){const{transform:L}=o();P=mt(I,N);const{handle:D,validHandleResult:q}=Of(I,u,Er(P,L,!1,[1,1]),p,S,F=>_i(F,d,n,t,s?"target":"source",a,u));if(b=D,G||(O(),G=!0),M=q.handleDomNode,V=q.connection,y=q.isValid,i({connectionPosition:b&&y?yi({x:b.x,y:b.y},L):P,connectionStatus:Pf(!!b,y),connectionEndHandle:q.endHandle}),!b&&!y&&!M)return Qn(T);V.source!==V.target&&M&&(Qn(T),T=M,M.classList.add("connecting","react-flow__handle-connecting"),M.classList.toggle("valid",y),M.classList.toggle("react-flow__handle-valid",y))}function k(I){var L,D;(b||M)&&V&&y&&(r==null||r(V)),(D=(L=o()).onConnectEnd)==null||D.call(L,I),c&&(l==null||l(I)),Qn(T),E(),cancelAnimationFrame(C),G=!1,y=!1,V=null,M=null,u.removeEventListener("mousemove",z),u.removeEventListener("mouseup",k),u.removeEventListener("touchmove",z),u.removeEventListener("touchend",k)}u.addEventListener("mousemove",z),u.addEventListener("mouseup",k),u.addEventListener("touchmove",z),u.addEventListener("touchend",k)}const Cs=()=>!0,zf=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Hf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:o,connectionClickStartHandle:i}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n,clickConnecting:(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n}},Ni=w.forwardRef(({type:e="source",position:t=K.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:o=!0,id:i,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var N,T;const p=i||null,x=e==="target",_=Ne(),g=Mf(),{connectOnClick:E,noPanClassName:C}=ge(zf,ke),{connecting:b,clickConnecting:$}=ge(Hf(g,p,e),ke);g||(T=(N=_.getState()).onError)==null||T.call(N,"010",ot.error010());const j=P=>{const{defaultEdgeOptions:G,onConnect:V,hasDefaultEdges:y}=_.getState(),M={...G,...P};if(y){const{edges:S,setEdges:O}=_.getState();O(If(M,S))}V==null||V(M),a==null||a(M)},v=P=>{if(!g)return;const G=fi(P);s&&(G&&P.button===0||!G)&&Ei({event:P,handleId:p,nodeId:g,onConnect:j,isTarget:x,getState:_.getState,setState:_.setState,isValidConnection:n||_.getState().isValidConnection||Cs}),G?u==null||u(P):d==null||d(P)},R=P=>{const{onClickConnectStart:G,onClickConnectEnd:V,connectionClickStartHandle:y,connectionMode:M,isValidConnection:S}=_.getState();if(!g||!y&&!s)return;if(!y){G==null||G(P,{nodeId:g,handleId:p,handleType:e}),_.setState({connectionClickStartHandle:{nodeId:g,type:e,handleId:p}});return}const O=ci(P.target),z=n||S||Cs,{connection:k,isValid:I}=_i({nodeId:g,id:p,type:e},M,y.nodeId,y.handleId||null,y.type,z,O);I&&j(k),V==null||V(P),_.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":p,"data-nodeid":g,"data-handlepos":t,"data-id":`${g}-${p}-${e}`,className:Me(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",C,l,{source:!x,target:x,connectable:r,connectablestart:s,connectableend:o,connecting:$,connectionindicator:r&&(s&&!b||o&&b)}]),onMouseDown:v,onTouchStart:v,onClick:E?R:void 0,ref:f,...m},c)});Ni.displayName="Handle";var ft=w.memo(Ni);const Si=({data:e,isConnectable:t,targetPosition:n=K.Top,sourcePosition:r=K.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ft,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ft,{type:"source",position:r,isConnectable:t}));Si.displayName="DefaultNode";var Nr=w.memo(Si);const ki=({data:e,isConnectable:t,sourcePosition:n=K.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ft,{type:"source",position:n,isConnectable:t}));ki.displayName="InputNode";var ji=w.memo(ki);const Ci=({data:e,isConnectable:t,targetPosition:n=K.Top})=>A.createElement(A.Fragment,null,A.createElement(ft,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);Ci.displayName="OutputNode";var Mi=w.memo(Ci);const Br=()=>null;Br.displayName="GroupNode";const Ff=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),gn=e=>e.id;function Vf(e,t){return ke(e.selectedNodes.map(gn),t.selectedNodes.map(gn))&&ke(e.selectedEdges.map(gn),t.selectedEdges.map(gn))}const $i=w.memo(({onSelectionChange:e})=>{const t=Ne(),{selectedNodes:n,selectedEdges:r}=ge(Ff,Vf);return w.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(o=>o(s))},[n,r,e]),null});$i.displayName="SelectionListener";const Bf=e=>!!e.onSelectionChange;function Gf({onSelectionChange:e}){const t=ge(Bf);return e||t?A.createElement($i,{onSelectionChange:e}):null}const Yf=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Nt(e,t){w.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ae(e,t,n){w.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Xf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:o,onConnectEnd:i,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:p,minZoom:x,maxZoom:_,nodeExtent:g,onNodesChange:E,onEdgesChange:C,elementsSelectable:b,connectionMode:$,snapGrid:j,snapToGrid:v,translateExtent:R,connectOnClick:N,defaultEdgeOptions:T,fitView:P,fitViewOptions:G,onNodesDelete:V,onEdgesDelete:y,onNodeDrag:M,onNodeDragStart:S,onNodeDragStop:O,onSelectionDrag:z,onSelectionDragStart:k,onSelectionDragStop:I,noPanClassName:L,nodeOrigin:D,rfId:q,autoPanOnConnect:F,autoPanOnNodeDrag:J,onError:ee,connectionRadius:se,isValidConnection:le,nodeDragThreshold:ne})=>{const{setNodes:ce,setEdges:we,setDefaultNodesAndEdges:ye,setMinZoom:he,setMaxZoom:ue,setTranslateExtent:me,setNodeExtent:Se,reset:ie}=ge(Yf,ke),Z=Ne();return w.useEffect(()=>{const xe=r==null?void 0:r.map(je=>({...je,...T}));return ye(n,xe),()=>{ie()}},[]),ae("defaultEdgeOptions",T,Z.setState),ae("connectionMode",$,Z.setState),ae("onConnect",s,Z.setState),ae("onConnectStart",o,Z.setState),ae("onConnectEnd",i,Z.setState),ae("onClickConnectStart",a,Z.setState),ae("onClickConnectEnd",c,Z.setState),ae("nodesDraggable",l,Z.setState),ae("nodesConnectable",u,Z.setState),ae("nodesFocusable",d,Z.setState),ae("edgesFocusable",m,Z.setState),ae("edgesUpdatable",f,Z.setState),ae("elementsSelectable",b,Z.setState),ae("elevateNodesOnSelect",p,Z.setState),ae("snapToGrid",v,Z.setState),ae("snapGrid",j,Z.setState),ae("onNodesChange",E,Z.setState),ae("onEdgesChange",C,Z.setState),ae("connectOnClick",N,Z.setState),ae("fitViewOnInit",P,Z.setState),ae("fitViewOnInitOptions",G,Z.setState),ae("onNodesDelete",V,Z.setState),ae("onEdgesDelete",y,Z.setState),ae("onNodeDrag",M,Z.setState),ae("onNodeDragStart",S,Z.setState),ae("onNodeDragStop",O,Z.setState),ae("onSelectionDrag",z,Z.setState),ae("onSelectionDragStart",k,Z.setState),ae("onSelectionDragStop",I,Z.setState),ae("noPanClassName",L,Z.setState),ae("nodeOrigin",D,Z.setState),ae("rfId",q,Z.setState),ae("autoPanOnConnect",F,Z.setState),ae("autoPanOnNodeDrag",J,Z.setState),ae("onError",ee,Z.setState),ae("connectionRadius",se,Z.setState),ae("isValidConnection",le,Z.setState),ae("nodeDragThreshold",ne,Z.setState),Nt(e,ce),Nt(t,we),Nt(x,he),Nt(_,ue),Nt(R,me),Nt(g,Se),null},Ms={display:"none"},Wf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Ai="react-flow__node-desc",Ri="react-flow__edge-desc",Uf="react-flow__aria-live",qf=e=>e.ariaLiveMessage;function Kf({rfId:e}){const t=ge(qf);return A.createElement("div",{id:`${Uf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Wf},t)}function Zf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${Ai}-${e}`,style:Ms},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Ri}-${e}`,style:Ms},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Kf,{rfId:e}))}var nn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=w.useState(!1),s=w.useRef(!1),o=w.useRef(new Set([])),[i,a]=w.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return w.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&vr(f))return!1;const x=As(f.code,a);o.current.add(f[x]),$s(i,o.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&vr(f))return!1;const x=As(f.code,a);$s(i,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(f[x]),f.key==="Meta"&&o.current.clear(),s.current=!1},m=()=>{o.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function As(e,t){return t.includes(e)?"code":"key"}function Ii(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const o=t.get(s),i=bt(o,r);return Ii(o,t,{x:(n.x??0)+i.x,y:(n.y??0)+i.y,z:(((a=o[be])==null?void 0:a.z)??0)>(n.z??0)?((c=o[be])==null?void 0:c.z)??0:n.z??0},r)}function Ti(e,t,n){e.forEach(r=>{var o;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:i,y:a,z:c}=Ii(r,e,{...r.position,z:((o=r[be])==null?void 0:o.z)??0},t);r.positionAbsolute={x:i,y:a},r[be].z=c,n!=null&&n[r.id]&&(r[be].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,o={},i=r?1e3:0;return e.forEach(a=>{var f;const c=(ze(a.zIndex)?a.zIndex:0)+(a.selected?i:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(o[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,be,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[be])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Ti(s,n,o),s}function Oi(e,t={}){const{getNodes:n,width:r,height:s,minZoom:o,maxZoom:i,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const p=n().filter(_=>{var E;const g=t.includeHiddenNodes?_.width&&_.height:!_.hidden;return(E=t.nodes)!=null&&E.length?g&&t.nodes.some(C=>C.id===_.id):g}),x=p.every(_=>_.width&&_.height);if(p.length>0&&x){const _=an(p,d),{x:g,y:E,zoom:C}=bi(_,r,s,t.minZoom??o,t.maxZoom??i,t.padding??.1),b=rt.translate(g,E).scale(C);return typeof t.duration=="number"&&t.duration>0?a.transform(gt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Qf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[be]:r[be],selected:n.selected})}),new Map(t)}function Jf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function yn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:o,onNodesChange:i,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Qf(e,s)}),i==null||i(e)),t!=null&&t.length&&(l&&r({edges:Jf(t,o)}),a==null||a(t))}const St=()=>{},eh={zoomIn:St,zoomOut:St,zoomTo:St,getZoom:()=>1,setViewport:St,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:St,fitBounds:St,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},th=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),nh=()=>{const e=Ne(),{d3Zoom:t,d3Selection:n}=ge(th,ke);return w.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(gt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(gt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,o)=>t.scaleTo(gt(n,o==null?void 0:o.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,o)=>{const[i,a,c]=e.getState().transform,l=rt.translate(s.x??i,s.y??a).scale(s.zoom??c);t.transform(gt(n,o==null?void 0:o.duration),l)},getViewport:()=>{const[s,o,i]=e.getState().transform;return{x:s,y:o,zoom:i}},fitView:s=>Oi(e.getState,s),setCenter:(s,o,i)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(i==null?void 0:i.zoom)<"u"?i.zoom:l,d=a/2-s*u,m=c/2-o*u,f=rt.translate(d,m).scale(u);t.transform(gt(n,i==null?void 0:i.duration),f)},fitBounds:(s,o)=>{const{width:i,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=bi(s,i,a,c,l,(o==null?void 0:o.padding)??.1),f=rt.translate(u,d).scale(m);t.transform(gt(n,o==null?void 0:o.duration),f)},project:s=>{const{transform:o,snapToGrid:i,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),Er(s,o,i,a)},screenToFlowPosition:s=>{const{transform:o,snapToGrid:i,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return Er(d,o,i,a)},flowToScreenPosition:s=>{const{transform:o,domNode:i}=e.getState();if(!i)return s;const{x:a,y:c}=i.getBoundingClientRect(),l=yi(s,o);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:eh,[t,n])};function cn(){const e=nh(),t=Ne(),n=w.useCallback(()=>t.getState().getNodes().map(x=>({...x})),[]),r=w.useCallback(x=>t.getState().nodeInternals.get(x),[]),s=w.useCallback(()=>{const{edges:x=[]}=t.getState();return x.map(_=>({..._}))},[]),o=w.useCallback(x=>{const{edges:_=[]}=t.getState();return _.find(g=>g.id===x)},[]),i=w.useCallback(x=>{const{getNodes:_,setNodes:g,hasDefaultNodes:E,onNodesChange:C}=t.getState(),b=_(),$=typeof x=="function"?x(b):x;if(E)g($);else if(C){const j=$.length===0?b.map(v=>({type:"remove",id:v.id})):$.map(v=>({item:v,type:"reset"}));C(j)}},[]),a=w.useCallback(x=>{const{edges:_=[],setEdges:g,hasDefaultEdges:E,onEdgesChange:C}=t.getState(),b=typeof x=="function"?x(_):x;if(E)g(b);else if(C){const $=b.length===0?_.map(j=>({type:"remove",id:j.id})):b.map(j=>({item:j,type:"reset"}));C($)}},[]),c=w.useCallback(x=>{const _=Array.isArray(x)?x:[x],{getNodes:g,setNodes:E,hasDefaultNodes:C,onNodesChange:b}=t.getState();if(C){const j=[...g(),..._];E(j)}else if(b){const $=_.map(j=>({item:j,type:"add"}));b($)}},[]),l=w.useCallback(x=>{const _=Array.isArray(x)?x:[x],{edges:g=[],setEdges:E,hasDefaultEdges:C,onEdgesChange:b}=t.getState();if(C)E([...g,..._]);else if(b){const $=_.map(j=>({item:j,type:"add"}));b($)}},[]),u=w.useCallback(()=>{const{getNodes:x,edges:_=[],transform:g}=t.getState(),[E,C,b]=g;return{nodes:x().map($=>({...$})),edges:_.map($=>({...$})),viewport:{x:E,y:C,zoom:b}}},[]),d=w.useCallback(({nodes:x,edges:_})=>{const{nodeInternals:g,getNodes:E,edges:C,hasDefaultNodes:b,hasDefaultEdges:$,onNodesDelete:j,onEdgesDelete:v,onNodesChange:R,onEdgesChange:N}=t.getState(),T=(x||[]).map(M=>M.id),P=(_||[]).map(M=>M.id),G=E().reduce((M,S)=>{const O=S.parentNode||S.parentId,z=!T.includes(S.id)&&O&&M.find(I=>I.id===O);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(T.includes(S.id)||z)&&M.push(S),M},[]),V=C.filter(M=>typeof M.deletable=="boolean"?M.deletable:!0),y=V.filter(M=>P.includes(M.id));if(G||y){const M=wi(G,V),S=[...y,...M],O=S.reduce((z,k)=>(z.includes(k.id)||z.push(k.id),z),[]);if(($||b)&&($&&t.setState({edges:C.filter(z=>!O.includes(z.id))}),b&&(G.forEach(z=>{g.delete(z.id)}),t.setState({nodeInternals:new Map(g)}))),O.length>0&&(v==null||v(S),N&&N(O.map(z=>({id:z,type:"remove"})))),G.length>0&&(j==null||j(G),R)){const z=G.map(k=>({id:k.id,type:"remove"}));R(z)}}},[]),m=w.useCallback(x=>{const _=vf(x),g=_?null:t.getState().nodeInternals.get(x.id);return!_&&!g?[null,null,_]:[_?x:_s(g),g,_]},[]),f=w.useCallback((x,_=!0,g)=>{const[E,C,b]=m(x);return E?(g||t.getState().getNodes()).filter($=>{if(!b&&($.id===C.id||!$.positionAbsolute))return!1;const j=_s($),v=br(j,E);return _&&v>0||v>=E.width*E.height}):[]},[]),p=w.useCallback((x,_,g=!0)=>{const[E]=m(x);if(!E)return!1;const C=br(E,_);return g&&C>0||C>=E.width*E.height},[]);return w.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:o,setNodes:i,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:p}),[e,n,r,s,o,i,a,c,l,u,d,f,p])}const rh={actInsideInputWithModifier:!1};var sh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ne(),{deleteElements:r}=cn(),s=nn(e,rh),o=nn(t);w.useEffect(()=>{if(s){const{edges:i,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=i.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),w.useEffect(()=>{n.setState({multiSelectionActive:o})},[o])};function oh(e){const t=Ne();w.useEffect(()=>{let n;const r=()=>{var o,i;if(!e.current)return;const s=Lr(e.current);(s.height===0||s.width===0)&&((i=(o=t.getState()).onError)==null||i.call(o,"004",ot.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Gr={position:"absolute",width:"100%",height:"100%",top:0,left:0},ih=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,xn=e=>({x:e.x,y:e.y,zoom:e.k}),kt=(e,t)=>e.target.closest(`.${t}`),Rs=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Is=e=>{const t=e.ctrlKey&&$n()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},ah=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),ch=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:o=!0,panOnScroll:i=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=xt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:p,maxZoom:x,zoomActivationKeyCode:_,preventScrolling:g=!0,children:E,noWheelClassName:C,noPanClassName:b})=>{const $=w.useRef(),j=Ne(),v=w.useRef(!1),R=w.useRef(!1),N=w.useRef(null),T=w.useRef({x:0,y:0,zoom:0}),{d3Zoom:P,d3Selection:G,d3ZoomHandler:V,userSelectionActive:y}=ge(ah,ke),M=nn(_),S=w.useRef(0),O=w.useRef(!1),z=w.useRef();return oh(N),w.useEffect(()=>{if(N.current){const k=N.current.getBoundingClientRect(),I=oi().scaleExtent([p,x]).translateExtent(f),L=Pe(N.current).call(I),D=rt.translate(m.x,m.y).scale(Lt(m.zoom,p,x)),q=[[0,0],[k.width,k.height]],F=I.constrain()(D,q,f);I.transform(L,F),I.wheelDelta(Is),j.setState({d3Zoom:I,d3Selection:L,d3ZoomHandler:L.on("wheel.zoom"),transform:[F.x,F.y,F.k],domNode:N.current.closest(".react-flow")})}},[]),w.useEffect(()=>{G&&P&&(i&&!M&&!y?G.on("wheel.zoom",k=>{if(kt(k,C))return!1;k.preventDefault(),k.stopImmediatePropagation();const I=G.property("__zoom").k||1;if(k.ctrlKey&&o){const le=Ge(k),ne=Is(k),ce=I*Math.pow(2,ne);P.scaleTo(G,ce,le,k);return}const L=k.deltaMode===1?20:1;let D=c===xt.Vertical?0:k.deltaX*L,q=c===xt.Horizontal?0:k.deltaY*L;!$n()&&k.shiftKey&&c!==xt.Vertical&&(D=k.deltaY*L,q=0),P.translateBy(G,-(D/I)*a,-(q/I)*a,{internal:!0});const F=xn(G.property("__zoom")),{onViewportChangeStart:J,onViewportChange:ee,onViewportChangeEnd:se}=j.getState();clearTimeout(z.current),O.current||(O.current=!0,t==null||t(k,F),J==null||J(F)),O.current&&(e==null||e(k,F),ee==null||ee(F),z.current=setTimeout(()=>{n==null||n(k,F),se==null||se(F),O.current=!1},150))},{passive:!1}):typeof V<"u"&&G.on("wheel.zoom",function(k,I){if(!g&&k.type==="wheel"&&!k.ctrlKey||kt(k,C))return null;k.preventDefault(),V.call(this,k,I)},{passive:!1}))},[y,i,c,G,P,V,M,o,g,C,t,e,n]),w.useEffect(()=>{P&&P.on("start",k=>{var D,q;if(!k.sourceEvent||k.sourceEvent.internal)return null;S.current=(D=k.sourceEvent)==null?void 0:D.button;const{onViewportChangeStart:I}=j.getState(),L=xn(k.transform);v.current=!0,T.current=L,((q=k.sourceEvent)==null?void 0:q.type)==="mousedown"&&j.setState({paneDragging:!0}),I==null||I(L),t==null||t(k.sourceEvent,L)})},[P,t]),w.useEffect(()=>{P&&(y&&!v.current?P.on("zoom",null):y||P.on("zoom",k=>{var L;const{onViewportChange:I}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),R.current=!!(r&&Rs(d,S.current??0)),(e||I)&&!((L=k.sourceEvent)!=null&&L.internal)){const D=xn(k.transform);I==null||I(D),e==null||e(k.sourceEvent,D)}}))},[y,P,e,d,r]),w.useEffect(()=>{P&&P.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:I}=j.getState();if(v.current=!1,j.setState({paneDragging:!1}),r&&Rs(d,S.current??0)&&!R.current&&r(k.sourceEvent),R.current=!1,(n||I)&&ih(T.current,k.transform)){const L=xn(k.transform);T.current=L,clearTimeout($.current),$.current=setTimeout(()=>{I==null||I(L),n==null||n(k.sourceEvent,L)},i?150:0)}})},[P,i,d,n,r]),w.useEffect(()=>{P&&P.filter(k=>{const I=M||s,L=o&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(kt(k,"react-flow__node")||kt(k,"react-flow__edge")))return!0;if(!d&&!I&&!i&&!l&&!o||y||!l&&k.type==="dblclick"||kt(k,C)&&k.type==="wheel"||kt(k,b)&&(k.type!=="wheel"||i&&k.type==="wheel"&&!M)||!o&&k.ctrlKey&&k.type==="wheel"||!I&&!i&&!L&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const D=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&D})},[y,P,s,o,i,l,d,u,M]),A.createElement("div",{className:"react-flow__renderer",ref:N,style:Gr},E)},lh=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function uh(){const{userSelectionActive:e,userSelectionRect:t}=ge(lh,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Ts(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,o=t.position.y+t.height-r.height;if(s>0||o>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),o>0&&(r.style.height+=o),t.position.x<0){const i=Math.abs(t.position.x);r.position.x=r.position.x-i,r.style.width+=i,t.position.x=0}if(t.position.y<0){const i=Math.abs(t.position.y);r.position.y=r.position.y-i,r.style.height+=i,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function dh(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const o=e.filter(a=>a.id===s.id);if(o.length===0)return r.push(s),r;const i={...s};for(const a of o)if(a)switch(a.type){case"select":{i.selected=a.selected;break}case"position":{typeof a.position<"u"&&(i.position=a.position),typeof a.positionAbsolute<"u"&&(i.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(i.dragging=a.dragging),i.expandParent&&Ts(r,i);break}case"dimensions":{typeof a.dimensions<"u"&&(i.width=a.dimensions.width,i.height=a.dimensions.height),typeof a.updateStyle<"u"&&(i.style={...i.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(i.resizing=a.resizing),i.expandParent&&Ts(r,i);break}case"remove":return r}return r.push(i),r},n)}function fh(e,t){return dh(e,t)}const ut=(e,t)=>({id:e,type:"select",selected:t});function Ct(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ut(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ut(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},hh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Li=w.memo(({isSelecting:e,selectionMode:t=tn.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:o,onPaneContextMenu:i,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=w.useRef(null),f=Ne(),p=w.useRef(0),x=w.useRef(0),_=w.useRef(),{userSelectionActive:g,elementsSelectable:E,dragging:C}=ge(hh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),p.current=0,x.current=0},$=V=>{o==null||o(V),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=V=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){V.preventDefault();return}i==null||i(V)},v=a?V=>a(V):void 0,R=V=>{const{resetSelectedElements:y,domNode:M}=f.getState();if(_.current=M==null?void 0:M.getBoundingClientRect(),!E||!e||V.button!==0||V.target!==m.current||!_.current)return;const{x:S,y:O}=mt(V,_.current);y(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:O,x:S,y:O}}),r==null||r(V)},N=V=>{const{userSelectionRect:y,nodeInternals:M,edges:S,transform:O,onNodesChange:z,onEdgesChange:k,nodeOrigin:I,getNodes:L}=f.getState();if(!e||!_.current||!y)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const D=mt(V,_.current),q=y.startX??0,F=y.startY??0,J={...y,x:D.xce.id),ne=se.map(ce=>ce.id);if(p.current!==ne.length){p.current=ne.length;const ce=Ct(ee,ne);ce.length&&(z==null||z(ce))}if(x.current!==le.length){x.current=le.length;const ce=Ct(S,le);ce.length&&(k==null||k(ce))}f.setState({userSelectionRect:J})},T=V=>{if(V.button!==0)return;const{userSelectionRect:y}=f.getState();!g&&y&&V.target===m.current&&($==null||$(V)),f.setState({nodesSelectionActive:p.current>0}),b(),s==null||s(V)},P=V=>{g&&(f.setState({nodesSelectionActive:p.current>0}),s==null||s(V)),b()},G=E&&(e||g);return A.createElement("div",{className:Me(["react-flow__pane",{dragging:C,selection:e}]),onClick:G?void 0:er($,m),onContextMenu:er(j,m),onWheel:er(v,m),onMouseEnter:G?void 0:c,onMouseDown:G?R:void 0,onMouseMove:G?N:l,onMouseUp:G?T:void 0,onMouseLeave:G?P:u,ref:m,style:Gr},d,A.createElement(uh,null))});Li.displayName="Pane";function Di(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Di(r,t):!1}function Os(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function mh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Di(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var o,i;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((o=s.positionAbsolute)==null?void 0:o.x)??0),y:n.y-(((i=s.positionAbsolute)==null?void 0:i.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function ph(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function Pi(e,t,n,r,s=[0,0],o){const i=ph(e,e.extent||r);let a=i;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=bt(d,s).positionAbsolute;a=d&&ze(m)&&ze(f)&&ze(d.width)&&ze(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else o==null||o("005",ot.error005()),a=i;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=bt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=bt(d,s).positionAbsolute}const u=a&&a!=="parent"?Dr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Ls=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const o=Array.from(s),i=t.getBoundingClientRect(),a={x:i.width*r[0],y:i.height*r[1]};return o.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-i.left-a.x)/n,y:(l.top-i.top-a.y)/n,...Lr(c)}})};function Bt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Sr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:o,multiSelectionActive:i,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",ot.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&i)&&(o({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function gh(){const e=Ne();return w.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:o}=e.getState(),i=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(i-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:o?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:o?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function zi({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:o,selectNodesOnDrag:i}){const a=Ne(),[c,l]=w.useState(!1),u=w.useRef([]),d=w.useRef({x:null,y:null}),m=w.useRef(0),f=w.useRef(null),p=w.useRef({x:0,y:0}),x=w.useRef(null),_=w.useRef(!1),g=w.useRef(!1),E=w.useRef(!1),C=gh();return w.useEffect(()=>{if(e!=null&&e.current){const b=Pe(e.current),$=({x:R,y:N})=>{const{nodeInternals:T,onNodeDrag:P,onSelectionDrag:G,updateNodePositions:V,nodeExtent:y,snapGrid:M,snapToGrid:S,nodeOrigin:O,onError:z}=a.getState();d.current={x:R,y:N};let k=!1,I={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&y){const D=an(u.current,O);I=en(D)}if(u.current=u.current.map(D=>{const q={x:R-D.distance.x,y:N-D.distance.y};S&&(q.x=M[0]*Math.round(q.x/M[0]),q.y=M[1]*Math.round(q.y/M[1]));const F=[[y[0][0],y[0][1]],[y[1][0],y[1][1]]];u.current.length>1&&y&&!D.extent&&(F[0][0]=D.positionAbsolute.x-I.x+y[0][0],F[1][0]=D.positionAbsolute.x+(D.width??0)-I.x2+y[1][0],F[0][1]=D.positionAbsolute.y-I.y+y[0][1],F[1][1]=D.positionAbsolute.y+(D.height??0)-I.y2+y[1][1]);const J=Pi(D,q,T,F,O,z);return k=k||D.position.x!==J.position.x||D.position.y!==J.position.y,D.position=J.position,D.positionAbsolute=J.positionAbsolute,D}),!k)return;V(u.current,!0,!0),l(!0);const L=s?P:nr(G);if(L&&x.current){const[D,q]=tr({nodeId:s,dragItems:u.current,nodeInternals:T});L(x.current,D,q)}},j=()=>{if(!f.current)return;const[R,N]=ai(p.current,f.current);if(R!==0||N!==0){const{transform:T,panBy:P}=a.getState();d.current.x=(d.current.x??0)-R/T[2],d.current.y=(d.current.y??0)-N/T[2],P({x:R,y:N})&&$(d.current)}m.current=requestAnimationFrame(j)},v=R=>{var O;const{nodeInternals:N,multiSelectionActive:T,nodesDraggable:P,unselectNodesAndEdges:G,onNodeDragStart:V,onSelectionDragStart:y}=a.getState();g.current=!0;const M=s?V:nr(y);(!i||!o)&&!T&&s&&((O=N.get(s))!=null&&O.selected||G()),s&&o&&i&&Sr({id:s,store:a,nodeRef:e});const S=C(R);if(d.current=S,u.current=mh(N,P,S,s),M&&u.current){const[z,k]=tr({nodeId:s,dragItems:u.current,nodeInternals:N});M(R.sourceEvent,z,k)}};if(t)b.on(".drag",null);else{const R=Nu().on("start",N=>{const{domNode:T,nodeDragThreshold:P}=a.getState();P===0&&v(N),E.current=!1;const G=C(N);d.current=G,f.current=(T==null?void 0:T.getBoundingClientRect())||null,p.current=mt(N.sourceEvent,f.current)}).on("drag",N=>{var V,y;const T=C(N),{autoPanOnNodeDrag:P,nodeDragThreshold:G}=a.getState();if(N.sourceEvent.type==="touchmove"&&N.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!_.current&&g.current&&P&&(_.current=!0,j()),!g.current){const M=T.xSnapped-(((V=d==null?void 0:d.current)==null?void 0:V.x)??0),S=T.ySnapped-(((y=d==null?void 0:d.current)==null?void 0:y.y)??0);Math.sqrt(M*M+S*S)>G&&v(N)}(d.current.x!==T.xSnapped||d.current.y!==T.ySnapped)&&u.current&&g.current&&(x.current=N.sourceEvent,p.current=mt(N.sourceEvent,f.current),$(T))}}).on("end",N=>{if(!(!g.current||E.current)&&(l(!1),_.current=!1,g.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:T,nodeInternals:P,onNodeDragStop:G,onSelectionDragStop:V}=a.getState(),y=s?G:nr(V);if(T(u.current,!1,!1),y){const[M,S]=tr({nodeId:s,dragItems:u.current,nodeInternals:P});y(N.sourceEvent,M,S)}}}).filter(N=>{const T=N.target;return!N.button&&(!n||!Os(T,`.${n}`,e))&&(!r||Os(T,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,o,a,s,i,C]),c}function Hi(){const e=Ne();return w.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:o,getNodes:i,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=i().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,p=n.isShiftPressed?4:1,x=n.x*m*p,_=n.y*f*p,g=d.map(E=>{if(E.positionAbsolute){const C={x:E.positionAbsolute.x+x,y:E.positionAbsolute.y+_};a&&(C.x=c[0]*Math.round(C.x/c[0]),C.y=c[1]*Math.round(C.y/c[1]));const{positionAbsolute:b,position:$}=Pi(E,C,r,s,void 0,l);E.position=$,E.positionAbsolute=b}return E});o(g,!0,!1)},[])}const Rt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Gt=e=>{const t=({id:n,type:r,data:s,xPos:o,yPos:i,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:p,onDoubleClick:x,style:_,className:g,isDraggable:E,isSelectable:C,isConnectable:b,isFocusable:$,selectNodesOnDrag:j,sourcePosition:v,targetPosition:R,hidden:N,resizeObserver:T,dragHandle:P,zIndex:G,isParent:V,noDragClassName:y,noPanClassName:M,initialized:S,disableKeyboardA11y:O,ariaLabel:z,rfId:k,hasHandleBounds:I})=>{const L=Ne(),D=w.useRef(null),q=w.useRef(null),F=w.useRef(v),J=w.useRef(R),ee=w.useRef(r),se=C||E||u||d||m||f,le=Hi(),ne=Bt(n,L.getState,d),ce=Bt(n,L.getState,m),we=Bt(n,L.getState,f),ye=Bt(n,L.getState,p),he=Bt(n,L.getState,x),ue=ie=>{const{nodeDragThreshold:Z}=L.getState();if(C&&(!j||!E||Z>0)&&Sr({id:n,store:L,nodeRef:D}),u){const xe=L.getState().nodeInternals.get(n);xe&&u(ie,{...xe})}},me=ie=>{if(!vr(ie)&&!O)if(di.includes(ie.key)&&C){const Z=ie.key==="Escape";Sr({id:n,store:L,unselect:Z,nodeRef:D})}else E&&l&&Object.prototype.hasOwnProperty.call(Rt,ie.key)&&(L.setState({ariaLiveMessage:`Moved selected node ${ie.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~o}, y: ${~~i}`}),le({x:Rt[ie.key].x,y:Rt[ie.key].y,isShiftPressed:ie.shiftKey}))};w.useEffect(()=>()=>{q.current&&(T==null||T.unobserve(q.current),q.current=null)},[]),w.useEffect(()=>{if(D.current&&!N){const ie=D.current;(!S||!I||q.current!==ie)&&(q.current&&(T==null||T.unobserve(q.current)),T==null||T.observe(ie),q.current=ie)}},[N,S,I]),w.useEffect(()=>{const ie=ee.current!==r,Z=F.current!==v,xe=J.current!==R;D.current&&(ie||Z||xe)&&(ie&&(ee.current=r),Z&&(F.current=v),xe&&(J.current=R),L.getState().updateNodeDimensions([{id:n,nodeElement:D.current,forceUpdate:!0}]))},[n,r,v,R]);const Se=zi({nodeRef:D,disabled:N||!E,noDragClassName:y,handleSelector:P,nodeId:n,isSelectable:C,selectNodesOnDrag:j});return N?null:A.createElement("div",{className:Me(["react-flow__node",`react-flow__node-${r}`,{[M]:E},g,{selected:l,selectable:C,parent:V,dragging:Se}]),ref:D,style:{zIndex:G,transform:`translate(${a}px,${c}px)`,pointerEvents:se?"all":"none",visibility:S?"visible":"hidden",..._},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:ce,onMouseLeave:we,onContextMenu:ye,onClick:ue,onDoubleClick:he,onKeyDown:$?me:void 0,tabIndex:$?0:void 0,role:$?"button":void 0,"aria-describedby":O?void 0:`${Ai}-${k}`,"aria-label":z},A.createElement(Cf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:o,yPos:i,selected:l,isConnectable:b,sourcePosition:v,targetPosition:R,dragging:Se,dragHandle:P,zIndex:G})))};return t.displayName="NodeWrapper",w.memo(t)};const yh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...an(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function xh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ne(),{width:s,height:o,x:i,y:a,transformString:c,userSelectionActive:l}=ge(yh,ke),u=Hi(),d=w.useRef(null);if(w.useEffect(()=>{var p;n||(p=d.current)==null||p.focus({preventScroll:!0})},[n]),zi({nodeRef:d}),l||!s||!o)return null;const m=e?p=>{const x=r.getState().getNodes().filter(_=>_.selected);e(p,x)}:void 0,f=p=>{Object.prototype.hasOwnProperty.call(Rt,p.key)&&u({x:Rt[p.key].x,y:Rt[p.key].y,isShiftPressed:p.shiftKey})};return A.createElement("div",{className:Me(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:o,top:a,left:i}}))}var wh=w.memo(xh);const bh=e=>e.nodesSelectionActive,Fi=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:i,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:p,onSelectionEnd:x,multiSelectionKeyCode:_,panActivationKeyCode:g,zoomActivationKeyCode:E,elementsSelectable:C,zoomOnScroll:b,zoomOnPinch:$,panOnScroll:j,panOnScrollSpeed:v,panOnScrollMode:R,zoomOnDoubleClick:N,panOnDrag:T,defaultViewport:P,translateExtent:G,minZoom:V,maxZoom:y,preventScrolling:M,onSelectionContextMenu:S,noWheelClassName:O,noPanClassName:z,disableKeyboardA11y:k})=>{const I=ge(bh),L=nn(d),D=nn(g),q=D||T,F=D||j,J=L||m&&q!==!0;return sh({deleteKeyCode:a,multiSelectionKeyCode:_}),A.createElement(ch,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:o,elementsSelectable:C,zoomOnScroll:b,zoomOnPinch:$,panOnScroll:F,panOnScrollSpeed:v,panOnScrollMode:R,zoomOnDoubleClick:N,panOnDrag:!L&&q,defaultViewport:P,translateExtent:G,minZoom:V,maxZoom:y,zoomActivationKeyCode:E,preventScrolling:M,noWheelClassName:O,noPanClassName:z},A.createElement(Li,{onSelectionStart:p,onSelectionEnd:x,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:i,panOnDrag:q,isSelecting:!!J,selectionMode:f},e,I&&A.createElement(wh,{onSelectionContextMenu:S,noPanClassName:z,disableKeyboardA11y:k})))};Fi.displayName="FlowRenderer";var vh=w.memo(Fi);function _h(e){return ge(w.useCallback(n=>e?xi(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function Eh(e){const t={input:Gt(e.input||ji),default:Gt(e.default||Nr),output:Gt(e.output||Mi),group:Gt(e.group||Br)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,o)=>(s[o]=Gt(e[o]||Nr),s),n);return{...t,...r}}const Nh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},Sh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Vi=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:o,onError:i}=ge(Sh,ke),a=_h(e.onlyRenderVisibleElements),c=w.useRef(),l=w.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));o(m)});return c.current=u,u},[]);return w.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Gr},a.map(u=>{var $,j,v;let d=u.type||"default";e.nodeTypes[d]||(i==null||i("003",ot.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),p=!!(u.selectable||s&&typeof u.selectable>"u"),x=!!(u.connectable||n&&typeof u.connectable>"u"),_=!!(u.focusable||r&&typeof u.focusable>"u"),g=e.nodeExtent?Dr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(g==null?void 0:g.x)??0,C=(g==null?void 0:g.y)??0,b=Nh({x:E,y:C,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||K.Bottom,targetPosition:u.targetPosition||K.Top,hidden:u.hidden,xPos:E,yPos:C,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:p,isConnectable:x,isFocusable:_,resizeObserver:l,dragHandle:u.dragHandle,zIndex:(($=u[be])==null?void 0:$.z)??0,isParent:!!((j=u[be])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((v=u[be])!=null&&v.handleBounds)})}))};Vi.displayName="NodeRenderer";var kh=w.memo(Vi);const jh=(e,t,n)=>n===K.Left?e-t:n===K.Right?e+t:e,Ch=(e,t,n)=>n===K.Top?e-t:n===K.Bottom?e+t:e,Ds="react-flow__edgeupdater",Ps=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:o,onMouseOut:i,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:o,onMouseOut:i,className:Me([Ds,`${Ds}-${a}`]),cx:jh(t,r,e),cy:Ch(n,r,e),r,stroke:"transparent",fill:"transparent"}),Mh=()=>!0;var jt=e=>{const t=({id:n,className:r,type:s,data:o,onClick:i,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:x,style:_,source:g,target:E,sourceX:C,sourceY:b,targetX:$,targetY:j,sourcePosition:v,targetPosition:R,elementsSelectable:N,hidden:T,sourceHandleId:P,targetHandleId:G,onContextMenu:V,onMouseEnter:y,onMouseMove:M,onMouseLeave:S,reconnectRadius:O,onReconnect:z,onReconnectStart:k,onReconnectEnd:I,markerEnd:L,markerStart:D,rfId:q,ariaLabel:F,isFocusable:J,isReconnectable:ee,pathOptions:se,interactionWidth:le,disableKeyboardA11y:ne})=>{const ce=w.useRef(null),[we,ye]=w.useState(!1),[he,ue]=w.useState(!1),me=Ne(),Se=w.useMemo(()=>`url('#${_r(D,q)}')`,[D,q]),ie=w.useMemo(()=>`url('#${_r(L,q)}')`,[L,q]);if(T)return null;const Z=W=>{var fe;const{edges:te,addSelectedEdges:pe,unselectNodesAndEdges:Q,multiSelectionActive:oe}=me.getState(),re=te.find(Ce=>Ce.id===n);re&&(N&&(me.setState({nodesSelectionActive:!1}),re.selected&&oe?(Q({nodes:[],edges:[re]}),(fe=ce.current)==null||fe.blur()):pe([n])),i&&i(W,re))},xe=Vt(n,me.getState,a),je=Vt(n,me.getState,V),Ae=Vt(n,me.getState,y),Le=Vt(n,me.getState,M),Re=Vt(n,me.getState,S),Ie=(W,te)=>{if(W.button!==0)return;const{edges:pe,isValidConnection:Q}=me.getState(),oe=te?E:g,re=(te?G:P)||null,fe=te?"target":"source",Ce=Q||Mh,Te=te,$e=pe.find(Be=>Be.id===n);ue(!0),k==null||k(W,$e,fe);const Ue=Be=>{ue(!1),I==null||I(Be,$e,fe)};Ei({event:W,handleId:re,nodeId:oe,onConnect:Be=>z==null?void 0:z($e,Be),isTarget:Te,getState:me.getState,setState:me.setState,isValidConnection:Ce,edgeUpdaterType:fe,onReconnectEnd:Ue})},Ve=W=>Ie(W,!0),H=W=>Ie(W,!1),X=()=>ye(!0),B=()=>ye(!1),U=!N&&!i,Y=W=>{var te;if(!ne&&di.includes(W.key)&&N){const{unselectNodesAndEdges:pe,addSelectedEdges:Q,edges:oe}=me.getState();W.key==="Escape"?((te=ce.current)==null||te.blur(),pe({edges:[oe.find(fe=>fe.id===n)]})):Q([n])}};return A.createElement("g",{className:Me(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:we}]),onClick:Z,onDoubleClick:xe,onContextMenu:je,onMouseEnter:Ae,onMouseMove:Le,onMouseLeave:Re,onKeyDown:J?Y:void 0,tabIndex:J?0:void 0,role:J?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":F===null?void 0:F||`Edge from ${g} to ${E}`,"aria-describedby":J?`${Ri}-${q}`:void 0,ref:ce},!he&&A.createElement(e,{id:n,source:g,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:x,data:o,style:_,sourceX:C,sourceY:b,targetX:$,targetY:j,sourcePosition:v,targetPosition:R,sourceHandleId:P,targetHandleId:G,markerStart:Se,markerEnd:ie,pathOptions:se,interactionWidth:le}),ee&&A.createElement(A.Fragment,null,(ee==="source"||ee===!0)&&A.createElement(Ps,{position:v,centerX:C,centerY:b,radius:O,onMouseDown:Ve,onMouseEnter:X,onMouseOut:B,type:"source"}),(ee==="target"||ee===!0)&&A.createElement(Ps,{position:R,centerX:$,centerY:j,radius:O,onMouseDown:H,onMouseEnter:X,onMouseOut:B,type:"target"})))};return t.displayName="EdgeWrapper",w.memo(t)};function $h(e){const t={default:jt(e.default||In),straight:jt(e.bezier||Hr),step:jt(e.step||zr),smoothstep:jt(e.step||Bn),simplebezier:jt(e.simplebezier||Pr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,o)=>(s[o]=jt(e[o]||In),s),n);return{...t,...r}}function zs(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,o=(n==null?void 0:n.width)||t.width,i=(n==null?void 0:n.height)||t.height;switch(e){case K.Top:return{x:r+o/2,y:s};case K.Right:return{x:r+o,y:s+i/2};case K.Bottom:return{x:r+o/2,y:s+i};case K.Left:return{x:r,y:s+i/2}}}function Hs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const Ah=(e,t,n,r,s,o)=>{const i=zs(n,e,t),a=zs(o,r,s);return{sourceX:i.x,sourceY:i.y,targetX:a.x,targetY:a.y}};function Rh({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:o,width:i,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+o)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=en({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:i/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Fs(e){var r,s,o,i,a;const t=((r=e==null?void 0:e[be])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.y)<"u";return[{x:((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const Ih=[{level:0,isMaxLevel:!0,edges:[]}];function Th(e,t,n=!1){let r=-1;const s=e.reduce((i,a)=>{var u,d;const c=ze(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),p=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),x=Math.max(((u=f==null?void 0:f[be])==null?void 0:u.z)||0,((d=m==null?void 0:m[be])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(p?x:0)}return i[l]?i[l].push(a):i[l]=[a],r=l>r?l:r,i},{}),o=Object.entries(s).map(([i,a])=>{const c=+i;return{edges:a,level:c,isMaxLevel:c===r}});return o.length===0?Ih:o}function Oh(e,t,n){const r=ge(w.useCallback(s=>e?s.edges.filter(o=>{const i=t.get(o.source),a=t.get(o.target);return(i==null?void 0:i.width)&&(i==null?void 0:i.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Rh({sourcePos:i.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:i.width,sourceHeight:i.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Th(r,t,n)}const Lh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Dh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Vs={[An.Arrow]:Lh,[An.ArrowClosed]:Dh};function Ph(e){const t=Ne();return w.useMemo(()=>{var s,o;return Object.prototype.hasOwnProperty.call(Vs,e)?Vs[e]:((o=(s=t.getState()).onError)==null||o.call(s,"009",ot.error009(e)),null)},[e])}const zh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:o="strokeWidth",strokeWidth:i,orient:a="auto-start-reverse"})=>{const c=Ph(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:i})):null},Hh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,o)=>([o.markerStart,o.markerEnd].forEach(i=>{if(i&&typeof i=="object"){const a=_r(i,t);r.includes(a)||(s.push({id:a,color:i.color||e,...i}),r.push(a))}}),s),[]).sort((s,o)=>s.id.localeCompare(o.id))},Bi=({defaultColor:e,rfId:t})=>{const n=ge(w.useCallback(Hh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((o,i)=>o.id!==s[i].id)));return A.createElement("defs",null,n.map(r=>A.createElement(zh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};Bi.displayName="MarkerDefinitions";var Fh=w.memo(Bi);const Vh=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Gi=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:o,onEdgeContextMenu:i,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:x,children:_,disableKeyboardA11y:g})=>{const{edgesFocusable:E,edgesUpdatable:C,elementsSelectable:b,width:$,height:j,connectionMode:v,nodeInternals:R,onError:N}=ge(Vh,ke),T=Oh(t,R,n);return $?A.createElement(A.Fragment,null,T.map(({level:P,edges:G,isMaxLevel:V})=>A.createElement("svg",{key:P,style:{zIndex:P},width:$,height:j,className:"react-flow__edges react-flow__container"},V&&A.createElement(Fh,{defaultColor:e,rfId:r}),A.createElement("g",null,G.map(y=>{const[M,S,O]=Fs(R.get(y.source)),[z,k,I]=Fs(R.get(y.target));if(!O||!I)return null;let L=y.type||"default";s[L]||(N==null||N("011",ot.error011(L)),L="default");const D=s[L]||s.default,q=v===_t.Strict?k.target:(k.target??[]).concat(k.source??[]),F=Hs(S.source,y.sourceHandle),J=Hs(q,y.targetHandle),ee=(F==null?void 0:F.position)||K.Bottom,se=(J==null?void 0:J.position)||K.Top,le=!!(y.focusable||E&&typeof y.focusable>"u"),ne=y.reconnectable||y.updatable,ce=typeof m<"u"&&(ne||C&&typeof ne>"u");if(!F||!J)return N==null||N("008",ot.error008(F,y)),null;const{sourceX:we,sourceY:ye,targetX:he,targetY:ue}=Ah(M,F,ee,z,J,se);return A.createElement(D,{key:y.id,id:y.id,className:Me([y.className,o]),type:L,data:y.data,selected:!!y.selected,animated:!!y.animated,hidden:!!y.hidden,label:y.label,labelStyle:y.labelStyle,labelShowBg:y.labelShowBg,labelBgStyle:y.labelBgStyle,labelBgPadding:y.labelBgPadding,labelBgBorderRadius:y.labelBgBorderRadius,style:y.style,source:y.source,target:y.target,sourceHandleId:y.sourceHandle,targetHandleId:y.targetHandle,markerEnd:y.markerEnd,markerStart:y.markerStart,sourceX:we,sourceY:ye,targetX:he,targetY:ue,sourcePosition:ee,targetPosition:se,elementsSelectable:b,onContextMenu:i,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:x,rfId:r,ariaLabel:y.ariaLabel,isFocusable:le,isReconnectable:ce,pathOptions:"pathOptions"in y?y.pathOptions:void 0,interactionWidth:y.interactionWidth,disableKeyboardA11y:g})})))),_):null};Gi.displayName="EdgeRenderer";var Bh=w.memo(Gi);const Gh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Yh({children:e}){const t=ge(Gh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Xh(e){const t=cn(),n=w.useRef(!1);w.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Wh={[K.Left]:K.Right,[K.Right]:K.Left,[K.Top]:K.Bottom,[K.Bottom]:K.Top},Yi=({nodeId:e,handleType:t,style:n,type:r=dt.Bezier,CustomComponent:s,connectionStatus:o})=>{var j,v,R;const{fromNode:i,handleId:a,toX:c,toY:l,connectionMode:u}=ge(w.useCallback(N=>({fromNode:N.nodeInternals.get(e),handleId:N.connectionHandleId,toX:(N.connectionPosition.x-N.transform[0])/N.transform[2],toY:(N.connectionPosition.y-N.transform[1])/N.transform[2],connectionMode:N.connectionMode}),[e]),ke),d=(j=i==null?void 0:i[be])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(u===_t.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!i||!m)return null;const f=a?m.find(N=>N.id===a):m[0],p=f?f.x+f.width/2:(i.width??0)/2,x=f?f.y+f.height/2:i.height??0,_=(((v=i.positionAbsolute)==null?void 0:v.x)??0)+p,g=(((R=i.positionAbsolute)==null?void 0:R.y)??0)+x,E=f==null?void 0:f.position,C=E?Wh[E]:null;if(!E||!C)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:i,fromHandle:f,fromX:_,fromY:g,toX:c,toY:l,fromPosition:E,toPosition:C,connectionStatus:o});let b="";const $={sourceX:_,sourceY:g,sourcePosition:E,targetX:c,targetY:l,targetPosition:C};return r===dt.Bezier?[b]=gi($):r===dt.Step?[b]=Rn({...$,borderRadius:0}):r===dt.SmoothStep?[b]=Rn($):r===dt.SimpleBezier?[b]=pi($):b=`M${_},${g} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Yi.displayName="ConnectionLine";const Uh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function qh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:o,nodesConnectable:i,width:a,height:c,connectionStatus:l}=ge(Uh,ke);return!(s&&o&&a&&i)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:Me(["react-flow__connection",l])},A.createElement(Yi,{nodeId:s,handleType:o,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Bs(e,t){return w.useRef(null),Ne(),w.useMemo(()=>t(e),[e])}const Xi=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:o,onNodeClick:i,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:p,onSelectionStart:x,onSelectionEnd:_,connectionLineType:g,connectionLineStyle:E,connectionLineComponent:C,connectionLineContainerStyle:b,selectionKeyCode:$,selectionOnDrag:j,selectionMode:v,multiSelectionKeyCode:R,panActivationKeyCode:N,zoomActivationKeyCode:T,deleteKeyCode:P,onlyRenderVisibleElements:G,elementsSelectable:V,selectNodesOnDrag:y,defaultViewport:M,translateExtent:S,minZoom:O,maxZoom:z,preventScrolling:k,defaultMarkerColor:I,zoomOnScroll:L,zoomOnPinch:D,panOnScroll:q,panOnScrollSpeed:F,panOnScrollMode:J,zoomOnDoubleClick:ee,panOnDrag:se,onPaneClick:le,onPaneMouseEnter:ne,onPaneMouseMove:ce,onPaneMouseLeave:we,onPaneScroll:ye,onPaneContextMenu:he,onEdgeContextMenu:ue,onEdgeMouseEnter:me,onEdgeMouseMove:Se,onEdgeMouseLeave:ie,onReconnect:Z,onReconnectStart:xe,onReconnectEnd:je,reconnectRadius:Ae,noDragClassName:Le,noWheelClassName:Re,noPanClassName:Ie,elevateEdgesOnSelect:Ve,disableKeyboardA11y:H,nodeOrigin:X,nodeExtent:B,rfId:U})=>{const Y=Bs(e,Eh),W=Bs(t,$h);return Xh(o),A.createElement(vh,{onPaneClick:le,onPaneMouseEnter:ne,onPaneMouseMove:ce,onPaneMouseLeave:we,onPaneContextMenu:he,onPaneScroll:ye,deleteKeyCode:P,selectionKeyCode:$,selectionOnDrag:j,selectionMode:v,onSelectionStart:x,onSelectionEnd:_,multiSelectionKeyCode:R,panActivationKeyCode:N,zoomActivationKeyCode:T,elementsSelectable:V,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:L,zoomOnPinch:D,zoomOnDoubleClick:ee,panOnScroll:q,panOnScrollSpeed:F,panOnScrollMode:J,panOnDrag:se,defaultViewport:M,translateExtent:S,minZoom:O,maxZoom:z,onSelectionContextMenu:p,preventScrolling:k,noDragClassName:Le,noWheelClassName:Re,noPanClassName:Ie,disableKeyboardA11y:H},A.createElement(Yh,null,A.createElement(Bh,{edgeTypes:W,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:G,onEdgeContextMenu:ue,onEdgeMouseEnter:me,onEdgeMouseMove:Se,onEdgeMouseLeave:ie,onReconnect:Z,onReconnectStart:xe,onReconnectEnd:je,reconnectRadius:Ae,defaultMarkerColor:I,noPanClassName:Ie,elevateEdgesOnSelect:!!Ve,disableKeyboardA11y:H,rfId:U},A.createElement(qh,{style:E,type:g,component:C,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(kh,{nodeTypes:Y,onNodeClick:i,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:y,onlyRenderVisibleElements:G,noPanClassName:Ie,noDragClassName:Le,disableKeyboardA11y:H,nodeOrigin:X,nodeExtent:B,rfId:U})))};Xi.displayName="GraphView";var Kh=w.memo(Xi);const kr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],at={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:kr,nodeExtent:kr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:_t.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:_f,isValidConnection:void 0},Zh=()=>Lc((e,t)=>({...at,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:o}=t();e({nodeInternals:Jn(n,r,s,o)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",o=typeof r<"u",i=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:i,edges:o?r:[],hasDefaultNodes:s,hasDefaultEdges:o})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:o,fitViewOnInitDone:i,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((x,_)=>{const g=s.get(_.id);if(g!=null&&g.hidden)s.set(g.id,{...g,[be]:{...g[be],handleBounds:void 0}});else if(g){const E=Lr(_.nodeElement);!!(E.width&&E.height&&(g.width!==E.width||g.height!==E.height||_.forceUpdate))&&(s.set(g.id,{...g,[be]:{...g[be],handleBounds:{source:Ls(".source",_.nodeElement,m,l),target:Ls(".target",_.nodeElement,m,l)}},...E}),x.push({id:g.id,type:"dimensions",dimensions:E}))}return x},[]);Ti(s,l);const p=i||o&&!i&&Oi(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:p}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:o}=t(),i=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});o(i)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:o,nodeOrigin:i,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(o){const l=fh(n,a()),u=Jn(l,s,i,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:o}=t();let i,a=null;r?i=n.map(c=>ut(c,!0)):(i=Ct(o(),n),a=Ct(s,[])),yn({changedNodes:i,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:o}=t();let i,a=null;r?i=n.map(c=>ut(c,!0)):(i=Ct(s,n),a=Ct(o(),[])),yn({changedNodes:a,changedEdges:i,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:o}=t(),i=n||o(),a=r||s,c=i.map(u=>(u.selected=!1,ut(u.id,!1))),l=a.map(u=>ut(u.id,!1));yn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),o=r().filter(a=>a.selected).map(a=>ut(a.id,!1)),i=n.filter(a=>a.selected).map(a=>ut(a.id,!1));yn({changedNodes:o,changedEdges:i,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Dr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:o,d3Zoom:i,d3Selection:a,translateExtent:c}=t();if(!i||!a||!n.x&&!n.y)return!1;const l=rt.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,o]],d=i==null?void 0:i.constrain()(l,u,c);return i.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:at.connectionNodeId,connectionHandleId:at.connectionHandleId,connectionHandleType:at.connectionHandleType,connectionStatus:at.connectionStatus,connectionStartHandle:at.connectionStartHandle,connectionEndHandle:at.connectionEndHandle}),reset:()=>e({...at})}),Object.is),Wi=({children:e})=>{const t=w.useRef(null);return t.current||(t.current=Zh()),A.createElement(pf,{value:t.current},e)};Wi.displayName="ReactFlowProvider";const Ui=({children:e})=>w.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Wi,null,e);Ui.displayName="ReactFlowWrapper";const Qh={input:ji,default:Nr,output:Mi,group:Br},Jh={default:In,straight:Hr,step:zr,smoothstep:Bn,simplebezier:Pr},em=[0,0],tm=[15,15],nm={x:0,y:0,zoom:1},rm={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},qi=w.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:o=Qh,edgeTypes:i=Jh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:p,onConnectEnd:x,onClickConnectStart:_,onClickConnectEnd:g,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:b,onNodeContextMenu:$,onNodeDoubleClick:j,onNodeDragStart:v,onNodeDrag:R,onNodeDragStop:N,onNodesDelete:T,onEdgesDelete:P,onSelectionChange:G,onSelectionDragStart:V,onSelectionDrag:y,onSelectionDragStop:M,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:z,connectionMode:k=_t.Strict,connectionLineType:I=dt.Bezier,connectionLineStyle:L,connectionLineComponent:D,connectionLineContainerStyle:q,deleteKeyCode:F="Backspace",selectionKeyCode:J="Shift",selectionOnDrag:ee=!1,selectionMode:se=tn.Full,panActivationKeyCode:le="Space",multiSelectionKeyCode:ne=$n()?"Meta":"Control",zoomActivationKeyCode:ce=$n()?"Meta":"Control",snapToGrid:we=!1,snapGrid:ye=tm,onlyRenderVisibleElements:he=!1,selectNodesOnDrag:ue=!0,nodesDraggable:me,nodesConnectable:Se,nodesFocusable:ie,nodeOrigin:Z=em,edgesFocusable:xe,edgesUpdatable:je,elementsSelectable:Ae,defaultViewport:Le=nm,minZoom:Re=.5,maxZoom:Ie=2,translateExtent:Ve=kr,preventScrolling:H=!0,nodeExtent:X,defaultMarkerColor:B="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:Y=!0,panOnScroll:W=!1,panOnScrollSpeed:te=.5,panOnScrollMode:pe=xt.Free,zoomOnDoubleClick:Q=!0,panOnDrag:oe=!0,onPaneClick:re,onPaneMouseEnter:fe,onPaneMouseMove:Ce,onPaneMouseLeave:Te,onPaneScroll:$e,onPaneContextMenu:Ue,children:Dt,onEdgeContextMenu:Be,onEdgeDoubleClick:Pt,onEdgeMouseEnter:de,onEdgeMouseMove:Qe,onEdgeMouseLeave:zt,onEdgeUpdate:Ta,onEdgeUpdateStart:Oa,onEdgeUpdateEnd:La,onReconnect:Da,onReconnectStart:Pa,onReconnectEnd:za,reconnectRadius:Ha=10,edgeUpdaterRadius:Fa=10,onNodesChange:Va,onEdgesChange:Ba,noDragClassName:Ga="nodrag",noWheelClassName:Ya="nowheel",noPanClassName:Qr="nopan",fitView:Xa=!1,fitViewOptions:Wa,connectOnClick:Ua=!0,attributionPosition:qa,proOptions:Ka,defaultEdgeOptions:Za,elevateNodesOnSelect:Qa=!0,elevateEdgesOnSelect:Ja=!1,disableKeyboardA11y:Jr=!1,autoPanOnConnect:ec=!0,autoPanOnNodeDrag:tc=!0,connectionRadius:nc=20,isValidConnection:rc,onError:sc,style:oc,id:es,nodeDragThreshold:ic,...ac},cc)=>{const Xn=es||"1";return A.createElement("div",{...ac,style:{...oc,...rm},ref:cc,className:Me(["react-flow",s]),"data-testid":"rf__wrapper",id:es},A.createElement(Ui,null,A.createElement(Kh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:b,onNodeContextMenu:$,onNodeDoubleClick:j,nodeTypes:o,edgeTypes:i,connectionLineType:I,connectionLineStyle:L,connectionLineComponent:D,connectionLineContainerStyle:q,selectionKeyCode:J,selectionOnDrag:ee,selectionMode:se,deleteKeyCode:F,multiSelectionKeyCode:ne,panActivationKeyCode:le,zoomActivationKeyCode:ce,onlyRenderVisibleElements:he,selectNodesOnDrag:ue,defaultViewport:Le,translateExtent:Ve,minZoom:Re,maxZoom:Ie,preventScrolling:H,zoomOnScroll:U,zoomOnPinch:Y,zoomOnDoubleClick:Q,panOnScroll:W,panOnScrollSpeed:te,panOnScrollMode:pe,panOnDrag:oe,onPaneClick:re,onPaneMouseEnter:fe,onPaneMouseMove:Ce,onPaneMouseLeave:Te,onPaneScroll:$e,onPaneContextMenu:Ue,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:z,onEdgeContextMenu:Be,onEdgeDoubleClick:Pt,onEdgeMouseEnter:de,onEdgeMouseMove:Qe,onEdgeMouseLeave:zt,onReconnect:Da??Ta,onReconnectStart:Pa??Oa,onReconnectEnd:za??La,reconnectRadius:Ha??Fa,defaultMarkerColor:B,noDragClassName:Ga,noWheelClassName:Ya,noPanClassName:Qr,elevateEdgesOnSelect:Ja,rfId:Xn,disableKeyboardA11y:Jr,nodeOrigin:Z,nodeExtent:X}),A.createElement(Xf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:p,onConnectEnd:x,onClickConnectStart:_,onClickConnectEnd:g,nodesDraggable:me,nodesConnectable:Se,nodesFocusable:ie,edgesFocusable:xe,edgesUpdatable:je,elementsSelectable:Ae,elevateNodesOnSelect:Qa,minZoom:Re,maxZoom:Ie,nodeExtent:X,onNodesChange:Va,onEdgesChange:Ba,snapToGrid:we,snapGrid:ye,connectionMode:k,translateExtent:Ve,connectOnClick:Ua,defaultEdgeOptions:Za,fitView:Xa,fitViewOptions:Wa,onNodesDelete:T,onEdgesDelete:P,onNodeDragStart:v,onNodeDrag:R,onNodeDragStop:N,onSelectionDrag:y,onSelectionDragStart:V,onSelectionDragStop:M,noPanClassName:Qr,nodeOrigin:Z,rfId:Xn,autoPanOnConnect:ec,autoPanOnNodeDrag:tc,onError:sc,connectionRadius:nc,isValidConnection:rc,nodeDragThreshold:ic}),A.createElement(Gf,{onSelectionChange:G}),Dt,A.createElement(yf,{proOptions:Ka,position:qa}),A.createElement(Zf,{rfId:Xn,disableKeyboardA11y:Jr})))});qi.displayName="ReactFlow";const Ki=({id:e,x:t,y:n,width:r,height:s,style:o,color:i,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:p,backgroundColor:x}=o||{},_=i||p||x;return A.createElement("rect",{className:Me(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:_,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?g=>m(g,e):void 0})};Ki.displayName="MiniMapNode";var sm=w.memo(Ki);const om=e=>e.nodeOrigin,im=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function am({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:o=sm,onClick:i}){const a=ge(im,ke),c=ge(om),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:p,y:x}=bt(f,c).positionAbsolute;return A.createElement(o,{key:f.id,x:p,y:x,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:i,id:f.id})}))}var cm=w.memo(am);const lm=200,um=150,dm=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?bf(an(t,e.nodeOrigin),n):n,rfId:e.rfId}},fm="react-flow__minimap-desc";function Zi({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:o=5,nodeStrokeWidth:i=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:p=!1,zoomable:x=!1,ariaLabel:_="React Flow mini map",inversePan:g=!1,zoomStep:E=10,offsetScale:C=5}){const b=Ne(),$=w.useRef(null),{boundingRect:j,viewBB:v,rfId:R}=ge(dm,ke),N=(e==null?void 0:e.width)??lm,T=(e==null?void 0:e.height)??um,P=j.width/N,G=j.height/T,V=Math.max(P,G),y=V*N,M=V*T,S=C*V,O=j.x-(y-j.width)/2-S,z=j.y-(M-j.height)/2-S,k=y+S*2,I=M+S*2,L=`${fm}-${R}`,D=w.useRef(0);D.current=V,w.useEffect(()=>{if($.current){const J=Pe($.current),ee=ne=>{const{transform:ce,d3Selection:we,d3Zoom:ye}=b.getState();if(ne.sourceEvent.type!=="wheel"||!we||!ye)return;const he=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,ue=ce[2]*Math.pow(2,he);ye.scaleTo(we,ue)},se=ne=>{const{transform:ce,d3Selection:we,d3Zoom:ye,translateExtent:he,width:ue,height:me}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!we||!ye)return;const Se=D.current*Math.max(1,ce[2])*(g?-1:1),ie={x:ce[0]-ne.sourceEvent.movementX*Se,y:ce[1]-ne.sourceEvent.movementY*Se},Z=[[0,0],[ue,me]],xe=rt.translate(ie.x,ie.y).scale(ce[2]),je=ye.constrain()(xe,Z,he);ye.transform(we,je)},le=oi().on("zoom",p?se:null).on("zoom.wheel",x?ee:null);return J.call(le),()=>{J.on("zoom",null)}}},[p,x,g,E]);const q=m?J=>{const ee=Ge(J);m(J,{x:ee[0],y:ee[1]})}:void 0,F=f?(J,ee)=>{const se=b.getState().nodeInternals.get(ee);f(J,se)}:void 0;return A.createElement(Or,{position:d,style:e,className:Me(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:N,height:T,viewBox:`${O} ${z} ${k} ${I}`,role:"img","aria-labelledby":L,ref:$,onClick:q},_&&A.createElement("title",{id:L},_),A.createElement(cm,{onClick:F,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:o,nodeClassName:s,nodeStrokeWidth:i,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${O-S},${z-S}h${k+S*2}v${I+S*2}h${-k-S*2}z + M${v.x},${v.y}h${v.width}v${v.height}h${-v.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Zi.displayName="MiniMap";var hm=w.memo(Zi);function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function pm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function gm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function ym(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function xm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Wt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:Me(["react-flow__controls-button",t]),...n},e);Wt.displayName="ControlButton";const wm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Qi=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:o,onZoomOut:i,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ne(),[f,p]=w.useState(!1),{isInteractive:x,minZoomReached:_,maxZoomReached:g}=ge(wm,ke),{zoomIn:E,zoomOut:C,fitView:b}=cn();if(w.useEffect(()=>{p(!0)},[]),!f)return null;const $=()=>{E(),o==null||o()},j=()=>{C(),i==null||i()},v=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!x,nodesConnectable:!x,elementsSelectable:!x}),c==null||c(!x)};return A.createElement(Or,{className:Me(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Wt,{onClick:$,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:g},A.createElement(mm,null)),A.createElement(Wt,{onClick:j,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:_},A.createElement(pm,null))),n&&A.createElement(Wt,{className:"react-flow__controls-fitview",onClick:v,title:"fit view","aria-label":"fit view"},A.createElement(gm,null)),r&&A.createElement(Wt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},x?A.createElement(xm,null):A.createElement(ym,null)),u)};Qi.displayName="Controls";var bm=w.memo(Qi),He;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(He||(He={}));function vm({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function _m({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const Em={[He.Dots]:"#91919a",[He.Lines]:"#eee",[He.Cross]:"#e2e2e2"},Nm={[He.Dots]:1,[He.Lines]:1,[He.Cross]:6},Sm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Ji({id:e,variant:t=He.Dots,gap:n=20,size:r,lineWidth:s=1,offset:o=2,color:i,style:a,className:c}){const l=w.useRef(null),{transform:u,patternId:d}=ge(Sm,ke),m=i||Em[t],f=r||Nm[t],p=t===He.Dots,x=t===He.Cross,_=Array.isArray(n)?n:[n,n],g=[_[0]*u[2]||1,_[1]*u[2]||1],E=f*u[2],C=x?[E,E]:g,b=p?[E/o,E/o]:[C[0]/o,C[1]/o];return A.createElement("svg",{className:Me(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%g[0],y:u[1]%g[1],width:g[0],height:g[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},p?A.createElement(_m,{color:m,radius:E/o}):A.createElement(vm,{dimensions:C,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}Ji.displayName="Background";var km=w.memo(Ji);const Yr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Yr+e}async function ve(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function it(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new ea(r.error??`${e}: ${n.status}`,n.status);return r}class ea extends Error{constructor(n,r){super(n);_e(this,"status");this.status=r}}const Dx=e=>ve(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),Px=()=>ve("/api/diagnostics"),ta=(e,t)=>ve(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),na=()=>ve("/api/ontology/ontologies"),jm=e=>ve(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Cm=()=>ve("/api/ontology/stack"),Mm=()=>ve("/api/ontology/coverage"),$m=(e,t,n)=>it("/api/command",{op:e,payload:t,fingerprint:n??""}),Am=()=>ve("/api/git/status"),Rm=()=>ve("/api/git/diff"),Im=e=>it("/api/git/commit",{message:e}),Tm=()=>it("/api/git/discard",{}),Om=()=>ve("/api/decisions"),Gs=(e,t)=>it(`/api/decisions/${e}/verdict`,{verdict:t}),zx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),ve(`/api/glossary/terms?${t.toString()}`)},Hx=()=>ve("/api/glossary/config"),Fx=e=>it("/api/git/propose",e),Vx=(e="HEAD")=>ve(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Bx=(e="HEAD")=>ve(`/api/git/classify?base=${encodeURIComponent(e)}`),Gx=e=>it("/api/git/classify",{changes:e}),Yx=e=>ve(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Xx=(e="")=>ve(`/api/git/context?user=${encodeURIComponent(e)}`),Wx=(e="")=>ve(`/api/git/proposals?user=${encodeURIComponent(e)}`),Lm=()=>ve("/api/export"),Dm=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Yr}/api/export/${encodeURIComponent(e)}${n}`},Pm=(e,t,n)=>it("/api/import",{format:e,content:t,dialect:n}),zm=(e,t)=>it("/api/import/preview",{format:e,content:t}),Ux=e=>ve(`/api/import/stash/${encodeURIComponent(e)}`),qx=async(e,t=!1)=>{for(const n of e)try{await $m(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Kx=(e,t,n)=>fetch(`${Yr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new ea(await r.text(),r.status);return await r.json()}),Zx=()=>ve("/api/glossary/subject-areas"),Qx=e=>ve(`/api/glossary/subject-area/${e}`),Jx=(e,t)=>it(`/api/glossary/subject-area/${e}/expand`,t);function ew(){return{async load(e){try{const t=await ve(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Hm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Fm(e){return e??""}const Xr="__entity_source",Wr="__entity_target",Vm=w.memo(function({data:t,selected:n}){var j;const{entity:r,color:s,dimmed:o,highlighted:i,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:p}=t,x=v=>v.role==="business_key"?0:d!=null&&d.has(v.id)?1:2,_=[...r.attributes].map((v,R)=>({a:v,i:R})).sort((v,R)=>x(v.a)-x(R.a)||v.i-R.i).map(v=>v.a),g=_.filter(v=>v.role==="business_key");let E=_.filter(v=>v.role!=="business_key");const C=!!c&&!l;let b=0;if(C){const v=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-v.length,E=v}const $=(v,R)=>{const N="attr-row"+(m!=null&&m.has(v.id)?" rel-hit":"")+(f!=null&&f.has(v.id)?" rel-dim":"")+(d!=null&&d.has(v.id)?" endpoint":"");return h.jsxs("div",{className:N,onMouseEnter:p?()=>p(v.id):void 0,onMouseLeave:p?()=>p(null):void 0,children:[h.jsx(ft,{id:v.id,type:"target",position:K.Left,className:"port attr-port"}),h.jsx(ft,{id:v.id,type:"source",position:K.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Hm[v.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:v.name}),a&&h.jsx("span",{className:"attr-type",children:Fm(v.domain)}),!v.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},v.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(o?" dimmed":"")+(i?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ft,{id:Wr,type:"target",position:K.Left,className:"port"}),h.jsx(ft,{id:Xr,type:"source",position:K.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((j=r.conceptual)==null?void 0:j.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var N;const v=(((N=r.conceptual)==null?void 0:N.ontology_refs)??[]).filter(T=>T.uri);if(v.length===0)return null;const R=v.map(T=>T.uri).join(` +`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",v.length>1?` ${v.length}`:""]})})()]})]}),g.length>0&&h.jsx("div",{className:"attr-section keys",children:g.map(v=>$(v,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(v=>$(v,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),Bm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Gm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:o,onAlign:i,onEditMapping:a}){var m,f,p,x,_,g,E,C,b,$,j,v,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(N=>N.from.entity===e.id||N.to.entity===e.id),d=N=>{var T;return((T=t.entities.find(P=>P.id===N))==null?void 0:T.name)??N};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(et,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,name:N})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(et,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,physical_name:N})})]}),h.jsxs("div",{children:[h.jsx(Xm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Um,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(et,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:N=>r("set_definition",{id:e.id,definition:N})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>i(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((p=l==null?void 0:l.ontology_refs)==null?void 0:p.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Ym,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(x=e.term_map)!=null&&x.subject_template||(_=e.term_map)!=null&&_.class_iri?"Edit mapping…":"Map…"}),(((g=e.term_map)==null?void 0:g.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),(C=e.term_map)!=null&&C.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[(($=e.term_map)==null?void 0:$.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(et,{value:((v=l==null?void 0:l.stewardship)==null?void 0:v.owner)??"",placeholder:"—",readOnly:c,onCommit:N=>{var T;return r("set_stewardship",{id:e.id,owner:N,steward:((T=l==null?void 0:l.stewardship)==null?void 0:T.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(et,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:N=>{var T;return r("set_stewardship",{id:e.id,owner:((T=l==null?void 0:l.stewardship)==null?void 0:T.owner)??null,steward:N})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(N=>h.jsx(Km,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(Zm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(N=>{const T=N.members.map(P=>{var G;return((G=e.attributes.find(V=>V.id===P))==null?void 0:G.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+N.type,children:N.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:N.name}),h.jsx("span",{className:"key-cols",children:T})]},N.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([N,T])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:N}),h.jsx("td",{className:"udp-val",children:String(T)})]},N))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(N=>{const T=N.from.entity===e.id?N.to.entity:N.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>o(T),children:[h.jsx("span",{className:"rel-card",children:Qm(N,e.id)}),d(T)]}),(N.verb_phrase||N.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(et,{value:N.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,verb_phrase:P})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(et,{value:N.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,inverse_verb_phrase:P})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${N.name}`,onClick:()=>r("delete_relationship",{id:N.id}),children:"✕"})]},N.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var N;return(N=navigator.clipboard)==null?void 0:N.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Ym({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,o=t.filter(i=>i.uri);return o.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:o.map((i,a)=>{const c=i.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:i.uri??void 0,children:i.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[i.predicate&&h.jsx("span",{className:"ref-pill",children:i.predicate}),i.layer&&h.jsx("span",{className:`chip layer-${i.layer}`,children:i.layer}),i.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",i.resolved_via]}),typeof i.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(i.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:i.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:i.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${i.uri}-${a}`)})})}function et({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:o=""}){const[i,a]=w.useState(e);w.useEffect(()=>a(e),[e]);const c=()=>{i.trim()!==e.trim()&&t(i.trim())};return n?h.jsx("span",{className:o,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${o}`,value:i,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${o}`,value:i,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Xm({entity:e,doc:t,readOnly:n,exec:r}){var o,i,a;const s=((i=(o=e.conceptual)==null?void 0:o.subject_area)==null?void 0:i.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Wm=["","scd2","hub","link","satellite","bridge"];function Um({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Wm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const qm=["attribute","business_key","measure","surrogate_key"];function Km({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const o=i=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...i});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(et,{value:e.name,readOnly:!1,onCommit:i=>o({name:i})}),(e.physical_name||!1)&&h.jsx(et,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:i=>o({physical_name:i})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:i=>o({domain:i.target.value}),children:[...new Set([...Bm,...n.domains??[],e.domain??"string"])].sort().map(i=>h.jsx("option",{value:i,children:i},i))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:i=>o({role:i.target.value}),title:"role",children:qm.map(i=>h.jsx("option",{value:i,children:i==="business_key"?"🔑 key":i==="measure"?"Σ measure":i},i))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:i=>o({nullable:!i.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Zm({entity:e,exec:t}){const[n,r]=w.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:o=>r(o.target.value),onKeyDown:o=>o.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Qm(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var Jm="\0",pt="\0",Ys="";let ep=class{constructor(t){_e(this,"_isDirected",!0);_e(this,"_isMultigraph",!1);_e(this,"_isCompound",!1);_e(this,"_label");_e(this,"_defaultNodeLabelFn",()=>{});_e(this,"_defaultEdgeLabelFn",()=>{});_e(this,"_nodes",{});_e(this,"_in",{});_e(this,"_preds",{});_e(this,"_out",{});_e(this,"_sucs",{});_e(this,"_edgeObjs",{});_e(this,"_edgeLabels",{});_e(this,"_nodeCount",0);_e(this,"_edgeCount",0);_e(this,"_parent");_e(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[pt]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(o){r.length>1?s.setNode(o,n):s.setNode(o)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=pt,this._children[t]={},this._children[pt][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=pt;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==pt)return n}}children(t=pt){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===pt)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([i,a]){t(i)&&n.setNode(i,a)}),Object.values(this._edgeObjs).forEach(function(i){n.hasNode(i.v)&&n.hasNode(i.w)&&n.setEdge(i,r.edge(i))});var s={};function o(i){var a=r.parent(i);return a===void 0||n.hasNode(a)?(s[i]=a,a):a in s?s[a]:o(a)}return this._isCompound&&n.nodes().forEach(i=>n.setParent(i,o(i))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(o,i){return s.length>1?r.setEdge(o,i,n):r.setEdge(o,i),i}),this}setEdge(){var t,n,r,s,o=!1,i=arguments[0];typeof i=="object"&&i!==null&&"v"in i?(t=i.v,n=i.w,r=i.name,arguments.length===2&&(s=arguments[1],o=!0)):(t=i,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],o=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Ut(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return o&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=o?s:this._defaultEdgeLabelFn(t,n,r);var c=tp(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Xs(this._preds[n],t),Xs(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r),o=this._edgeObjs[s];return o&&(t=o.v,n=o.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Ws(this._preds[n],t),Ws(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(o=>o.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(o=>o.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Xs(e,t){e[t]?e[t]++:e[t]=1}function Ws(e,t){--e[t]||delete e[t]}function Ut(e,t,n,r){var s=""+t,o=""+n;if(!e&&s>o){var i=s;s=o,o=i}return s+Ys+o+Ys+(r===void 0?Jm:r)}function tp(e,t,n,r){var s=""+t,o=""+n;if(!e&&s>o){var i=s;s=o,o=i}var a={v:s,w:o};return r&&(a.name=r),a}function sr(e,t){return Ut(e,t.v,t.w,t.name)}var Ur=ep,np="2.2.4",rp={Graph:Ur,version:np},sp=Ur,op={write:ip,read:lp};function ip(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:ap(e),edges:cp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function ap(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function cp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function lp(e){var t=new sp(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var up=dp;function dp(e){var t={},n=[],r;function s(o){Object.hasOwn(t,o)||(t[o]=!0,r.push(o),e.successors(o).forEach(s),e.predecessors(o).forEach(s))}return e.nodes().forEach(function(o){r=[],s(o),r.length&&n.push(r)}),n}let fp=class{constructor(){_e(this,"_arr",[]);_e(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,o=s.length;return r[t]=o,s.push({key:t,priority:n}),this._decrease(o),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,o=t;r>1,!(n[s].priority1;function pp(e,t,n,r){return gp(e,String(t),n||mp,r||function(s){return e.outEdges(s)})}function gp(e,t,n,r){var s={},o=new hp,i,a,c=function(l){var u=l.v!==i?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(i=o.removeMin(),a=s[i],a.distance!==Number.POSITIVE_INFINITY);)r(i).forEach(c);return s}var yp=sa,xp=wp;function wp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=yp(e,s,t,n),r},{})}var oa=bp;function bp(e){var t=0,n=[],r={},s=[];function o(i){var a=r[i]={onStack:!0,lowlink:t,index:t++};if(n.push(i),e.successors(i).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(o(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(i!==l);s.push(c)}}return e.nodes().forEach(function(i){Object.hasOwn(r,i)||o(i)}),s}var vp=oa,_p=Ep;function Ep(e){return vp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var Np=kp,Sp=()=>1;function kp(e,t,n){return jp(e,t||Sp,n||function(r){return e.outEdges(r)})}function jp(e,t,n){var r={},s=e.nodes();return s.forEach(function(o){r[o]={},r[o][o]={distance:0},s.forEach(function(i){o!==i&&(r[o][i]={distance:Number.POSITIVE_INFINITY})}),n(o).forEach(function(i){var a=i.v===o?i.w:i.v,c=t(i);r[o][a]={distance:c,predecessor:o}})}),s.forEach(function(o){var i=r[o];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[o],d=i[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?Ap:Rp,o=[],i={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,i,o)}),o}function Ap(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var o=s.pop();o[1]?r.push(o[0]):Object.hasOwn(n,o[0])||(n[o[0]]=!0,s.push([o[0],!0]),la(t(o[0]),i=>s.push([i,!1])))}}function Rp(e,t,n,r){for(var s=[e];s.length>0;){var o=s.pop();Object.hasOwn(n,o)||(n[o]=!0,r.push(o),la(t(o),i=>s.push(i)))}}function la(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var Ip=ca,Tp=Op;function Op(e,t){return Ip(e,t,"post")}var Lp=ca,Dp=Pp;function Pp(e,t){return Lp(e,t,"pre")}var zp=Ur,Hp=ra,Fp=Vp;function Vp(e,t){var n=new zp,r={},s=new Hp,o;function i(c){var l=c.v===o?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(o=s.removeMin(),Object.hasOwn(r,o))n.setEdge(o,r[o]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(o).forEach(i)}return n}var Bp={components:up,dijkstra:sa,dijkstraAll:xp,findCycles:_p,floydWarshall:Np,isAcyclic:Cp,postorder:Tp,preorder:Dp,prim:Fp,tarjan:oa,topsort:aa},qs=rp,We={Graph:qs.Graph,json:op,alg:Bp,version:qs.version};let Gp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Ks(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Ks(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Yp)),r=r._prev;return"["+t.join(", ")+"]"}};function Ks(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Yp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Xp=Gp;let Wp=We.Graph,Up=Xp;var qp=Zp;let Kp=()=>1;function Zp(e,t){if(e.nodeCount()<=1)return[];let n=Jp(e,t||Kp);return Qp(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Qp(e,t,n){let r=[],s=t[t.length-1],o=t[0],i;for(;e.nodeCount();){for(;i=o.dequeue();)or(e,t,n,i);for(;i=s.dequeue();)or(e,t,n,i);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(i=t[a].dequeue(),i){r=r.concat(or(e,t,n,i,!0));break}}}return r}function or(e,t,n,r,s){let o=s?[]:void 0;return e.inEdges(r.v).forEach(i=>{let a=e.edge(i),c=e.node(i.v);s&&o.push({v:i.v,w:i.w}),c.out-=a,Cr(t,n,c)}),e.outEdges(r.v).forEach(i=>{let a=e.edge(i),c=i.w,l=e.node(c);l.in-=a,Cr(t,n,l)}),e.removeNode(r.v),o}function Jp(e,t){let n=new Wp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let o=eg(s+r+3).map(()=>new Up),i=r+1;return n.nodes().forEach(a=>{Cr(o,i,n.node(a))}),{graph:n,buckets:o,zeroIdx:i}}function Cr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function eg(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function ng(e){let t=new ua({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function rg(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return qr(e.nodes(),t)}function sg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return qr(e.nodes(),t)}function og(e,t){let n=e.x,r=e.y,s=t.x-n,o=t.y-r,i=e.width/2,a=e.height/2;if(!s&&!o)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(o)*i>Math.abs(s)*a?(o<0&&(a=-a),c=a*s/o,l=a):(s<0&&(i=-i),c=i,l=i*o/s),{x:n+c,y:r+l}}function ig(e){let t=pa(ha(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function ag(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function cg(e){let t=e.nodes().map(i=>e.node(i).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(i=>{let a=e.node(i).rank-n;r[a]||(r[a]=[]),r[a].push(i)});let s=0,o=e.graph().nodeRankFactor;Array.from(r).forEach((i,a)=>{i===void 0&&a%o!==0?--s:i!==void 0&&s&&i.forEach(c=>e.node(c).rank+=s)})}function lg(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),da(e,"border",s,t)}function ug(e,t=fa){const n=[];for(let r=0;rfa){const n=ug(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function ha(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function dg(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function fg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function hg(e,t){return t()}let mg=0;function ma(e){var t=++mg;return e+(""+t)}function pa(e,t,n=1){t==null&&(t=e,e=0);let r=o=>otr[t]),Object.entries(e).reduce((r,[s,o])=>(r[s]=n(o,s),r),{})}function qr(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let yg=qp,xg=Ee.uniqueId;var wg={run:bg,undo:_g};function bg(e){(e.graph().acyclicer==="greedy"?yg(e,n(e)):vg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,xg("rev"))});function n(r){return s=>r.edge(s).weight}}function vg(e){let t=[],n={},r={};function s(o){Object.hasOwn(r,o)||(r[o]=!0,n[o]=!0,e.outEdges(o).forEach(i=>{Object.hasOwn(n,i.w)?t.push(i):s(i.w)}),delete n[o])}return e.nodes().forEach(s),t}function _g(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let Eg=Ee;var Ng={run:Sg,undo:jg};function Sg(e){e.graph().dummyChains=[],e.edges().forEach(t=>kg(e,t))}function kg(e,t){let n=t.v,r=e.node(n).rank,s=t.w,o=e.node(s).rank,i=t.name,a=e.edge(t),c=a.labelRank;if(o===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Cg}=Ee;var Yn={longestPath:Mg,slack:$g};function Mg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let o=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var i=Cg(Math.min,o);return i===Number.POSITIVE_INFINITY&&(i=0),s.rank=i}e.sources().forEach(n)}function $g(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var Ag=We.Graph,On=Yn.slack,ga=Rg;function Rg(e){var t=new Ag({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,o;Ig(t,e){var o=s.v,i=r===o?s.w:o;!e.hasNode(i)&&!On(t,s)&&(e.setNode(i,{}),e.setEdge(r,i,{}),n(i))})}return e.nodes().forEach(n),e.nodeCount()}function Tg(e,t){return t.edges().reduce((r,s)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(o=On(t,s)),ot.node(r).rank+=n)}var Lg=ga,Zs=Yn.slack,Dg=Yn.longestPath,Pg=We.alg.preorder,zg=We.alg.postorder,Hg=Ee.simplify,Fg=Et;Et.initLowLimValues=Zr;Et.initCutValues=Kr;Et.calcCutValue=ya;Et.leaveEdge=wa;Et.enterEdge=ba;Et.exchangeEdges=va;function Et(e){e=Hg(e),Dg(e);var t=Lg(e);Zr(t),Kr(t,e);for(var n,r;n=wa(t);)r=ba(t,e,n),va(t,e,n,r)}function Kr(e,t){var n=zg(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Vg(e,t,r))}function Vg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ya(e,t,n)}function ya(e,t,n){var r=e.node(n),s=r.parent,o=!0,i=t.edge(n,s),a=0;return i||(o=!1,i=t.edge(s,n)),a=i.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===o,m=t.edge(c).weight;if(a+=d?m:-m,Gg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Zr(e,t){arguments.length<2&&(t=e.nodes()[0]),xa(e,{},1,t)}function xa(e,t,n,r,s){var o=n,i=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=xa(e,t,n,a,r))}),i.low=o,i.lim=n++,s?i.parent=s:delete i.parent,n}function wa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ba(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var o=e.node(r),i=e.node(s),a=o,c=!1;o.lim>i.lim&&(a=i,c=!0);var l=t.edges().filter(u=>c===Qs(e,e.node(u.v),a)&&c!==Qs(e,e.node(u.w),a));return l.reduce((u,d)=>Zs(t,d)!t.node(s).parent),r=Pg(e,n);r=r.slice(1),r.forEach(s=>{var o=e.node(s).parent,i=t.edge(s,o),a=!1;i||(i=t.edge(o,s),a=!0),t.node(s).rank=t.node(o).rank+(a?i.minlen:-i.minlen)})}function Gg(e,t,n){return e.hasEdge(t,n)}function Qs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Yg=Yn,_a=Yg.longestPath,Xg=ga,Wg=Fg,Ug=qg;function qg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Js(e);break;case"tight-tree":Zg(e);break;case"longest-path":Kg(e);break;case"none":break;default:Js(e)}}var Kg=_a;function Zg(e){_a(e),Xg(e)}function Js(e){Wg(e)}var Qg=Jg;function Jg(e){let t=ty(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,o=ey(e,t,s.v,s.w),i=o.path,a=o.lca,c=0,l=i[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=i[c])!==a&&e.node(l).maxRanki||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)o.push(c);return{path:s.concat(o.reverse()),lca:l}}function ty(e){let t={},n=0;function r(s){let o=n;e.children(s).forEach(r),t[s]={low:o,lim:n++}}return e.children().forEach(r),t}let Ln=Ee;var ny={run:ry,cleanup:iy};function ry(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=sy(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,o=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=o);let i=oy(e)+1;e.children().forEach(a=>Ea(e,t,o,i,s,n,a)),e.graph().nodeRankFactor=o}function Ea(e,t,n,r,s,o,i){let a=e.children(i);if(!a.length){i!==t&&e.setEdge(t,i,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(i);e.setParent(c,i),u.borderTop=c,e.setParent(l,i),u.borderBottom=l,a.forEach(d=>{Ea(e,t,n,r,s,o,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,p=m.borderBottom?m.borderBottom:d,x=m.borderTop?r:2*r,_=f!==p?1:s-o[i]+1;e.setEdge(c,f,{weight:x,minlen:_,nestingEdge:!0}),e.setEdge(p,l,{weight:x,minlen:_,nestingEdge:!0})}),e.parent(i)||e.setEdge(t,c,{weight:0,minlen:s+o[i]})}function sy(e){var t={};function n(r,s){var o=e.children(r);o&&o.length&&o.forEach(i=>n(i,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function oy(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function iy(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let ay=Ee;var cy=ly;function ly(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let o=s.minRank,i=s.maxRank+1;oto(e.node(t))),e.edges().forEach(t=>to(e.edge(t)))}function to(e){let t=e.width;e.width=e.height,e.height=t}function hy(e){e.nodes().forEach(t=>ir(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ir),Object.hasOwn(n,"y")&&ir(n)})}function ir(e){e.y=-e.y}function my(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let no=Ee;var py=gy;function gy(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=no.applyWithChunking(Math.max,r),o=no.range(s+1).map(()=>[]);function i(c){if(t[c])return;t[c]=!0;let l=e.node(c);o[l.rank].push(c),e.successors(c).forEach(i)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(i),o}let yy=Ee.zipObject;var xy=wy;function wy(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),o=1;for(;o{let u=l.pos+o;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var vy=_y;function _y(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((o,i)=>{let a=e.edge(i),c=e.node(i.v);return{sum:o.sum+a.weight*c.order,weight:o.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let Ey=Ee;var Ny=Sy;function Sy(e,t){let n={};e.forEach((s,o)=>{let i=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i:o};s.barycenter!==void 0&&(i.barycenter=s.barycenter,i.weight=s.weight)}),t.edges().forEach(s=>{let o=n[s.v],i=n[s.w];o!==void 0&&i!==void 0&&(i.indegree++,o.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return ky(r)}function ky(e){let t=[];function n(s){return o=>{o.merged||(o.barycenter===void 0||s.barycenter===void 0||o.barycenter>=s.barycenter)&&jy(s,o)}}function r(s){return o=>{o.in.push(s),--o.indegree===0&&e.push(o)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>Ey.pick(s,["vs","i","barycenter","weight"]))}function jy(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let Cy=Ee;var My=$y;function $y(e,t){let n=Cy.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),o=[],i=0,a=0,c=0;r.sort(Ay(!!t)),c=ro(o,s,c),r.forEach(u=>{c+=u.vs.length,o.push(u.vs),i+=u.barycenter*u.weight,a+=u.weight,c=ro(o,s,c)});let l={vs:o.flat(!0)};return a&&(l.barycenter=i/a,l.weight=a),l}function ro(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function Ay(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Ry=vy,Iy=Ny,Ty=My;var Oy=Sa;function Sa(e,t,n,r){let s=e.children(t),o=e.node(t),i=o?o.borderLeft:void 0,a=o?o.borderRight:void 0,c={};i&&(s=s.filter(m=>m!==i&&m!==a));let l=Ry(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=Sa(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&Dy(m,f)}});let u=Iy(l,n);Ly(u,c);let d=Ty(u,r);if(i&&(d.vs=[i,d.vs,a].flat(!0),e.predecessors(i).length)){let m=e.node(e.predecessors(i)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function Ly(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function Dy(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let Py=We.Graph,zy=Ee;var Hy=Fy;function Fy(e,t,n,r){r||(r=e.nodes());let s=Vy(e),o=new Py({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(i=>e.node(i));return r.forEach(i=>{let a=e.node(i),c=e.parent(i);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(o.setNode(i),o.setParent(i,c||s),e[n](i).forEach(l=>{let u=l.v===i?l.w:l.v,d=o.edge(u,i),m=d!==void 0?d.weight:0;o.setEdge(u,i,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&o.setNode(i,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),o}function Vy(e){for(var t;e.hasNode(t=zy.uniqueId("_root")););return t}var By=Gy;function Gy(e,t,n){let r={},s;n.forEach(o=>{let i=e.parent(o),a,c;for(;i;){if(a=e.parent(i),a?(c=r[a],r[a]=i):(c=s,s=i),c&&c!==i){t.setEdge(c,i);return}i=a}})}let Yy=py,Xy=xy,Wy=Oy,Uy=Hy,qy=By,Ky=We.Graph,wn=Ee;var Zy=ka;function ka(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,ka);return}let n=wn.maxRank(e),r=so(e,wn.range(1,n+1),"inEdges"),s=so(e,wn.range(n-1,-1,-1),"outEdges"),o=Yy(e);if(oo(e,o),t&&t.disableOptimalOrderHeuristic)return;let i=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){Qy(c%2?r:s,c%4>=2),o=wn.buildLayerMatrix(e);let u=Xy(e,o);u{r.has(o)||r.set(o,[]),r.get(o).push(i)};for(const o of e.nodes()){const i=e.node(o);if(typeof i.rank=="number"&&s(i.rank,o),typeof i.minRank=="number"&&typeof i.maxRank=="number")for(let a=i.minRank;a<=i.maxRank;a++)a!==i.rank&&s(a,o)}return t.map(function(o){return Uy(e,o,n,r.get(o)||[])})}function Qy(e,t){let n=new Ky;e.forEach(function(r){let s=r.graph().root,o=Wy(r,s,n,t);o.vs.forEach((i,a)=>r.node(i).order=a),qy(r,n,o.vs)})}function oo(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let Jy=We.Graph,tt=Ee;var e0={positionX:d0};function t0(e,t){let n={};function r(s,o){let i=0,a=0,c=s.length,l=o[o.length-1];return o.forEach((u,d)=>{let m=r0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(o.slice(a,d+1).forEach(p=>{e.predecessors(p).forEach(x=>{let _=e.node(x),g=_.order;(g{u=o[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&ja(n,m,u)})})}function s(o,i){let a=-1,c,l=0;return i.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(i,l,d,a,c),l=d,a=c)}r(i,l,i.length,c,o.length)}),i}return t.length&&t.reduce(s),n}function r0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function ja(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function s0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function o0(e,t,n,r){let s={},o={},i={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,o[c]=c,i[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>i[m]-i[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let p=u[m];o[l]===l&&cMath.max(m,o[f.v]+i.edge(f)),0)}function u(d){let m=i.outEdges(d).reduce((p,x)=>Math.min(p,o[x.w]-i.edge(x)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(o[d]=Math.max(o[d],m))}return c(l,i.predecessors.bind(i)),c(u,i.successors.bind(i)),Object.keys(r).forEach(d=>o[d]=o[n[d]]),o}function a0(e,t,n,r){let s=new Jy,o=e.graph(),i=f0(o.nodesep,o.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(i(e,l,c),m||0))}c=l})}),s}function c0(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=h0(e,a)/2;s=Math.max(c+l,s),o=Math.min(c-l,o)});const i=s-o;return i{["l","r"].forEach(i=>{let a=o+i,c=e[a];if(c===t)return;let l=Object.values(c),u=r-tt.applyWithChunking(Math.min,l);i!=="l"&&(u=s-tt.applyWithChunking(Math.max,l)),u&&(e[a]=tt.mapValues(c,d=>d+u))})})}function u0(e,t){return tt.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(o=>o[r]).sort((o,i)=>o-i);return(s[1]+s[2])/2}})}function d0(e){let t=tt.buildLayerMatrix(e),n=Object.assign(t0(e,t),n0(e,t)),r={},s;["u","d"].forEach(i=>{s=i==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(i==="u"?e.predecessors:e.successors).bind(e),l=o0(e,s,n,c),u=i0(e,s,l.root,l.align,a==="r");a==="r"&&(u=tt.mapValues(u,d=>-d)),r[i+a]=u})});let o=c0(e,r);return l0(r,o),u0(r,e.graph().align)}function f0(e,t,n){return(r,s,o)=>{let i=r.node(s),a=r.node(o),c=0,l;if(c+=i.width/2,Object.hasOwn(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":l=-i.width/2;break;case"r":l=i.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(i.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function h0(e,t){return e.node(t).width}let Ca=Ee,m0=e0.positionX;var p0=g0;function g0(e){e=Ca.asNonCompoundGraph(e),y0(e),Object.entries(m0(e)).forEach(([t,n])=>e.node(t).x=n)}function y0(e){let t=Ca.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const o=s.reduce((i,a)=>{const c=e.node(a).height;return i>c?i:c},0);s.forEach(i=>e.node(i).y=r+o/2),r+=o+n})}let io=wg,ao=Ng,x0=Ug,w0=Ee.normalizeRanks,b0=Qg,v0=Ee.removeEmptyRanks,co=ny,_0=cy,lo=uy,E0=Zy,N0=p0,Fe=Ee,S0=We.Graph;var k0=j0;function j0(e,t){let n=t&&t.debugTiming?Fe.time:Fe.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>D0(e));n(" runLayout",()=>C0(r,n,t)),n(" updateInputGraph",()=>M0(e,r))})}function C0(e,t,n){t(" makeSpaceForEdgeLabels",()=>P0(e)),t(" removeSelfEdges",()=>W0(e)),t(" acyclic",()=>io.run(e)),t(" nestingGraph.run",()=>co.run(e)),t(" rank",()=>x0(Fe.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>z0(e)),t(" removeEmptyRanks",()=>v0(e)),t(" nestingGraph.cleanup",()=>co.cleanup(e)),t(" normalizeRanks",()=>w0(e)),t(" assignRankMinMax",()=>H0(e)),t(" removeEdgeLabelProxies",()=>F0(e)),t(" normalize.run",()=>ao.run(e)),t(" parentDummyChains",()=>b0(e)),t(" addBorderSegments",()=>_0(e)),t(" order",()=>E0(e,n)),t(" insertSelfEdges",()=>U0(e)),t(" adjustCoordinateSystem",()=>lo.adjust(e)),t(" position",()=>N0(e)),t(" positionSelfEdges",()=>q0(e)),t(" removeBorderNodes",()=>X0(e)),t(" normalize.undo",()=>ao.undo(e)),t(" fixupEdgeLabelCoords",()=>G0(e)),t(" undoCoordinateSystem",()=>lo.undo(e)),t(" translateGraph",()=>V0(e)),t(" assignNodeIntersects",()=>B0(e)),t(" reversePoints",()=>Y0(e)),t(" acyclic.undo",()=>io.undo(e))}function M0(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let $0=["nodesep","edgesep","ranksep","marginx","marginy"],A0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},R0=["acyclicer","ranker","rankdir","align"],I0=["width","height","rank"],uo={width:0,height:0},T0=["minlen","weight","width","height","labeloffset"],O0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},L0=["labelpos"];function D0(e){let t=new S0({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},A0,cr(n,$0),Fe.pick(n,R0))),e.nodes().forEach(r=>{let s=lr(e.node(r));const o=cr(s,I0);Object.keys(uo).forEach(i=>{o[i]===void 0&&(o[i]=uo[i])}),t.setNode(r,o),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},O0,cr(s,T0),Fe.pick(s,L0)))}),t}function P0(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function z0(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),o={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};Fe.addDummyNode(e,"edge-proxy",o,"_ep")}})}function H0(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function F0(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function V0(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,o=e.graph(),i=o.marginx||0,a=o.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=i,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),o.width=n-t+i,o.height=s-r+a}function B0(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),o,i;n.points?(o=n.points[0],i=n.points[n.points.length-1]):(n.points=[],o=s,i=r),n.points.unshift(Fe.intersectRect(r,o)),n.points.push(Fe.intersectRect(s,i))})}function G0(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Y0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function X0(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),o=e.node(n.borderLeft[n.borderLeft.length-1]),i=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(i.x-o.x),n.height=Math.abs(s.y-r.y),n.x=o.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function W0(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function U0(e){var t=Fe.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,o)=>{var i=e.node(s);i.order=o+r,(i.selfEdges||[]).forEach(a=>{Fe.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:i.rank,order:o+ ++r,e:a.e,label:a.label},"_se")}),delete i.selfEdges})})}function q0(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,o=r.y,i=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*i/3,y:o-a},{x:s+5*i/6,y:o-a},{x:s+i,y:o},{x:s+5*i/6,y:o+a},{x:s+2*i/3,y:o+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return Fe.mapValues(Fe.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let K0=Ee,Z0=We.Graph;var Q0={debugOrdering:J0};function J0(e){let t=K0.buildLayerMatrix(e),n=new Z0({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let o="layer"+s;n.setNode(o,{rank:"same"}),r.reduce((i,a)=>(n.setEdge(i,a,{style:"invis"}),a))}),n}var ex="1.1.8",tx={graphlib:We,layout:k0,debug:Q0,util:{time:Ee.time,notime:Ee.notime},version:ex};const fo=ko(tx),Ke=264,nx=44,rx=26,sx=14;function ht(e){const t=Math.max(e.attributes.length,1);return nx+t*rx+sx}const ox=40;function ur(e,t,n,r="auto",s,o="LR"){const i=ix(n,s);return r==="grid"?go(e,n,i):r==="clustered"?po(e,t,n,i,o):r==="hierarchical"||e.length<=ox?ho(e,t,n,o):new Set(e.map(c=>i(c.id)).filter(Boolean)).size>1?po(e,t,n,i,o):go(e,n,i)}function ix(e,t){return n=>{var r,s,o;if(t){const i=t.get(n);if(i)return i.name}return((o=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:o.name)??""}}function Ma(e,t,n,r=!1,s="LR"){const o=new fo.graphlib.Graph;o.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),o.setDefaultEdgeLabel(()=>({}));const i=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);o.setNode(u.id,{width:Ke,height:d?ht(d):120})}for(const u of t)i.has(u.source)&&i.has(u.target)&&o.setEdge(u.source,u.target,{minlen:1,weight:2});fo.layout(o);let a=0,c=0;return{nodes:e.map(u=>{const d=o.node(u.id),m=n.get(u.id),f=m?ht(m):120,p=d.x-Ke/2,x=d.y-f/2;return a=Math.max(a,p+Ke),c=Math.max(c,x+f),{...u,position:{x:p,y:x}}}),width:a,height:c}}function ho(e,t,n,r="LR"){return Ma(e,t,n,!1,r).nodes}function ax(e,t){const n=a=>{const c=t.get(a);return c?ht(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let o=0,i=0;for(let a=0;a{const d=u*(Ke+$a);s.push({...l,position:{x:d,y:o}}),i=Math.max(i,d+Ke)}),o+=Math.max(...c.map(l=>n(l.id)))+Aa}return{nodes:s,width:i,height:o}}const mo=120;function po(e,t,n,r,s="LR"){const o=new Map;for(const m of e){const f=r(m.id);(o.get(f)??o.set(f,[]).get(f)).push(m)}const a=[...o.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=o.get(m),p=new Set(f.map(E=>E.id));let x=0;for(const E of t)p.has(E.source)&&p.has(E.target)&&x++;const g=f.length<=8&&x>=f.length-1?Ma(f,t,n,!0,s):ax(f,n);return{name:m,...g}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const $a=40,Aa=40;function go(e,t,n){const r=l=>{const u=t.get(l);return u?ht(u):120},s=[...e].sort((l,u)=>{var x,_;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((x=t.get(l.id))==null?void 0:x.name)??l.id,p=((_=t.get(u.id))==null?void 0:_.name)??u.id;return f.localeCompare(p)}),o=Math.max(1,Math.round(Math.sqrt(s.length))),i=Array.from({length:o},(l,u)=>u*(Ke+$a)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:i[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+Aa}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function ln({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const cx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ra=["industry","core","domain","specialised"];function lx({entity:e,exec:t,onClose:n}){var b,$;const[r,s]=w.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[o,i]=w.useState([]),[a,c]=w.useState(null),[l,u]=w.useState(null),[d,m]=w.useState("skos:exactMatch"),[f,p]=w.useState((($=e.conceptual)==null?void 0:$.ontology_layer)??"core"),[x,_]=w.useState([]),[g,E]=w.useState("");w.useEffect(()=>{na().then(j=>_(j.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return i([]);ta(r,g||void 0).then(v=>{i(v.results),c(v.loaded_terms)}).catch(()=>i([]))},200);return()=>clearTimeout(j)},[r,g]);const C=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(ln,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[x.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(g===""?" active":""),onClick:()=>E(""),children:"all sources"}),x.map(j=>h.jsx("button",{className:"src-chip"+(g===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:g?`Search within ${g}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&x.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[o.map(j=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===j.iri?" picked":""),onClick:()=>u(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&o.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:cx.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>p(j.target.value),children:Ra.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:C,children:["Align",l?` to ${l.label}`:""]})]})]})}function ux({entity:e,doc:t,exec:n,onClose:r}){var b,$,j;const[s,o]=w.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[i,a]=w.useState((($=e.term_map)==null?void 0:$.class_iri)??""),c=new Set(e.attributes.map(v=>v.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(v=>v[1]).filter(v=>!c.has(v)),d=v=>!v||v.startsWith("http://")||v.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(v),m=u.length===0&&d(i),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:i.trim()||null}).then(r)},p=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",x=t.project.kg_base_iri||`urn:${p}:`,_=(j=(e.key_groups??[]).find(v=>v.type==="pk"))==null?void 0:j.members.map(v=>{var R;return(R=e.attributes.find(N=>N.id===v))==null?void 0:R.name}).filter(Boolean),g=_&&_.length?`${x}${e.id}/${_.map(v=>`{${v}}`).join("_")}`:"(blank-node: entity has no primary key)",E=i.trim()||`${x}${e.id}`,C=s.trim()||g;return h.jsxs(ln,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:i,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:v=>a(v.target.value)}),d(i)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:v=>o(v.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",C]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((_==null?void 0:_[0])??"id")+"}",". Columns:"," ",e.attributes.map(v=>v.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function dx({doc:e,exec:t,onClose:n,onCreated:r}){const[s,o]=w.useState(""),[i,a]=w.useState(""),[c,l]=w.useState(""),[u,d]=w.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:i||null,subject_area:c||null,layer:u||null}).then(f=>{const p=f==null?void 0:f.created_id;n(),p&&r(p)})};return h.jsxs(ln,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>o(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:i,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ra.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const Ia=["many_to_one","one_to_many","one_to_one","many_to_many"];function fx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:o,onClose:i}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=w.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=w.useState(r??""),[m,f]=w.useState(s??(l==null?void 0:l.id)??""),[p,x]=w.useState("many_to_one"),[_,g]=w.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",C=()=>o("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:p,optionality:_}).then(i);return h.jsxs(ln,{title:`${a.name} → ${c.name}`,onClose:i,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:p,onChange:b=>x(b.target.value),children:Ia.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:_,onChange:b=>g(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:C,children:"Create relationship"})})]})}function hx({rel:e,doc:t,exec:n,onClose:r}){const s=g=>{var E;return((E=t.entities.find(C=>C.id===g))==null?void 0:E.name)??"?"},[o,i]=w.useState(e.name),[a,c]=w.useState(e.cardinality),[l,u]=w.useState(e.optionality),[d,m]=w.useState(e.identifying),[f,p]=w.useState(!1),x=async()=>{o.trim()&&o.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:o.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},_=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(ln,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:o,onChange:g=>i(g.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:g=>c(g.target.value),children:Ia.map(g=>h.jsx("option",{children:g},g))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:g=>u(g.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:g=>m(g.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:_,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>p(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:x,children:"Save"})]})]})}const yo=10,mx=6,Mt=24;function px(e,t){return t?e:Math.round(e/yo)*yo}function gx(e,t,n){const r=[...t];for(const i of n)r.push(i.left-Mt,i.right+Mt);let s=e,o=mx;for(const i of r){const a=Math.abs(i-e);at.left&&ei.left&&no.left&&n=i.right?(u.push({x:n,y:t.y},{x:i.right,y:t.y}),m={ox:1,oy:0}):(u.push({x:n,y:t.y},{x:i.left,y:t.y}),m={ox:-1,oy:0});return{path:vx(u),sourceOut:d,targetOut:m}}const ct=8;function Ex(e,t,n){const r=Math.abs(e-n.left),s=Math.abs(e-n.right),o=Math.abs(t-n.top),i=Math.abs(t-n.bottom),a=Math.min(r,s,o,i),c=(l,u,d)=>Math.min(Math.max(l,u),d);return a===r?{side:"left",x:n.left,y:c(t,n.top+ct,n.bottom-ct)}:a===s?{side:"right",x:n.right,y:c(t,n.top+ct,n.bottom-ct)}:a===o?{side:"top",x:c(e,n.left+ct,n.right-ct),y:n.top}:{side:"bottom",x:c(e,n.left+ct,n.right-ct),y:n.bottom}}function wo(e,t){const n=(r,s,o)=>Math.min(Math.max(r,s),o);switch(e.side){case"left":return{x:t.left,y:n(e.y,t.top,t.bottom),out:{ox:-1,oy:0}};case"right":return{x:t.right,y:n(e.y,t.top,t.bottom),out:{ox:1,oy:0}};case"top":return{x:n(e.x??(t.left+t.right)/2,t.left,t.right),y:t.top,out:{ox:0,oy:-1}};default:return{x:n(e.x??(t.left+t.right)/2,t.left,t.right),y:t.bottom,out:{ox:0,oy:1}}}}const dr=3,Nx=w.memo(function({id:t,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:i,targetPosition:a,data:c,selected:l}){const{screenToFlowPosition:u}=cn(),d=ge(U=>U.transform[2]),[m,f]=w.useState(null),[p,x]=w.useState(null),_=w.useRef(!1),g=w.useRef(0),E=c==null?void 0:c.onRouteChange,C=!!E,b=m??(c==null?void 0:c.routeX),$=c==null?void 0:c.sourceCard,j=c==null?void 0:c.targetCard,v=(p==null?void 0:p.end)==="source"?p.a:c==null?void 0:c.sourceAnchor,R=(p==null?void 0:p.end)==="target"?p.a:c==null?void 0:c.targetAnchor,N=v&&$?wo(v,$):{x:n,y:r,out:null},T=R&&j?wo(R,j):{x:s,y:o,out:null},P=N.x,G=N.y,V=T.x,y=T.y,M=(v==null?void 0:v.side)==="right"?K.Right:(v==null?void 0:v.side)==="left"?K.Left:i,S=(R==null?void 0:R.side)==="right"?K.Right:(R==null?void 0:R.side)==="left"?K.Left:a,[O,z,k]=Rn({sourceX:P,sourceY:G,sourcePosition:M,targetX:V,targetY:y,targetPosition:S,borderRadius:10,...b!=null?{centerX:b}:{}}),I=c==null?void 0:c.sourceCard,L=c==null?void 0:c.targetCard,D=b!=null&&I&&L?_x({x:P,y:G},{y},b,M===K.Left?-1:1,S===K.Left?-1:1,I,L):null,q=D?D.path:O,F=c==null?void 0:c.relationship,J=(c==null?void 0:c.dimmed)??!1,ee=(F==null?void 0:F.cardinality)??"many_to_one",se=(F==null?void 0:F.optionality)==="optional",le=(F==null?void 0:F.identifying)??!1,ne=ee==="many_to_one"||ee==="many_to_many",ce=ee==="one_to_many"||ee==="many_to_many",we="rel-edge"+(l?" selected":"")+(J?" dimmed":""),ye=((c==null?void 0:c.memberCount)??0)>1,he=c==null?void 0:c.onHoverEdge,ue=b??z,me=k,Se=ue,ie=me,Z=D?D.sourceOut:N.out??{ox:M===K.Left?-1:1,oy:0},xe=D?D.targetOut:T.out??{ox:S===K.Left?-1:1,oy:0},je={x:P,y:G},Ae=D&&L?xe.oy!==0?{x:b,y:xe.oy<0?L.top:L.bottom}:{x:xe.ox>0?L.right:L.left,y}:{x:V,y},Le=w.useCallback(U=>E&&F&&E(F.id,U),[E,F]),Re=w.useCallback(U=>{var re,fe;if(!C||U.button!==0)return;U.stopPropagation(),(fe=(re=U.target).setPointerCapture)==null||fe.call(re,U.pointerId),_.current=!0,g.current=0;const W=u({x:U.clientX,y:U.clientY}).x;let te=0,pe=b??ue;const Q=Ce=>{const Te=u({x:Ce.clientX,y:Ce.clientY});g.current=Math.max(g.current,Math.abs(Te.x-W)),pe=xx(Te.x,{shift:Ce.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),te||(te=requestAnimationFrame(()=>{te=0,f(pe)}))},oe=()=>{window.removeEventListener("pointermove",Q),window.removeEventListener("pointerup",oe),te&&cancelAnimationFrame(te),_.current=!1,f(null),g.current>=dr&&Le(pe)};window.addEventListener("pointermove",Q),window.addEventListener("pointerup",oe)},[C,u,b,ue,c,n,s,Le]),Ie=w.useCallback(U=>{g.current>=dr&&(U.stopPropagation(),g.current=0)},[]),Ve=w.useCallback(U=>{C&&(U.stopPropagation(),Le(null))},[C,Le]),H=c==null?void 0:c.onAnchorChange,X=w.useCallback(U=>Y=>{var fe,Ce;const W=U==="source"?c==null?void 0:c.sourceCard:c==null?void 0:c.targetCard;if(!H||!F||!W||Y.button!==0)return;Y.stopPropagation(),(Ce=(fe=Y.target).setPointerCapture)==null||Ce.call(fe,Y.pointerId),g.current=0;const te=u({x:Y.clientX,y:Y.clientY});let pe=0,Q=null;const oe=Te=>{const $e=u({x:Te.clientX,y:Te.clientY});g.current=Math.max(g.current,Math.hypot($e.x-te.x,$e.y-te.y)),Q=Ex($e.x,$e.y,W),pe||(pe=requestAnimationFrame(()=>{pe=0,x({end:U,a:Q})}))},re=()=>{window.removeEventListener("pointermove",oe),window.removeEventListener("pointerup",re),pe&&cancelAnimationFrame(pe),x(null),g.current>=dr&&Q&&H(F.id,U,Q)};window.addEventListener("pointermove",oe),window.addEventListener("pointerup",re)},[H,F,c,u]),B=w.useCallback(U=>Y=>{!H||!F||(Y.stopPropagation(),H(F.id,U,null))},[H,F]);return h.jsxs("g",{className:we,onMouseEnter:he?()=>he(F.id):void 0,onMouseLeave:he?()=>he(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:q,fill:"none",strokeDasharray:le?void 0:"6 4"}),h.jsx("path",{d:q,fill:"none",strokeWidth:16/d,stroke:"transparent"}),h.jsx(vo,{x:je.x,y:je.y,out:Z,many:ne,optional:se}),h.jsx(vo,{x:Ae.x,y:Ae.y,out:xe,many:ce,optional:!1}),!!H&&((c==null?void 0:c.hovered)||l||p!=null)&&h.jsxs(h.Fragment,{children:[h.jsx(bo,{x:je.x,y:je.y,zoom:d,onPointerDown:X("source"),onDoubleClick:B("source")}),h.jsx(bo,{x:Ae.x,y:Ae.y,zoom:d,onPointerDown:X("target"),onDoubleClick:B("target")})]}),C&&((c==null?void 0:c.hovered)||l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:Re,onClickCapture:Ie,onDoubleClick:Ve,children:[h.jsx("rect",{x:ue-20/d,y:Math.min(G,y),width:40/d,height:Math.max(Math.abs(y-G),24/d),fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:ue-5.5/d,y:me-11/d,width:11/d,height:22/d,rx:5/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:ue,cy:me-4.5/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:ue,cy:me,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:ue,cy:me+4.5/d,r:1.1/d})]}),(l||ye)&&F&&h.jsxs("text",{className:"rel-label",x:Se,y:ie-8,children:[l?F.verb_phrase||F.name:"",ye?`${l?" ":""}(${c.memberCount})`:""]})]})});function bo({x:e,y:t,zoom:n,onPointerDown:r,onDoubleClick:s}){return h.jsxs("g",{className:"rel-endpoint",style:{cursor:"move"},onPointerDown:r,onDoubleClick:s,children:[h.jsx("circle",{cx:e,cy:t,r:10/n,fill:"transparent"}),h.jsx("circle",{className:"rel-endpoint-dot",cx:e,cy:t,r:3.5/n,strokeWidth:1.5/n})]})}function vo({x:e,y:t,out:n,many:r,optional:s}){const{ox:a,oy:c}=n,l=-c,u=a,d=p=>({x:e+a*p,y:t+c*p}),m=(p,x)=>({x:e+a*p+l*x,y:t+c*p+u*x}),f=[];if(r){const p=d(12),x=m(0,-7),_=d(0),g=m(0,7);f.push(h.jsx("path",{className:"rel-glyph",d:`M ${p.x} ${p.y} L ${x.x} ${x.y} M ${p.x} ${p.y} L ${_.x} ${_.y} M ${p.x} ${p.y} L ${g.x} ${g.y}`,fill:"none"},"foot"))}else{const p=m(9,-7),x=m(9,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:x.x,y2:x.y},"one"))}if(s){const p=d(18);f.push(h.jsx("circle",{className:"rel-glyph ring",cx:p.x,cy:p.y,r:4},"opt"))}else{const p=m(17,-7),x=m(17,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:x.x,y2:x.y},"mand"))}return h.jsx(h.Fragment,{children:f})}const Sx={entity:Vm},kx={relationship:Nx},_o=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],Eo="#8a7d6a";function No(e){return{side:e.side,y:Math.round(e.y),...e.x!=null?{x:Math.round(e.x)}:{}}}function jx(e,t,n){const s=Ke;let{x:o,y:i}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)ol.x&&il.y&&(i=l.y+l.h+16,a=!0)}return{x:o,y:i}}function Cx(e,t){const n=(o,i)=>{var a;return!!i&&!!((a=t.get(o))!=null&&a.attributes.some(c=>c.id===i))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Xr,targetHandle:n(e.to.entity,s)?s:Wr}}function sw({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:o="",showTypes:i=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:p,fitBounds:x,getNodes:_}=cn(),[g,E]=w.useState([]),[C,b]=w.useState([]),$=w.useRef(!1),j=w.useMemo(()=>{const H=u&&u.size>0?[...u].sort():null;return H?"sa:"+H.join("+"):"__all__"},[u]),v=w.useRef(null),[R,N]=w.useState(0),T=w.useRef(new Map),P=w.useRef(null);w.useEffect(()=>{if(!f){v.current=null;return}const H=T.current.get(j);if(H){v.current=H,$.current=!1,N(B=>B+1);return}let X=!1;return f.load(j).then(B=>{X||(T.current.set(j,B),v.current=B,$.current=!1,N(U=>U+1))}),()=>{X=!0}},[f,j]);const[G,V]=w.useState(null),[y,M]=w.useState(null),[S,O]=w.useState(!1),[z,k]=w.useState(null),[I,L]=w.useState(null),[D,q]=w.useState(null),[F,J]=w.useState(null),ee=w.useRef({}),se=!t.canEdit,le=w.useRef(null),ne=w.useCallback(()=>{f&&(le.current&&clearTimeout(le.current),le.current=setTimeout(()=>{const H={};for(const U of _())U.hidden||(H[U.id]={x:Math.round(U.position.x),y:Math.round(U.position.y)});const X={};for(const[U,Y]of Object.entries(ee.current)){const W={};Y.routeX!=null&&(W.routeX=Math.round(Y.routeX)),Y.sourceAnchor&&(W.sourceAnchor=No(Y.sourceAnchor)),Y.targetAnchor&&(W.targetAnchor=No(Y.targetAnchor)),(W.routeX!=null||W.sourceAnchor||W.targetAnchor)&&(X[U]=W)}const B={nodes:H,edges:X};T.current.set(j,B),v.current=B,f.save(j,B)},800))},[f,_,j]),ce=w.useCallback((H,X)=>{const B=ee.current[H]??{};X==null?delete B.routeX:B.routeX=X,ee.current[H]=B,b(U=>U.map(Y=>Y.id===H?{...Y,data:{...Y.data,routeX:X??void 0}}:Y)),ne()},[ne]),we=w.useCallback((H,X,B)=>{const U=ee.current[H]??{},Y=X==="source"?"sourceAnchor":"targetAnchor";B==null?delete U[Y]:U[Y]=B,ee.current[H]=U,b(W=>W.map(te=>te.id===H?{...te,data:{...te.data,[Y]:B??void 0}}:te)),ne()},[ne]),ye=w.useMemo(()=>{const H=new Map;return e.subject_areas.forEach((X,B)=>H.set(X.id,_o[B%_o.length])),H},[e]),he=w.useMemo(()=>{const H=new Map;return e.entities.forEach(X=>H.set(X.id,X)),H},[e]),ue=w.useMemo(()=>{const H=new Map,X=new Map;return e.subject_areas.forEach(B=>{(B.members??[]).forEach(U=>X.set(U,{id:B.id,name:B.name}))}),e.entities.forEach(B=>{var te,pe;const U=(te=B.conceptual)!=null&&te.id?X.get(B.conceptual.id):void 0,Y=(pe=B.conceptual)==null?void 0:pe.subject_area,W=U??(Y?{id:Y.id,name:Y.name??Y.id}:void 0);W&&H.set(B.id,W)}),H},[e]),me=w.useCallback(H=>{var B;if(!u||u.size===0)return!1;const X=(B=ue.get(H))==null?void 0:B.id;return!(X&&u.has(X))},[u,ue]),Se=w.useMemo(()=>{const H=new Map,X=(B,U)=>{if(!U.length)return;const Y=H.get(B)??new Set;U.forEach(W=>Y.add(W)),H.set(B,Y)};for(const B of e.relationships)X(B.from.entity,B.from.attributes),X(B.to.entity,B.to.attributes);return H},[e]);w.useEffect(()=>{var pe;const H=o.trim().toLowerCase(),X=new Set;if(H)for(const Q of e.entities)(Q.name.toLowerCase()+" "+(((pe=Q.conceptual)==null?void 0:pe.name.toLowerCase())??"")+" "+Q.attributes.map(re=>re.name.toLowerCase()).join(" ")).includes(H)&&X.add(Q.id);const B=new Set;if(r){B.add(r);for(const Q of e.relationships)Q.from.entity===r&&B.add(Q.to.entity),Q.to.entity===r&&B.add(Q.from.entity)}const U=e.entities.map(Q=>{const oe=H!==""&&!X.has(Q.id),re=r!==null&&!B.has(Q.id);return{id:Q.id,type:"entity",position:{x:0,y:0},hidden:me(Q.id),data:{entity:Q,color:(()=>{const fe=ue.get(Q.id);return fe?ye.get(fe.id)??Eo:Eo})(),dimmed:oe||re,highlighted:H!==""&&X.has(Q.id),showTypes:i,collapseDetail:a,expanded:(c==null?void 0:c.has(Q.id))??!1,onToggleExpand:l,endpointAttrs:Se.get(Q.id),highlightAttrs:void 0,onHoverAttr:q}}}),Y=e.relationships.filter(Q=>he.has(Q.from.entity)&&he.has(Q.to.entity)).map(Q=>{const{sourceHandle:oe,targetHandle:re}=Cx(Q,he),fe=r!==null&&Q.from.entity!==r&&Q.to.entity!==r;return{id:Q.id,source:Q.from.entity,target:Q.to.entity,sourceHandle:oe,targetHandle:re,type:"relationship",data:{relationship:Q,dimmed:fe,memberCount:Math.max(Q.from.attributes.length,Q.to.attributes.length),onHoverEdge:J}}}),W=v.current;if(ee.current={},W)for(const[Q,oe]of Object.entries(W.edges))ee.current[Q]={...oe.routeX!=null?{routeX:oe.routeX}:{},...oe.sourceAnchor?{sourceAnchor:oe.sourceAnchor}:{},...oe.targetAnchor?{targetAnchor:oe.targetAnchor}:{}};const te=Q=>{const oe=new Map;for(const re of Q)oe.set(re.id,{left:re.position.x,right:re.position.x+Ke,top:re.position.y,bottom:re.position.y+ht(re.data.entity)});b(Y.map(re=>{const fe=ee.current[re.id]??{};return{...re,data:{...re.data,routeX:fe.routeX,sourceAnchor:fe.sourceAnchor,targetAnchor:fe.targetAnchor,onRouteChange:f?ce:void 0,onAnchorChange:f?we:void 0,sourceCard:oe.get(re.source),targetCard:oe.get(re.target)}}}))};E(Q=>{const oe=new Map(Q.map(de=>[de.id,de.position])),re=U.every(de=>oe.has(de.id)),fe=((u==null?void 0:u.size)??0)>0;if($.current&&re&&Q.length>=U.length&&!fe){const de=U.map(Qe=>({...Qe,position:oe.get(Qe.id)??Qe.position}));return te(de),de}const Ce=fe?U.filter(de=>!de.hidden):U,Te=ur(Ce,Y,he,"auto",ue),$e=new Map(Te.map(de=>[de.id,de.position])),Ue=(W==null?void 0:W.nodes)??{},Dt=Object.keys(Ue).length>0,Be=[],Pt=U.map(de=>{const Qe=Ue[de.id];if(Qe){const zt={x:Qe.x,y:Qe.y};return Be.push({x:zt.x,y:zt.y,w:Ke,h:ht(de.data.entity)}),{...de,position:zt}}return $e.has(de.id)?{...de,position:$e.get(de.id)}:oe.has(de.id)&&$.current?{...de,position:oe.get(de.id)}:de});if(Dt)for(const de of Pt)Ue[de.id]||de.hidden||(de.position=jx(de.position,ht(de.data.entity),Be),Be.push({x:de.position.x,y:de.position.y,w:Ke,h:ht(de.data.entity)}));return $.current=!0,Dt||requestAnimationFrame(()=>p({padding:.15,duration:300})),te(Pt),Pt})},[e,o,r,i,a,c,l,ye,he,ue,me,u,Se,p,f,ce,we,R]);const ie=w.useMemo(()=>{const H=new Set,X=new Set,B=new Map,U=(Y,W)=>{if(!W.length)return;const te=B.get(Y)??new Set;W.forEach(pe=>te.add(pe)),B.set(Y,te)};if(D)for(const Y of e.relationships)(Y.from.attributes.includes(D)||Y.to.attributes.includes(D))&&(H.add(Y.id),X.add(Y.from.entity),X.add(Y.to.entity),U(Y.from.entity,Y.from.attributes),U(Y.to.entity,Y.to.attributes));if(F){const Y=e.relationships.find(W=>W.id===F);Y&&(U(Y.from.entity,Y.from.attributes),U(Y.to.entity,Y.to.attributes))}return{active:D!==null,relsForAttr:H,entsForAttr:X,hitAttrsByEntity:B}},[e,D,F]);w.useEffect(()=>{var U;const H=o.trim().toLowerCase(),X=new Set;if(H)for(const Y of e.entities)(Y.name.toLowerCase()+" "+(((U=Y.conceptual)==null?void 0:U.name.toLowerCase())??"")+" "+Y.attributes.map(te=>te.name.toLowerCase()).join(" ")).includes(H)&&X.add(Y.id);const B=new Set;if(r){B.add(r);for(const Y of e.relationships)Y.from.entity===r&&B.add(Y.to.entity),Y.to.entity===r&&B.add(Y.from.entity)}E(Y=>Y.map(W=>{const te=H!==""&&!X.has(W.id),pe=r!==null&&!B.has(W.id),Q=ie.active&&!ie.entsForAttr.has(W.id),oe=te||pe||Q,re=H!==""&&X.has(W.id)||ie.active&&ie.entsForAttr.has(W.id),fe=ie.hitAttrsByEntity.get(W.id);return W.data.dimmed===oe&&W.data.highlighted===re&&W.data.highlightAttrs===fe?W:{...W,data:{...W.data,dimmed:oe,highlighted:re,highlightAttrs:fe}}})),b(Y=>Y.map(W=>{var Te,$e,Ue;const te=(Te=W.data)==null?void 0:Te.relationship,pe=r!==null&&te!==void 0&&te.from.entity!==r&&te.to.entity!==r,Q=ie.active&&!ie.relsForAttr.has(W.id),oe=pe||Q,re=F===W.id,fe=r!==null&&te!==void 0&&(te.from.entity===r||te.to.entity===r),Ce=re||fe?1e3:0;return(($e=W.data)==null?void 0:$e.dimmed)===oe&&((Ue=W.data)==null?void 0:Ue.hovered)===re&&W.zIndex===Ce?W:{...W,zIndex:Ce,data:{...W.data,dimmed:oe,hovered:re}}}))},[ie,F,o,r,e]),w.useEffect(()=>{var U;const H=o.trim().toLowerCase();if(!H)return;const X=new Set;for(const Y of e.entities)(Y.name.toLowerCase()+" "+(((U=Y.conceptual)==null?void 0:U.name.toLowerCase())??"")+" "+Y.attributes.map(te=>te.name.toLowerCase()).join(" ")).includes(H)&&X.add(Y.id);if(!X.size)return;const B=requestAnimationFrame(()=>{const Y=_().filter(te=>X.has(te.id));if(!Y.length)return;const W=Tf(Y);x(W,{padding:.35,duration:400})});return()=>cancelAnimationFrame(B)},[o,e,_,x]);const Z=w.useCallback((H="auto",X="LR")=>{P.current=Object.fromEntries(_().map(B=>[B.id,{x:B.position.x,y:B.position.y}])),E(B=>ur(B,C,he,H,ue,X)),requestAnimationFrame(()=>p({padding:.15,duration:300})),ne()},[C,he,ue,p,_,ne]),xe=w.useCallback(()=>{const H=P.current;H&&(E(X=>X.map(B=>H[B.id]?{...B,position:H[B.id]}:B)),P.current=null,ne())},[ne]),je=w.useCallback(()=>{f==null||f.reset(j),T.current.delete(j),v.current=null,ee.current={},$.current=!1,b(H=>H.map(X=>({...X,data:{...X.data,routeX:void 0}}))),E(H=>{const X=ur(H,C,he,"auto",ue);return requestAnimationFrame(()=>p({padding:.15,duration:300})),X})},[f,j,C,he,ue,p]),Ae=w.useCallback(H=>{s(H),E(X=>(X.find(U=>U.id===H)&&requestAnimationFrame(()=>p({nodes:[{id:H}],padding:.4,duration:400})),X))},[p,s]);w.useImperativeHandle(m,()=>({relayout:Z,fitView:()=>p({padding:.15,duration:300}),focusEntity:Ae,newEntity:()=>O(!0),resetLayout:je,undoRelayout:xe}),[Z,p,Ae,je,xe]);const Le=w.useCallback(H=>{if(se||!H.source||!H.target||H.source===H.target)return;const X=H.sourceHandle&&H.sourceHandle!==Xr?H.sourceHandle:void 0,B=H.targetHandle&&H.targetHandle!==Wr?H.targetHandle:void 0;k({from:H.source,to:H.target,fromAttr:X,toAttr:B})},[se]),Re=w.useCallback(async(H,X)=>{try{return await n(H,X)}catch(B){throw d==null||d(B instanceof Error?B.message:String(B)),B}},[n,d]),Ie=r?he.get(r)??null:null,Ve=e.relationships.find(H=>H.id===I)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(qi,{nodes:g,edges:C,nodeTypes:Sx,edgeTypes:kx,onNodeClick:(H,X)=>s(X.id),onEdgeDoubleClick:(H,X)=>!se&&L(X.id),onPaneClick:()=>{s(null),L(null)},onNodeDragStop:(H,X)=>{E(B=>B.map(U=>U.id===X.id?{...U,position:X.position}:U)),ne()},onConnect:Le,nodesConnectable:!se,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(km,{variant:He.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(hm,{pannable:!0,zoomable:!0,nodeColor:H=>{var X;return((X=H.data)==null?void 0:X.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(bm,{showInteractive:!1})]}),Ie&&h.jsx(Gm,{entity:Ie,doc:e,caps:t,exec:Re,onClose:()=>s(null),onFocusEntity:Ae,onAlign:V,onEditMapping:M}),G&&h.jsx(lx,{entity:G,exec:Re,onClose:()=>V(null)}),y&&h.jsx(ux,{entity:y,doc:e,exec:Re,onClose:()=>M(null)}),S&&h.jsx(dx,{doc:e,exec:Re,onClose:()=>O(!1),onCreated:Ae}),z&&h.jsx(fx,{doc:e,fromId:z.from,toId:z.to,initialFromAttr:z.fromAttr,initialToAttr:z.toAttr,exec:Re,onClose:()=>k(null)}),Ve&&h.jsx(hx,{rel:Ve,doc:e,exec:Re,onClose:()=>L(null)})]})}function ow({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:o}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(Mx,{}),e==="layers"&&h.jsx(Ax,{refreshKey:r,onFocusEntity:o}),e==="changes"&&h.jsx(Rx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Ix,{readOnly:n})]})}function Mx(){const[e,t]=w.useState(""),[n,r]=w.useState([]),[s,o]=w.useState({loaded:0,vocabs:[]}),[i,a]=w.useState(null),[c,l]=w.useState([]),[u,d]=w.useState("");w.useEffect(()=>{na().then(f=>l(f.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const f=setTimeout(()=>{ta(e||"a",u||void 0).then(p=>{r(e?p.results:[]),o({loaded:p.loaded_terms,vocabs:p.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=w.useCallback(f=>{jm(f).then(a).catch(()=>{})},[]);return i?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:i.label}),h.jsx("code",{className:"term-iri",children:i.prefixed}),i.definition&&h.jsx("p",{className:"term-def",children:i.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:i.source})]}),i.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),i.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),i.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),i.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const $x=["industry","core","domain","specialised"];function Ax({refreshKey:e,onFocusEntity:t}){const[n,r]=w.useState(null),[s,o]=w.useState(null);if(w.useEffect(()=>{Cm().then(r).catch(()=>{}),Mm().then(o).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const i=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),$x.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(i.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Rx({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=w.useState(null),[o,i]=w.useState(""),[a,c]=w.useState(""),[l,u]=w.useState(!1),d=w.useCallback(()=>{Am().then(s).catch(()=>s(null)),Rm().then(m=>i([m.diff,...m.untracked].filter(Boolean).join(` + +`))).catch(()=>i(""))},[]);return w.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:o.split(` +`).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` +`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:l,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(u(!0),Tm().then(()=>{u(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:l||!a.trim(),onClick:()=>{u(!0),Im(a).then(()=>{u(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Ix({readOnly:e}){const[t,n]=w.useState([]),r=w.useCallback(()=>{Om().then(o=>n(o.decisions)).catch(()=>n([]))},[]);if(w.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(o=>h.jsxs("div",{className:"decision "+o.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[o.verdict]}),h.jsx("span",{className:"chip",children:o.confidence}),h.jsx("span",{className:"chip",children:o.signal})]}),h.jsx("p",{className:"decision-subject",children:o.subject}),!e&&o.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Gs(o.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Gs(o.signal_key,"rejected").then(r),children:"Reject"})]})]},o.signal_key))})}function iw({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:o,openImport:i=!1,prefillImport:a="",onPreview:c}){const[l,u]=w.useState(i&&t?"import":null),[d,m]=w.useState([]),[f,p]=w.useState("postgres"),x=w.useRef(null);w.useEffect(()=>{Lm().then(g=>m(g.formats)).catch(()=>m([]))},[]),w.useEffect(()=>{if(!l)return;const g=E=>{x.current&&!x.current.contains(E.target)&&u(null)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[l]);const _=d.find(g=>g.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:x,children:[h.jsxs("button",{className:s+(l==="export"?" on":""),onClick:()=>u(l==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(l==="import"?" on":""),onClick:()=>u(l==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),l==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(_==null?void 0:_.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:g=>p(g.target.value),children:_.dialects.map(g=>h.jsx("option",{value:g,children:g},g))})]}),d.map(g=>h.jsx("a",{className:"ie-item",href:Dm(g.id,g.id==="sql"?f:void 0),download:!0,onClick:()=>u(null),children:g.label},g.id))]}),l==="import"&&h.jsx(Tx,{exec:e,submitLabel:r,buttonClass:s,applyBatch:o,onClose:()=>u(null),onImported:g=>{u(null),n==null||n(g)},onPreview:c,prefillImport:a})]})}const So=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function Tx({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:o,onPreview:i,prefillImport:a}){var j;const[c,l]=w.useState(i?"erwin":"sql"),[u,d]=w.useState("postgres"),[m,f]=w.useState(a??""),[p,x]=w.useState(!1),[_,g]=w.useState(null),[E,C]=w.useState([]);w.useEffect(()=>{a&&f(a)},[a]);const b=v=>{v&&v.text().then(f).catch(()=>g("could not read that file"))},$=async()=>{x(!0),g(null),C([]);try{if(i&&c==="erwin"){const R=await zm(c,m);if(!R.changes.length){g(R.warnings[0]??"nothing to import from that document"),x(!1);return}s(),i(R),x(!1);return}const v=await Pm(c,m,c==="sql"?u:void 0);if(!v.changes.length){g(v.warnings[0]??"nothing to import from that document"),x(!1);return}if(r)await r(v.changes);else for(const R of v.changes)await e(R.op,R.payload);C(v.warnings),o(v.tables)}catch(v){g(v instanceof Error?v.message:String(v))}finally{x(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:So.map(v=>h.jsx("button",{className:"ie-tab"+(c===v.id?" active":""),onClick:()=>l(v.id),children:v.label},v.id))}),h.jsx("p",{className:"ie-hint",children:(j=So.find(v=>v.id===c))==null?void 0:j.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:u,onChange:v=>d(v.target.value),children:["postgres","snowflake","mysql","duckdb"].map(v=>h.jsx("option",{children:v},v))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:v=>f(v.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:v=>{var R;return b(((R=v.target.files)==null?void 0:R[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((v,R)=>h.jsx("p",{className:"ie-warn",children:v},R)),_&&h.jsx("p",{className:"ie-error",children:_}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:p||!m.trim(),onClick:$,children:p?"Importing…":t})]})]})}export{ea as A,km as B,bm as C,Vm as E,iw as I,Ax as L,sw as M,Mx as O,_o as P,Wi as R,ow as S,Px as a,qx as b,Xx as c,Zx as d,Qx as e,Dx as f,Am as g,ew as h,Jx as i,Wx as j,Fx as k,Vx as l,Bx as m,Yx as n,ta as o,Kx as p,Ux as q,Gx as r,$m as s,zx as t,Hx as u,ur as v,qi as w,Nx as x,hm as y}; diff --git a/packages/server/src/mdl_server/static/assets/styles-kEWh7gJm.js b/packages/server/src/mdl_server/static/assets/styles-kEWh7gJm.js deleted file mode 100644 index 9dac276..0000000 --- a/packages/server/src/mdl_server/static/assets/styles-kEWh7gJm.js +++ /dev/null @@ -1,23 +0,0 @@ -var ic=Object.defineProperty;var oc=(e,t,n)=>t in e?ic(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Ee=(e,t,n)=>oc(e,typeof t!="symbol"?t+"":t,n);import{r as w,g as bi,R as A,j as h}from"./client-DOmNpTln.js";function Ce(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?mc:hc;Ni.useSyncExternalStore=It.useSyncExternalStore!==void 0?It.useSyncExternalStore:pc;Ei.exports=Ni;var gc=Ei.exports;/** - * @license React - * use-sync-external-store-shim/with-selector.production.js - * - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var On=w,yc=gc;function xc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var wc=typeof Object.is=="function"?Object.is:xc,bc=yc.useSyncExternalStore,vc=On.useRef,_c=On.useEffect,Ec=On.useMemo,Nc=On.useDebugValue;_i.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var i=vc(null);if(i.current===null){var o={hasValue:!1,value:null};i.current=o}else o=i.current;i=Ec(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&o.hasValue){var p=o.value;if(s(p,f))return d=p}return d=f}if(p=d,wc(u,f))return p;var y=r(f);return s!==void 0&&s(p,y)?(u=f,p):(u=f,d=y)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=bc(e,i[0],i[1]);return _c(function(){o.hasValue=!0,o.value=a},[a]),Nc(a),a};vi.exports=_i;var Sc=vi.exports;const kc=bi(Sc),jc={},Qr=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(p=>p(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(jc?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Cc=e=>e?Qr(e):Qr,{useDebugValue:$c}=A,{useSyncExternalStoreWithSelector:Mc}=kc,Ac=e=>e;function Si(e,t=Ac,n){const r=Mc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return $c(r),r}const Jr=(e,t)=>{const n=Cc(e),r=(s,i=t)=>Si(n,s,i);return Object.assign(r,n),r},Rc=(e,t)=>e?Jr(e,t):Jr;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Ic={value:()=>{}};function Ln(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}xn.prototype=Ln.prototype={constructor:xn,on:function(e,t){var n=this._,r=Tc(e+"",n),s,i=-1,o=r.length;if(arguments.length<2){for(;++i0)for(var n=new Array(s),r=0,s,i;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),ts.hasOwnProperty(t)?{space:ts[t],local:e}:e}function Lc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===lr&&t.documentElement.namespaceURI===lr?t.createElement(e):t.createElementNS(n,e)}}function Dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ki(e){var t=Dn(e);return(t.local?Dc:Lc)(t)}function Pc(){}function kr(e){return e==null?Pc:function(){return this.querySelector(e)}}function zc(e){typeof e!="function"&&(e=kr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=C&&(C=E+1);!(M=b[C])&&++C=0;)(o=r[s])&&(i&&o.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(o,i),i=o);return this}function ul(e){e||(e=dl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),i=0;it?1:e>=t?0:NaN}function fl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function hl(){return Array.from(this)}function ml(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Sl:typeof t=="function"?jl:kl)(e,t,n??"")):Tt(this.node(),e)}function Tt(e,t){return e.style.getPropertyValue(t)||Ai(e).getComputedStyle(e,null).getPropertyValue(t)}function $l(e){return function(){delete this[e]}}function Ml(e,t){return function(){this[e]=t}}function Al(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Rl(e,t){return arguments.length>1?this.each((t==null?$l:typeof t=="function"?Al:Ml)(e,t)):this.node()[e]}function Ri(e){return e.trim().split(/^|\s+/)}function jr(e){return e.classList||new Ii(e)}function Ii(e){this._node=e,this._names=Ri(e.getAttribute("class")||"")}Ii.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Ti(e,t){for(var n=jr(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function ou(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,i;n()=>e;function ur(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:i,x:o,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}ur.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function gu(e){return!e.ctrlKey&&!e.button}function yu(){return this.parentNode}function xu(e,t){return t??{x:e.x,y:e.y}}function wu(){return navigator.maxTouchPoints||"ontouchstart"in this}function bu(){var e=gu,t=yu,n=xu,r=wu,s={},i=Ln("start","drag","end"),o=0,a,c,l,u,d=0;function m(v){v.on("mousedown.drag",f).filter(r).on("touchstart.drag",b).on("touchmove.drag",g,pu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(v,M){if(!(u||!e.call(this,v,M))){var j=C(this,t.call(this,v,M),v,M,"mouse");j&&(Oe(v.view).on("mousemove.drag",p,Ut).on("mouseup.drag",y,Ut),Pi(v.view),Wn(v),l=!1,a=v.clientX,c=v.clientY,j("start",v))}}function p(v){if(Mt(v),!l){var M=v.clientX-a,j=v.clientY-c;l=M*M+j*j>d}s.mouse("drag",v)}function y(v){Oe(v.view).on("mousemove.drag mouseup.drag",null),zi(v.view,l),Mt(v),s.mouse("end",v)}function b(v,M){if(e.call(this,v,M)){var j=v.changedTouches,_=t.call(this,v,M),I=j.length,N,R;for(N=0;N>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?ln(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?ln(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=_u.exec(e))?new Ae(t[1],t[2],t[3],1):(t=Eu.exec(e))?new Ae(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Nu.exec(e))?ln(t[1],t[2],t[3],t[4]):(t=Su.exec(e))?ln(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ku.exec(e))?cs(t[1],t[2]/100,t[3]/100,1):(t=ju.exec(e))?cs(t[1],t[2]/100,t[3]/100,t[4]):ns.hasOwnProperty(e)?is(ns[e]):e==="transparent"?new Ae(NaN,NaN,NaN,0):null}function is(e){return new Ae(e>>16&255,e>>8&255,e&255,1)}function ln(e,t,n,r){return r<=0&&(e=t=n=NaN),new Ae(e,t,n,r)}function Mu(e){return e instanceof nn||(e=Kt(e)),e?(e=e.rgb(),new Ae(e.r,e.g,e.b,e.opacity)):new Ae}function dr(e,t,n,r){return arguments.length===1?Mu(e):new Ae(e,t,n,r??1)}function Ae(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Cr(Ae,dr,Hi(nn,{brighter(e){return e=e==null?En:Math.pow(En,e),new Ae(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Xt:Math.pow(Xt,e),new Ae(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Ae(yt(this.r),yt(this.g),yt(this.b),Nn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:os,formatHex:os,formatHex8:Au,formatRgb:as,toString:as}));function os(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}`}function Au(){return`#${pt(this.r)}${pt(this.g)}${pt(this.b)}${pt((isNaN(this.opacity)?1:this.opacity)*255)}`}function as(){const e=Nn(this.opacity);return`${e===1?"rgb(":"rgba("}${yt(this.r)}, ${yt(this.g)}, ${yt(this.b)}${e===1?")":`, ${e})`}`}function Nn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pt(e){return e=yt(e),(e<16?"0":"")+e.toString(16)}function cs(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ve(e,t,n,r)}function Fi(e){if(e instanceof Ve)return new Ve(e.h,e.s,e.l,e.opacity);if(e instanceof nn||(e=Kt(e)),!e)return new Ve;if(e instanceof Ve)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),i=Math.max(t,n,r),o=NaN,a=i-s,c=(i+s)/2;return a?(t===i?o=(n-r)/a+(n0&&c<1?0:o,new Ve(o,a,c,e.opacity)}function Ru(e,t,n,r){return arguments.length===1?Fi(e):new Ve(e,t,n,r??1)}function Ve(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Cr(Ve,Ru,Hi(nn,{brighter(e){return e=e==null?En:Math.pow(En,e),new Ve(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Xt:Math.pow(Xt,e),new Ve(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Ae(Un(e>=240?e-240:e+120,s,r),Un(e,s,r),Un(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Ve(ls(this.h),un(this.s),un(this.l),Nn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Nn(this.opacity);return`${e===1?"hsl(":"hsla("}${ls(this.h)}, ${un(this.s)*100}%, ${un(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ls(e){return e=(e||0)%360,e<0?e+360:e}function un(e){return Math.max(0,Math.min(1,e||0))}function Un(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Vi=e=>()=>e;function Iu(e,t){return function(n){return e+n*t}}function Tu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Ou(e){return(e=+e)==1?Bi:function(t,n){return n-t?Tu(t,n,e):Vi(isNaN(t)?n:t)}}function Bi(e,t){var n=t-e;return n?Iu(e,n):Vi(isNaN(e)?t:e)}const us=function e(t){var n=Ou(t);function r(s,i){var o=n((s=dr(s)).r,(i=dr(i)).r),a=n(s.g,i.g),c=n(s.b,i.b),l=Bi(s.opacity,i.opacity);return function(u){return s.r=o(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function at(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var fr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Xn=new RegExp(fr.source,"g");function Lu(e){return function(){return e}}function Du(e){return function(t){return e(t)+""}}function Pu(e,t){var n=fr.lastIndex=Xn.lastIndex=0,r,s,i,o=-1,a=[],c=[];for(e=e+"",t=t+"";(r=fr.exec(e))&&(s=Xn.exec(t));)(i=s.index)>n&&(i=t.slice(n,i),a[o]?a[o]+=i:a[++o]=i),(r=r[0])===(s=s[0])?a[o]?a[o]+=s:a[++o]=s:(a[++o]=null,c.push({i:o,x:at(r,s)})),n=Xn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:at(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:at(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,p){if(l!==d||u!==m){var y=f.push(s(f)+"scale(",null,",",null,")");p.push({i:y-4,x:at(l,d)},{i:y-2,x:at(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,d,m),o(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var p=-1,y=m.length,b;++p=0&&e._call.call(void 0,t),e=e._next;--Ot}function hs(){wt=(kn=Zt.now())+Pn,Ot=Bt=0;try{Xu()}finally{Ot=0,Ku(),wt=0}}function qu(){var e=Zt.now(),t=e-kn;t>Wi&&(Pn-=t,kn=e)}function Ku(){for(var e,t=Sn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Sn=n);Gt=e,mr(r)}function mr(e){if(!Ot){Bt&&(Bt=clearTimeout(Bt));var t=e-wt;t>24?(e<1/0&&(Bt=setTimeout(hs,e-Zt.now()-Pn)),Pt&&(Pt=clearInterval(Pt))):(Pt||(kn=Zt.now(),Pt=setInterval(qu,Wi)),Ot=1,Ui(hs))}}function ms(e,t,n){var r=new jn;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var Zu=Ln("start","end","cancel","interrupt"),Qu=[],qi=0,ps=1,pr=2,wn=3,gs=4,gr=5,bn=6;function zn(e,t,n,r,s,i){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ju(e,n,{name:t,index:r,group:s,on:Zu,tween:Qu,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:qi})}function Mr(e,t){var n=Be(e,t);if(n.state>qi)throw new Error("too late; already scheduled");return n}function Xe(e,t){var n=Be(e,t);if(n.state>wn)throw new Error("too late; already running");return n}function Be(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Ju(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=Xi(i,0,n.time);function i(l){n.state=ps,n.timer.restart(o,n.delay,n.time),n.delay<=l&&o(l-n.delay)}function o(l){var u,d,m,f;if(n.state!==ps)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===wn)return ms(o);f.state===gs?(f.state=bn,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+upr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function $d(e,t,n){var r,s,i=Cd(t)?Mr:Xe;return function(){var o=i(this,e),a=o.on;a!==r&&(s=(r=a).copy()).on(t,n),o.on=s}}function Md(e,t){var n=this._id;return arguments.length<2?Be(this.node(),n).on.on(e):this.each($d(n,e,t))}function Ad(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rd(){return this.on("end.remove",Ad(this._id))}function Id(e){var t=this._name,n=this._id;typeof e!="function"&&(e=kr(e));for(var r=this._groups,s=r.length,i=new Array(s),o=0;o()=>e;function sf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function tt(e,t,n){this.k=e,this.x=t,this.y=n}tt.prototype={constructor:tt,scale:function(e){return e===1?this:new tt(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new tt(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var nt=new tt(1,0,0);tt.prototype;function qn(e){e.stopImmediatePropagation()}function zt(e){e.preventDefault(),e.stopImmediatePropagation()}function of(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function af(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function ys(){return this.__zoom||nt}function cf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function lf(){return navigator.maxTouchPoints||"ontouchstart"in this}function uf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),o>i?(i+o)/2:Math.min(0,i)||Math.max(0,o))}function Ji(){var e=of,t=af,n=uf,r=cf,s=lf,i=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Wu,l=Ln("start","zoom","end"),u,d,m,f=500,p=150,y=0,b=10;function g(x){x.property("__zoom",ys).on("wheel.zoom",I,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",R).filter(s).on("touchstart.zoom",P).on("touchmove.zoom",V).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(x,$,S,O){var D=x.selection?x.selection():x;D.property("__zoom",ys),x!==D?M(x,$,S,O):D.interrupt().each(function(){j(this,arguments).event(O).start().zoom(null,typeof $=="function"?$.apply(this,arguments):$).end()})},g.scaleBy=function(x,$,S,O){g.scaleTo(x,function(){var D=this.__zoom.k,k=typeof $=="function"?$.apply(this,arguments):$;return D*k},S,O)},g.scaleTo=function(x,$,S,O){g.transform(x,function(){var D=t.apply(this,arguments),k=this.__zoom,T=S==null?v(D):typeof S=="function"?S.apply(this,arguments):S,L=k.invert(T),z=typeof $=="function"?$.apply(this,arguments):$;return n(C(E(k,z),T,L),D,o)},S,O)},g.translateBy=function(x,$,S,O){g.transform(x,function(){return n(this.__zoom.translate(typeof $=="function"?$.apply(this,arguments):$,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),o)},null,O)},g.translateTo=function(x,$,S,O,D){g.transform(x,function(){var k=t.apply(this,arguments),T=this.__zoom,L=O==null?v(k):typeof O=="function"?O.apply(this,arguments):O;return n(nt.translate(L[0],L[1]).scale(T.k).translate(typeof $=="function"?-$.apply(this,arguments):-$,typeof S=="function"?-S.apply(this,arguments):-S),k,o)},O,D)};function E(x,$){return $=Math.max(i[0],Math.min(i[1],$)),$===x.k?x:new tt($,x.x,x.y)}function C(x,$,S){var O=$[0]-S[0]*x.k,D=$[1]-S[1]*x.k;return O===x.x&&D===x.y?x:new tt(x.k,O,D)}function v(x){return[(+x[0][0]+ +x[1][0])/2,(+x[0][1]+ +x[1][1])/2]}function M(x,$,S,O){x.on("start.zoom",function(){j(this,arguments).event(O).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(O).end()}).tween("zoom",function(){var D=this,k=arguments,T=j(D,k).event(O),L=t.apply(D,k),z=S==null?v(L):typeof S=="function"?S.apply(D,k):S,W=Math.max(L[1][0]-L[0][0],L[1][1]-L[0][1]),G=D.__zoom,X=typeof $=="function"?$.apply(D,k):$,Z=c(G.invert(z).concat(W/G.k),X.invert(z).concat(W/X.k));return function(ne){if(ne===1)ne=X;else{var ie=Z(ne),re=W/ie[2];ne=new tt(re,z[0]-ie[0]*re,z[1]-ie[1]*re)}T.zoom(null,ne)}})}function j(x,$,S){return!S&&x.__zooming||new _(x,$)}function _(x,$){this.that=x,this.args=$,this.active=0,this.sourceEvent=null,this.extent=t.apply(x,$),this.taps=0}_.prototype={event:function(x){return x&&(this.sourceEvent=x),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(x,$){return this.mouse&&x!=="mouse"&&(this.mouse[1]=$.invert(this.mouse[0])),this.touch0&&x!=="touch"&&(this.touch0[1]=$.invert(this.touch0[0])),this.touch1&&x!=="touch"&&(this.touch1[1]=$.invert(this.touch1[0])),this.that.__zoom=$,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(x){var $=Oe(this.that).datum();l.call(x,this.that,new sf(x,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:l}),$)}};function I(x,...$){if(!e.apply(this,arguments))return;var S=j(this,$).event(x),O=this.__zoom,D=Math.max(i[0],Math.min(i[1],O.k*Math.pow(2,r.apply(this,arguments)))),k=Fe(x);if(S.wheel)(S.mouse[0][0]!==k[0]||S.mouse[0][1]!==k[1])&&(S.mouse[1]=O.invert(S.mouse[0]=k)),clearTimeout(S.wheel);else{if(O.k===D)return;S.mouse=[k,O.invert(k)],vn(this),S.start()}zt(x),S.wheel=setTimeout(T,p),S.zoom("mouse",n(C(E(O,D),S.mouse[0],S.mouse[1]),S.extent,o));function T(){S.wheel=null,S.end()}}function N(x,...$){if(m||!e.apply(this,arguments))return;var S=x.currentTarget,O=j(this,$,!0).event(x),D=Oe(x.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",W,!0),k=Fe(x,S),T=x.clientX,L=x.clientY;Pi(x.view),qn(x),O.mouse=[k,this.__zoom.invert(k)],vn(this),O.start();function z(G){if(zt(G),!O.moved){var X=G.clientX-T,Z=G.clientY-L;O.moved=X*X+Z*Z>y}O.event(G).zoom("mouse",n(C(O.that.__zoom,O.mouse[0]=Fe(G,S),O.mouse[1]),O.extent,o))}function W(G){D.on("mousemove.zoom mouseup.zoom",null),zi(G.view,O.moved),zt(G),O.event(G).end()}}function R(x,...$){if(e.apply(this,arguments)){var S=this.__zoom,O=Fe(x.changedTouches?x.changedTouches[0]:x,this),D=S.invert(O),k=S.k*(x.shiftKey?.5:2),T=n(C(E(S,k),O,D),t.apply(this,$),o);zt(x),a>0?Oe(this).transition().duration(a).call(M,T,O,x):Oe(this).call(g.transform,T,O,x)}}function P(x,...$){if(e.apply(this,arguments)){var S=x.touches,O=S.length,D=j(this,$,x.changedTouches.length===O).event(x),k,T,L,z;for(qn(x),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},eo=st.error001();function he(e,t){const n=w.useContext(Hn);if(n===null)throw new Error(eo);return Si(n,e,t)}const Se=()=>{const e=w.useContext(Hn);if(e===null)throw new Error(eo);return w.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},ff=e=>e.userSelectionActive?"none":"all";function Rr({position:e,children:t,className:n,style:r,...s}){const i=he(ff),o=`${e}`.split("-");return A.createElement("div",{className:Ce(["react-flow__panel",n,...o]),style:{...r,pointerEvents:i},...s},t)}function hf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Rr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const mf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:i={},labelBgPadding:o=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=w.useRef(null),[m,f]=w.useState({x:0,y:0,width:0,height:0}),p=Ce(["react-flow__edge-textwrapper",l]);return w.useEffect(()=>{if(d.current){const y=d.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:p,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var pf=w.memo(mf);const Ir=e=>({width:e.offsetWidth,height:e.offsetHeight}),Lt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Tr=(e={x:0,y:0},t)=>({x:Lt(e.x,t[0][0],t[1][0]),y:Lt(e.y,t[0][1],t[1][1])}),xs=(e,t,n)=>en?-Lt(Math.abs(e-n),1,50)/50:0,to=(e,t)=>{const n=xs(e.x,35,t.width-35)*20,r=xs(e.y,35,t.height-35)*20;return[n,r]},no=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},ro=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Qt=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),so=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),ws=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),gf=(e,t)=>so(ro(Qt(e),Qt(t))),yr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},yf=e=>Le(e.width)&&Le(e.height)&&Le(e.x)&&Le(e.y),Le=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),io=["Enter"," ","Escape"],xf=(e,t)=>{},wf=e=>"nativeEvent"in e;function xr(e){var s,i;const t=wf(e)?e.nativeEvent:e,n=((i=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:i[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const oo=e=>"clientX"in e,ft=(e,t)=>{var i,o;const n=oo(e),r=n?e.clientX:(i=e.touches)==null?void 0:i[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Cn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},rn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Le(n)&&Le(r)?A.createElement(pf,{x:n,y:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);rn.displayName="BaseEdge";function Ht(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(i=>i.id===e);s&&n(r,{...s})}}function ao({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,i=n{const[b,g,E]=lo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i});return A.createElement(rn,{path:b,labelX:g,labelY:E,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:y})});Or.displayName="SimpleBezierEdge";const vs={[U.Left]:{x:-1,y:0},[U.Right]:{x:1,y:0},[U.Top]:{x:0,y:-1},[U.Bottom]:{x:0,y:1}},bf=({source:e,sourcePosition:t=U.Bottom,target:n})=>t===U.Left||t===U.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vf({source:e,sourcePosition:t=U.Bottom,target:n,targetPosition:r=U.Top,center:s,offset:i}){const o=vs[t],a=vs[r],c={x:e.x+o.x*i,y:e.y+o.y*i},l={x:n.x+a.x*i,y:n.y+a.y*i},u=bf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],p,y;const b={x:0,y:0},g={x:0,y:0},[E,C,v,M]=ao({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(o[d]*a[d]===-1){p=s.x??E,y=s.y??C;const _=[{x:p,y:c.y},{x:p,y:l.y}],I=[{x:c.x,y},{x:l.x,y}];o[d]===m?f=d==="x"?_:I:f=d==="x"?I:_}else{const _=[{x:c.x,y:l.y}],I=[{x:l.x,y:c.y}];if(d==="x"?f=o.x===m?I:_:f=o.y===m?_:I,t===r){const H=Math.abs(e[d]-n[d]);if(H<=i){const x=Math.min(i-1,i-H);o[d]===m?b[d]=(c[d]>e[d]?-1:1)*x:g[d]=(l[d]>n[d]?-1:1)*x}}if(t!==r){const H=d==="x"?"y":"x",x=o[d]===a[H],$=c[H]>l[H],S=c[H]=V?(p=(N.x+R.x)/2,y=f[0].y):(p=f[0].x,y=(N.y+R.y)/2)}return[[e,{x:c.x+b.x,y:c.y+b.y},...f,{x:l.x+g.x,y:l.y+g.y},n],p,y,v,M]}function _f(e,t,n,r){const s=Math.min(_s(e,t)/2,_s(t,n)/2,r),{x:i,y:o}=t;if(e.x===i&&i===n.x||e.y===o&&o===n.y)return`L${i} ${o}`;if(e.y===o){const l=e.x{let C="";return E>0&&E{const[g,E,C]=Mn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:y==null?void 0:y.borderRadius,offset:y==null?void 0:y.offset});return A.createElement(rn,{path:g,labelX:E,labelY:C,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:p,interactionWidth:b})});Fn.displayName="SmoothStepEdge";const Lr=w.memo(e=>{var t;return A.createElement(Fn,{...e,pathOptions:w.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Lr.displayName="StepEdge";function Ef({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,i,o,a]=ao({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,i,o,a]}const Dr=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[p,y,b]=Ef({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(rn,{path:p,labelX:y,labelY:b,label:s,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});Dr.displayName="StraightEdge";function hn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Es({pos:e,x1:t,y1:n,x2:r,y2:s,c:i}){switch(e){case U.Left:return[t-hn(t-r,i),n];case U.Right:return[t+hn(r-t,i),n];case U.Top:return[t,n-hn(n-s,i)];case U.Bottom:return[t,n+hn(s-n,i)]}}function uo({sourceX:e,sourceY:t,sourcePosition:n=U.Bottom,targetX:r,targetY:s,targetPosition:i=U.Top,curvature:o=.25}){const[a,c]=Es({pos:n,x1:e,y1:t,x2:r,y2:s,c:o}),[l,u]=Es({pos:i,x1:r,y1:s,x2:e,y2:t,c:o}),[d,m,f,p]=co({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,p]}const An=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=U.Bottom,targetPosition:i=U.Top,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,pathOptions:y,interactionWidth:b})=>{const[g,E,C]=uo({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:i,curvature:y==null?void 0:y.curvature});return A.createElement(rn,{path:g,labelX:E,labelY:C,label:o,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:b})});An.displayName="BezierEdge";const Pr=w.createContext(null),Nf=Pr.Provider;Pr.Consumer;const Sf=()=>w.useContext(Pr),kf=e=>"id"in e&&"source"in e&&"target"in e,jf=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,wr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Cf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),$f=(e,t)=>{if(!e.source||!e.target)return t;let n;return kf(e)?n={...e}:n={...e,id:jf(e)},Cf(n,t)?t:t.concat(n)},br=({x:e,y:t},[n,r,s],i,[o,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return i?{x:o*Math.round(c.x/o),y:a*Math.round(c.y/a)}:c},fo=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),xt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},sn=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:i,y:o}=xt(s,t).positionAbsolute;return ro(r,Qt({x:i,y:o,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return so(n)},Mf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),sn(e,t)),ho=(e,t,[n,r,s]=[0,0,1],i=!1,o=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:p=!1}=u;if(o&&!f||p)return!1;const{positionAbsolute:y}=xt(u,a),b={x:y.x,y:y.y,width:d||0,height:m||0},g=yr(c,b),E=typeof d>"u"||typeof m>"u"||d===null||m===null,C=i&&g>0,v=(d||0)*(m||0);(E||C||g>=v||u.dragging)&&l.push(u)}),l},mo=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},po=(e,t,n,r,s,i=.1)=>{const o=t/(e.width*(1+i)),a=n/(e.height*(1+i)),c=Math.min(o,a),l=Lt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},mt=(e,t=0)=>e.transition().duration(t);function Ns(e,t,n,r){return(t[n]||[]).reduce((s,i)=>{var o,a;return`${e.id}-${i.id}-${n}`!==r&&s.push({id:i.id||null,type:n,nodeId:e.id,x:(((o=e.positionAbsolute)==null?void 0:o.x)??0)+i.x+i.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+i.y+i.height/2}),s},[])}function Af(e,t,n,r,s,i){const{x:o,y:a}=ft(e),l=t.elementsFromPoint(o,a).find(p=>p.classList.contains("react-flow__handle"));if(l){const p=l.getAttribute("data-nodeid");if(p){const y=zr(void 0,l),b=l.getAttribute("data-handleid"),g=i({nodeId:p,id:b,type:y});if(g){const E=s.find(C=>C.nodeId===p&&C.type===y&&C.id===b);return{handle:{id:b,type:y,nodeId:p,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:g}}}}let u=[],d=1/0;if(s.forEach(p=>{const y=Math.sqrt((p.x-n.x)**2+(p.y-n.y)**2);if(y<=r){const b=i(p);y<=d&&(yp.isValid),f=u.some(({handle:p})=>p.type==="target");return u.find(({handle:p,validHandleResult:y})=>f?p.type==="target":m?y.isValid:!0)||u[0]}const Rf={source:null,target:null,sourceHandle:null,targetHandle:null},go=()=>({handleDomNode:null,isValid:!1,connection:Rf,endHandle:null});function yo(e,t,n,r,s,i,o){const a=s==="target",c=o.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...go(),handleDomNode:c};if(c){const u=zr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),p=c.classList.contains("connectableend"),y={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=y,f&&p&&(t===bt.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=i(y))}return l}function If({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,i)=>{if(i[we]){const{handleBounds:o}=i[we];let a=[],c=[];o&&(a=Ns(i,o,"source",`${t}-${n}-${r}`),c=Ns(i,o,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function zr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Kn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Tf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function xo({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:i,setState:o,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=no(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:p,onConnectStart:y,panBy:b,getNodes:g,cancelConnection:E}=i();let C=0,v;const{x:M,y:j}=ft(e),_=u==null?void 0:u.elementFromPoint(M,j),I=zr(c,_),N=m==null?void 0:m.getBoundingClientRect();if(!N||!I)return;let R,P=ft(e,N),V=!1,H=null,x=!1,$=null;const S=If({nodes:g(),nodeId:n,handleId:t,handleType:I}),O=()=>{if(!f)return;const[T,L]=to(P,N);b({x:T,y:L}),C=requestAnimationFrame(O)};o({connectionPosition:P,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:I,connectionStartHandle:{nodeId:n,handleId:t,type:I},connectionEndHandle:null}),y==null||y(e,{nodeId:n,handleId:t,handleType:I});function D(T){const{transform:L}=i();P=ft(T,N);const{handle:z,validHandleResult:W}=Af(T,u,br(P,L,!1,[1,1]),p,S,G=>yo(G,d,n,t,s?"target":"source",a,u));if(v=z,V||(O(),V=!0),$=W.handleDomNode,H=W.connection,x=W.isValid,o({connectionPosition:v&&x?fo({x:v.x,y:v.y},L):P,connectionStatus:Tf(!!v,x),connectionEndHandle:W.endHandle}),!v&&!x&&!$)return Kn(R);H.source!==H.target&&$&&(Kn(R),R=$,$.classList.add("connecting","react-flow__handle-connecting"),$.classList.toggle("valid",x),$.classList.toggle("react-flow__handle-valid",x))}function k(T){var L,z;(v||$)&&H&&x&&(r==null||r(H)),(z=(L=i()).onConnectEnd)==null||z.call(L,T),c&&(l==null||l(T)),Kn(R),E(),cancelAnimationFrame(C),V=!1,x=!1,H=null,$=null,u.removeEventListener("mousemove",D),u.removeEventListener("mouseup",k),u.removeEventListener("touchmove",D),u.removeEventListener("touchend",k)}u.addEventListener("mousemove",D),u.addEventListener("mouseup",k),u.addEventListener("touchmove",D),u.addEventListener("touchend",k)}const Ss=()=>!0,Of=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Lf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:i,connectionClickStartHandle:o}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n,clickConnecting:(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n}},wo=w.forwardRef(({type:e="source",position:t=U.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:i=!0,id:o,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var N,R;const p=o||null,y=e==="target",b=Se(),g=Sf(),{connectOnClick:E,noPanClassName:C}=he(Of,ke),{connecting:v,clickConnecting:M}=he(Lf(g,p,e),ke);g||(R=(N=b.getState()).onError)==null||R.call(N,"010",st.error010());const j=P=>{const{defaultEdgeOptions:V,onConnect:H,hasDefaultEdges:x}=b.getState(),$={...V,...P};if(x){const{edges:S,setEdges:O}=b.getState();O($f($,S))}H==null||H($),a==null||a($)},_=P=>{if(!g)return;const V=oo(P);s&&(V&&P.button===0||!V)&&xo({event:P,handleId:p,nodeId:g,onConnect:j,isTarget:y,getState:b.getState,setState:b.setState,isValidConnection:n||b.getState().isValidConnection||Ss}),V?u==null||u(P):d==null||d(P)},I=P=>{const{onClickConnectStart:V,onClickConnectEnd:H,connectionClickStartHandle:x,connectionMode:$,isValidConnection:S}=b.getState();if(!g||!x&&!s)return;if(!x){V==null||V(P,{nodeId:g,handleId:p,handleType:e}),b.setState({connectionClickStartHandle:{nodeId:g,type:e,handleId:p}});return}const O=no(P.target),D=n||S||Ss,{connection:k,isValid:T}=yo({nodeId:g,id:p,type:e},$,x.nodeId,x.handleId||null,x.type,D,O);T&&j(k),H==null||H(P),b.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":p,"data-nodeid":g,"data-handlepos":t,"data-id":`${g}-${p}-${e}`,className:Ce(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",C,l,{source:!y,target:y,connectable:r,connectablestart:s,connectableend:i,connecting:M,connectionindicator:r&&(s&&!v||i&&v)}]),onMouseDown:_,onTouchStart:_,onClick:E?I:void 0,ref:f,...m},c)});wo.displayName="Handle";var ut=w.memo(wo);const bo=({data:e,isConnectable:t,targetPosition:n=U.Top,sourcePosition:r=U.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ut,{type:"source",position:r,isConnectable:t}));bo.displayName="DefaultNode";var vr=w.memo(bo);const vo=({data:e,isConnectable:t,sourcePosition:n=U.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ut,{type:"source",position:n,isConnectable:t}));vo.displayName="InputNode";var _o=w.memo(vo);const Eo=({data:e,isConnectable:t,targetPosition:n=U.Top})=>A.createElement(A.Fragment,null,A.createElement(ut,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);Eo.displayName="OutputNode";var No=w.memo(Eo);const Hr=()=>null;Hr.displayName="GroupNode";const Df=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),mn=e=>e.id;function Pf(e,t){return ke(e.selectedNodes.map(mn),t.selectedNodes.map(mn))&&ke(e.selectedEdges.map(mn),t.selectedEdges.map(mn))}const So=w.memo(({onSelectionChange:e})=>{const t=Se(),{selectedNodes:n,selectedEdges:r}=he(Df,Pf);return w.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(i=>i(s))},[n,r,e]),null});So.displayName="SelectionListener";const zf=e=>!!e.onSelectionChange;function Hf({onSelectionChange:e}){const t=he(zf);return e||t?A.createElement(So,{onSelectionChange:e}):null}const Ff=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Nt(e,t){w.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function oe(e,t,n){w.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Vf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:i,onConnectEnd:o,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:p,minZoom:y,maxZoom:b,nodeExtent:g,onNodesChange:E,onEdgesChange:C,elementsSelectable:v,connectionMode:M,snapGrid:j,snapToGrid:_,translateExtent:I,connectOnClick:N,defaultEdgeOptions:R,fitView:P,fitViewOptions:V,onNodesDelete:H,onEdgesDelete:x,onNodeDrag:$,onNodeDragStart:S,onNodeDragStop:O,onSelectionDrag:D,onSelectionDragStart:k,onSelectionDragStop:T,noPanClassName:L,nodeOrigin:z,rfId:W,autoPanOnConnect:G,autoPanOnNodeDrag:X,onError:Z,connectionRadius:ne,isValidConnection:ie,nodeDragThreshold:re})=>{const{setNodes:ae,setEdges:ye,setDefaultNodesAndEdges:te,setMinZoom:me,setMaxZoom:ve,setTranslateExtent:de,setNodeExtent:pe,reset:le}=he(Ff,ke),q=Se();return w.useEffect(()=>{const _e=r==null?void 0:r.map(je=>({...je,...R}));return te(n,_e),()=>{le()}},[]),oe("defaultEdgeOptions",R,q.setState),oe("connectionMode",M,q.setState),oe("onConnect",s,q.setState),oe("onConnectStart",i,q.setState),oe("onConnectEnd",o,q.setState),oe("onClickConnectStart",a,q.setState),oe("onClickConnectEnd",c,q.setState),oe("nodesDraggable",l,q.setState),oe("nodesConnectable",u,q.setState),oe("nodesFocusable",d,q.setState),oe("edgesFocusable",m,q.setState),oe("edgesUpdatable",f,q.setState),oe("elementsSelectable",v,q.setState),oe("elevateNodesOnSelect",p,q.setState),oe("snapToGrid",_,q.setState),oe("snapGrid",j,q.setState),oe("onNodesChange",E,q.setState),oe("onEdgesChange",C,q.setState),oe("connectOnClick",N,q.setState),oe("fitViewOnInit",P,q.setState),oe("fitViewOnInitOptions",V,q.setState),oe("onNodesDelete",H,q.setState),oe("onEdgesDelete",x,q.setState),oe("onNodeDrag",$,q.setState),oe("onNodeDragStart",S,q.setState),oe("onNodeDragStop",O,q.setState),oe("onSelectionDrag",D,q.setState),oe("onSelectionDragStart",k,q.setState),oe("onSelectionDragStop",T,q.setState),oe("noPanClassName",L,q.setState),oe("nodeOrigin",z,q.setState),oe("rfId",W,q.setState),oe("autoPanOnConnect",G,q.setState),oe("autoPanOnNodeDrag",X,q.setState),oe("onError",Z,q.setState),oe("connectionRadius",ne,q.setState),oe("isValidConnection",ie,q.setState),oe("nodeDragThreshold",re,q.setState),Nt(e,ae),Nt(t,ye),Nt(y,me),Nt(b,ve),Nt(I,de),Nt(g,pe),null},ks={display:"none"},Bf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},ko="react-flow__node-desc",jo="react-flow__edge-desc",Gf="react-flow__aria-live",Yf=e=>e.ariaLiveMessage;function Wf({rfId:e}){const t=he(Yf);return A.createElement("div",{id:`${Gf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Bf},t)}function Uf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${ko}-${e}`,style:ks},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${jo}-${e}`,style:ks},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Wf,{rfId:e}))}var en=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=w.useState(!1),s=w.useRef(!1),i=w.useRef(new Set([])),[o,a]=w.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return w.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&xr(f))return!1;const y=Cs(f.code,a);i.current.add(f[y]),js(o,i.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&xr(f))return!1;const y=Cs(f.code,a);js(o,i.current,!0)?(r(!1),i.current.clear()):i.current.delete(f[y]),f.key==="Meta"&&i.current.clear(),s.current=!1},m=()=>{i.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function js(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Cs(e,t){return t.includes(e)?"code":"key"}function Co(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const i=t.get(s),o=xt(i,r);return Co(i,t,{x:(n.x??0)+o.x,y:(n.y??0)+o.y,z:(((a=i[we])==null?void 0:a.z)??0)>(n.z??0)?((c=i[we])==null?void 0:c.z)??0:n.z??0},r)}function $o(e,t,n){e.forEach(r=>{var i;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:o,y:a,z:c}=Co(r,e,{...r.position,z:((i=r[we])==null?void 0:i.z)??0},t);r.positionAbsolute={x:o,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function Zn(e,t,n,r){const s=new Map,i={},o=r?1e3:0;return e.forEach(a=>{var f;const c=(Le(a.zIndex)?a.zIndex:0)+(a.selected?o:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(i[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,we,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),$o(s,n,i),s}function Mo(e,t={}){const{getNodes:n,width:r,height:s,minZoom:i,maxZoom:o,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const p=n().filter(b=>{var E;const g=t.includeHiddenNodes?b.width&&b.height:!b.hidden;return(E=t.nodes)!=null&&E.length?g&&t.nodes.some(C=>C.id===b.id):g}),y=p.every(b=>b.width&&b.height);if(p.length>0&&y){const b=sn(p,d),{x:g,y:E,zoom:C}=po(b,r,s,t.minZoom??i,t.maxZoom??o,t.padding??.1),v=nt.translate(g,E).scale(C);return typeof t.duration=="number"&&t.duration>0?a.transform(mt(c,t.duration),v):a.transform(c,v),!0}}return!1}function Xf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function qf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function pn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:i,onNodesChange:o,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Xf(e,s)}),o==null||o(e)),t!=null&&t.length&&(l&&r({edges:qf(t,i)}),a==null||a(t))}const St=()=>{},Kf={zoomIn:St,zoomOut:St,zoomTo:St,getZoom:()=>1,setViewport:St,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:St,fitBounds:St,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},Zf=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),Qf=()=>{const e=Se(),{d3Zoom:t,d3Selection:n}=he(Zf,ke);return w.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(mt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,i)=>t.scaleTo(mt(n,i==null?void 0:i.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,i)=>{const[o,a,c]=e.getState().transform,l=nt.translate(s.x??o,s.y??a).scale(s.zoom??c);t.transform(mt(n,i==null?void 0:i.duration),l)},getViewport:()=>{const[s,i,o]=e.getState().transform;return{x:s,y:i,zoom:o}},fitView:s=>Mo(e.getState,s),setCenter:(s,i,o)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(o==null?void 0:o.zoom)<"u"?o.zoom:l,d=a/2-s*u,m=c/2-i*u,f=nt.translate(d,m).scale(u);t.transform(mt(n,o==null?void 0:o.duration),f)},fitBounds:(s,i)=>{const{width:o,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=po(s,o,a,c,l,(i==null?void 0:i.padding)??.1),f=nt.translate(u,d).scale(m);t.transform(mt(n,i==null?void 0:i.duration),f)},project:s=>{const{transform:i,snapToGrid:o,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),br(s,i,o,a)},screenToFlowPosition:s=>{const{transform:i,snapToGrid:o,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return br(d,i,o,a)},flowToScreenPosition:s=>{const{transform:i,domNode:o}=e.getState();if(!o)return s;const{x:a,y:c}=o.getBoundingClientRect(),l=fo(s,i);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:Kf,[t,n])};function on(){const e=Qf(),t=Se(),n=w.useCallback(()=>t.getState().getNodes().map(y=>({...y})),[]),r=w.useCallback(y=>t.getState().nodeInternals.get(y),[]),s=w.useCallback(()=>{const{edges:y=[]}=t.getState();return y.map(b=>({...b}))},[]),i=w.useCallback(y=>{const{edges:b=[]}=t.getState();return b.find(g=>g.id===y)},[]),o=w.useCallback(y=>{const{getNodes:b,setNodes:g,hasDefaultNodes:E,onNodesChange:C}=t.getState(),v=b(),M=typeof y=="function"?y(v):y;if(E)g(M);else if(C){const j=M.length===0?v.map(_=>({type:"remove",id:_.id})):M.map(_=>({item:_,type:"reset"}));C(j)}},[]),a=w.useCallback(y=>{const{edges:b=[],setEdges:g,hasDefaultEdges:E,onEdgesChange:C}=t.getState(),v=typeof y=="function"?y(b):y;if(E)g(v);else if(C){const M=v.length===0?b.map(j=>({type:"remove",id:j.id})):v.map(j=>({item:j,type:"reset"}));C(M)}},[]),c=w.useCallback(y=>{const b=Array.isArray(y)?y:[y],{getNodes:g,setNodes:E,hasDefaultNodes:C,onNodesChange:v}=t.getState();if(C){const j=[...g(),...b];E(j)}else if(v){const M=b.map(j=>({item:j,type:"add"}));v(M)}},[]),l=w.useCallback(y=>{const b=Array.isArray(y)?y:[y],{edges:g=[],setEdges:E,hasDefaultEdges:C,onEdgesChange:v}=t.getState();if(C)E([...g,...b]);else if(v){const M=b.map(j=>({item:j,type:"add"}));v(M)}},[]),u=w.useCallback(()=>{const{getNodes:y,edges:b=[],transform:g}=t.getState(),[E,C,v]=g;return{nodes:y().map(M=>({...M})),edges:b.map(M=>({...M})),viewport:{x:E,y:C,zoom:v}}},[]),d=w.useCallback(({nodes:y,edges:b})=>{const{nodeInternals:g,getNodes:E,edges:C,hasDefaultNodes:v,hasDefaultEdges:M,onNodesDelete:j,onEdgesDelete:_,onNodesChange:I,onEdgesChange:N}=t.getState(),R=(y||[]).map($=>$.id),P=(b||[]).map($=>$.id),V=E().reduce(($,S)=>{const O=S.parentNode||S.parentId,D=!R.includes(S.id)&&O&&$.find(T=>T.id===O);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(R.includes(S.id)||D)&&$.push(S),$},[]),H=C.filter($=>typeof $.deletable=="boolean"?$.deletable:!0),x=H.filter($=>P.includes($.id));if(V||x){const $=mo(V,H),S=[...x,...$],O=S.reduce((D,k)=>(D.includes(k.id)||D.push(k.id),D),[]);if((M||v)&&(M&&t.setState({edges:C.filter(D=>!O.includes(D.id))}),v&&(V.forEach(D=>{g.delete(D.id)}),t.setState({nodeInternals:new Map(g)}))),O.length>0&&(_==null||_(S),N&&N(O.map(D=>({id:D,type:"remove"})))),V.length>0&&(j==null||j(V),I)){const D=V.map(k=>({id:k.id,type:"remove"}));I(D)}}},[]),m=w.useCallback(y=>{const b=yf(y),g=b?null:t.getState().nodeInternals.get(y.id);return!b&&!g?[null,null,b]:[b?y:ws(g),g,b]},[]),f=w.useCallback((y,b=!0,g)=>{const[E,C,v]=m(y);return E?(g||t.getState().getNodes()).filter(M=>{if(!v&&(M.id===C.id||!M.positionAbsolute))return!1;const j=ws(M),_=yr(j,E);return b&&_>0||_>=E.width*E.height}):[]},[]),p=w.useCallback((y,b,g=!0)=>{const[E]=m(y);if(!E)return!1;const C=yr(E,b);return g&&C>0||C>=E.width*E.height},[]);return w.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:i,setNodes:o,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:p}),[e,n,r,s,i,o,a,c,l,u,d,f,p])}const Jf={actInsideInputWithModifier:!1};var eh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Se(),{deleteElements:r}=on(),s=en(e,Jf),i=en(t);w.useEffect(()=>{if(s){const{edges:o,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=o.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),w.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])};function th(e){const t=Se();w.useEffect(()=>{let n;const r=()=>{var i,o;if(!e.current)return;const s=Ir(e.current);(s.height===0||s.width===0)&&((o=(i=t.getState()).onError)==null||o.call(i,"004",st.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Fr={position:"absolute",width:"100%",height:"100%",top:0,left:0},nh=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,gn=e=>({x:e.x,y:e.y,zoom:e.k}),kt=(e,t)=>e.target.closest(`.${t}`),$s=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Ms=e=>{const t=e.ctrlKey&&Cn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),sh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:i=!0,panOnScroll:o=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=gt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:p,maxZoom:y,zoomActivationKeyCode:b,preventScrolling:g=!0,children:E,noWheelClassName:C,noPanClassName:v})=>{const M=w.useRef(),j=Se(),_=w.useRef(!1),I=w.useRef(!1),N=w.useRef(null),R=w.useRef({x:0,y:0,zoom:0}),{d3Zoom:P,d3Selection:V,d3ZoomHandler:H,userSelectionActive:x}=he(rh,ke),$=en(b),S=w.useRef(0),O=w.useRef(!1),D=w.useRef();return th(N),w.useEffect(()=>{if(N.current){const k=N.current.getBoundingClientRect(),T=Ji().scaleExtent([p,y]).translateExtent(f),L=Oe(N.current).call(T),z=nt.translate(m.x,m.y).scale(Lt(m.zoom,p,y)),W=[[0,0],[k.width,k.height]],G=T.constrain()(z,W,f);T.transform(L,G),T.wheelDelta(Ms),j.setState({d3Zoom:T,d3Selection:L,d3ZoomHandler:L.on("wheel.zoom"),transform:[G.x,G.y,G.k],domNode:N.current.closest(".react-flow")})}},[]),w.useEffect(()=>{V&&P&&(o&&!$&&!x?V.on("wheel.zoom",k=>{if(kt(k,C))return!1;k.preventDefault(),k.stopImmediatePropagation();const T=V.property("__zoom").k||1;if(k.ctrlKey&&i){const ie=Fe(k),re=Ms(k),ae=T*Math.pow(2,re);P.scaleTo(V,ae,ie,k);return}const L=k.deltaMode===1?20:1;let z=c===gt.Vertical?0:k.deltaX*L,W=c===gt.Horizontal?0:k.deltaY*L;!Cn()&&k.shiftKey&&c!==gt.Vertical&&(z=k.deltaY*L,W=0),P.translateBy(V,-(z/T)*a,-(W/T)*a,{internal:!0});const G=gn(V.property("__zoom")),{onViewportChangeStart:X,onViewportChange:Z,onViewportChangeEnd:ne}=j.getState();clearTimeout(D.current),O.current||(O.current=!0,t==null||t(k,G),X==null||X(G)),O.current&&(e==null||e(k,G),Z==null||Z(G),D.current=setTimeout(()=>{n==null||n(k,G),ne==null||ne(G),O.current=!1},150))},{passive:!1}):typeof H<"u"&&V.on("wheel.zoom",function(k,T){if(!g&&k.type==="wheel"&&!k.ctrlKey||kt(k,C))return null;k.preventDefault(),H.call(this,k,T)},{passive:!1}))},[x,o,c,V,P,H,$,i,g,C,t,e,n]),w.useEffect(()=>{P&&P.on("start",k=>{var z,W;if(!k.sourceEvent||k.sourceEvent.internal)return null;S.current=(z=k.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=j.getState(),L=gn(k.transform);_.current=!0,R.current=L,((W=k.sourceEvent)==null?void 0:W.type)==="mousedown"&&j.setState({paneDragging:!0}),T==null||T(L),t==null||t(k.sourceEvent,L)})},[P,t]),w.useEffect(()=>{P&&(x&&!_.current?P.on("zoom",null):x||P.on("zoom",k=>{var L;const{onViewportChange:T}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),I.current=!!(r&&$s(d,S.current??0)),(e||T)&&!((L=k.sourceEvent)!=null&&L.internal)){const z=gn(k.transform);T==null||T(z),e==null||e(k.sourceEvent,z)}}))},[x,P,e,d,r]),w.useEffect(()=>{P&&P.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=j.getState();if(_.current=!1,j.setState({paneDragging:!1}),r&&$s(d,S.current??0)&&!I.current&&r(k.sourceEvent),I.current=!1,(n||T)&&nh(R.current,k.transform)){const L=gn(k.transform);R.current=L,clearTimeout(M.current),M.current=setTimeout(()=>{T==null||T(L),n==null||n(k.sourceEvent,L)},o?150:0)}})},[P,o,d,n,r]),w.useEffect(()=>{P&&P.filter(k=>{const T=$||s,L=i&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(kt(k,"react-flow__node")||kt(k,"react-flow__edge")))return!0;if(!d&&!T&&!o&&!l&&!i||x||!l&&k.type==="dblclick"||kt(k,C)&&k.type==="wheel"||kt(k,v)&&(k.type!=="wheel"||o&&k.type==="wheel"&&!$)||!i&&k.ctrlKey&&k.type==="wheel"||!T&&!o&&!L&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&z})},[x,P,s,i,o,l,d,u,$]),A.createElement("div",{className:"react-flow__renderer",ref:N,style:Fr},E)},ih=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function oh(){const{userSelectionActive:e,userSelectionRect:t}=he(ih,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function As(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,i=t.position.y+t.height-r.height;if(s>0||i>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),i>0&&(r.style.height+=i),t.position.x<0){const o=Math.abs(t.position.x);r.position.x=r.position.x-o,r.style.width+=o,t.position.x=0}if(t.position.y<0){const o=Math.abs(t.position.y);r.position.y=r.position.y-o,r.style.height+=o,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function ah(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const i=e.filter(a=>a.id===s.id);if(i.length===0)return r.push(s),r;const o={...s};for(const a of i)if(a)switch(a.type){case"select":{o.selected=a.selected;break}case"position":{typeof a.position<"u"&&(o.position=a.position),typeof a.positionAbsolute<"u"&&(o.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(o.dragging=a.dragging),o.expandParent&&As(r,o);break}case"dimensions":{typeof a.dimensions<"u"&&(o.width=a.dimensions.width,o.height=a.dimensions.height),typeof a.updateStyle<"u"&&(o.style={...o.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(o.resizing=a.resizing),o.expandParent&&As(r,o);break}case"remove":return r}return r.push(o),r},n)}function ch(e,t){return ah(e,t)}const ct=(e,t)=>({id:e,type:"select",selected:t});function Ct(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ct(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ct(r.id,!1))),n},[])}const Qn=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},lh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Ao=w.memo(({isSelecting:e,selectionMode:t=Jt.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:i,onPaneContextMenu:o,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=w.useRef(null),f=Se(),p=w.useRef(0),y=w.useRef(0),b=w.useRef(),{userSelectionActive:g,elementsSelectable:E,dragging:C}=he(lh,ke),v=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),p.current=0,y.current=0},M=H=>{i==null||i(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}o==null||o(H)},_=a?H=>a(H):void 0,I=H=>{const{resetSelectedElements:x,domNode:$}=f.getState();if(b.current=$==null?void 0:$.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!b.current)return;const{x:S,y:O}=ft(H,b.current);x(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:O,x:S,y:O}}),r==null||r(H)},N=H=>{const{userSelectionRect:x,nodeInternals:$,edges:S,transform:O,onNodesChange:D,onEdgesChange:k,nodeOrigin:T,getNodes:L}=f.getState();if(!e||!b.current||!x)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=ft(H,b.current),W=x.startX??0,G=x.startY??0,X={...x,x:z.xae.id),re=ne.map(ae=>ae.id);if(p.current!==re.length){p.current=re.length;const ae=Ct(Z,re);ae.length&&(D==null||D(ae))}if(y.current!==ie.length){y.current=ie.length;const ae=Ct(S,ie);ae.length&&(k==null||k(ae))}f.setState({userSelectionRect:X})},R=H=>{if(H.button!==0)return;const{userSelectionRect:x}=f.getState();!g&&x&&H.target===m.current&&(M==null||M(H)),f.setState({nodesSelectionActive:p.current>0}),v(),s==null||s(H)},P=H=>{g&&(f.setState({nodesSelectionActive:p.current>0}),s==null||s(H)),v()},V=E&&(e||g);return A.createElement("div",{className:Ce(["react-flow__pane",{dragging:C,selection:e}]),onClick:V?void 0:Qn(M,m),onContextMenu:Qn(j,m),onWheel:Qn(_,m),onMouseEnter:V?void 0:c,onMouseDown:V?I:void 0,onMouseMove:V?N:l,onMouseUp:V?R:void 0,onMouseLeave:V?P:u,ref:m,style:Fr},d,A.createElement(oh,null))});Ao.displayName="Pane";function Ro(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Ro(r,t):!1}function Rs(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function uh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Ro(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var i,o;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((i=s.positionAbsolute)==null?void 0:i.x)??0),y:n.y-(((o=s.positionAbsolute)==null?void 0:o.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function dh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function Io(e,t,n,r,s=[0,0],i){const o=dh(e,e.extent||r);let a=o;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=d&&Le(m)&&Le(f)&&Le(d.width)&&Le(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else i==null||i("005",st.error005()),a=o;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=xt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=xt(d,s).positionAbsolute}const u=a&&a!=="parent"?Tr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function Jn({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Is=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const i=Array.from(s),o=t.getBoundingClientRect(),a={x:o.width*r[0],y:o.height*r[1]};return i.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-o.left-a.x)/n,y:(l.top-o.top-a.y)/n,...Ir(c)}})};function Ft(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function _r({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:i,multiSelectionActive:o,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",st.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function fh(){const e=Se();return w.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:i}=e.getState(),o=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(o-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:i?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:i?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function er(e){return(t,n,r)=>e==null?void 0:e(t,r)}function To({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:i,selectNodesOnDrag:o}){const a=Se(),[c,l]=w.useState(!1),u=w.useRef([]),d=w.useRef({x:null,y:null}),m=w.useRef(0),f=w.useRef(null),p=w.useRef({x:0,y:0}),y=w.useRef(null),b=w.useRef(!1),g=w.useRef(!1),E=w.useRef(!1),C=fh();return w.useEffect(()=>{if(e!=null&&e.current){const v=Oe(e.current),M=({x:I,y:N})=>{const{nodeInternals:R,onNodeDrag:P,onSelectionDrag:V,updateNodePositions:H,nodeExtent:x,snapGrid:$,snapToGrid:S,nodeOrigin:O,onError:D}=a.getState();d.current={x:I,y:N};let k=!1,T={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&x){const z=sn(u.current,O);T=Qt(z)}if(u.current=u.current.map(z=>{const W={x:I-z.distance.x,y:N-z.distance.y};S&&(W.x=$[0]*Math.round(W.x/$[0]),W.y=$[1]*Math.round(W.y/$[1]));const G=[[x[0][0],x[0][1]],[x[1][0],x[1][1]]];u.current.length>1&&x&&!z.extent&&(G[0][0]=z.positionAbsolute.x-T.x+x[0][0],G[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+x[1][0],G[0][1]=z.positionAbsolute.y-T.y+x[0][1],G[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+x[1][1]);const X=Io(z,W,R,G,O,D);return k=k||z.position.x!==X.position.x||z.position.y!==X.position.y,z.position=X.position,z.positionAbsolute=X.positionAbsolute,z}),!k)return;H(u.current,!0,!0),l(!0);const L=s?P:er(V);if(L&&y.current){const[z,W]=Jn({nodeId:s,dragItems:u.current,nodeInternals:R});L(y.current,z,W)}},j=()=>{if(!f.current)return;const[I,N]=to(p.current,f.current);if(I!==0||N!==0){const{transform:R,panBy:P}=a.getState();d.current.x=(d.current.x??0)-I/R[2],d.current.y=(d.current.y??0)-N/R[2],P({x:I,y:N})&&M(d.current)}m.current=requestAnimationFrame(j)},_=I=>{var O;const{nodeInternals:N,multiSelectionActive:R,nodesDraggable:P,unselectNodesAndEdges:V,onNodeDragStart:H,onSelectionDragStart:x}=a.getState();g.current=!0;const $=s?H:er(x);(!o||!i)&&!R&&s&&((O=N.get(s))!=null&&O.selected||V()),s&&i&&o&&_r({id:s,store:a,nodeRef:e});const S=C(I);if(d.current=S,u.current=uh(N,P,S,s),$&&u.current){const[D,k]=Jn({nodeId:s,dragItems:u.current,nodeInternals:N});$(I.sourceEvent,D,k)}};if(t)v.on(".drag",null);else{const I=bu().on("start",N=>{const{domNode:R,nodeDragThreshold:P}=a.getState();P===0&&_(N),E.current=!1;const V=C(N);d.current=V,f.current=(R==null?void 0:R.getBoundingClientRect())||null,p.current=ft(N.sourceEvent,f.current)}).on("drag",N=>{var H,x;const R=C(N),{autoPanOnNodeDrag:P,nodeDragThreshold:V}=a.getState();if(N.sourceEvent.type==="touchmove"&&N.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!b.current&&g.current&&P&&(b.current=!0,j()),!g.current){const $=R.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=R.ySnapped-(((x=d==null?void 0:d.current)==null?void 0:x.y)??0);Math.sqrt($*$+S*S)>V&&_(N)}(d.current.x!==R.xSnapped||d.current.y!==R.ySnapped)&&u.current&&g.current&&(y.current=N.sourceEvent,p.current=ft(N.sourceEvent,f.current),M(R))}}).on("end",N=>{if(!(!g.current||E.current)&&(l(!1),b.current=!1,g.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:R,nodeInternals:P,onNodeDragStop:V,onSelectionDragStop:H}=a.getState(),x=s?V:er(H);if(R(u.current,!1,!1),x){const[$,S]=Jn({nodeId:s,dragItems:u.current,nodeInternals:P});x(N.sourceEvent,$,S)}}}).filter(N=>{const R=N.target;return!N.button&&(!n||!Rs(R,`.${n}`,e))&&(!r||Rs(R,r,e))});return v.call(I),()=>{v.on(".drag",null)}}}},[e,t,n,r,i,a,s,o,C]),c}function Oo(){const e=Se();return w.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:i,getNodes:o,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=o().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,p=n.isShiftPressed?4:1,y=n.x*m*p,b=n.y*f*p,g=d.map(E=>{if(E.positionAbsolute){const C={x:E.positionAbsolute.x+y,y:E.positionAbsolute.y+b};a&&(C.x=c[0]*Math.round(C.x/c[0]),C.y=c[1]*Math.round(C.y/c[1]));const{positionAbsolute:v,position:M}=Io(E,C,r,s,void 0,l);E.position=M,E.positionAbsolute=v}return E});i(g,!0,!1)},[])}const Rt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Vt=e=>{const t=({id:n,type:r,data:s,xPos:i,yPos:o,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:p,onDoubleClick:y,style:b,className:g,isDraggable:E,isSelectable:C,isConnectable:v,isFocusable:M,selectNodesOnDrag:j,sourcePosition:_,targetPosition:I,hidden:N,resizeObserver:R,dragHandle:P,zIndex:V,isParent:H,noDragClassName:x,noPanClassName:$,initialized:S,disableKeyboardA11y:O,ariaLabel:D,rfId:k,hasHandleBounds:T})=>{const L=Se(),z=w.useRef(null),W=w.useRef(null),G=w.useRef(_),X=w.useRef(I),Z=w.useRef(r),ne=C||E||u||d||m||f,ie=Oo(),re=Ft(n,L.getState,d),ae=Ft(n,L.getState,m),ye=Ft(n,L.getState,f),te=Ft(n,L.getState,p),me=Ft(n,L.getState,y),ve=le=>{const{nodeDragThreshold:q}=L.getState();if(C&&(!j||!E||q>0)&&_r({id:n,store:L,nodeRef:z}),u){const _e=L.getState().nodeInternals.get(n);_e&&u(le,{..._e})}},de=le=>{if(!xr(le)&&!O)if(io.includes(le.key)&&C){const q=le.key==="Escape";_r({id:n,store:L,unselect:q,nodeRef:z})}else E&&l&&Object.prototype.hasOwnProperty.call(Rt,le.key)&&(L.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~i}, y: ${~~o}`}),ie({x:Rt[le.key].x,y:Rt[le.key].y,isShiftPressed:le.shiftKey}))};w.useEffect(()=>()=>{W.current&&(R==null||R.unobserve(W.current),W.current=null)},[]),w.useEffect(()=>{if(z.current&&!N){const le=z.current;(!S||!T||W.current!==le)&&(W.current&&(R==null||R.unobserve(W.current)),R==null||R.observe(le),W.current=le)}},[N,S,T]),w.useEffect(()=>{const le=Z.current!==r,q=G.current!==_,_e=X.current!==I;z.current&&(le||q||_e)&&(le&&(Z.current=r),q&&(G.current=_),_e&&(X.current=I),L.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,I]);const pe=To({nodeRef:z,disabled:N||!E,noDragClassName:x,handleSelector:P,nodeId:n,isSelectable:C,selectNodesOnDrag:j});return N?null:A.createElement("div",{className:Ce(["react-flow__node",`react-flow__node-${r}`,{[$]:E},g,{selected:l,selectable:C,parent:H,dragging:pe}]),ref:z,style:{zIndex:V,transform:`translate(${a}px,${c}px)`,pointerEvents:ne?"all":"none",visibility:S?"visible":"hidden",...b},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:re,onMouseMove:ae,onMouseLeave:ye,onContextMenu:te,onClick:ve,onDoubleClick:me,onKeyDown:M?de:void 0,tabIndex:M?0:void 0,role:M?"button":void 0,"aria-describedby":O?void 0:`${ko}-${k}`,"aria-label":D},A.createElement(Nf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:i,yPos:o,selected:l,isConnectable:v,sourcePosition:_,targetPosition:I,dragging:pe,dragHandle:P,zIndex:V})))};return t.displayName="NodeWrapper",w.memo(t)};const hh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...sn(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function mh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Se(),{width:s,height:i,x:o,y:a,transformString:c,userSelectionActive:l}=he(hh,ke),u=Oo(),d=w.useRef(null);if(w.useEffect(()=>{var p;n||(p=d.current)==null||p.focus({preventScroll:!0})},[n]),To({nodeRef:d}),l||!s||!i)return null;const m=e?p=>{const y=r.getState().getNodes().filter(b=>b.selected);e(p,y)}:void 0,f=p=>{Object.prototype.hasOwnProperty.call(Rt,p.key)&&u({x:Rt[p.key].x,y:Rt[p.key].y,isShiftPressed:p.shiftKey})};return A.createElement("div",{className:Ce(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:i,top:a,left:o}}))}var ph=w.memo(mh);const gh=e=>e.nodesSelectionActive,Lo=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:p,onSelectionEnd:y,multiSelectionKeyCode:b,panActivationKeyCode:g,zoomActivationKeyCode:E,elementsSelectable:C,zoomOnScroll:v,zoomOnPinch:M,panOnScroll:j,panOnScrollSpeed:_,panOnScrollMode:I,zoomOnDoubleClick:N,panOnDrag:R,defaultViewport:P,translateExtent:V,minZoom:H,maxZoom:x,preventScrolling:$,onSelectionContextMenu:S,noWheelClassName:O,noPanClassName:D,disableKeyboardA11y:k})=>{const T=he(gh),L=en(d),z=en(g),W=z||R,G=z||j,X=L||m&&W!==!0;return eh({deleteKeyCode:a,multiSelectionKeyCode:b}),A.createElement(sh,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:i,elementsSelectable:C,zoomOnScroll:v,zoomOnPinch:M,panOnScroll:G,panOnScrollSpeed:_,panOnScrollMode:I,zoomOnDoubleClick:N,panOnDrag:!L&&W,defaultViewport:P,translateExtent:V,minZoom:H,maxZoom:x,zoomActivationKeyCode:E,preventScrolling:$,noWheelClassName:O,noPanClassName:D},A.createElement(Ao,{onSelectionStart:p,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:i,onPaneScroll:o,panOnDrag:W,isSelecting:!!X,selectionMode:f},e,T&&A.createElement(ph,{onSelectionContextMenu:S,noPanClassName:D,disableKeyboardA11y:k})))};Lo.displayName="FlowRenderer";var yh=w.memo(Lo);function xh(e){return he(w.useCallback(n=>e?ho(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function wh(e){const t={input:Vt(e.input||_o),default:Vt(e.default||vr),output:Vt(e.output||No),group:Vt(e.group||Hr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,i)=>(s[i]=Vt(e[i]||vr),s),n);return{...t,...r}}const bh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},vh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Do=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:i,onError:o}=he(vh,ke),a=xh(e.onlyRenderVisibleElements),c=w.useRef(),l=w.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));i(m)});return c.current=u,u},[]);return w.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Fr},a.map(u=>{var M,j,_;let d=u.type||"default";e.nodeTypes[d]||(o==null||o("003",st.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),p=!!(u.selectable||s&&typeof u.selectable>"u"),y=!!(u.connectable||n&&typeof u.connectable>"u"),b=!!(u.focusable||r&&typeof u.focusable>"u"),g=e.nodeExtent?Tr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(g==null?void 0:g.x)??0,C=(g==null?void 0:g.y)??0,v=bh({x:E,y:C,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||U.Bottom,targetPosition:u.targetPosition||U.Top,hidden:u.hidden,xPos:E,yPos:C,xPosOrigin:v.x,yPosOrigin:v.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:p,isConnectable:y,isFocusable:b,resizeObserver:l,dragHandle:u.dragHandle,zIndex:((M=u[we])==null?void 0:M.z)??0,isParent:!!((j=u[we])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((_=u[we])!=null&&_.handleBounds)})}))};Do.displayName="NodeRenderer";var _h=w.memo(Do);const Eh=(e,t,n)=>n===U.Left?e-t:n===U.Right?e+t:e,Nh=(e,t,n)=>n===U.Top?e-t:n===U.Bottom?e+t:e,Ts="react-flow__edgeupdater",Os=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:i,onMouseOut:o,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:i,onMouseOut:o,className:Ce([Ts,`${Ts}-${a}`]),cx:Eh(t,r,e),cy:Nh(n,r,e),r,stroke:"transparent",fill:"transparent"}),Sh=()=>!0;var jt=e=>{const t=({id:n,className:r,type:s,data:i,onClick:o,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:y,style:b,source:g,target:E,sourceX:C,sourceY:v,targetX:M,targetY:j,sourcePosition:_,targetPosition:I,elementsSelectable:N,hidden:R,sourceHandleId:P,targetHandleId:V,onContextMenu:H,onMouseEnter:x,onMouseMove:$,onMouseLeave:S,reconnectRadius:O,onReconnect:D,onReconnectStart:k,onReconnectEnd:T,markerEnd:L,markerStart:z,rfId:W,ariaLabel:G,isFocusable:X,isReconnectable:Z,pathOptions:ne,interactionWidth:ie,disableKeyboardA11y:re})=>{const ae=w.useRef(null),[ye,te]=w.useState(!1),[me,ve]=w.useState(!1),de=Se(),pe=w.useMemo(()=>`url('#${wr(z,W)}')`,[z,W]),le=w.useMemo(()=>`url('#${wr(L,W)}')`,[L,W]);if(R)return null;const q=se=>{var Me;const{edges:ge,addSelectedEdges:J,unselectNodesAndEdges:fe,multiSelectionActive:ce}=de.getState(),xe=ge.find(Ye=>Ye.id===n);xe&&(N&&(de.setState({nodesSelectionActive:!1}),xe.selected&&ce?(fe({nodes:[],edges:[xe]}),(Me=ae.current)==null||Me.blur()):J([n])),o&&o(se,xe))},_e=Ht(n,de.getState,a),je=Ht(n,de.getState,H),ze=Ht(n,de.getState,x),$e=Ht(n,de.getState,$),qe=Ht(n,de.getState,S),Ie=(se,ge)=>{if(se.button!==0)return;const{edges:J,isValidConnection:fe}=de.getState(),ce=ge?E:g,xe=(ge?V:P)||null,Me=ge?"target":"source",Ye=fe||Sh,Ke=ge,Te=J.find(He=>He.id===n);ve(!0),k==null||k(se,Te,Me);const _t=He=>{ve(!1),T==null||T(He,Te,Me)};xo({event:se,handleId:xe,nodeId:ce,onConnect:He=>D==null?void 0:D(Te,He),isTarget:Ke,getState:de.getState,setState:de.setState,isValidConnection:Ye,edgeUpdaterType:Me,onReconnectEnd:_t})},F=se=>Ie(se,!0),Y=se=>Ie(se,!1),B=()=>te(!0),Q=()=>te(!1),K=!N&&!o,ee=se=>{var ge;if(!re&&io.includes(se.key)&&N){const{unselectNodesAndEdges:J,addSelectedEdges:fe,edges:ce}=de.getState();se.key==="Escape"?((ge=ae.current)==null||ge.blur(),J({edges:[ce.find(Me=>Me.id===n)]})):fe([n])}};return A.createElement("g",{className:Ce(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:K,updating:ye}]),onClick:q,onDoubleClick:_e,onContextMenu:je,onMouseEnter:ze,onMouseMove:$e,onMouseLeave:qe,onKeyDown:X?ee:void 0,tabIndex:X?0:void 0,role:X?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":G===null?void 0:G||`Edge from ${g} to ${E}`,"aria-describedby":X?`${jo}-${W}`:void 0,ref:ae},!me&&A.createElement(e,{id:n,source:g,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:y,data:i,style:b,sourceX:C,sourceY:v,targetX:M,targetY:j,sourcePosition:_,targetPosition:I,sourceHandleId:P,targetHandleId:V,markerStart:pe,markerEnd:le,pathOptions:ne,interactionWidth:ie}),Z&&A.createElement(A.Fragment,null,(Z==="source"||Z===!0)&&A.createElement(Os,{position:_,centerX:C,centerY:v,radius:O,onMouseDown:F,onMouseEnter:B,onMouseOut:Q,type:"source"}),(Z==="target"||Z===!0)&&A.createElement(Os,{position:I,centerX:M,centerY:j,radius:O,onMouseDown:Y,onMouseEnter:B,onMouseOut:Q,type:"target"})))};return t.displayName="EdgeWrapper",w.memo(t)};function kh(e){const t={default:jt(e.default||An),straight:jt(e.bezier||Dr),step:jt(e.step||Lr),smoothstep:jt(e.step||Fn),simplebezier:jt(e.simplebezier||Or)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,i)=>(s[i]=jt(e[i]||An),s),n);return{...t,...r}}function Ls(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,i=(n==null?void 0:n.width)||t.width,o=(n==null?void 0:n.height)||t.height;switch(e){case U.Top:return{x:r+i/2,y:s};case U.Right:return{x:r+i,y:s+o/2};case U.Bottom:return{x:r+i/2,y:s+o};case U.Left:return{x:r,y:s+o/2}}}function Ds(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const jh=(e,t,n,r,s,i)=>{const o=Ls(n,e,t),a=Ls(i,r,s);return{sourceX:o.x,sourceY:o.y,targetX:a.x,targetY:a.y}};function Ch({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:i,width:o,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+i)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=Qt({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:o/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Ps(e){var r,s,i,o,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.y)<"u";return[{x:((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const $h=[{level:0,isMaxLevel:!0,edges:[]}];function Mh(e,t,n=!1){let r=-1;const s=e.reduce((o,a)=>{var u,d;const c=Le(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),p=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),y=Math.max(((u=f==null?void 0:f[we])==null?void 0:u.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(p?y:0)}return o[l]?o[l].push(a):o[l]=[a],r=l>r?l:r,o},{}),i=Object.entries(s).map(([o,a])=>{const c=+o;return{edges:a,level:c,isMaxLevel:c===r}});return i.length===0?$h:i}function Ah(e,t,n){const r=he(w.useCallback(s=>e?s.edges.filter(i=>{const o=t.get(i.source),a=t.get(i.target);return(o==null?void 0:o.width)&&(o==null?void 0:o.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Ch({sourcePos:o.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:o.width,sourceHeight:o.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Mh(r,t,n)}const Rh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Ih=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),zs={[$n.Arrow]:Rh,[$n.ArrowClosed]:Ih};function Th(e){const t=Se();return w.useMemo(()=>{var s,i;return Object.prototype.hasOwnProperty.call(zs,e)?zs[e]:((i=(s=t.getState()).onError)==null||i.call(s,"009",st.error009(e)),null)},[e])}const Oh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:i="strokeWidth",strokeWidth:o,orient:a="auto-start-reverse"})=>{const c=Th(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:o})):null},Lh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,i)=>([i.markerStart,i.markerEnd].forEach(o=>{if(o&&typeof o=="object"){const a=wr(o,t);r.includes(a)||(s.push({id:a,color:o.color||e,...o}),r.push(a))}}),s),[]).sort((s,i)=>s.id.localeCompare(i.id))},Po=({defaultColor:e,rfId:t})=>{const n=he(w.useCallback(Lh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((i,o)=>i.id!==s[o].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Oh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};Po.displayName="MarkerDefinitions";var Dh=w.memo(Po);const Ph=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),zo=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:i,onEdgeContextMenu:o,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:y,children:b,disableKeyboardA11y:g})=>{const{edgesFocusable:E,edgesUpdatable:C,elementsSelectable:v,width:M,height:j,connectionMode:_,nodeInternals:I,onError:N}=he(Ph,ke),R=Ah(t,I,n);return M?A.createElement(A.Fragment,null,R.map(({level:P,edges:V,isMaxLevel:H})=>A.createElement("svg",{key:P,style:{zIndex:P},width:M,height:j,className:"react-flow__edges react-flow__container"},H&&A.createElement(Dh,{defaultColor:e,rfId:r}),A.createElement("g",null,V.map(x=>{const[$,S,O]=Ps(I.get(x.source)),[D,k,T]=Ps(I.get(x.target));if(!O||!T)return null;let L=x.type||"default";s[L]||(N==null||N("011",st.error011(L)),L="default");const z=s[L]||s.default,W=_===bt.Strict?k.target:(k.target??[]).concat(k.source??[]),G=Ds(S.source,x.sourceHandle),X=Ds(W,x.targetHandle),Z=(G==null?void 0:G.position)||U.Bottom,ne=(X==null?void 0:X.position)||U.Top,ie=!!(x.focusable||E&&typeof x.focusable>"u"),re=x.reconnectable||x.updatable,ae=typeof m<"u"&&(re||C&&typeof re>"u");if(!G||!X)return N==null||N("008",st.error008(G,x)),null;const{sourceX:ye,sourceY:te,targetX:me,targetY:ve}=jh($,G,Z,D,X,ne);return A.createElement(z,{key:x.id,id:x.id,className:Ce([x.className,i]),type:L,data:x.data,selected:!!x.selected,animated:!!x.animated,hidden:!!x.hidden,label:x.label,labelStyle:x.labelStyle,labelShowBg:x.labelShowBg,labelBgStyle:x.labelBgStyle,labelBgPadding:x.labelBgPadding,labelBgBorderRadius:x.labelBgBorderRadius,style:x.style,source:x.source,target:x.target,sourceHandleId:x.sourceHandle,targetHandleId:x.targetHandle,markerEnd:x.markerEnd,markerStart:x.markerStart,sourceX:ye,sourceY:te,targetX:me,targetY:ve,sourcePosition:Z,targetPosition:ne,elementsSelectable:v,onContextMenu:o,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:y,rfId:r,ariaLabel:x.ariaLabel,isFocusable:ie,isReconnectable:ae,pathOptions:"pathOptions"in x?x.pathOptions:void 0,interactionWidth:x.interactionWidth,disableKeyboardA11y:g})})))),b):null};zo.displayName="EdgeRenderer";var zh=w.memo(zo);const Hh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Fh({children:e}){const t=he(Hh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Vh(e){const t=on(),n=w.useRef(!1);w.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Bh={[U.Left]:U.Right,[U.Right]:U.Left,[U.Top]:U.Bottom,[U.Bottom]:U.Top},Ho=({nodeId:e,handleType:t,style:n,type:r=lt.Bezier,CustomComponent:s,connectionStatus:i})=>{var j,_,I;const{fromNode:o,handleId:a,toX:c,toY:l,connectionMode:u}=he(w.useCallback(N=>({fromNode:N.nodeInternals.get(e),handleId:N.connectionHandleId,toX:(N.connectionPosition.x-N.transform[0])/N.transform[2],toY:(N.connectionPosition.y-N.transform[1])/N.transform[2],connectionMode:N.connectionMode}),[e]),ke),d=(j=o==null?void 0:o[we])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(u===bt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!o||!m)return null;const f=a?m.find(N=>N.id===a):m[0],p=f?f.x+f.width/2:(o.width??0)/2,y=f?f.y+f.height/2:o.height??0,b=(((_=o.positionAbsolute)==null?void 0:_.x)??0)+p,g=(((I=o.positionAbsolute)==null?void 0:I.y)??0)+y,E=f==null?void 0:f.position,C=E?Bh[E]:null;if(!E||!C)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:o,fromHandle:f,fromX:b,fromY:g,toX:c,toY:l,fromPosition:E,toPosition:C,connectionStatus:i});let v="";const M={sourceX:b,sourceY:g,sourcePosition:E,targetX:c,targetY:l,targetPosition:C};return r===lt.Bezier?[v]=uo(M):r===lt.Step?[v]=Mn({...M,borderRadius:0}):r===lt.SmoothStep?[v]=Mn(M):r===lt.SimpleBezier?[v]=lo(M):v=`M${b},${g} ${c},${l}`,A.createElement("path",{d:v,fill:"none",className:"react-flow__connection-path",style:n})};Ho.displayName="ConnectionLine";const Gh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Yh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:i,nodesConnectable:o,width:a,height:c,connectionStatus:l}=he(Gh,ke);return!(s&&i&&a&&o)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:Ce(["react-flow__connection",l])},A.createElement(Ho,{nodeId:s,handleType:i,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Hs(e,t){return w.useRef(null),Se(),w.useMemo(()=>t(e),[e])}const Fo=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:i,onNodeClick:o,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:p,onSelectionStart:y,onSelectionEnd:b,connectionLineType:g,connectionLineStyle:E,connectionLineComponent:C,connectionLineContainerStyle:v,selectionKeyCode:M,selectionOnDrag:j,selectionMode:_,multiSelectionKeyCode:I,panActivationKeyCode:N,zoomActivationKeyCode:R,deleteKeyCode:P,onlyRenderVisibleElements:V,elementsSelectable:H,selectNodesOnDrag:x,defaultViewport:$,translateExtent:S,minZoom:O,maxZoom:D,preventScrolling:k,defaultMarkerColor:T,zoomOnScroll:L,zoomOnPinch:z,panOnScroll:W,panOnScrollSpeed:G,panOnScrollMode:X,zoomOnDoubleClick:Z,panOnDrag:ne,onPaneClick:ie,onPaneMouseEnter:re,onPaneMouseMove:ae,onPaneMouseLeave:ye,onPaneScroll:te,onPaneContextMenu:me,onEdgeContextMenu:ve,onEdgeMouseEnter:de,onEdgeMouseMove:pe,onEdgeMouseLeave:le,onReconnect:q,onReconnectStart:_e,onReconnectEnd:je,reconnectRadius:ze,noDragClassName:$e,noWheelClassName:qe,noPanClassName:Ie,elevateEdgesOnSelect:F,disableKeyboardA11y:Y,nodeOrigin:B,nodeExtent:Q,rfId:K})=>{const ee=Hs(e,wh),se=Hs(t,kh);return Vh(i),A.createElement(yh,{onPaneClick:ie,onPaneMouseEnter:re,onPaneMouseMove:ae,onPaneMouseLeave:ye,onPaneContextMenu:me,onPaneScroll:te,deleteKeyCode:P,selectionKeyCode:M,selectionOnDrag:j,selectionMode:_,onSelectionStart:y,onSelectionEnd:b,multiSelectionKeyCode:I,panActivationKeyCode:N,zoomActivationKeyCode:R,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:L,zoomOnPinch:z,zoomOnDoubleClick:Z,panOnScroll:W,panOnScrollSpeed:G,panOnScrollMode:X,panOnDrag:ne,defaultViewport:$,translateExtent:S,minZoom:O,maxZoom:D,onSelectionContextMenu:p,preventScrolling:k,noDragClassName:$e,noWheelClassName:qe,noPanClassName:Ie,disableKeyboardA11y:Y},A.createElement(Fh,null,A.createElement(zh,{edgeTypes:se,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:V,onEdgeContextMenu:ve,onEdgeMouseEnter:de,onEdgeMouseMove:pe,onEdgeMouseLeave:le,onReconnect:q,onReconnectStart:_e,onReconnectEnd:je,reconnectRadius:ze,defaultMarkerColor:T,noPanClassName:Ie,elevateEdgesOnSelect:!!F,disableKeyboardA11y:Y,rfId:K},A.createElement(Yh,{style:E,type:g,component:C,containerStyle:v})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(_h,{nodeTypes:ee,onNodeClick:o,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:x,onlyRenderVisibleElements:V,noPanClassName:Ie,noDragClassName:$e,disableKeyboardA11y:Y,nodeOrigin:B,nodeExtent:Q,rfId:K})))};Fo.displayName="GraphView";var Wh=w.memo(Fo);const Er=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ot={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Er,nodeExtent:Er,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:bt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:xf,isValidConnection:void 0},Uh=()=>Rc((e,t)=>({...ot,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:i}=t();e({nodeInternals:Zn(n,r,s,i)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",i=typeof r<"u",o=s?Zn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:o,edges:i?r:[],hasDefaultNodes:s,hasDefaultEdges:i})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:i,fitViewOnInitDone:o,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((y,b)=>{const g=s.get(b.id);if(g!=null&&g.hidden)s.set(g.id,{...g,[we]:{...g[we],handleBounds:void 0}});else if(g){const E=Ir(b.nodeElement);!!(E.width&&E.height&&(g.width!==E.width||g.height!==E.height||b.forceUpdate))&&(s.set(g.id,{...g,[we]:{...g[we],handleBounds:{source:Is(".source",b.nodeElement,m,l),target:Is(".target",b.nodeElement,m,l)}},...E}),y.push({id:g.id,type:"dimensions",dimensions:E}))}return y},[]);$o(s,l);const p=o||i&&!o&&Mo(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:p}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:i}=t(),o=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});i(o)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:i,nodeOrigin:o,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(i){const l=ch(n,a()),u=Zn(l,s,o,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(i(),n),a=Ct(s,[])),pn({changedNodes:o,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:i}=t();let o,a=null;r?o=n.map(c=>ct(c,!0)):(o=Ct(s,n),a=Ct(i(),[])),pn({changedNodes:a,changedEdges:o,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:i}=t(),o=n||i(),a=r||s,c=o.map(u=>(u.selected=!1,ct(u.id,!1))),l=a.map(u=>ct(u.id,!1));pn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),i=r().filter(a=>a.selected).map(a=>ct(a.id,!1)),o=n.filter(a=>a.selected).map(a=>ct(a.id,!1));pn({changedNodes:i,changedEdges:o,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Tr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:i,d3Zoom:o,d3Selection:a,translateExtent:c}=t();if(!o||!a||!n.x&&!n.y)return!1;const l=nt.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,i]],d=o==null?void 0:o.constrain()(l,u,c);return o.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:ot.connectionNodeId,connectionHandleId:ot.connectionHandleId,connectionHandleType:ot.connectionHandleType,connectionStatus:ot.connectionStatus,connectionStartHandle:ot.connectionStartHandle,connectionEndHandle:ot.connectionEndHandle}),reset:()=>e({...ot})}),Object.is),Vo=({children:e})=>{const t=w.useRef(null);return t.current||(t.current=Uh()),A.createElement(df,{value:t.current},e)};Vo.displayName="ReactFlowProvider";const Bo=({children:e})=>w.useContext(Hn)?A.createElement(A.Fragment,null,e):A.createElement(Vo,null,e);Bo.displayName="ReactFlowWrapper";const Xh={input:_o,default:vr,output:No,group:Hr},qh={default:An,straight:Dr,step:Lr,smoothstep:Fn,simplebezier:Or},Kh=[0,0],Zh=[15,15],Qh={x:0,y:0,zoom:1},Jh={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Go=w.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:i=Xh,edgeTypes:o=qh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:p,onConnectEnd:y,onClickConnectStart:b,onClickConnectEnd:g,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:v,onNodeContextMenu:M,onNodeDoubleClick:j,onNodeDragStart:_,onNodeDrag:I,onNodeDragStop:N,onNodesDelete:R,onEdgesDelete:P,onSelectionChange:V,onSelectionDragStart:H,onSelectionDrag:x,onSelectionDragStop:$,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,connectionMode:k=bt.Strict,connectionLineType:T=lt.Bezier,connectionLineStyle:L,connectionLineComponent:z,connectionLineContainerStyle:W,deleteKeyCode:G="Backspace",selectionKeyCode:X="Shift",selectionOnDrag:Z=!1,selectionMode:ne=Jt.Full,panActivationKeyCode:ie="Space",multiSelectionKeyCode:re=Cn()?"Meta":"Control",zoomActivationKeyCode:ae=Cn()?"Meta":"Control",snapToGrid:ye=!1,snapGrid:te=Zh,onlyRenderVisibleElements:me=!1,selectNodesOnDrag:ve=!0,nodesDraggable:de,nodesConnectable:pe,nodesFocusable:le,nodeOrigin:q=Kh,edgesFocusable:_e,edgesUpdatable:je,elementsSelectable:ze,defaultViewport:$e=Qh,minZoom:qe=.5,maxZoom:Ie=2,translateExtent:F=Er,preventScrolling:Y=!0,nodeExtent:B,defaultMarkerColor:Q="#b1b1b7",zoomOnScroll:K=!0,zoomOnPinch:ee=!0,panOnScroll:se=!1,panOnScrollSpeed:ge=.5,panOnScrollMode:J=gt.Free,zoomOnDoubleClick:fe=!0,panOnDrag:ce=!0,onPaneClick:xe,onPaneMouseEnter:Me,onPaneMouseMove:Ye,onPaneMouseLeave:Ke,onPaneScroll:Te,onPaneContextMenu:_t,children:Et,onEdgeContextMenu:He,onEdgeDoubleClick:ue,onEdgeMouseEnter:Ze,onEdgeMouseMove:Dt,onEdgeMouseLeave:$a,onEdgeUpdate:Ma,onEdgeUpdateStart:Aa,onEdgeUpdateEnd:Ra,onReconnect:Ia,onReconnectStart:Ta,onReconnectEnd:Oa,reconnectRadius:La=10,edgeUpdaterRadius:Da=10,onNodesChange:Pa,onEdgesChange:za,noDragClassName:Ha="nodrag",noWheelClassName:Fa="nowheel",noPanClassName:qr="nopan",fitView:Va=!1,fitViewOptions:Ba,connectOnClick:Ga=!0,attributionPosition:Ya,proOptions:Wa,defaultEdgeOptions:Ua,elevateNodesOnSelect:Xa=!0,elevateEdgesOnSelect:qa=!1,disableKeyboardA11y:Kr=!1,autoPanOnConnect:Ka=!0,autoPanOnNodeDrag:Za=!0,connectionRadius:Qa=20,isValidConnection:Ja,onError:ec,style:tc,id:Zr,nodeDragThreshold:nc,...rc},sc)=>{const Gn=Zr||"1";return A.createElement("div",{...rc,style:{...tc,...Jh},ref:sc,className:Ce(["react-flow",s]),"data-testid":"rf__wrapper",id:Zr},A.createElement(Bo,null,A.createElement(Wh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:v,onNodeContextMenu:M,onNodeDoubleClick:j,nodeTypes:i,edgeTypes:o,connectionLineType:T,connectionLineStyle:L,connectionLineComponent:z,connectionLineContainerStyle:W,selectionKeyCode:X,selectionOnDrag:Z,selectionMode:ne,deleteKeyCode:G,multiSelectionKeyCode:re,panActivationKeyCode:ie,zoomActivationKeyCode:ae,onlyRenderVisibleElements:me,selectNodesOnDrag:ve,defaultViewport:$e,translateExtent:F,minZoom:qe,maxZoom:Ie,preventScrolling:Y,zoomOnScroll:K,zoomOnPinch:ee,zoomOnDoubleClick:fe,panOnScroll:se,panOnScrollSpeed:ge,panOnScrollMode:J,panOnDrag:ce,onPaneClick:xe,onPaneMouseEnter:Me,onPaneMouseMove:Ye,onPaneMouseLeave:Ke,onPaneScroll:Te,onPaneContextMenu:_t,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,onEdgeContextMenu:He,onEdgeDoubleClick:ue,onEdgeMouseEnter:Ze,onEdgeMouseMove:Dt,onEdgeMouseLeave:$a,onReconnect:Ia??Ma,onReconnectStart:Ta??Aa,onReconnectEnd:Oa??Ra,reconnectRadius:La??Da,defaultMarkerColor:Q,noDragClassName:Ha,noWheelClassName:Fa,noPanClassName:qr,elevateEdgesOnSelect:qa,rfId:Gn,disableKeyboardA11y:Kr,nodeOrigin:q,nodeExtent:B}),A.createElement(Vf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:p,onConnectEnd:y,onClickConnectStart:b,onClickConnectEnd:g,nodesDraggable:de,nodesConnectable:pe,nodesFocusable:le,edgesFocusable:_e,edgesUpdatable:je,elementsSelectable:ze,elevateNodesOnSelect:Xa,minZoom:qe,maxZoom:Ie,nodeExtent:B,onNodesChange:Pa,onEdgesChange:za,snapToGrid:ye,snapGrid:te,connectionMode:k,translateExtent:F,connectOnClick:Ga,defaultEdgeOptions:Ua,fitView:Va,fitViewOptions:Ba,onNodesDelete:R,onEdgesDelete:P,onNodeDragStart:_,onNodeDrag:I,onNodeDragStop:N,onSelectionDrag:x,onSelectionDragStart:H,onSelectionDragStop:$,noPanClassName:qr,nodeOrigin:q,rfId:Gn,autoPanOnConnect:Ka,autoPanOnNodeDrag:Za,onError:ec,connectionRadius:Qa,isValidConnection:Ja,nodeDragThreshold:nc}),A.createElement(Hf,{onSelectionChange:V}),Et,A.createElement(hf,{proOptions:Wa,position:Ya}),A.createElement(Uf,{rfId:Gn,disableKeyboardA11y:Kr})))});Go.displayName="ReactFlow";const Yo=({id:e,x:t,y:n,width:r,height:s,style:i,color:o,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:p,backgroundColor:y}=i||{},b=o||p||y;return A.createElement("rect",{className:Ce(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:b,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?g=>m(g,e):void 0})};Yo.displayName="MiniMapNode";var em=w.memo(Yo);const tm=e=>e.nodeOrigin,nm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),tr=e=>e instanceof Function?e:()=>e;function rm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:i=em,onClick:o}){const a=he(nm,ke),c=he(tm),l=tr(t),u=tr(e),d=tr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:p,y}=xt(f,c).positionAbsolute;return A.createElement(i,{key:f.id,x:p,y,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:o,id:f.id})}))}var sm=w.memo(rm);const im=200,om=150,am=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?gf(sn(t,e.nodeOrigin),n):n,rfId:e.rfId}},cm="react-flow__minimap-desc";function Wo({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:o=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:p=!1,zoomable:y=!1,ariaLabel:b="React Flow mini map",inversePan:g=!1,zoomStep:E=10,offsetScale:C=5}){const v=Se(),M=w.useRef(null),{boundingRect:j,viewBB:_,rfId:I}=he(am,ke),N=(e==null?void 0:e.width)??im,R=(e==null?void 0:e.height)??om,P=j.width/N,V=j.height/R,H=Math.max(P,V),x=H*N,$=H*R,S=C*H,O=j.x-(x-j.width)/2-S,D=j.y-($-j.height)/2-S,k=x+S*2,T=$+S*2,L=`${cm}-${I}`,z=w.useRef(0);z.current=H,w.useEffect(()=>{if(M.current){const X=Oe(M.current),Z=re=>{const{transform:ae,d3Selection:ye,d3Zoom:te}=v.getState();if(re.sourceEvent.type!=="wheel"||!ye||!te)return;const me=-re.sourceEvent.deltaY*(re.sourceEvent.deltaMode===1?.05:re.sourceEvent.deltaMode?1:.002)*E,ve=ae[2]*Math.pow(2,me);te.scaleTo(ye,ve)},ne=re=>{const{transform:ae,d3Selection:ye,d3Zoom:te,translateExtent:me,width:ve,height:de}=v.getState();if(re.sourceEvent.type!=="mousemove"||!ye||!te)return;const pe=z.current*Math.max(1,ae[2])*(g?-1:1),le={x:ae[0]-re.sourceEvent.movementX*pe,y:ae[1]-re.sourceEvent.movementY*pe},q=[[0,0],[ve,de]],_e=nt.translate(le.x,le.y).scale(ae[2]),je=te.constrain()(_e,q,me);te.transform(ye,je)},ie=Ji().on("zoom",p?ne:null).on("zoom.wheel",y?Z:null);return X.call(ie),()=>{X.on("zoom",null)}}},[p,y,g,E]);const W=m?X=>{const Z=Fe(X);m(X,{x:Z[0],y:Z[1]})}:void 0,G=f?(X,Z)=>{const ne=v.getState().nodeInternals.get(Z);f(X,ne)}:void 0;return A.createElement(Rr,{position:d,style:e,className:Ce(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:N,height:R,viewBox:`${O} ${D} ${k} ${T}`,role:"img","aria-labelledby":L,ref:M,onClick:W},b&&A.createElement("title",{id:L},b),A.createElement(sm,{onClick:G,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${O-S},${D-S}h${k+S*2}v${T+S*2}h${-k-S*2}z - M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Wo.displayName="MiniMap";var lm=w.memo(Wo);function um(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function dm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function fm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function hm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Yt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:Ce(["react-flow__controls-button",t]),...n},e);Yt.displayName="ControlButton";const pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Uo=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Se(),[f,p]=w.useState(!1),{isInteractive:y,minZoomReached:b,maxZoomReached:g}=he(pm,ke),{zoomIn:E,zoomOut:C,fitView:v}=on();if(w.useEffect(()=>{p(!0)},[]),!f)return null;const M=()=>{E(),i==null||i()},j=()=>{C(),o==null||o()},_=()=>{v(s),a==null||a()},I=()=>{m.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c==null||c(!y)};return A.createElement(Rr,{className:Ce(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Yt,{onClick:M,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:g},A.createElement(um,null)),A.createElement(Yt,{onClick:j,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:b},A.createElement(dm,null))),n&&A.createElement(Yt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(fm,null)),r&&A.createElement(Yt,{className:"react-flow__controls-interactive",onClick:I,title:"toggle interactivity","aria-label":"toggle interactivity"},y?A.createElement(mm,null):A.createElement(hm,null)),u)};Uo.displayName="Controls";var gm=w.memo(Uo),De;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(De||(De={}));function ym({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function xm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const wm={[De.Dots]:"#91919a",[De.Lines]:"#eee",[De.Cross]:"#e2e2e2"},bm={[De.Dots]:1,[De.Lines]:1,[De.Cross]:6},vm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Xo({id:e,variant:t=De.Dots,gap:n=20,size:r,lineWidth:s=1,offset:i=2,color:o,style:a,className:c}){const l=w.useRef(null),{transform:u,patternId:d}=he(vm,ke),m=o||wm[t],f=r||bm[t],p=t===De.Dots,y=t===De.Cross,b=Array.isArray(n)?n:[n,n],g=[b[0]*u[2]||1,b[1]*u[2]||1],E=f*u[2],C=y?[E,E]:g,v=p?[E/i,E/i]:[C[0]/i,C[1]/i];return A.createElement("svg",{className:Ce(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%g[0],y:u[1]%g[1],width:g[0],height:g[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${v[0]},-${v[1]})`},p?A.createElement(xm,{color:m,radius:E/i}):A.createElement(ym,{dimensions:C,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}Xo.displayName="Background";var _m=w.memo(Xo);const Vr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Rn(e){return Vr+e}async function be(e){const t=await fetch(Rn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function it(e,t){const n=await fetch(Rn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new qo(r.error??`${e}: ${n.status}`,n.status);return r}class qo extends Error{constructor(n,r){super(n);Ee(this,"status");this.status=r}}const Rx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),Ix=()=>be("/api/diagnostics"),Ko=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),Zo=()=>be("/api/ontology/ontologies"),Em=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Nm=()=>be("/api/ontology/stack"),Sm=()=>be("/api/ontology/coverage"),km=(e,t,n)=>it("/api/command",{op:e,payload:t,fingerprint:n??""}),jm=()=>be("/api/git/status"),Cm=()=>be("/api/git/diff"),$m=e=>it("/api/git/commit",{message:e}),Mm=()=>it("/api/git/discard",{}),Am=()=>be("/api/decisions"),Fs=(e,t)=>it(`/api/decisions/${e}/verdict`,{verdict:t}),Tx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Ox=()=>be("/api/glossary/config"),Lx=e=>it("/api/git/propose",e),Dx=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Px=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),zx=e=>it("/api/git/classify",{changes:e}),Hx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Fx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Vx=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Rm=()=>be("/api/export"),Im=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Vr}/api/export/${encodeURIComponent(e)}${n}`},Tm=(e,t,n)=>it("/api/import",{format:e,content:t,dialect:n}),Om=(e,t)=>it("/api/import/preview",{format:e,content:t}),Bx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Gx=async(e,t=!1)=>{for(const n of e)try{await km(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Yx=(e,t,n)=>fetch(`${Vr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new qo(await r.text(),r.status);return await r.json()}),Wx=()=>be("/api/glossary/subject-areas"),Ux=e=>be(`/api/glossary/subject-area/${e}`),Xx=(e,t)=>it(`/api/glossary/subject-area/${e}/expand`,t);function qx(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Rn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Rn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Lm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Dm(e){return e??""}const Br="__entity_source",Gr="__entity_target",Pm=w.memo(function({data:t,selected:n}){var j;const{entity:r,color:s,dimmed:i,highlighted:o,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:p}=t,y=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,b=[...r.attributes].map((_,I)=>({a:_,i:I})).sort((_,I)=>y(_.a)-y(I.a)||_.i-I.i).map(_=>_.a),g=b.filter(_=>_.role==="business_key");let E=b.filter(_=>_.role!=="business_key");const C=!!c&&!l;let v=0;if(C){const _=E.filter(I=>d==null?void 0:d.has(I.id));v=E.length-_.length,E=_}const M=(_,I)=>{const N="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:N,onMouseEnter:p?()=>p(_.id):void 0,onMouseLeave:p?()=>p(null):void 0,children:[h.jsx(ut,{id:_.id,type:"target",position:U.Left,className:"port attr-port"}),h.jsx(ut,{id:_.id,type:"source",position:U.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Lm[_.role]}),h.jsx("span",{className:"attr-name"+(I?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Dm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(i?" dimmed":"")+(o?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ut,{id:Gr,type:"target",position:U.Left,className:"port"}),h.jsx(ut,{id:Br,type:"source",position:U.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((j=r.conceptual)==null?void 0:j.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var N;const _=(((N=r.conceptual)==null?void 0:N.ontology_refs)??[]).filter(R=>R.uri);if(_.length===0)return null;const I=_.map(R=>R.uri).join(` -`);return h.jsxs("span",{className:"badge ontology",title:I,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),g.length>0&&h.jsx("div",{className:"attr-section keys",children:g.map(_=>M(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>M(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),v>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${v} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),zm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Hm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:i,onAlign:o,onEditMapping:a}){var m,f,p,y,b,g,E,C,v,M,j,_,I;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(N=>N.from.entity===e.id||N.to.entity===e.id),d=N=>{var R;return((R=t.entities.find(P=>P.id===N))==null?void 0:R.name)??N};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(Je,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,name:N})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(Je,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,physical_name:N})})]}),h.jsxs("div",{children:[h.jsx(Vm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Gm,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(Je,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:N=>r("set_definition",{id:e.id,definition:N})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>o(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((p=l==null?void 0:l.ontology_refs)==null?void 0:p.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Fm,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(y=e.term_map)!=null&&y.subject_template||(b=e.term_map)!=null&&b.class_iri?"Edit mapping…":"Map…"}),(((g=e.term_map)==null?void 0:g.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),(C=e.term_map)!=null&&C.subject_template||(v=e.term_map)!=null&&v.class_iri?h.jsxs(h.Fragment,{children:[((M=e.term_map)==null?void 0:M.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(Je,{value:((_=l==null?void 0:l.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:N=>{var R;return r("set_stewardship",{id:e.id,owner:N,steward:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(Je,{value:((I=l==null?void 0:l.stewardship)==null?void 0:I.steward)??"",placeholder:"—",readOnly:c,onCommit:N=>{var R;return r("set_stewardship",{id:e.id,owner:((R=l==null?void 0:l.stewardship)==null?void 0:R.owner)??null,steward:N})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(N=>h.jsx(Wm,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(Um,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(N=>{const R=N.members.map(P=>{var V;return((V=e.attributes.find(H=>H.id===P))==null?void 0:V.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+N.type,children:N.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:N.name}),h.jsx("span",{className:"key-cols",children:R})]},N.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([N,R])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:N}),h.jsx("td",{className:"udp-val",children:String(R)})]},N))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(N=>{const R=N.from.entity===e.id?N.to.entity:N.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>i(R),children:[h.jsx("span",{className:"rel-card",children:Xm(N,e.id)}),d(R)]}),(N.verb_phrase||N.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(Je,{value:N.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,verb_phrase:P})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(Je,{value:N.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,inverse_verb_phrase:P})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${N.name}`,onClick:()=>r("delete_relationship",{id:N.id}),children:"✕"})]},N.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var N;return(N=navigator.clipboard)==null?void 0:N.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Fm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,i=t.filter(o=>o.uri);return i.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:i.map((o,a)=>{const c=o.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:o.uri??void 0,children:o.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[o.predicate&&h.jsx("span",{className:"ref-pill",children:o.predicate}),o.layer&&h.jsx("span",{className:`chip layer-${o.layer}`,children:o.layer}),o.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",o.resolved_via]}),typeof o.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(o.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:o.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:o.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${o.uri}-${a}`)})})}function Je({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:i=""}){const[o,a]=w.useState(e);w.useEffect(()=>a(e),[e]);const c=()=>{o.trim()!==e.trim()&&t(o.trim())};return n?h.jsx("span",{className:i,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${i}`,value:o,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${i}`,value:o,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Vm({entity:e,doc:t,readOnly:n,exec:r}){var i,o,a;const s=((o=(i=e.conceptual)==null?void 0:i.subject_area)==null?void 0:o.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Bm=["","scd2","hub","link","satellite","bridge"];function Gm({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Bm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Ym=["attribute","business_key","measure","surrogate_key"];function Wm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const i=o=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...o});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(Je,{value:e.name,readOnly:!1,onCommit:o=>i({name:o})}),(e.physical_name||!1)&&h.jsx(Je,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:o=>i({physical_name:o})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:o=>i({domain:o.target.value}),children:[...new Set([...zm,...n.domains??[],e.domain??"string"])].sort().map(o=>h.jsx("option",{value:o,children:o},o))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:o=>i({role:o.target.value}),title:"role",children:Ym.map(o=>h.jsx("option",{value:o,children:o==="business_key"?"🔑 key":o==="measure"?"Σ measure":o},o))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:o=>i({nullable:!o.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Um({entity:e,exec:t}){const[n,r]=w.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Xm(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var qm="\0",ht="\0",Vs="";let Km=class{constructor(t){Ee(this,"_isDirected",!0);Ee(this,"_isMultigraph",!1);Ee(this,"_isCompound",!1);Ee(this,"_label");Ee(this,"_defaultNodeLabelFn",()=>{});Ee(this,"_defaultEdgeLabelFn",()=>{});Ee(this,"_nodes",{});Ee(this,"_in",{});Ee(this,"_preds",{});Ee(this,"_out",{});Ee(this,"_sucs",{});Ee(this,"_edgeObjs",{});Ee(this,"_edgeLabels",{});Ee(this,"_nodeCount",0);Ee(this,"_edgeCount",0);Ee(this,"_parent");Ee(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[ht]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(i){r.length>1?s.setNode(i,n):s.setNode(i)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=ht,this._children[t]={},this._children[ht][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=ht;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==ht)return n}}children(t=ht){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===ht)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([o,a]){t(o)&&n.setNode(o,a)}),Object.values(this._edgeObjs).forEach(function(o){n.hasNode(o.v)&&n.hasNode(o.w)&&n.setEdge(o,r.edge(o))});var s={};function i(o){var a=r.parent(o);return a===void 0||n.hasNode(a)?(s[o]=a,a):a in s?s[a]:i(a)}return this._isCompound&&n.nodes().forEach(o=>n.setParent(o,i(o))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(i,o){return s.length>1?r.setEdge(i,o,n):r.setEdge(i,o),o}),this}setEdge(){var t,n,r,s,i=!1,o=arguments[0];typeof o=="object"&&o!==null&&"v"in o?(t=o.v,n=o.w,r=o.name,arguments.length===2&&(s=arguments[1],i=!0)):(t=o,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],i=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Wt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return i&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=i?s:this._defaultEdgeLabelFn(t,n,r);var c=Zm(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Bs(this._preds[n],t),Bs(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?nr(this._isDirected,arguments[0]):Wt(this._isDirected,t,n,r),i=this._edgeObjs[s];return i&&(t=i.v,n=i.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Gs(this._preds[n],t),Gs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(i=>i.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Bs(e,t){e[t]?e[t]++:e[t]=1}function Gs(e,t){--e[t]||delete e[t]}function Wt(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}return s+Vs+i+Vs+(r===void 0?qm:r)}function Zm(e,t,n,r){var s=""+t,i=""+n;if(!e&&s>i){var o=s;s=i,i=o}var a={v:s,w:i};return r&&(a.name=r),a}function nr(e,t){return Wt(e,t.v,t.w,t.name)}var Yr=Km,Qm="2.2.4",Jm={Graph:Yr,version:Qm},ep=Yr,tp={write:np,read:ip};function np(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rp(e),edges:sp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function rp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function sp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function ip(e){var t=new ep(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var op=ap;function ap(e){var t={},n=[],r;function s(i){Object.hasOwn(t,i)||(t[i]=!0,r.push(i),e.successors(i).forEach(s),e.predecessors(i).forEach(s))}return e.nodes().forEach(function(i){r=[],s(i),r.length&&n.push(r)}),n}let cp=class{constructor(){Ee(this,"_arr",[]);Ee(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,i=s.length;return r[t]=i,s.push({key:t,priority:n}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,i=t;r>1,!(n[s].priority1;function dp(e,t,n,r){return fp(e,String(t),n||up,r||function(s){return e.outEdges(s)})}function fp(e,t,n,r){var s={},i=new lp,o,a,c=function(l){var u=l.v!==o?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(o=i.removeMin(),a=s[o],a.distance!==Number.POSITIVE_INFINITY);)r(o).forEach(c);return s}var hp=Jo,mp=pp;function pp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=hp(e,s,t,n),r},{})}var ea=gp;function gp(e){var t=0,n=[],r={},s=[];function i(o){var a=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),e.successors(o).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(i(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(o!==l);s.push(c)}}return e.nodes().forEach(function(o){Object.hasOwn(r,o)||i(o)}),s}var yp=ea,xp=wp;function wp(e){return yp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var bp=_p,vp=()=>1;function _p(e,t,n){return Ep(e,t||vp,n||function(r){return e.outEdges(r)})}function Ep(e,t,n){var r={},s=e.nodes();return s.forEach(function(i){r[i]={},r[i][i]={distance:0},s.forEach(function(o){i!==o&&(r[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var a=o.v===i?o.w:o.v,c=t(o);r[i][a]={distance:c,predecessor:i}})}),s.forEach(function(i){var o=r[i];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[i],d=o[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?jp:Cp,i=[],o={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,o,i)}),i}function jp(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var i=s.pop();i[1]?r.push(i[0]):Object.hasOwn(n,i[0])||(n[i[0]]=!0,s.push([i[0],!0]),sa(t(i[0]),o=>s.push([o,!1])))}}function Cp(e,t,n,r){for(var s=[e];s.length>0;){var i=s.pop();Object.hasOwn(n,i)||(n[i]=!0,r.push(i),sa(t(i),o=>s.push(o)))}}function sa(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var $p=ra,Mp=Ap;function Ap(e,t){return $p(e,t,"post")}var Rp=ra,Ip=Tp;function Tp(e,t){return Rp(e,t,"pre")}var Op=Yr,Lp=Qo,Dp=Pp;function Pp(e,t){var n=new Op,r={},s=new Lp,i;function o(c){var l=c.v===i?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(i=s.removeMin(),Object.hasOwn(r,i))n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(o)}return n}var zp={components:op,dijkstra:Jo,dijkstraAll:mp,findCycles:xp,floydWarshall:bp,isAcyclic:Np,postorder:Mp,preorder:Ip,prim:Dp,tarjan:ea,topsort:na},Ws=Jm,Ge={Graph:Ws.Graph,json:tp,alg:zp,version:Ws.version};let Hp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Us(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Us(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Fp)),r=r._prev;return"["+t.join(", ")+"]"}};function Us(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Fp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Vp=Hp;let Bp=Ge.Graph,Gp=Vp;var Yp=Up;let Wp=()=>1;function Up(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Wp);return Xp(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Xp(e,t,n){let r=[],s=t[t.length-1],i=t[0],o;for(;e.nodeCount();){for(;o=i.dequeue();)rr(e,t,n,o);for(;o=s.dequeue();)rr(e,t,n,o);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(o=t[a].dequeue(),o){r=r.concat(rr(e,t,n,o,!0));break}}}return r}function rr(e,t,n,r,s){let i=s?[]:void 0;return e.inEdges(r.v).forEach(o=>{let a=e.edge(o),c=e.node(o.v);s&&i.push({v:o.v,w:o.w}),c.out-=a,Sr(t,n,c)}),e.outEdges(r.v).forEach(o=>{let a=e.edge(o),c=o.w,l=e.node(c);l.in-=a,Sr(t,n,l)}),e.removeNode(r.v),i}function qp(e,t){let n=new Bp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let i=Kp(s+r+3).map(()=>new Gp),o=r+1;return n.nodes().forEach(a=>{Sr(i,o,n.node(a))}),{graph:n,buckets:i,zeroIdx:o}}function Sr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function Kp(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function Qp(e){let t=new ia({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Jp(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Wr(e.nodes(),t)}function eg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Wr(e.nodes(),t)}function tg(e,t){let n=e.x,r=e.y,s=t.x-n,i=t.y-r,o=e.width/2,a=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(i)*o>Math.abs(s)*a?(i<0&&(a=-a),c=a*s/i,l=a):(s<0&&(o=-o),c=o,l=o*i/s),{x:n+c,y:r+l}}function ng(e){let t=ua(ca(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function rg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Vn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function sg(e){let t=e.nodes().map(o=>e.node(o).rank),n=Vn(Math.min,t),r=[];e.nodes().forEach(o=>{let a=e.node(o).rank-n;r[a]||(r[a]=[]),r[a].push(o)});let s=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((o,a)=>{o===void 0&&a%i!==0?--s:o!==void 0&&s&&o.forEach(c=>e.node(c).rank+=s)})}function ig(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),oa(e,"border",s,t)}function og(e,t=aa){const n=[];for(let r=0;raa){const n=og(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function ca(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Vn(Math.max,n)}function ag(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function cg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function lg(e,t){return t()}let ug=0;function la(e){var t=++ug;return e+(""+t)}function ua(e,t,n=1){t==null&&(t=e,e=0);let r=i=>itr[t]),Object.entries(e).reduce((r,[s,i])=>(r[s]=n(i,s),r),{})}function Wr(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let hg=Yp,mg=Ne.uniqueId;var pg={run:gg,undo:xg};function gg(e){(e.graph().acyclicer==="greedy"?hg(e,n(e)):yg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,mg("rev"))});function n(r){return s=>r.edge(s).weight}}function yg(e){let t=[],n={},r={};function s(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(o=>{Object.hasOwn(n,o.w)?t.push(o):s(o.w)}),delete n[i])}return e.nodes().forEach(s),t}function xg(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let wg=Ne;var bg={run:vg,undo:Eg};function vg(e){e.graph().dummyChains=[],e.edges().forEach(t=>_g(e,t))}function _g(e,t){let n=t.v,r=e.node(n).rank,s=t.w,i=e.node(s).rank,o=t.name,a=e.edge(t),c=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Ng}=Ne;var Bn={longestPath:Sg,slack:kg};function Sg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let i=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var o=Ng(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}e.sources().forEach(n)}function kg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var jg=Ge.Graph,In=Bn.slack,da=Cg;function Cg(e){var t=new jg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,i;$g(t,e){var i=s.v,o=r===i?s.w:i;!e.hasNode(o)&&!In(t,s)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Mg(e,t){return t.edges().reduce((r,s)=>{let i=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(i=In(t,s)),it.node(r).rank+=n)}var Rg=da,Xs=Bn.slack,Ig=Bn.longestPath,Tg=Ge.alg.preorder,Og=Ge.alg.postorder,Lg=Ne.simplify,Dg=vt;vt.initLowLimValues=Xr;vt.initCutValues=Ur;vt.calcCutValue=fa;vt.leaveEdge=ma;vt.enterEdge=pa;vt.exchangeEdges=ga;function vt(e){e=Lg(e),Ig(e);var t=Rg(e);Xr(t),Ur(t,e);for(var n,r;n=ma(t);)r=pa(t,e,n),ga(t,e,n,r)}function Ur(e,t){var n=Og(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Pg(e,t,r))}function Pg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=fa(e,t,n)}function fa(e,t,n){var r=e.node(n),s=r.parent,i=!0,o=t.edge(n,s),a=0;return o||(i=!1,o=t.edge(s,n)),a=o.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===i,m=t.edge(c).weight;if(a+=d?m:-m,Hg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Xr(e,t){arguments.length<2&&(t=e.nodes()[0]),ha(e,{},1,t)}function ha(e,t,n,r,s){var i=n,o=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ha(e,t,n,a,r))}),o.low=i,o.lim=n++,s?o.parent=s:delete o.parent,n}function ma(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function pa(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var i=e.node(r),o=e.node(s),a=i,c=!1;i.lim>o.lim&&(a=o,c=!0);var l=t.edges().filter(u=>c===qs(e,e.node(u.v),a)&&c!==qs(e,e.node(u.w),a));return l.reduce((u,d)=>Xs(t,d)!t.node(s).parent),r=Tg(e,n);r=r.slice(1),r.forEach(s=>{var i=e.node(s).parent,o=t.edge(s,i),a=!1;o||(o=t.edge(i,s),a=!0),t.node(s).rank=t.node(i).rank+(a?o.minlen:-o.minlen)})}function Hg(e,t,n){return e.hasEdge(t,n)}function qs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Fg=Bn,ya=Fg.longestPath,Vg=da,Bg=Dg,Gg=Yg;function Yg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Ks(e);break;case"tight-tree":Ug(e);break;case"longest-path":Wg(e);break;case"none":break;default:Ks(e)}}var Wg=ya;function Ug(e){ya(e),Vg(e)}function Ks(e){Bg(e)}var Xg=qg;function qg(e){let t=Zg(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,i=Kg(e,t,s.v,s.w),o=i.path,a=i.lca,c=0,l=o[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=o[c])!==a&&e.node(l).maxRanko||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)i.push(c);return{path:s.concat(i.reverse()),lca:l}}function Zg(e){let t={},n=0;function r(s){let i=n;e.children(s).forEach(r),t[s]={low:i,lim:n++}}return e.children().forEach(r),t}let Tn=Ne;var Qg={run:Jg,cleanup:ny};function Jg(e){let t=Tn.addDummyNode(e,"root",{},"_root"),n=ey(e),r=Object.values(n),s=Tn.applyWithChunking(Math.max,r)-1,i=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let o=ty(e)+1;e.children().forEach(a=>xa(e,t,i,o,s,n,a)),e.graph().nodeRankFactor=i}function xa(e,t,n,r,s,i,o){let a=e.children(o);if(!a.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Tn.addBorderNode(e,"_bt"),l=Tn.addBorderNode(e,"_bb"),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,a.forEach(d=>{xa(e,t,n,r,s,i,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,p=m.borderBottom?m.borderBottom:d,y=m.borderTop?r:2*r,b=f!==p?1:s-i[o]+1;e.setEdge(c,f,{weight:y,minlen:b,nestingEdge:!0}),e.setEdge(p,l,{weight:y,minlen:b,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:s+i[o]})}function ey(e){var t={};function n(r,s){var i=e.children(r);i&&i.length&&i.forEach(o=>n(o,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function ty(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function ny(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let ry=Ne;var sy=iy;function iy(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;iQs(e.node(t))),e.edges().forEach(t=>Qs(e.edge(t)))}function Qs(e){let t=e.width;e.width=e.height,e.height=t}function ly(e){e.nodes().forEach(t=>sr(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(sr),Object.hasOwn(n,"y")&&sr(n)})}function sr(e){e.y=-e.y}function uy(e){e.nodes().forEach(t=>ir(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ir),Object.hasOwn(n,"x")&&ir(n)})}function ir(e){let t=e.x;e.x=e.y,e.y=t}let Js=Ne;var dy=fy;function fy(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=Js.applyWithChunking(Math.max,r),i=Js.range(s+1).map(()=>[]);function o(c){if(t[c])return;t[c]=!0;let l=e.node(c);i[l.rank].push(c),e.successors(c).forEach(o)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(o),i}let hy=Ne.zipObject;var my=py;function py(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),i=1;for(;i{let u=l.pos+i;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var yy=xy;function xy(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((i,o)=>{let a=e.edge(o),c=e.node(o.v);return{sum:i.sum+a.weight*c.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let wy=Ne;var by=vy;function vy(e,t){let n={};e.forEach((s,i)=>{let o=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i};s.barycenter!==void 0&&(o.barycenter=s.barycenter,o.weight=s.weight)}),t.edges().forEach(s=>{let i=n[s.v],o=n[s.w];i!==void 0&&o!==void 0&&(o.indegree++,i.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return _y(r)}function _y(e){let t=[];function n(s){return i=>{i.merged||(i.barycenter===void 0||s.barycenter===void 0||i.barycenter>=s.barycenter)&&Ey(s,i)}}function r(s){return i=>{i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>wy.pick(s,["vs","i","barycenter","weight"]))}function Ey(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let Ny=Ne;var Sy=ky;function ky(e,t){let n=Ny.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),i=[],o=0,a=0,c=0;r.sort(jy(!!t)),c=ei(i,s,c),r.forEach(u=>{c+=u.vs.length,i.push(u.vs),o+=u.barycenter*u.weight,a+=u.weight,c=ei(i,s,c)});let l={vs:i.flat(!0)};return a&&(l.barycenter=o/a,l.weight=a),l}function ei(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function jy(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Cy=yy,$y=by,My=Sy;var Ay=ba;function ba(e,t,n,r){let s=e.children(t),i=e.node(t),o=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,c={};o&&(s=s.filter(m=>m!==o&&m!==a));let l=Cy(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=ba(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&Iy(m,f)}});let u=$y(l,n);Ry(u,c);let d=My(u,r);if(o&&(d.vs=[o,d.vs,a].flat(!0),e.predecessors(o).length)){let m=e.node(e.predecessors(o)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function Ry(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function Iy(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let Ty=Ge.Graph,Oy=Ne;var Ly=Dy;function Dy(e,t,n,r){r||(r=e.nodes());let s=Py(e),i=new Ty({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(o=>e.node(o));return r.forEach(o=>{let a=e.node(o),c=e.parent(o);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(o),i.setParent(o,c||s),e[n](o).forEach(l=>{let u=l.v===o?l.w:l.v,d=i.edge(u,o),m=d!==void 0?d.weight:0;i.setEdge(u,o,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),i}function Py(e){for(var t;e.hasNode(t=Oy.uniqueId("_root")););return t}var zy=Hy;function Hy(e,t,n){let r={},s;n.forEach(i=>{let o=e.parent(i),a,c;for(;o;){if(a=e.parent(o),a?(c=r[a],r[a]=o):(c=s,s=o),c&&c!==o){t.setEdge(c,o);return}o=a}})}let Fy=dy,Vy=my,By=Ay,Gy=Ly,Yy=zy,Wy=Ge.Graph,yn=Ne;var Uy=va;function va(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,va);return}let n=yn.maxRank(e),r=ti(e,yn.range(1,n+1),"inEdges"),s=ti(e,yn.range(n-1,-1,-1),"outEdges"),i=Fy(e);if(ni(e,i),t&&t.disableOptimalOrderHeuristic)return;let o=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){Xy(c%2?r:s,c%4>=2),i=yn.buildLayerMatrix(e);let u=Vy(e,i);u{r.has(i)||r.set(i,[]),r.get(i).push(o)};for(const i of e.nodes()){const o=e.node(i);if(typeof o.rank=="number"&&s(o.rank,i),typeof o.minRank=="number"&&typeof o.maxRank=="number")for(let a=o.minRank;a<=o.maxRank;a++)a!==o.rank&&s(a,i)}return t.map(function(i){return Gy(e,i,n,r.get(i)||[])})}function Xy(e,t){let n=new Wy;e.forEach(function(r){let s=r.graph().root,i=By(r,s,n,t);i.vs.forEach((o,a)=>r.node(o).order=a),Yy(r,n,i.vs)})}function ni(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let qy=Ge.Graph,et=Ne;var Ky={positionX:a0};function Zy(e,t){let n={};function r(s,i){let o=0,a=0,c=s.length,l=i[i.length-1];return i.forEach((u,d)=>{let m=Jy(e,u),f=m?e.node(m).order:c;(m||u===l)&&(i.slice(a,d+1).forEach(p=>{e.predecessors(p).forEach(y=>{let b=e.node(y),g=b.order;(g{u=i[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&_a(n,m,u)})})}function s(i,o){let a=-1,c,l=0;return o.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(o,l,d,a,c),l=d,a=c)}r(o,l,o.length,c,i.length)}),o}return t.length&&t.reduce(s),n}function Jy(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function _a(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function e0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function t0(e,t,n,r){let s={},i={},o={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,i[c]=c,o[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>o[m]-o[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let p=u[m];i[l]===l&&cMath.max(m,i[f.v]+o.edge(f)),0)}function u(d){let m=o.outEdges(d).reduce((p,y)=>Math.min(p,i[y.w]-o.edge(y)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(i[d]=Math.max(i[d],m))}return c(l,o.predecessors.bind(o)),c(u,o.successors.bind(o)),Object.keys(r).forEach(d=>i[d]=i[n[d]]),i}function r0(e,t,n,r){let s=new qy,i=e.graph(),o=c0(i.nodesep,i.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(o(e,l,c),m||0))}c=l})}),s}function s0(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=l0(e,a)/2;s=Math.max(c+l,s),i=Math.min(c-l,i)});const o=s-i;return o{["l","r"].forEach(o=>{let a=i+o,c=e[a];if(c===t)return;let l=Object.values(c),u=r-et.applyWithChunking(Math.min,l);o!=="l"&&(u=s-et.applyWithChunking(Math.max,l)),u&&(e[a]=et.mapValues(c,d=>d+u))})})}function o0(e,t){return et.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(i=>i[r]).sort((i,o)=>i-o);return(s[1]+s[2])/2}})}function a0(e){let t=et.buildLayerMatrix(e),n=Object.assign(Zy(e,t),Qy(e,t)),r={},s;["u","d"].forEach(o=>{s=o==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(o==="u"?e.predecessors:e.successors).bind(e),l=t0(e,s,n,c),u=n0(e,s,l.root,l.align,a==="r");a==="r"&&(u=et.mapValues(u,d=>-d)),r[o+a]=u})});let i=s0(e,r);return i0(r,i),o0(r,e.graph().align)}function c0(e,t,n){return(r,s,i)=>{let o=r.node(s),a=r.node(i),c=0,l;if(c+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":l=-o.width/2;break;case"r":l=o.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(o.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function l0(e,t){return e.node(t).width}let Ea=Ne,u0=Ky.positionX;var d0=f0;function f0(e){e=Ea.asNonCompoundGraph(e),h0(e),Object.entries(u0(e)).forEach(([t,n])=>e.node(t).x=n)}function h0(e){let t=Ea.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const i=s.reduce((o,a)=>{const c=e.node(a).height;return o>c?o:c},0);s.forEach(o=>e.node(o).y=r+i/2),r+=i+n})}let ri=pg,si=bg,m0=Gg,p0=Ne.normalizeRanks,g0=Xg,y0=Ne.removeEmptyRanks,ii=Qg,x0=sy,oi=oy,w0=Uy,b0=d0,Pe=Ne,v0=Ge.Graph;var _0=E0;function E0(e,t){let n=t&&t.debugTiming?Pe.time:Pe.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>I0(e));n(" runLayout",()=>N0(r,n,t)),n(" updateInputGraph",()=>S0(e,r))})}function N0(e,t,n){t(" makeSpaceForEdgeLabels",()=>T0(e)),t(" removeSelfEdges",()=>B0(e)),t(" acyclic",()=>ri.run(e)),t(" nestingGraph.run",()=>ii.run(e)),t(" rank",()=>m0(Pe.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>O0(e)),t(" removeEmptyRanks",()=>y0(e)),t(" nestingGraph.cleanup",()=>ii.cleanup(e)),t(" normalizeRanks",()=>p0(e)),t(" assignRankMinMax",()=>L0(e)),t(" removeEdgeLabelProxies",()=>D0(e)),t(" normalize.run",()=>si.run(e)),t(" parentDummyChains",()=>g0(e)),t(" addBorderSegments",()=>x0(e)),t(" order",()=>w0(e,n)),t(" insertSelfEdges",()=>G0(e)),t(" adjustCoordinateSystem",()=>oi.adjust(e)),t(" position",()=>b0(e)),t(" positionSelfEdges",()=>Y0(e)),t(" removeBorderNodes",()=>V0(e)),t(" normalize.undo",()=>si.undo(e)),t(" fixupEdgeLabelCoords",()=>H0(e)),t(" undoCoordinateSystem",()=>oi.undo(e)),t(" translateGraph",()=>P0(e)),t(" assignNodeIntersects",()=>z0(e)),t(" reversePoints",()=>F0(e)),t(" acyclic.undo",()=>ri.undo(e))}function S0(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let k0=["nodesep","edgesep","ranksep","marginx","marginy"],j0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},C0=["acyclicer","ranker","rankdir","align"],$0=["width","height","rank"],ai={width:0,height:0},M0=["minlen","weight","width","height","labeloffset"],A0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},R0=["labelpos"];function I0(e){let t=new v0({multigraph:!0,compound:!0}),n=ar(e.graph());return t.setGraph(Object.assign({},j0,or(n,k0),Pe.pick(n,C0))),e.nodes().forEach(r=>{let s=ar(e.node(r));const i=or(s,$0);Object.keys(ai).forEach(o=>{i[o]===void 0&&(i[o]=ai[o])}),t.setNode(r,i),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=ar(e.edge(r));t.setEdge(r,Object.assign({},A0,or(s,M0),Pe.pick(s,R0)))}),t}function T0(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function O0(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),i={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};Pe.addDummyNode(e,"edge-proxy",i,"_ep")}})}function L0(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function D0(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function P0(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,i=e.graph(),o=i.marginx||0,a=i.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=o,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),i.width=n-t+o,i.height=s-r+a}function z0(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),i,o;n.points?(i=n.points[0],o=n.points[n.points.length-1]):(n.points=[],i=s,o=r),n.points.unshift(Pe.intersectRect(r,i)),n.points.push(Pe.intersectRect(s,o))})}function H0(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function F0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function V0(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-i.x),n.height=Math.abs(s.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function B0(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function G0(e){var t=Pe.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,i)=>{var o=e.node(s);o.order=i+r,(o.selfEdges||[]).forEach(a=>{Pe.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:o.rank,order:i+ ++r,e:a.e,label:a.label},"_se")}),delete o.selfEdges})})}function Y0(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,i=r.y,o=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*o/3,y:i-a},{x:s+5*o/6,y:i-a},{x:s+o,y:i},{x:s+5*o/6,y:i+a},{x:s+2*o/3,y:i+a}],n.label.x=n.x,n.label.y=n.y}})}function or(e,t){return Pe.mapValues(Pe.pick(e,t),Number)}function ar(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let W0=Ne,U0=Ge.Graph;var X0={debugOrdering:q0};function q0(e){let t=W0.buildLayerMatrix(e),n=new U0({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),r.reduce((o,a)=>(n.setEdge(o,a,{style:"invis"}),a))}),n}var K0="1.1.8",Z0={graphlib:Ge,layout:_0,debug:X0,util:{time:Ne.time,notime:Ne.notime},version:K0};const ci=bi(Z0),Ue=264,Q0=44,J0=26,ex=14;function dt(e){const t=Math.max(e.attributes.length,1);return Q0+t*J0+ex}const tx=40;function cr(e,t,n,r="auto",s,i="LR"){const o=nx(n,s);return r==="grid"?fi(e,n,o):r==="clustered"?di(e,t,n,o,i):r==="hierarchical"||e.length<=tx?li(e,t,n,i):new Set(e.map(c=>o(c.id)).filter(Boolean)).size>1?di(e,t,n,o,i):fi(e,n,o)}function nx(e,t){return n=>{var r,s,i;if(t){const o=t.get(n);if(o)return o.name}return((i=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:i.name)??""}}function Na(e,t,n,r=!1,s="LR"){const i=new ci.graphlib.Graph;i.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),i.setDefaultEdgeLabel(()=>({}));const o=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);i.setNode(u.id,{width:Ue,height:d?dt(d):120})}for(const u of t)o.has(u.source)&&o.has(u.target)&&i.setEdge(u.source,u.target,{minlen:1,weight:2});ci.layout(i);let a=0,c=0;return{nodes:e.map(u=>{const d=i.node(u.id),m=n.get(u.id),f=m?dt(m):120,p=d.x-Ue/2,y=d.y-f/2;return a=Math.max(a,p+Ue),c=Math.max(c,y+f),{...u,position:{x:p,y}}}),width:a,height:c}}function li(e,t,n,r="LR"){return Na(e,t,n,!1,r).nodes}function rx(e,t){const n=a=>{const c=t.get(a);return c?dt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let i=0,o=0;for(let a=0;a{const d=u*(Ue+Sa);s.push({...l,position:{x:d,y:i}}),o=Math.max(o,d+Ue)}),i+=Math.max(...c.map(l=>n(l.id)))+ka}return{nodes:s,width:o,height:i}}const ui=120;function di(e,t,n,r,s="LR"){const i=new Map;for(const m of e){const f=r(m.id);(i.get(f)??i.set(f,[]).get(f)).push(m)}const a=[...i.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=i.get(m),p=new Set(f.map(E=>E.id));let y=0;for(const E of t)p.has(E.source)&&p.has(E.target)&&y++;const g=f.length<=8&&y>=f.length-1?Na(f,t,n,!0,s):rx(f,n);return{name:m,...g}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const Sa=40,ka=40;function fi(e,t,n){const r=l=>{const u=t.get(l);return u?dt(u):120},s=[...e].sort((l,u)=>{var y,b;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((y=t.get(l.id))==null?void 0:y.name)??l.id,p=((b=t.get(u.id))==null?void 0:b.name)??u.id;return f.localeCompare(p)}),i=Math.max(1,Math.round(Math.sqrt(s.length))),o=Array.from({length:i},(l,u)=>u*(Ue+Sa)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:o[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+ka}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function an({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const sx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],ja=["industry","core","domain","specialised"];function ix({entity:e,exec:t,onClose:n}){var v,M;const[r,s]=w.useState(((v=e.conceptual)==null?void 0:v.name)??e.name),[i,o]=w.useState([]),[a,c]=w.useState(null),[l,u]=w.useState(null),[d,m]=w.useState("skos:exactMatch"),[f,p]=w.useState(((M=e.conceptual)==null?void 0:M.ontology_layer)??"core"),[y,b]=w.useState([]),[g,E]=w.useState("");w.useEffect(()=>{Zo().then(j=>b(j.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return o([]);Ko(r,g||void 0).then(_=>{o(_.results),c(_.loaded_terms)}).catch(()=>o([]))},200);return()=>clearTimeout(j)},[r,g]);const C=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(an,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[y.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(g===""?" active":""),onClick:()=>E(""),children:"all sources"}),y.map(j=>h.jsx("button",{className:"src-chip"+(g===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:g?`Search within ${g}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&y.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[i.map(j=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===j.iri?" picked":""),onClick:()=>u(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&i.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:sx.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>p(j.target.value),children:ja.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:C,children:["Align",l?` to ${l.label}`:""]})]})]})}function ox({entity:e,doc:t,exec:n,onClose:r}){var v,M,j;const[s,i]=w.useState(((v=e.term_map)==null?void 0:v.subject_template)??""),[o,a]=w.useState(((M=e.term_map)==null?void 0:M.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=u.length===0&&d(o),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:o.trim()||null}).then(r)},p=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",y=t.project.kg_base_iri||`urn:${p}:`,b=(j=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:j.members.map(_=>{var I;return(I=e.attributes.find(N=>N.id===_))==null?void 0:I.name}).filter(Boolean),g=b&&b.length?`${y}${e.id}/${b.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=o.trim()||`${y}${e.id}`,C=s.trim()||g;return h.jsxs(an,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:o,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(o)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>i(_.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",C]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((b==null?void 0:b[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function ax({doc:e,exec:t,onClose:n,onCreated:r}){const[s,i]=w.useState(""),[o,a]=w.useState(""),[c,l]=w.useState(""),[u,d]=w.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:o||null,subject_area:c||null,layer:u||null}).then(f=>{const p=f==null?void 0:f.created_id;n(),p&&r(p)})};return h.jsxs(an,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>i(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:o,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),ja.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const Ca=["many_to_one","one_to_many","one_to_one","many_to_many"];function cx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:i,onClose:o}){const a=e.entities.find(v=>v.id===t),c=e.entities.find(v=>v.id===n),l=w.useMemo(()=>c==null?void 0:c.attributes.find(v=>v.role==="business_key"),[c]),[u,d]=w.useState(r??""),[m,f]=w.useState(s??(l==null?void 0:l.id)??""),[p,y]=w.useState("many_to_one"),[b,g]=w.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",C=()=>i("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:p,optionality:b}).then(o);return h.jsxs(an,{title:`${a.name} → ${c.name}`,onClose:o,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:p,onChange:v=>y(v.target.value),children:Ca.map(v=>h.jsx("option",{children:v},v))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:v=>d(v.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(v=>h.jsx("option",{value:v.id,children:v.name},v.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:v=>f(v.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(v=>h.jsxs("option",{value:v.id,children:[v.name,v.role==="business_key"?" 🔑":""]},v.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:b,onChange:v=>g(v.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:C,children:"Create relationship"})})]})}function lx({rel:e,doc:t,exec:n,onClose:r}){const s=g=>{var E;return((E=t.entities.find(C=>C.id===g))==null?void 0:E.name)??"?"},[i,o]=w.useState(e.name),[a,c]=w.useState(e.cardinality),[l,u]=w.useState(e.optionality),[d,m]=w.useState(e.identifying),[f,p]=w.useState(!1),y=async()=>{i.trim()&&i.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:i.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},b=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(an,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:i,onChange:g=>o(g.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:g=>c(g.target.value),children:Ca.map(g=>h.jsx("option",{children:g},g))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:g=>u(g.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:g=>m(g.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:b,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>p(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:y,children:"Save"})]})]})}const hi=10,ux=6,$t=24;function dx(e,t){return t?e:Math.round(e/hi)*hi}function fx(e,t,n){const r=[...t];for(const o of n)r.push(o.left-$t,o.right+$t);let s=e,i=ux;for(const o of r){const a=Math.abs(o-e);at.left&&eo.left&&ni.left&&n=o.right?(u.push({x:n,y:t.y},{x:o.right,y:t.y}),m={ox:1,oy:0}):(u.push({x:n,y:t.y},{x:o.left,y:t.y}),m={ox:-1,oy:0});return{path:yx(u),sourceOut:d,targetOut:m}}const pi=3,wx=w.memo(function({id:t,sourceX:n,sourceY:r,targetX:s,targetY:i,sourcePosition:o,targetPosition:a,data:c,selected:l}){const{screenToFlowPosition:u}=on(),d=he(te=>te.transform[2]),[m,f]=w.useState(null),p=w.useRef(!1),y=w.useRef(0),b=c==null?void 0:c.onRouteChange,g=!!b,E=m??(c==null?void 0:c.routeX),[C,v,M]=Mn({sourceX:n,sourceY:r,sourcePosition:o,targetX:s,targetY:i,targetPosition:a,borderRadius:10,...E!=null?{centerX:E}:{}}),j=c==null?void 0:c.sourceCard,_=c==null?void 0:c.targetCard,I=E!=null&&j&&_?xx({x:n,y:r},{y:i},E,o===U.Left?-1:1,a===U.Left?-1:1,j,_):null,N=I?I.path:C,R=c==null?void 0:c.relationship,P=(c==null?void 0:c.dimmed)??!1,V=(R==null?void 0:R.cardinality)??"many_to_one",H=(R==null?void 0:R.optionality)==="optional",x=(R==null?void 0:R.identifying)??!1,$=V==="many_to_one"||V==="many_to_many",S=V==="one_to_many"||V==="many_to_many",O="rel-edge"+(l?" selected":"")+(P?" dimmed":""),D=((c==null?void 0:c.memberCount)??0)>1,k=c==null?void 0:c.onHoverEdge,T=E??v,L=M,z=T,W=L,G=I?I.sourceOut:{ox:o===U.Left?-1:1,oy:0},X=I?I.targetOut:{ox:a===U.Left?-1:1,oy:0},Z={x:n,y:r},ne=I&&_?X.oy!==0?{x:E,y:X.oy<0?_.top:_.bottom}:{x:X.ox>0?_.right:_.left,y:i}:{x:s,y:i},ie=w.useCallback(te=>b&&R&&b(R.id,te),[b,R]),re=w.useCallback(te=>{var _e,je;if(!g||te.button!==0)return;te.stopPropagation(),(je=(_e=te.target).setPointerCapture)==null||je.call(_e,te.pointerId),p.current=!0,y.current=0;const ve=u({x:te.clientX,y:te.clientY}).x;let de=0,pe=E??T;const le=ze=>{const $e=u({x:ze.clientX,y:ze.clientY});y.current=Math.max(y.current,Math.abs($e.x-ve)),pe=mx($e.x,{shift:ze.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),de||(de=requestAnimationFrame(()=>{de=0,f(pe)}))},q=()=>{window.removeEventListener("pointermove",le),window.removeEventListener("pointerup",q),de&&cancelAnimationFrame(de),p.current=!1,f(null),y.current>=pi&&ie(pe)};window.addEventListener("pointermove",le),window.addEventListener("pointerup",q)},[g,u,E,T,c,n,s,ie]),ae=w.useCallback(te=>{y.current>=pi&&(te.stopPropagation(),y.current=0)},[]),ye=w.useCallback(te=>{g&&(te.stopPropagation(),ie(null))},[g,ie]);return h.jsxs("g",{className:O,onMouseEnter:k?()=>k(R.id):void 0,onMouseLeave:k?()=>k(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:N,fill:"none",strokeDasharray:x?void 0:"6 4"}),h.jsx("path",{d:N,fill:"none",strokeWidth:16/d,stroke:"transparent"}),h.jsx(gi,{x:Z.x,y:Z.y,out:G,many:$,optional:H}),h.jsx(gi,{x:ne.x,y:ne.y,out:X,many:S,optional:!1}),g&&((c==null?void 0:c.hovered)||l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:re,onClickCapture:ae,onDoubleClick:ye,children:[h.jsx("rect",{x:T-20/d,y:Math.min(r,i),width:40/d,height:Math.max(Math.abs(i-r),24/d),fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:T-5.5/d,y:L-11/d,width:11/d,height:22/d,rx:5/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L-4.5/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:T,cy:L+4.5/d,r:1.1/d})]}),(l||D)&&R&&h.jsxs("text",{className:"rel-label",x:z,y:W-8,children:[l?R.verb_phrase||R.name:"",D?`${l?" ":""}(${c.memberCount})`:""]})]})});function gi({x:e,y:t,out:n,many:r,optional:s}){const{ox:a,oy:c}=n,l=-c,u=a,d=p=>({x:e+a*p,y:t+c*p}),m=(p,y)=>({x:e+a*p+l*y,y:t+c*p+u*y}),f=[];if(r){const p=d(12),y=m(0,-7),b=d(0),g=m(0,7);f.push(h.jsx("path",{className:"rel-glyph",d:`M ${p.x} ${p.y} L ${y.x} ${y.y} M ${p.x} ${p.y} L ${b.x} ${b.y} M ${p.x} ${p.y} L ${g.x} ${g.y}`,fill:"none"},"foot"))}else{const p=m(9,-7),y=m(9,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:y.x,y2:y.y},"one"))}if(s){const p=d(18);f.push(h.jsx("circle",{className:"rel-glyph ring",cx:p.x,cy:p.y,r:4},"opt"))}else{const p=m(17,-7),y=m(17,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:y.x,y2:y.y},"mand"))}return h.jsx(h.Fragment,{children:f})}const bx={entity:Pm},vx={relationship:wx},yi=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],xi="#8a7d6a";function _x(e,t,n){const s=Ue;let{x:i,y:o}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)il.x&&ol.y&&(o=l.y+l.h+16,a=!0)}return{x:i,y:o}}function Ex(e,t){const n=(i,o)=>{var a;return!!o&&!!((a=t.get(i))!=null&&a.attributes.some(c=>c.id===o))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Br,targetHandle:n(e.to.entity,s)?s:Gr}}function Jx({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:i="",showTypes:o=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:p,fitBounds:y,getNodes:b}=on(),[g,E]=w.useState([]),[C,v]=w.useState([]),M=w.useRef(!1),j=w.useMemo(()=>{const F=u&&u.size>0?[...u].sort():null;return F?"sa:"+F.join("+"):"__all__"},[u]),_=w.useRef(null),[I,N]=w.useState(0),R=w.useRef(new Map),P=w.useRef(null);w.useEffect(()=>{if(!f){_.current=null;return}const F=R.current.get(j);if(F){_.current=F,M.current=!1,N(B=>B+1);return}let Y=!1;return f.load(j).then(B=>{Y||(R.current.set(j,B),_.current=B,M.current=!1,N(Q=>Q+1))}),()=>{Y=!0}},[f,j]);const[V,H]=w.useState(null),[x,$]=w.useState(null),[S,O]=w.useState(!1),[D,k]=w.useState(null),[T,L]=w.useState(null),[z,W]=w.useState(null),[G,X]=w.useState(null),Z=w.useRef({}),ne=!t.canEdit,ie=w.useRef(null),re=w.useCallback(()=>{f&&(ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>{const F={};for(const Q of b())Q.hidden||(F[Q.id]={x:Math.round(Q.position.x),y:Math.round(Q.position.y)});const Y={};for(const[Q,K]of Object.entries(Z.current))Y[Q]={routeX:Math.round(K)};const B={nodes:F,edges:Y};R.current.set(j,B),_.current=B,f.save(j,B)},800))},[f,b,j]),ae=w.useCallback((F,Y)=>{Y==null?delete Z.current[F]:Z.current[F]=Y,v(B=>B.map(Q=>Q.id===F?{...Q,data:{...Q.data,routeX:Y??void 0}}:Q)),re()},[re]),ye=w.useMemo(()=>{const F=new Map;return e.subject_areas.forEach((Y,B)=>F.set(Y.id,yi[B%yi.length])),F},[e]),te=w.useMemo(()=>{const F=new Map;return e.entities.forEach(Y=>F.set(Y.id,Y)),F},[e]),me=w.useMemo(()=>{const F=new Map,Y=new Map;return e.subject_areas.forEach(B=>{(B.members??[]).forEach(Q=>Y.set(Q,{id:B.id,name:B.name}))}),e.entities.forEach(B=>{var se,ge;const Q=(se=B.conceptual)!=null&&se.id?Y.get(B.conceptual.id):void 0,K=(ge=B.conceptual)==null?void 0:ge.subject_area,ee=Q??(K?{id:K.id,name:K.name??K.id}:void 0);ee&&F.set(B.id,ee)}),F},[e]),ve=w.useCallback(F=>{var B;if(!u||u.size===0)return!1;const Y=(B=me.get(F))==null?void 0:B.id;return!(Y&&u.has(Y))},[u,me]),de=w.useMemo(()=>{const F=new Map,Y=(B,Q)=>{if(!Q.length)return;const K=F.get(B)??new Set;Q.forEach(ee=>K.add(ee)),F.set(B,K)};for(const B of e.relationships)Y(B.from.entity,B.from.attributes),Y(B.to.entity,B.to.attributes);return F},[e]);w.useEffect(()=>{var ge;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const J of e.entities)(J.name.toLowerCase()+" "+(((ge=J.conceptual)==null?void 0:ge.name.toLowerCase())??"")+" "+J.attributes.map(ce=>ce.name.toLowerCase()).join(" ")).includes(F)&&Y.add(J.id);const B=new Set;if(r){B.add(r);for(const J of e.relationships)J.from.entity===r&&B.add(J.to.entity),J.to.entity===r&&B.add(J.from.entity)}const Q=e.entities.map(J=>{const fe=F!==""&&!Y.has(J.id),ce=r!==null&&!B.has(J.id);return{id:J.id,type:"entity",position:{x:0,y:0},hidden:ve(J.id),data:{entity:J,color:(()=>{const xe=me.get(J.id);return xe?ye.get(xe.id)??xi:xi})(),dimmed:fe||ce,highlighted:F!==""&&Y.has(J.id),showTypes:o,collapseDetail:a,expanded:(c==null?void 0:c.has(J.id))??!1,onToggleExpand:l,endpointAttrs:de.get(J.id),highlightAttrs:void 0,onHoverAttr:W}}}),K=e.relationships.filter(J=>te.has(J.from.entity)&&te.has(J.to.entity)).map(J=>{const{sourceHandle:fe,targetHandle:ce}=Ex(J,te),xe=r!==null&&J.from.entity!==r&&J.to.entity!==r;return{id:J.id,source:J.from.entity,target:J.to.entity,sourceHandle:fe,targetHandle:ce,type:"relationship",data:{relationship:J,dimmed:xe,memberCount:Math.max(J.from.attributes.length,J.to.attributes.length),onHoverEdge:X}}}),ee=_.current;if(Z.current={},ee)for(const[J,fe]of Object.entries(ee.edges))Z.current[J]=fe.routeX;const se=J=>{const fe=new Map;for(const ce of J)fe.set(ce.id,{left:ce.position.x,right:ce.position.x+Ue,top:ce.position.y,bottom:ce.position.y+dt(ce.data.entity)});v(K.map(ce=>({...ce,data:{...ce.data,routeX:Z.current[ce.id],onRouteChange:f?ae:void 0,sourceCard:fe.get(ce.source),targetCard:fe.get(ce.target)}})))};E(J=>{const fe=new Map(J.map(ue=>[ue.id,ue.position])),ce=Q.every(ue=>fe.has(ue.id)),xe=((u==null?void 0:u.size)??0)>0;if(M.current&&ce&&J.length>=Q.length&&!xe){const ue=Q.map(Ze=>({...Ze,position:fe.get(Ze.id)??Ze.position}));return se(ue),ue}const Me=xe?Q.filter(ue=>!ue.hidden):Q,Ye=cr(Me,K,te,"auto",me),Ke=new Map(Ye.map(ue=>[ue.id,ue.position])),Te=(ee==null?void 0:ee.nodes)??{},_t=Object.keys(Te).length>0,Et=[],He=Q.map(ue=>{const Ze=Te[ue.id];if(Ze){const Dt={x:Ze.x,y:Ze.y};return Et.push({x:Dt.x,y:Dt.y,w:Ue,h:dt(ue.data.entity)}),{...ue,position:Dt}}return Ke.has(ue.id)?{...ue,position:Ke.get(ue.id)}:fe.has(ue.id)&&M.current?{...ue,position:fe.get(ue.id)}:ue});if(_t)for(const ue of He)Te[ue.id]||ue.hidden||(ue.position=_x(ue.position,dt(ue.data.entity),Et),Et.push({x:ue.position.x,y:ue.position.y,w:Ue,h:dt(ue.data.entity)}));return M.current=!0,_t||requestAnimationFrame(()=>p({padding:.15,duration:300})),se(He),He})},[e,i,r,o,a,c,l,ye,te,me,ve,u,de,p,f,ae,I]);const pe=w.useMemo(()=>{const F=new Set,Y=new Set,B=new Map,Q=(K,ee)=>{if(!ee.length)return;const se=B.get(K)??new Set;ee.forEach(ge=>se.add(ge)),B.set(K,se)};if(z)for(const K of e.relationships)(K.from.attributes.includes(z)||K.to.attributes.includes(z))&&(F.add(K.id),Y.add(K.from.entity),Y.add(K.to.entity),Q(K.from.entity,K.from.attributes),Q(K.to.entity,K.to.attributes));if(G){const K=e.relationships.find(ee=>ee.id===G);K&&(Q(K.from.entity,K.from.attributes),Q(K.to.entity,K.to.attributes))}return{active:z!==null,relsForAttr:F,entsForAttr:Y,hitAttrsByEntity:B}},[e,z,G]);w.useEffect(()=>{var Q;const F=i.trim().toLowerCase(),Y=new Set;if(F)for(const K of e.entities)(K.name.toLowerCase()+" "+(((Q=K.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+K.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(K.id);const B=new Set;if(r){B.add(r);for(const K of e.relationships)K.from.entity===r&&B.add(K.to.entity),K.to.entity===r&&B.add(K.from.entity)}E(K=>K.map(ee=>{const se=F!==""&&!Y.has(ee.id),ge=r!==null&&!B.has(ee.id),J=pe.active&&!pe.entsForAttr.has(ee.id),fe=se||ge||J,ce=F!==""&&Y.has(ee.id)||pe.active&&pe.entsForAttr.has(ee.id),xe=pe.hitAttrsByEntity.get(ee.id);return ee.data.dimmed===fe&&ee.data.highlighted===ce&&ee.data.highlightAttrs===xe?ee:{...ee,data:{...ee.data,dimmed:fe,highlighted:ce,highlightAttrs:xe}}})),v(K=>K.map(ee=>{var Ye,Ke,Te;const se=(Ye=ee.data)==null?void 0:Ye.relationship,ge=r!==null&&se!==void 0&&se.from.entity!==r&&se.to.entity!==r,J=pe.active&&!pe.relsForAttr.has(ee.id),fe=ge||J,ce=G===ee.id,xe=r!==null&&se!==void 0&&(se.from.entity===r||se.to.entity===r),Me=ce||xe?1e3:0;return((Ke=ee.data)==null?void 0:Ke.dimmed)===fe&&((Te=ee.data)==null?void 0:Te.hovered)===ce&&ee.zIndex===Me?ee:{...ee,zIndex:Me,data:{...ee.data,dimmed:fe,hovered:ce}}}))},[pe,G,i,r,e]),w.useEffect(()=>{var Q;const F=i.trim().toLowerCase();if(!F)return;const Y=new Set;for(const K of e.entities)(K.name.toLowerCase()+" "+(((Q=K.conceptual)==null?void 0:Q.name.toLowerCase())??"")+" "+K.attributes.map(se=>se.name.toLowerCase()).join(" ")).includes(F)&&Y.add(K.id);if(!Y.size)return;const B=requestAnimationFrame(()=>{const K=b().filter(se=>Y.has(se.id));if(!K.length)return;const ee=Mf(K);y(ee,{padding:.35,duration:400})});return()=>cancelAnimationFrame(B)},[i,e,b,y]);const le=w.useCallback((F="auto",Y="LR")=>{P.current=Object.fromEntries(b().map(B=>[B.id,{x:B.position.x,y:B.position.y}])),E(B=>cr(B,C,te,F,me,Y)),requestAnimationFrame(()=>p({padding:.15,duration:300})),re()},[C,te,me,p,b,re]),q=w.useCallback(()=>{const F=P.current;F&&(E(Y=>Y.map(B=>F[B.id]?{...B,position:F[B.id]}:B)),P.current=null,re())},[re]),_e=w.useCallback(()=>{f==null||f.reset(j),R.current.delete(j),_.current=null,Z.current={},M.current=!1,v(F=>F.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(F=>{const Y=cr(F,C,te,"auto",me);return requestAnimationFrame(()=>p({padding:.15,duration:300})),Y})},[f,j,C,te,me,p]),je=w.useCallback(F=>{s(F),E(Y=>(Y.find(Q=>Q.id===F)&&requestAnimationFrame(()=>p({nodes:[{id:F}],padding:.4,duration:400})),Y))},[p,s]);w.useImperativeHandle(m,()=>({relayout:le,fitView:()=>p({padding:.15,duration:300}),focusEntity:je,newEntity:()=>O(!0),resetLayout:_e,undoRelayout:q}),[le,p,je,_e,q]);const ze=w.useCallback(F=>{if(ne||!F.source||!F.target||F.source===F.target)return;const Y=F.sourceHandle&&F.sourceHandle!==Br?F.sourceHandle:void 0,B=F.targetHandle&&F.targetHandle!==Gr?F.targetHandle:void 0;k({from:F.source,to:F.target,fromAttr:Y,toAttr:B})},[ne]),$e=w.useCallback(async(F,Y)=>{try{return await n(F,Y)}catch(B){throw d==null||d(B instanceof Error?B.message:String(B)),B}},[n,d]),qe=r?te.get(r)??null:null,Ie=e.relationships.find(F=>F.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Go,{nodes:g,edges:C,nodeTypes:bx,edgeTypes:vx,onNodeClick:(F,Y)=>s(Y.id),onEdgeDoubleClick:(F,Y)=>!ne&&L(Y.id),onPaneClick:()=>{s(null),L(null)},onNodeDragStop:(F,Y)=>{E(B=>B.map(Q=>Q.id===Y.id?{...Q,position:Y.position}:Q)),re()},onConnect:ze,nodesConnectable:!ne,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(_m,{variant:De.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(lm,{pannable:!0,zoomable:!0,nodeColor:F=>{var Y;return((Y=F.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(gm,{showInteractive:!1})]}),qe&&h.jsx(Hm,{entity:qe,doc:e,caps:t,exec:$e,onClose:()=>s(null),onFocusEntity:je,onAlign:H,onEditMapping:$}),V&&h.jsx(ix,{entity:V,exec:$e,onClose:()=>H(null)}),x&&h.jsx(ox,{entity:x,doc:e,exec:$e,onClose:()=>$(null)}),S&&h.jsx(ax,{doc:e,exec:$e,onClose:()=>O(!1),onCreated:je}),D&&h.jsx(cx,{doc:e,fromId:D.from,toId:D.to,initialFromAttr:D.fromAttr,initialToAttr:D.toAttr,exec:$e,onClose:()=>k(null)}),Ie&&h.jsx(lx,{rel:Ie,doc:e,exec:$e,onClose:()=>L(null)})]})}function ew({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:i}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(Nx,{}),e==="layers"&&h.jsx(kx,{refreshKey:r,onFocusEntity:i}),e==="changes"&&h.jsx(jx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Cx,{readOnly:n})]})}function Nx(){const[e,t]=w.useState(""),[n,r]=w.useState([]),[s,i]=w.useState({loaded:0,vocabs:[]}),[o,a]=w.useState(null),[c,l]=w.useState([]),[u,d]=w.useState("");w.useEffect(()=>{Zo().then(f=>l(f.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const f=setTimeout(()=>{Ko(e||"a",u||void 0).then(p=>{r(e?p.results:[]),i({loaded:p.loaded_terms,vocabs:p.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=w.useCallback(f=>{Em(f).then(a).catch(()=>{})},[]);return o?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:o.label}),h.jsx("code",{className:"term-iri",children:o.prefixed}),o.definition&&h.jsx("p",{className:"term-def",children:o.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:o.source})]}),o.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),o.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),o.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),o.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const Sx=["industry","core","domain","specialised"];function kx({refreshKey:e,onFocusEntity:t}){const[n,r]=w.useState(null),[s,i]=w.useState(null);if(w.useEffect(()=>{Nm().then(r).catch(()=>{}),Sm().then(i).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const o=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),Sx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(o.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function jx({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=w.useState(null),[i,o]=w.useState(""),[a,c]=w.useState(""),[l,u]=w.useState(!1),d=w.useCallback(()=>{jm().then(s).catch(()=>s(null)),Cm().then(m=>o([m.diff,...m.untracked].filter(Boolean).join(` - -`))).catch(()=>o(""))},[]);return w.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:i.split(` -`).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` -`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:l,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(u(!0),Mm().then(()=>{u(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:l||!a.trim(),onClick:()=>{u(!0),$m(a).then(()=>{u(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Cx({readOnly:e}){const[t,n]=w.useState([]),r=w.useCallback(()=>{Am().then(i=>n(i.decisions)).catch(()=>n([]))},[]);if(w.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(i=>h.jsxs("div",{className:"decision "+i.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[i.verdict]}),h.jsx("span",{className:"chip",children:i.confidence}),h.jsx("span",{className:"chip",children:i.signal})]}),h.jsx("p",{className:"decision-subject",children:i.subject}),!e&&i.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Fs(i.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Fs(i.signal_key,"rejected").then(r),children:"Reject"})]})]},i.signal_key))})}function tw({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:i,openImport:o=!1,prefillImport:a="",onPreview:c}){const[l,u]=w.useState(o&&t?"import":null),[d,m]=w.useState([]),[f,p]=w.useState("postgres"),y=w.useRef(null);w.useEffect(()=>{Rm().then(g=>m(g.formats)).catch(()=>m([]))},[]),w.useEffect(()=>{if(!l)return;const g=E=>{y.current&&!y.current.contains(E.target)&&u(null)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[l]);const b=d.find(g=>g.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:y,children:[h.jsxs("button",{className:s+(l==="export"?" on":""),onClick:()=>u(l==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(l==="import"?" on":""),onClick:()=>u(l==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),l==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(b==null?void 0:b.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:g=>p(g.target.value),children:b.dialects.map(g=>h.jsx("option",{value:g,children:g},g))})]}),d.map(g=>h.jsx("a",{className:"ie-item",href:Im(g.id,g.id==="sql"?f:void 0),download:!0,onClick:()=>u(null),children:g.label},g.id))]}),l==="import"&&h.jsx($x,{exec:e,submitLabel:r,buttonClass:s,applyBatch:i,onClose:()=>u(null),onImported:g=>{u(null),n==null||n(g)},onPreview:c,prefillImport:a})]})}const wi=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function $x({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:i,onPreview:o,prefillImport:a}){var j;const[c,l]=w.useState(o?"erwin":"sql"),[u,d]=w.useState("postgres"),[m,f]=w.useState(a??""),[p,y]=w.useState(!1),[b,g]=w.useState(null),[E,C]=w.useState([]);w.useEffect(()=>{a&&f(a)},[a]);const v=_=>{_&&_.text().then(f).catch(()=>g("could not read that file"))},M=async()=>{y(!0),g(null),C([]);try{if(o&&c==="erwin"){const I=await Om(c,m);if(!I.changes.length){g(I.warnings[0]??"nothing to import from that document"),y(!1);return}s(),o(I),y(!1);return}const _=await Tm(c,m,c==="sql"?u:void 0);if(!_.changes.length){g(_.warnings[0]??"nothing to import from that document"),y(!1);return}if(r)await r(_.changes);else for(const I of _.changes)await e(I.op,I.payload);C(_.warnings),i(_.tables)}catch(_){g(_ instanceof Error?_.message:String(_))}finally{y(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:wi.map(_=>h.jsx("button",{className:"ie-tab"+(c===_.id?" active":""),onClick:()=>l(_.id),children:_.label},_.id))}),h.jsx("p",{className:"ie-hint",children:(j=wi.find(_=>_.id===c))==null?void 0:j.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:u,onChange:_=>d(_.target.value),children:["postgres","snowflake","mysql","duckdb"].map(_=>h.jsx("option",{children:_},_))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:_=>f(_.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:_=>{var I;return v(((I=_.target.files)==null?void 0:I[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((_,I)=>h.jsx("p",{className:"ie-warn",children:_},I)),b&&h.jsx("p",{className:"ie-error",children:b}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:p||!m.trim(),onClick:M,children:p?"Importing…":t})]})]})}export{qo as A,_m as B,gm as C,Pm as E,tw as I,kx as L,Jx as M,Nx as O,yi as P,Vo as R,ew as S,Ix as a,Gx as b,Fx as c,Wx as d,Ux as e,Rx as f,jm as g,qx as h,Xx as i,Vx as j,Lx as k,Dx as l,Px as m,Hx as n,Ko as o,Yx as p,Bx as q,zx as r,km as s,Tx as t,Ox as u,cr as v,Go as w,wx as x,lm as y}; diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index 4377003..a060dab 100644 --- a/packages/server/src/mdl_server/static/index.html +++ b/packages/server/src/mdl_server/static/index.html @@ -4,10 +4,10 @@ Modelith - + - - + +
diff --git a/packages/server/src/mdl_server/static/sme.html b/packages/server/src/mdl_server/static/sme.html index 79e0d53..6d89fa5 100644 --- a/packages/server/src/mdl_server/static/sme.html +++ b/packages/server/src/mdl_server/static/sme.html @@ -4,10 +4,10 @@ Modelith Glossary - + - - + + diff --git a/packages/server/tests/test_layout_api.py b/packages/server/tests/test_layout_api.py index 4e6b42d..f8be37a 100644 --- a/packages/server/tests/test_layout_api.py +++ b/packages/server/tests/test_layout_api.py @@ -60,6 +60,35 @@ def test_put_then_get_roundtrips(client, model_dir): assert got["edges"][rel] == {"routeX": 481} +def test_edge_endpoint_anchors_roundtrip(client): + """Dragged endpoint anchors (visual only) persist: {side, y, x?}, rounded, and a + route record may carry routeX + anchors together.""" + model = client.get("/api/model").json() + rel = model["relationships"][0]["id"] + edges = { + rel: { + "routeX": 300.4, + "sourceAnchor": {"side": "right", "y": 140.7}, + "targetAnchor": {"side": "top", "y": 50.2, "x": 210.9}, + } + } + r = client.put("/api/layout", json={"view": "__all__", "nodes": {}, "edges": edges}) + assert r.status_code == 200, r.text + got = client.get("/api/layout?view=__all__").json()["edges"][rel] + assert got["routeX"] == 300 + assert got["sourceAnchor"] == {"side": "right", "y": 141} + assert got["targetAnchor"] == {"side": "top", "y": 50, "x": 211} + + +def test_bad_anchor_side_422(client): + rel = client.get("/api/model").json()["relationships"][0]["id"] + r = client.put( + "/api/layout", + json={"view": "__all__", "nodes": {}, "edges": {rel: {"sourceAnchor": {"side": "nope", "y": 1}}}}, + ) + assert r.status_code == 422 + + def test_file_is_key_sorted_integers(client, model_dir): model = client.get("/api/model").json() e0, e1 = model["entities"][0]["id"], model["entities"][1]["id"] From 949f8d8d666d9f12bfc07602c99b25bb9c54cc59 Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Mon, 12 Oct 2026 19:15:56 +1100 Subject: [PATCH 10/14] canvas: anchored edge endpoints track their node (fix dislodge on node move) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A dragged endpoint anchor was resolved against the card rect baked into edge data (a snapshot from the last derivation). Moving the entity updated node positions but not that snapshot, so the anchored endpoint stayed at the card's OLD position — a line floating in empty space. Resolve anchors (and the orthogonal router) against the LIVE node rect read from the React Flow store (nodeInternals: positionAbsolute + measured size), with a shallow-equality selector so an edge re-renders only when its own node's rect changes. Falls back to the data snapshot before a node is measured. Now an anchored endpoint, its crow's-foot and the route all follow the node as it moves. Verified live: anchored the ex->dm edge on dm's left edge, moved dm +200/+100 via the store — the endpoint followed cleanly to dm's new left edge, no dislodge. 49 canvas tests pass. --- canvas/src/RelationshipEdge.tsx | 41 ++++++++++++++++--- ...m-BKkR2OJE.js => ModelDiagram-JUW0CWvf.js} | 2 +- .../{main-B_vfjY00.js => main-BINydbdB.js} | 2 +- .../{sme-D4FCzUN8.js => sme-GKXcuii9.js} | 4 +- .../static/assets/styles-CY4hT8Nm.js | 23 +++++++++++ .../static/assets/styles-Dfh1I8li.js | 23 ----------- .../server/src/mdl_server/static/index.html | 4 +- .../server/src/mdl_server/static/sme.html | 4 +- 8 files changed, 66 insertions(+), 37 deletions(-) rename packages/server/src/mdl_server/static/assets/{ModelDiagram-BKkR2OJE.js => ModelDiagram-JUW0CWvf.js} (97%) rename packages/server/src/mdl_server/static/assets/{main-B_vfjY00.js => main-BINydbdB.js} (99%) rename packages/server/src/mdl_server/static/assets/{sme-D4FCzUN8.js => sme-GKXcuii9.js} (99%) create mode 100644 packages/server/src/mdl_server/static/assets/styles-CY4hT8Nm.js delete mode 100644 packages/server/src/mdl_server/static/assets/styles-Dfh1I8li.js diff --git a/canvas/src/RelationshipEdge.tsx b/canvas/src/RelationshipEdge.tsx index dabbcd0..1c226d4 100644 --- a/canvas/src/RelationshipEdge.tsx +++ b/canvas/src/RelationshipEdge.tsx @@ -51,6 +51,8 @@ const CLICK_SLOP = 3; */ export const RelationshipEdge = memo(function RelationshipEdge({ id, + source, + target, sourceX, sourceY, targetX, @@ -66,6 +68,12 @@ export const RelationshipEdge = memo(function RelationshipEdge({ // on screen at the default 0.33x zoom). Divide sizes by the zoom so the grip keeps // a constant on-screen size and stays grabbable at any zoom. const zoom = useStore((s) => s.transform[2]); + // LIVE source/target card rects, read from the store so they track a node as it moves + // (the data.sourceCard/targetCard snapshot goes stale on a node drag, which left an + // anchored endpoint floating at the card's OLD position). A node's rect is its absolute + // position + measured size; fall back to the data snapshot if the store has no size yet. + const liveSrcRect = useStore((s) => rectOf(s.nodeInternals.get(source)), rectEq); + const liveTgtRect = useStore((s) => rectOf(s.nodeInternals.get(target)), rectEq); // while dragging, the live route is kept here so we do NOT rebuild all edges // per move; the committed value rides in data.routeX. const [dragX, setDragX] = useState(null); @@ -82,8 +90,9 @@ export const RelationshipEdge = memo(function RelationshipEdge({ // Effective endpoints: a dragged/stored anchor overrides the attribute-row port, so the // line visually meets the box where the anchor sits (the data still links the real rows). - const srcCardR = data?.sourceCard; - const tgtCardR = data?.targetCard; + // Prefer the LIVE store rect (tracks node moves); fall back to the data snapshot. + const srcCardR = liveSrcRect ?? data?.sourceCard; + const tgtCardR = liveTgtRect ?? data?.targetCard; const liveSrcAnchor = dragAnchor?.end === "source" ? dragAnchor.a : data?.sourceAnchor; const liveTgtAnchor = @@ -124,8 +133,8 @@ export const RelationshipEdge = memo(function RelationshipEdge({ // When a route is set AND we know the card rectangles, use the side-aware orthogonal // router so a run dragged over a node enters it from the top/bottom (and the crow's-foot // follows). Otherwise keep the smooth-step path (the clean default / auto routing). - const sCard = data?.sourceCard; - const tCard = data?.targetCard; + const sCard = srcCardR; + const tCard = tgtCardR; const routed = routeX != null && sCard && tCard ? orthogonalPath( @@ -258,7 +267,7 @@ export const RelationshipEdge = memo(function RelationshipEdge({ // handle resets that end to its attribute-row port. const onEndpointDown = useCallback( (end: "source" | "target") => (e: React.PointerEvent) => { - const card = end === "source" ? data?.sourceCard : data?.targetCard; + const card = end === "source" ? srcCardR : tgtCardR; if (!onAnchorChange || !rel || !card || e.button !== 0) return; e.stopPropagation(); (e.target as Element).setPointerCapture?.(e.pointerId); @@ -287,7 +296,7 @@ export const RelationshipEdge = memo(function RelationshipEdge({ window.addEventListener("pointermove", onMove); window.addEventListener("pointerup", onUp); }, - [onAnchorChange, rel, data, screenToFlowPosition], + [onAnchorChange, rel, srcCardR, tgtCardR, screenToFlowPosition], ); const onEndpointDouble = useCallback( (end: "source" | "target") => (e: React.MouseEvent) => { @@ -385,6 +394,26 @@ export const RelationshipEdge = memo(function RelationshipEdge({ ); }); +type Rect4 = { left: number; right: number; top: number; bottom: number } | null; +/** Equality for the useStore rect selector, so the edge re-renders only when its node's + * rect actually changes (not on every unrelated store tick). */ +function rectEq(a: Rect4, b: Rect4): boolean { + if (a === b) return true; + if (!a || !b) return false; + return a.left === b.left && a.right === b.right && a.top === b.top && a.bottom === b.bottom; +} + +/** The live rect of a React Flow node from the store (absolute position + measured size), + * or null when it is not yet measured. Used so an anchored endpoint tracks the node as it + * moves, instead of resolving against a stale snapshot. */ +function rectOf( + n: { positionAbsolute?: { x: number; y: number }; width?: number | null; height?: number | null } | undefined, +): { left: number; right: number; top: number; bottom: number } | null { + if (!n?.positionAbsolute || n.width == null || n.height == null) return null; + const { x, y } = n.positionAbsolute; + return { left: x, right: x + n.width, top: y, bottom: y + n.height }; +} + /** A small circular grip at an edge endpoint; drag it to slide the endpoint along the * entity's border. Zoom-invariant, like the route grip. */ function EndpointHandle({ diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-BKkR2OJE.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-JUW0CWvf.js similarity index 97% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-BKkR2OJE.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-JUW0CWvf.js index c8fdaaf..e777f8c 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-BKkR2OJE.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-JUW0CWvf.js @@ -1 +1 @@ -import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-Dfh1I8li.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; +import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-CY4hT8Nm.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; diff --git a/packages/server/src/mdl_server/static/assets/main-B_vfjY00.js b/packages/server/src/mdl_server/static/assets/main-BINydbdB.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-B_vfjY00.js rename to packages/server/src/mdl_server/static/assets/main-BINydbdB.js index f13f5d3..84ac676 100644 --- a/packages/server/src/mdl_server/static/assets/main-B_vfjY00.js +++ b/packages/server/src/mdl_server/static/assets/main-BINydbdB.js @@ -1,2 +1,2 @@ -import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-Dfh1I8li.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` +import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-CY4hT8Nm.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` `)||"model valid",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),M]}):F?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14}),F]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!u&&e.jsxs("button",{className:"tool-btn primary",onClick:A,title:"New entity (n)",children:[e.jsx(ye,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),E("ontology",e.jsx(be,{size:15}),"Ontology","Ontology browser"),E("layers",e.jsx(we,{size:15}),"Layers","Four-layer stack & coverage"),E("changes",e.jsx(ve,{size:15}),"Changes",k?"Uncommitted changes":"Changes",k),E("decisions",e.jsx(Me,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(w?" active":""),onClick:g,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(m?" active":""),onClick:p,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Ne,{size:15})}),e.jsx(Ke,{onRelayout:f,onReset:v}),e.jsx("button",{className:"grp-btn icon-only",onClick:y,title:"Fit view","aria-label":"Fit view",children:e.jsx(ke,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:r,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Se,{size:15})}),e.jsx(de,{exec:S,canEdit:!u,onImported:I,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:_,openImport:$})]})]})]})}const U=["LR","TB","RL","BT"],$e={LR:0,TB:90,RL:180,BT:270},se={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function Ke({onRelayout:s,onReset:l}){const[j,h]=a.useState(!1),[x,w]=a.useState("LR"),[g,m]=a.useState("auto"),p=a.useRef(null);a.useEffect(()=>{if(!j)return;const r=u=>{p.current&&!p.current.contains(u.target)&&h(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[j]);const y=r=>{m(r),s(r,x)},f=r=>{y(r),h(!1)},v=()=>{const r=U[(U.indexOf(x)+1)%U.length];w(r),s(g,r)};return e.jsxs("div",{className:"layout-picker",ref:p,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>y("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ee,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(j?" active":""),onClick:()=>h(r=>!r),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:v,title:`Flow direction: ${se[x]} (click to rotate)`,"aria-label":`Flow direction: ${se[x]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${$e[x]}deg)`},children:e.jsx(Pe,{size:15})})}),j&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>f("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>f("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>f("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>f("grid"),children:"Grid"}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"layout-menu-sep",role:"separator"}),e.jsx("button",{onClick:()=>{l(),h(!1)},title:"Clear saved positions and routes for this view",children:"Reset layout"})]})]})]})}function He(){const[s,l]=a.useState(null),[j,h]=a.useState(null),[x,w]=a.useState(null),[g,m]=a.useState(null),[p,y]=a.useState(""),[f,v]=a.useState(!0),[r,u]=a.useState(!1),[k,b]=a.useState(()=>new Set),[q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[z,D]=a.useState(()=>new Set),[K,M]=a.useState(!1),[F,E]=a.useState(0),o=a.useRef(null),L=a.useRef(""),B=a.useRef(!1),O=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((c,n)=>t.set(c.id,Y[n%Y.length])),t},[s]),H=a.useMemo(()=>{const t=new Map;if(!s)return t;const c=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(d=>c.set(d,n.id))}),s.entities.forEach(n=>{var N,Q,X;const P=((N=n.conceptual)!=null&&N.id?c.get(n.conceptual.id):void 0)??((X=(Q=n.conceptual)==null?void 0:Q.subject_area)==null?void 0:X.id)??"";t.set(n.id,P)}),t},[s]),te=a.useMemo(()=>{const t=new Map;return H.forEach(c=>t.set(c,(t.get(c)??0)+1)),t},[H]),R=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>ge(R),[R]),ae=a.useMemo(()=>ue(),[]),V=a.useMemo(()=>new URLSearchParams(window.location.search),[]),T=V.get("minimal")==="1";a.useEffect(()=>{T&&u(!0)},[T]);const re=a.useCallback(t=>{b(c=>{const n=new Set(c);return n.has(t)?n.delete(t):n.add(t),n})},[]),ce=V.get("import")==="1",W=a.useRef(!1),C=a.useCallback(()=>{J().then(l).catch(t=>w(String(t))),Z().then(h).catch(()=>h(null)),ee().then(t=>M(!!(t.git&&!t.clean))).catch(()=>M(!1)),E(t=>t+1)},[]);a.useEffect(C,[C]),a.useEffect(()=>{const t=setInterval(()=>{J().then(c=>{l(n=>n&&c.fingerprint===n.fingerprint?n:(B.current||(L.current=c.fingerprint),T||(Z().then(h).catch(()=>h(null)),ee().then(d=>M(!!(d.git&&!d.clean))).catch(()=>M(!1))),E(d=>d+1),c))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[T]),a.useEffect(()=>{s!=null&&s.fingerprint&&(L.current=s.fingerprint)},[s]);const G=a.useCallback(async(t,c)=>{if(s){B.current=!0;try{const n=await xe(t,c,L.current||s.fingerprint);return n!=null&&n.fingerprint&&(L.current=n.fingerprint),C(),n}catch(n){throw n instanceof pe&&n.status===409?(m("Model changed on disk — view refreshed, please retry."),C()):m(n instanceof Error?n.message:String(n)),n}finally{B.current=!1}}},[s,C]);a.useEffect(()=>{if(!g)return;const t=setTimeout(()=>m(null),5e3);return()=>clearTimeout(t)},[g]),a.useEffect(()=>{if(!s||W.current)return;const t=V.get("focus");if(!t)return;const c=s.entities.find(n=>{var d;return n.name===t||((d=n.conceptual)==null?void 0:d.name)===t});c&&(W.current=!0,requestAnimationFrame(()=>{var n;return(n=o.current)==null?void 0:n.focusEntity(c.id)}))},[s,V]);const oe=a.useCallback(()=>{var n;if(!s)return;const t=p.trim().toLowerCase();if(!t)return;const c=s.entities.find(d=>{var N;return(d.name.toLowerCase()+" "+(((N=d.conceptual)==null?void 0:N.name.toLowerCase())??"")+" "+d.attributes.map(Q=>Q.name.toLowerCase()).join(" ")).includes(t)});c&&((n=o.current)==null||n.focusEntity(c.id))},[s,p]);return a.useEffect(()=>{const t=c=>{var d,P,N;const n=(d=document.activeElement)==null?void 0:d.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(c.key==="/"&&(c.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),c.key==="n"&&!R&&((N=o.current)==null||N.newEntity()),c.key==="Escape"&&(A(null),y(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[R]),x?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:x}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!T&&e.jsx(_e,{doc:s,diagnostics:j,query:p,onQuery:y,onSubmitQuery:oe,showTypes:f,onToggleTypes:()=>v(t=>!t),collapseDetail:r,onToggleCollapse:()=>u(t=>!t),onFitView:()=>{var t;return(t=o.current)==null?void 0:t.fitView()},onRelayout:(t,c)=>{var n;return(n=o.current)==null?void 0:n.relayout(t,c)},onResetLayout:()=>{var t;return(t=o.current)==null?void 0:t.resetLayout()},onRefresh:C,readOnly:R,dirty:K,panelTab:S,onPanelTab:t=>I(c=>c===t?null:t),onNewEntity:()=>{var t;return(t=o.current)==null?void 0:t.newEntity()},exec:G,onImported:C,onImportBatch:je,openImport:ce,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:z.size}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(me,{doc:s,caps:ne,exec:G,selectedId:S?null:q,onSelect:A,query:p,showTypes:f,collapseDetail:r,expandedEntities:k,onToggleExpand:re,activeAreas:z,onError:m,handleRef:o,layoutStore:ae}),!T&&e.jsx(Ae,{doc:s,saColors:O,countByArea:te,activeAreas:z,onSetActive:D,open:_,onClose:()=>$(!1)}),S&&e.jsx(fe,{tab:S,onClose:()=>I(null),readOnly:R,refreshKey:F,onModelChanged:C,onFocusEntity:t=>{var c;I(null),(c=o.current)==null||c.focusEntity(t)}}),g&&e.jsx("div",{className:"toast",children:g})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ve(){return e.jsx(he,{children:e.jsx(He,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(le.StrictMode,{children:e.jsx(Ve,{})})); diff --git a/packages/server/src/mdl_server/static/assets/sme-D4FCzUN8.js b/packages/server/src/mdl_server/static/assets/sme-GKXcuii9.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-D4FCzUN8.js rename to packages/server/src/mdl_server/static/assets/sme-GKXcuii9.js index 4592029..a29f54c 100644 --- a/packages/server/src/mdl_server/static/assets/sme-D4FCzUN8.js +++ b/packages/server/src/mdl_server/static/assets/sme-GKXcuii9.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-BKkR2OJE.js","assets/client-DOmNpTln.js","assets/styles-Dfh1I8li.js","assets/styles-BzOwieT6.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-Dfh1I8li.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-BKkR2OJE.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-JUW0CWvf.js","assets/client-DOmNpTln.js","assets/styles-CY4hT8Nm.js","assets/styles-BzOwieT6.css"])))=>i.map(i=>d[i]); +import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-CY4hT8Nm.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-JUW0CWvf.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); diff --git a/packages/server/src/mdl_server/static/assets/styles-CY4hT8Nm.js b/packages/server/src/mdl_server/static/assets/styles-CY4hT8Nm.js new file mode 100644 index 0000000..42cf482 --- /dev/null +++ b/packages/server/src/mdl_server/static/assets/styles-CY4hT8Nm.js @@ -0,0 +1,23 @@ +var dc=Object.defineProperty;var fc=(e,t,n)=>t in e?dc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _e=(e,t,n)=>fc(e,typeof t!="symbol"?t+"":t,n);import{r as w,g as Co,R as A,j as h}from"./client-DOmNpTln.js";function Re(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?bc:wc;Ro.useSyncExternalStore=Ot.useSyncExternalStore!==void 0?Ot.useSyncExternalStore:vc;Ao.exports=Ro;var _c=Ao.exports;/** + * @license React + * use-sync-external-store-shim/with-selector.production.js + * + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var Dn=w,Ec=_c;function Nc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var Sc=typeof Object.is=="function"?Object.is:Nc,kc=Ec.useSyncExternalStore,jc=Dn.useRef,Cc=Dn.useEffect,Mc=Dn.useMemo,$c=Dn.useDebugValue;$o.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var o=jc(null);if(o.current===null){var i={hasValue:!1,value:null};o.current=i}else i=o.current;o=Mc(function(){function c(f){if(!u){if(u=!0,l=f,f=r(f),s!==void 0&&i.hasValue){var p=i.value;if(s(p,f))return d=p}return d=f}if(p=d,Sc(l,f))return p;var x=r(f);return s!==void 0&&s(p,x)?(l=f,p):(l=f,d=x)}var u=!1,l,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=kc(e,o[0],o[1]);return Cc(function(){i.hasValue=!0,i.value=a},[a]),$c(a),a};Mo.exports=$o;var Ac=Mo.exports;const Rc=Co(Ac),Ic={},ts=e=>{let t;const n=new Set,r=(l,d)=>{const m=typeof l=="function"?l(t):l;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(p=>p(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>u,subscribe:l=>(n.add(l),()=>n.delete(l)),destroy:()=>{(Ic?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},u=t=e(r,s,c);return c},Tc=e=>e?ts(e):ts,{useDebugValue:Oc}=A,{useSyncExternalStoreWithSelector:Lc}=Rc,Dc=e=>e;function Io(e,t=Dc,n){const r=Lc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Oc(r),r}const ns=(e,t)=>{const n=Tc(e),r=(s,o=t)=>Io(n,s,o);return Object.assign(r,n),r},Pc=(e,t)=>e?ns(e,t):ns;function Ce(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var zc={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Hc(e+"",n),s,o=-1,i=r.length;if(arguments.length<2){for(;++o0)for(var n=new Array(s),r=0,s,o;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),ss.hasOwnProperty(t)?{space:ss[t],local:e}:e}function Vc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===fr&&t.documentElement.namespaceURI===fr?t.createElement(e):t.createElementNS(n,e)}}function Bc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function To(e){var t=zn(e);return(t.local?Bc:Vc)(t)}function Gc(){}function Mr(e){return e==null?Gc:function(){return this.querySelector(e)}}function Yc(e){typeof e!="function"&&(e=Mr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=M&&(M=E+1);!($=v[M])&&++M=0;)(i=r[s])&&(o&&i.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(i,o),o=i);return this}function gl(e){e||(e=yl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),o=0;ot?1:e>=t?0:NaN}function xl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function wl(){return Array.from(this)}function bl(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Al:typeof t=="function"?Il:Rl)(e,t,n??"")):Lt(this.node(),e)}function Lt(e,t){return e.style.getPropertyValue(t)||zo(e).getComputedStyle(e,null).getPropertyValue(t)}function Ol(e){return function(){delete this[e]}}function Ll(e,t){return function(){this[e]=t}}function Dl(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Pl(e,t){return arguments.length>1?this.each((t==null?Ol:typeof t=="function"?Dl:Ll)(e,t)):this.node()[e]}function Ho(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Fo(e)}function Fo(e){this._node=e,this._names=Ho(e.getAttribute("class")||"")}Fo.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Vo(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function fu(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,o;n()=>e;function hr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:o,x:i,y:a,dx:c,dy:u,dispatch:l}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:l}})}hr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function _u(e){return!e.ctrlKey&&!e.button}function Eu(){return this.parentNode}function Nu(e,t){return t??{x:e.x,y:e.y}}function Su(){return navigator.maxTouchPoints||"ontouchstart"in this}function ku(){var e=_u,t=Eu,n=Nu,r=Su,s={},o=Pn("start","drag","end"),i=0,a,c,u,l,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",g,vu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,$){if(!(l||!e.call(this,b,$))){var j=M(this,t.call(this,b,$),b,$,"mouse");j&&(Fe(b.view).on("mousemove.drag",p,qt).on("mouseup.drag",x,qt),Xo(b.view),Un(b),u=!1,a=b.clientX,c=b.clientY,j("start",b))}}function p(b){if(Rt(b),!u){var $=b.clientX-a,j=b.clientY-c;u=$*$+j*j>d}s.mouse("drag",b)}function x(b){Fe(b.view).on("mousemove.drag mouseup.drag",null),Wo(b.view,u),Rt(b),s.mouse("end",b)}function v(b,$){if(e.call(this,b,$)){var j=b.changedTouches,_=t.call(this,b,$),R=j.length,N,I;for(N=0;N>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?dn(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?dn(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Cu.exec(e))?new De(t[1],t[2],t[3],1):(t=Mu.exec(e))?new De(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=$u.exec(e))?dn(t[1],t[2],t[3],t[4]):(t=Au.exec(e))?dn(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Ru.exec(e))?ds(t[1],t[2]/100,t[3]/100,1):(t=Iu.exec(e))?ds(t[1],t[2]/100,t[3]/100,t[4]):os.hasOwnProperty(e)?cs(os[e]):e==="transparent"?new De(NaN,NaN,NaN,0):null}function cs(e){return new De(e>>16&255,e>>8&255,e&255,1)}function dn(e,t,n,r){return r<=0&&(e=t=n=NaN),new De(e,t,n,r)}function Lu(e){return e instanceof sn||(e=Qt(e)),e?(e=e.rgb(),new De(e.r,e.g,e.b,e.opacity)):new De}function mr(e,t,n,r){return arguments.length===1?Lu(e):new De(e,t,n,r??1)}function De(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Ar(De,mr,Uo(sn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new De(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Kt:Math.pow(Kt,e),new De(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new De(vt(this.r),vt(this.g),vt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:ls,formatHex:ls,formatHex8:Du,formatRgb:us,toString:us}));function ls(){return`#${wt(this.r)}${wt(this.g)}${wt(this.b)}`}function Du(){return`#${wt(this.r)}${wt(this.g)}${wt(this.b)}${wt((isNaN(this.opacity)?1:this.opacity)*255)}`}function us(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${vt(this.r)}, ${vt(this.g)}, ${vt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function vt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function wt(e){return e=vt(e),(e<16?"0":"")+e.toString(16)}function ds(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Xe(e,t,n,r)}function qo(e){if(e instanceof Xe)return new Xe(e.h,e.s,e.l,e.opacity);if(e instanceof sn||(e=Qt(e)),!e)return new Xe;if(e instanceof Xe)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),o=Math.max(t,n,r),i=NaN,a=o-s,c=(o+s)/2;return a?(t===o?i=(n-r)/a+(n0&&c<1?0:i,new Xe(i,a,c,e.opacity)}function Pu(e,t,n,r){return arguments.length===1?qo(e):new Xe(e,t,n,r??1)}function Xe(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Ar(Xe,Pu,Uo(sn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Xe(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Kt:Math.pow(Kt,e),new Xe(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new De(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Xe(fs(this.h),fn(this.s),fn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${fs(this.h)}, ${fn(this.s)*100}%, ${fn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function fs(e){return e=(e||0)%360,e<0?e+360:e}function fn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Ko=e=>()=>e;function zu(e,t){return function(n){return e+n*t}}function Hu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Fu(e){return(e=+e)==1?Zo:function(t,n){return n-t?Hu(t,n,e):Ko(isNaN(t)?n:t)}}function Zo(e,t){var n=t-e;return n?zu(e,n):Ko(isNaN(e)?t:e)}const hs=function e(t){var n=Fu(t);function r(s,o){var i=n((s=mr(s)).r,(o=mr(o)).r),a=n(s.g,o.g),c=n(s.b,o.b),u=Zo(s.opacity,o.opacity);return function(l){return s.r=i(l),s.g=a(l),s.b=c(l),s.opacity=u(l),s+""}}return r.gamma=e,r}(1);function dt(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var pr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(pr.source,"g");function Vu(e){return function(){return e}}function Bu(e){return function(t){return e(t)+""}}function Gu(e,t){var n=pr.lastIndex=Kn.lastIndex=0,r,s,o,i=-1,a=[],c=[];for(e=e+"",t=t+"";(r=pr.exec(e))&&(s=Kn.exec(t));)(o=s.index)>n&&(o=t.slice(n,o),a[i]?a[i]+=o:a[++i]=o),(r=r[0])===(s=s[0])?a[i]?a[i]+=s:a[++i]=s:(a[++i]=null,c.push({i,x:dt(r,s)})),n=Kn.lastIndex;return n180?l+=360:l-u>180&&(u+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:dt(u,l)})):l&&d.push(s(d)+"rotate("+l+r)}function a(u,l,d,m){u!==l?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:dt(u,l)}):l&&d.push(s(d)+"skewX("+l+r)}function c(u,l,d,m,f,p){if(u!==d||l!==m){var x=f.push(s(f)+"scale(",null,",",null,")");p.push({i:x-4,x:dt(u,d)},{i:x-2,x:dt(l,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(u,l){var d=[],m=[];return u=e(u),l=e(l),o(u.translateX,u.translateY,l.translateX,l.translateY,d,m),i(u.rotate,l.rotate,d,m),a(u.skewX,l.skewX,d,m),c(u.scaleX,u.scaleY,l.scaleX,l.scaleY,d,m),u=l=null,function(f){for(var p=-1,x=m.length,v;++p=0&&e._call.call(void 0,t),e=e._next;--Dt}function gs(){Et=(Cn=Jt.now())+Hn,Dt=Yt=0;try{ed()}finally{Dt=0,nd(),Et=0}}function td(){var e=Jt.now(),t=e-Cn;t>ei&&(Hn-=t,Cn=e)}function nd(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Xt=e,yr(r)}function yr(e){if(!Dt){Yt&&(Yt=clearTimeout(Yt));var t=e-Et;t>24?(e<1/0&&(Yt=setTimeout(gs,e-Jt.now()-Hn)),Ht&&(Ht=clearInterval(Ht))):(Ht||(Cn=Jt.now(),Ht=setInterval(td,ei)),Dt=1,ti(gs))}}function ys(e,t,n){var r=new Mn;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var rd=Pn("start","end","cancel","interrupt"),sd=[],ri=0,xs=1,xr=2,vn=3,ws=4,wr=5,_n=6;function Fn(e,t,n,r,s,o){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;od(e,n,{name:t,index:r,group:s,on:rd,tween:sd,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:ri})}function Ir(e,t){var n=We(e,t);if(n.state>ri)throw new Error("too late; already scheduled");return n}function Je(e,t){var n=We(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function We(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function od(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=ni(o,0,n.time);function o(u){n.state=xs,n.timer.restart(i,n.delay,n.time),n.delay<=u&&i(u-n.delay)}function i(u){var l,d,m,f;if(n.state!==xs)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===vn)return ys(i);f.state===ws?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[l]):+lxr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function Od(e,t,n){var r,s,o=Td(t)?Ir:Je;return function(){var i=o(this,e),a=i.on;a!==r&&(s=(r=a).copy()).on(t,n),i.on=s}}function Ld(e,t){var n=this._id;return arguments.length<2?We(this.node(),n).on.on(e):this.each(Od(n,e,t))}function Dd(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Pd(){return this.on("end.remove",Dd(this._id))}function zd(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Mr(e));for(var r=this._groups,s=r.length,o=new Array(s),i=0;i()=>e;function df(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function st(e,t,n){this.k=e,this.x=t,this.y=n}st.prototype={constructor:st,scale:function(e){return e===1?this:new st(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new st(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var ot=new st(1,0,0);st.prototype;function Zn(e){e.stopImmediatePropagation()}function Ft(e){e.preventDefault(),e.stopImmediatePropagation()}function ff(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function hf(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function bs(){return this.__zoom||ot}function mf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function pf(){return navigator.maxTouchPoints||"ontouchstart"in this}function gf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),i>o?(o+i)/2:Math.min(0,o)||Math.max(0,i))}function ai(){var e=ff,t=hf,n=gf,r=mf,s=pf,o=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Qu,u=Pn("start","zoom","end"),l,d,m,f=500,p=150,x=0,v=10;function g(y){y.property("__zoom",bs).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",I).filter(s).on("touchstart.zoom",L).on("touchmove.zoom",V).on("touchend.zoom touchcancel.zoom",F).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(y,C,S,O){var D=y.selection?y.selection():y;D.property("__zoom",bs),y!==D?$(y,C,S,O):D.interrupt().each(function(){j(this,arguments).event(O).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},g.scaleBy=function(y,C,S,O){g.scaleTo(y,function(){var D=this.__zoom.k,k=typeof C=="function"?C.apply(this,arguments):C;return D*k},S,O)},g.scaleTo=function(y,C,S,O){g.transform(y,function(){var D=t.apply(this,arguments),k=this.__zoom,T=S==null?b(D):typeof S=="function"?S.apply(this,arguments):S,P=k.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n(M(E(k,z),T,P),D,i)},S,O)},g.translateBy=function(y,C,S,O){g.transform(y,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),i)},null,O)},g.translateTo=function(y,C,S,O,D){g.transform(y,function(){var k=t.apply(this,arguments),T=this.__zoom,P=O==null?b(k):typeof O=="function"?O.apply(this,arguments):O;return n(ot.translate(P[0],P[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof S=="function"?-S.apply(this,arguments):-S),k,i)},O,D)};function E(y,C){return C=Math.max(o[0],Math.min(o[1],C)),C===y.k?y:new st(C,y.x,y.y)}function M(y,C,S){var O=C[0]-S[0]*y.k,D=C[1]-S[1]*y.k;return O===y.x&&D===y.y?y:new st(y.k,O,D)}function b(y){return[(+y[0][0]+ +y[1][0])/2,(+y[0][1]+ +y[1][1])/2]}function $(y,C,S,O){y.on("start.zoom",function(){j(this,arguments).event(O).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(O).end()}).tween("zoom",function(){var D=this,k=arguments,T=j(D,k).event(O),P=t.apply(D,k),z=S==null?b(P):typeof S=="function"?S.apply(D,k):S,U=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),X=D.__zoom,Z=typeof C=="function"?C.apply(D,k):C,J=c(X.invert(z).concat(U/X.k),Z.invert(z).concat(U/Z.k));return function(se){if(se===1)se=Z;else{var ee=J(se),oe=U/ee[2];se=new st(oe,z[0]-ee[0]*oe,z[1]-ee[1]*oe)}T.zoom(null,se)}})}function j(y,C,S){return!S&&y.__zooming||new _(y,C)}function _(y,C){this.that=y,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(y,C),this.taps=0}_.prototype={event:function(y){return y&&(this.sourceEvent=y),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(y,C){return this.mouse&&y!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&y!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&y!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(y){var C=Fe(this.that).datum();u.call(y,this.that,new df(y,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:u}),C)}};function R(y,...C){if(!e.apply(this,arguments))return;var S=j(this,C).event(y),O=this.__zoom,D=Math.max(o[0],Math.min(o[1],O.k*Math.pow(2,r.apply(this,arguments)))),k=Ye(y);if(S.wheel)(S.mouse[0][0]!==k[0]||S.mouse[0][1]!==k[1])&&(S.mouse[1]=O.invert(S.mouse[0]=k)),clearTimeout(S.wheel);else{if(O.k===D)return;S.mouse=[k,O.invert(k)],En(this),S.start()}Ft(y),S.wheel=setTimeout(T,p),S.zoom("mouse",n(M(E(O,D),S.mouse[0],S.mouse[1]),S.extent,i));function T(){S.wheel=null,S.end()}}function N(y,...C){if(m||!e.apply(this,arguments))return;var S=y.currentTarget,O=j(this,C,!0).event(y),D=Fe(y.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",U,!0),k=Ye(y,S),T=y.clientX,P=y.clientY;Xo(y.view),Zn(y),O.mouse=[k,this.__zoom.invert(k)],En(this),O.start();function z(X){if(Ft(X),!O.moved){var Z=X.clientX-T,J=X.clientY-P;O.moved=Z*Z+J*J>x}O.event(X).zoom("mouse",n(M(O.that.__zoom,O.mouse[0]=Ye(X,S),O.mouse[1]),O.extent,i))}function U(X){D.on("mousemove.zoom mouseup.zoom",null),Wo(X.view,O.moved),Ft(X),O.event(X).end()}}function I(y,...C){if(e.apply(this,arguments)){var S=this.__zoom,O=Ye(y.changedTouches?y.changedTouches[0]:y,this),D=S.invert(O),k=S.k*(y.shiftKey?.5:2),T=n(M(E(S,k),O,D),t.apply(this,C),i);Ft(y),a>0?Fe(this).transition().duration(a).call($,T,O,y):Fe(this).call(g.transform,T,O,y)}}function L(y,...C){if(e.apply(this,arguments)){var S=y.touches,O=S.length,D=j(this,C,y.changedTouches.length===O).event(y),k,T,P,z;for(Zn(y),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},ci=at.error001();function he(e,t){const n=w.useContext(Vn);if(n===null)throw new Error(ci);return Io(n,e,t)}const Se=()=>{const e=w.useContext(Vn);if(e===null)throw new Error(ci);return w.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},xf=e=>e.userSelectionActive?"none":"all";function Or({position:e,children:t,className:n,style:r,...s}){const o=he(xf),i=`${e}`.split("-");return A.createElement("div",{className:Re(["react-flow__panel",n,...i]),style:{...r,pointerEvents:o},...s},t)}function wf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Or,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const bf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:o={},labelBgPadding:i=[2,4],labelBgBorderRadius:a=2,children:c,className:u,...l})=>{const d=w.useRef(null),[m,f]=w.useState({x:0,y:0,width:0,height:0}),p=Re(["react-flow__edge-textwrapper",u]);return w.useEffect(()=>{if(d.current){const x=d.current.getBBox();f({x:x.x,y:x.y,width:x.width,height:x.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:p,visibility:m.width?"visible":"hidden",...l},s&&A.createElement("rect",{width:m.width+2*i[0],x:-i[0],y:-i[1],height:m.height+2*i[1],className:"react-flow__edge-textbg",style:o,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var vf=w.memo(bf);const Lr=e=>({width:e.offsetWidth,height:e.offsetHeight}),Pt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Dr=(e={x:0,y:0},t)=>({x:Pt(e.x,t[0][0],t[1][0]),y:Pt(e.y,t[0][1],t[1][1])}),vs=(e,t,n)=>en?-Pt(Math.abs(e-n),1,50)/50:0,li=(e,t)=>{const n=vs(e.x,35,t.width-35)*20,r=vs(e.y,35,t.height-35)*20;return[n,r]},ui=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},di=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),en=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),fi=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),_s=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),_f=(e,t)=>fi(di(en(e),en(t))),br=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},Ef=e=>Ve(e.width)&&Ve(e.height)&&Ve(e.x)&&Ve(e.y),Ve=e=>!isNaN(e)&&isFinite(e),be=Symbol.for("internals"),hi=["Enter"," ","Escape"],Nf=(e,t)=>{},Sf=e=>"nativeEvent"in e;function vr(e){var s,o;const t=Sf(e)?e.nativeEvent:e,n=((o=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:o[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const mi=e=>"clientX"in e,gt=(e,t)=>{var o,i;const n=mi(e),r=n?e.clientX:(o=e.touches)==null?void 0:o[0].clientX,s=n?e.clientY:(i=e.touches)==null?void 0:i[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},$n=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},on=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:l,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Ve(n)&&Ve(r)?A.createElement(vf,{x:n,y:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u}):null);on.displayName="BaseEdge";function Vt(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(o=>o.id===e);s&&n(r,{...s})}}function pi({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,o=n{const[v,g,E]=yi({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:o});return A.createElement(on,{path:v,labelX:g,labelY:E,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:x})});Pr.displayName="SimpleBezierEdge";const Ns={[K.Left]:{x:-1,y:0},[K.Right]:{x:1,y:0},[K.Top]:{x:0,y:-1},[K.Bottom]:{x:0,y:1}},kf=({source:e,sourcePosition:t=K.Bottom,target:n})=>t===K.Left||t===K.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function jf({source:e,sourcePosition:t=K.Bottom,target:n,targetPosition:r=K.Top,center:s,offset:o}){const i=Ns[t],a=Ns[r],c={x:e.x+i.x*o,y:e.y+i.y*o},u={x:n.x+a.x*o,y:n.y+a.y*o},l=kf({source:c,sourcePosition:t,target:u}),d=l.x!==0?"x":"y",m=l[d];let f=[],p,x;const v={x:0,y:0},g={x:0,y:0},[E,M,b,$]=pi({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(i[d]*a[d]===-1){p=s.x??E,x=s.y??M;const _=[{x:p,y:c.y},{x:p,y:u.y}],R=[{x:c.x,y:x},{x:u.x,y:x}];i[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:u.y}],R=[{x:u.x,y:c.y}];if(d==="x"?f=i.x===m?R:_:f=i.y===m?_:R,t===r){const F=Math.abs(e[d]-n[d]);if(F<=o){const y=Math.min(o-1,o-F);i[d]===m?v[d]=(c[d]>e[d]?-1:1)*y:g[d]=(u[d]>n[d]?-1:1)*y}}if(t!==r){const F=d==="x"?"y":"x",y=i[d]===a[F],C=c[F]>u[F],S=c[F]=V?(p=(N.x+I.x)/2,x=f[0].y):(p=f[0].x,x=(N.y+I.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:u.x+g.x,y:u.y+g.y},n],p,x,b,$]}function Cf(e,t,n,r){const s=Math.min(Ss(e,t)/2,Ss(t,n)/2,r),{x:o,y:i}=t;if(e.x===o&&o===n.x||e.y===i&&i===n.y)return`L${o} ${i}`;if(e.y===i){const u=e.x{let M="";return E>0&&E{const[g,E,M]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:x==null?void 0:x.borderRadius,offset:x==null?void 0:x.offset});return A.createElement(on,{path:g,labelX:E,labelY:M,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:f,markerStart:p,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const zr=w.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:w.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});zr.displayName="StepEdge";function Mf({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,o,i,a]=pi({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,o,i,a]}const Hr=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[p,x,v]=Mf({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(on,{path:p,labelX:x,labelY:v,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:d,markerStart:m,interactionWidth:f})});Hr.displayName="StraightEdge";function pn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function ks({pos:e,x1:t,y1:n,x2:r,y2:s,c:o}){switch(e){case K.Left:return[t-pn(t-r,o),n];case K.Right:return[t+pn(r-t,o),n];case K.Top:return[t,n-pn(n-s,o)];case K.Bottom:return[t,n+pn(s-n,o)]}}function xi({sourceX:e,sourceY:t,sourcePosition:n=K.Bottom,targetX:r,targetY:s,targetPosition:o=K.Top,curvature:i=.25}){const[a,c]=ks({pos:n,x1:e,y1:t,x2:r,y2:s,c:i}),[u,l]=ks({pos:o,x1:r,y1:s,x2:e,y2:t,c:i}),[d,m,f,p]=gi({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:u,targetControlY:l});return[`M${e},${t} C${a},${c} ${u},${l} ${r},${s}`,d,m,f,p]}const In=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=K.Bottom,targetPosition:o=K.Top,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,pathOptions:x,interactionWidth:v})=>{const[g,E,M]=xi({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:o,curvature:x==null?void 0:x.curvature});return A.createElement(on,{path:g,labelX:E,labelY:M,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:v})});In.displayName="BezierEdge";const Fr=w.createContext(null),$f=Fr.Provider;Fr.Consumer;const Af=()=>w.useContext(Fr),Rf=e=>"id"in e&&"source"in e&&"target"in e,If=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,_r=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Tf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),Of=(e,t)=>{if(!e.source||!e.target)return t;let n;return Rf(e)?n={...e}:n={...e,id:If(e)},Tf(n,t)?t:t.concat(n)},Er=({x:e,y:t},[n,r,s],o,[i,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return o?{x:i*Math.round(c.x/i),y:a*Math.round(c.y/a)}:c},wi=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),_t=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},an=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:o,y:i}=_t(s,t).positionAbsolute;return di(r,en({x:o,y:i,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return fi(n)},Lf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),an(e,t)),bi=(e,t,[n,r,s]=[0,0,1],o=!1,i=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},u=[];return e.forEach(l=>{const{width:d,height:m,selectable:f=!0,hidden:p=!1}=l;if(i&&!f||p)return!1;const{positionAbsolute:x}=_t(l,a),v={x:x.x,y:x.y,width:d||0,height:m||0},g=br(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,M=o&&g>0,b=(d||0)*(m||0);(E||M||g>=b||l.dragging)&&u.push(l)}),u},vi=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},_i=(e,t,n,r,s,o=.1)=>{const i=t/(e.width*(1+o)),a=n/(e.height*(1+o)),c=Math.min(i,a),u=Pt(c,r,s),l=e.x+e.width/2,d=e.y+e.height/2,m=t/2-l*u,f=n/2-d*u;return{x:m,y:f,zoom:u}},xt=(e,t=0)=>e.transition().duration(t);function js(e,t,n,r){return(t[n]||[]).reduce((s,o)=>{var i,a;return`${e.id}-${o.id}-${n}`!==r&&s.push({id:o.id||null,type:n,nodeId:e.id,x:(((i=e.positionAbsolute)==null?void 0:i.x)??0)+o.x+o.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+o.y+o.height/2}),s},[])}function Df(e,t,n,r,s,o){const{x:i,y:a}=gt(e),u=t.elementsFromPoint(i,a).find(p=>p.classList.contains("react-flow__handle"));if(u){const p=u.getAttribute("data-nodeid");if(p){const x=Vr(void 0,u),v=u.getAttribute("data-handleid"),g=o({nodeId:p,id:v,type:x});if(g){const E=s.find(M=>M.nodeId===p&&M.type===x&&M.id===v);return{handle:{id:v,type:x,nodeId:p,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:g}}}}let l=[],d=1/0;if(s.forEach(p=>{const x=Math.sqrt((p.x-n.x)**2+(p.y-n.y)**2);if(x<=r){const v=o(p);x<=d&&(xp.isValid),f=l.some(({handle:p})=>p.type==="target");return l.find(({handle:p,validHandleResult:x})=>f?p.type==="target":m?x.isValid:!0)||l[0]}const Pf={source:null,target:null,sourceHandle:null,targetHandle:null},Ei=()=>({handleDomNode:null,isValid:!1,connection:Pf,endHandle:null});function Ni(e,t,n,r,s,o,i){const a=s==="target",c=i.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),u={...Ei(),handleDomNode:c};if(c){const l=Vr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),p=c.classList.contains("connectableend"),x={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};u.connection=x,f&&p&&(t===Nt.Strict?a&&l==="source"||!a&&l==="target":d!==n||m!==r)&&(u.endHandle={nodeId:d,handleId:m,type:l},u.isValid=o(x))}return u}function zf({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,o)=>{if(o[be]){const{handleBounds:i}=o[be];let a=[],c=[];i&&(a=js(o,i,"source",`${t}-${n}-${r}`),c=js(o,i,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Vr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Hf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function Si({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:o,setState:i,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:u}){const l=ui(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:p,onConnectStart:x,panBy:v,getNodes:g,cancelConnection:E}=o();let M=0,b;const{x:$,y:j}=gt(e),_=l==null?void 0:l.elementFromPoint($,j),R=Vr(c,_),N=m==null?void 0:m.getBoundingClientRect();if(!N||!R)return;let I,L=gt(e,N),V=!1,F=null,y=!1,C=null;const S=zf({nodes:g(),nodeId:n,handleId:t,handleType:R}),O=()=>{if(!f)return;const[T,P]=li(L,N);v({x:T,y:P}),M=requestAnimationFrame(O)};i({connectionPosition:L,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),x==null||x(e,{nodeId:n,handleId:t,handleType:R});function D(T){const{transform:P}=o();L=gt(T,N);const{handle:z,validHandleResult:U}=Df(T,l,Er(L,P,!1,[1,1]),p,S,X=>Ni(X,d,n,t,s?"target":"source",a,l));if(b=z,V||(O(),V=!0),C=U.handleDomNode,F=U.connection,y=U.isValid,i({connectionPosition:b&&y?wi({x:b.x,y:b.y},P):L,connectionStatus:Hf(!!b,y),connectionEndHandle:U.endHandle}),!b&&!y&&!C)return Qn(I);F.source!==F.target&&C&&(Qn(I),I=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",y),C.classList.toggle("react-flow__handle-valid",y))}function k(T){var P,z;(b||C)&&F&&y&&(r==null||r(F)),(z=(P=o()).onConnectEnd)==null||z.call(P,T),c&&(u==null||u(T)),Qn(I),E(),cancelAnimationFrame(M),V=!1,y=!1,F=null,C=null,l.removeEventListener("mousemove",D),l.removeEventListener("mouseup",k),l.removeEventListener("touchmove",D),l.removeEventListener("touchend",k)}l.addEventListener("mousemove",D),l.addEventListener("mouseup",k),l.addEventListener("touchmove",D),l.addEventListener("touchend",k)}const Cs=()=>!0,Ff=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Vf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:o,connectionClickStartHandle:i}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n,clickConnecting:(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n}},ki=w.forwardRef(({type:e="source",position:t=K.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:o=!0,id:i,onConnect:a,children:c,className:u,onMouseDown:l,onTouchStart:d,...m},f)=>{var N,I;const p=i||null,x=e==="target",v=Se(),g=Af(),{connectOnClick:E,noPanClassName:M}=he(Ff,Ce),{connecting:b,clickConnecting:$}=he(Vf(g,p,e),Ce);g||(I=(N=v.getState()).onError)==null||I.call(N,"010",at.error010());const j=L=>{const{defaultEdgeOptions:V,onConnect:F,hasDefaultEdges:y}=v.getState(),C={...V,...L};if(y){const{edges:S,setEdges:O}=v.getState();O(Of(C,S))}F==null||F(C),a==null||a(C)},_=L=>{if(!g)return;const V=mi(L);s&&(V&&L.button===0||!V)&&Si({event:L,handleId:p,nodeId:g,onConnect:j,isTarget:x,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||Cs}),V?l==null||l(L):d==null||d(L)},R=L=>{const{onClickConnectStart:V,onClickConnectEnd:F,connectionClickStartHandle:y,connectionMode:C,isValidConnection:S}=v.getState();if(!g||!y&&!s)return;if(!y){V==null||V(L,{nodeId:g,handleId:p,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:g,type:e,handleId:p}});return}const O=ui(L.target),D=n||S||Cs,{connection:k,isValid:T}=Ni({nodeId:g,id:p,type:e},C,y.nodeId,y.handleId||null,y.type,D,O);T&&j(k),F==null||F(L),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":p,"data-nodeid":g,"data-handlepos":t,"data-id":`${g}-${p}-${e}`,className:Re(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",M,u,{source:!x,target:x,connectable:r,connectablestart:s,connectableend:o,connecting:$,connectionindicator:r&&(s&&!b||o&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});ki.displayName="Handle";var mt=w.memo(ki);const ji=({data:e,isConnectable:t,targetPosition:n=K.Top,sourcePosition:r=K.Bottom})=>A.createElement(A.Fragment,null,A.createElement(mt,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(mt,{type:"source",position:r,isConnectable:t}));ji.displayName="DefaultNode";var Nr=w.memo(ji);const Ci=({data:e,isConnectable:t,sourcePosition:n=K.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(mt,{type:"source",position:n,isConnectable:t}));Ci.displayName="InputNode";var Mi=w.memo(Ci);const $i=({data:e,isConnectable:t,targetPosition:n=K.Top})=>A.createElement(A.Fragment,null,A.createElement(mt,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);$i.displayName="OutputNode";var Ai=w.memo($i);const Br=()=>null;Br.displayName="GroupNode";const Bf=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),gn=e=>e.id;function Gf(e,t){return Ce(e.selectedNodes.map(gn),t.selectedNodes.map(gn))&&Ce(e.selectedEdges.map(gn),t.selectedEdges.map(gn))}const Ri=w.memo(({onSelectionChange:e})=>{const t=Se(),{selectedNodes:n,selectedEdges:r}=he(Bf,Gf);return w.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(o=>o(s))},[n,r,e]),null});Ri.displayName="SelectionListener";const Yf=e=>!!e.onSelectionChange;function Xf({onSelectionChange:e}){const t=he(Yf);return e||t?A.createElement(Ri,{onSelectionChange:e}):null}const Wf=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function kt(e,t){w.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ue(e,t,n){w.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Uf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:o,onConnectEnd:i,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:u,nodesConnectable:l,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:p,minZoom:x,maxZoom:v,nodeExtent:g,onNodesChange:E,onEdgesChange:M,elementsSelectable:b,connectionMode:$,snapGrid:j,snapToGrid:_,translateExtent:R,connectOnClick:N,defaultEdgeOptions:I,fitView:L,fitViewOptions:V,onNodesDelete:F,onEdgesDelete:y,onNodeDrag:C,onNodeDragStart:S,onNodeDragStop:O,onSelectionDrag:D,onSelectionDragStart:k,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:U,autoPanOnConnect:X,autoPanOnNodeDrag:Z,onError:J,connectionRadius:se,isValidConnection:ee,nodeDragThreshold:oe})=>{const{setNodes:ce,setEdges:we,setDefaultNodesAndEdges:ye,setMinZoom:me,setMaxZoom:pe,setTranslateExtent:ge,setNodeExtent:Ne,reset:ae}=he(Wf,Ce),q=Se();return w.useEffect(()=>{const xe=r==null?void 0:r.map(Te=>({...Te,...I}));return ye(n,xe),()=>{ae()}},[]),ue("defaultEdgeOptions",I,q.setState),ue("connectionMode",$,q.setState),ue("onConnect",s,q.setState),ue("onConnectStart",o,q.setState),ue("onConnectEnd",i,q.setState),ue("onClickConnectStart",a,q.setState),ue("onClickConnectEnd",c,q.setState),ue("nodesDraggable",u,q.setState),ue("nodesConnectable",l,q.setState),ue("nodesFocusable",d,q.setState),ue("edgesFocusable",m,q.setState),ue("edgesUpdatable",f,q.setState),ue("elementsSelectable",b,q.setState),ue("elevateNodesOnSelect",p,q.setState),ue("snapToGrid",_,q.setState),ue("snapGrid",j,q.setState),ue("onNodesChange",E,q.setState),ue("onEdgesChange",M,q.setState),ue("connectOnClick",N,q.setState),ue("fitViewOnInit",L,q.setState),ue("fitViewOnInitOptions",V,q.setState),ue("onNodesDelete",F,q.setState),ue("onEdgesDelete",y,q.setState),ue("onNodeDrag",C,q.setState),ue("onNodeDragStart",S,q.setState),ue("onNodeDragStop",O,q.setState),ue("onSelectionDrag",D,q.setState),ue("onSelectionDragStart",k,q.setState),ue("onSelectionDragStop",T,q.setState),ue("noPanClassName",P,q.setState),ue("nodeOrigin",z,q.setState),ue("rfId",U,q.setState),ue("autoPanOnConnect",X,q.setState),ue("autoPanOnNodeDrag",Z,q.setState),ue("onError",J,q.setState),ue("connectionRadius",se,q.setState),ue("isValidConnection",ee,q.setState),ue("nodeDragThreshold",oe,q.setState),kt(e,ce),kt(t,we),kt(x,me),kt(v,pe),kt(R,ge),kt(g,Ne),null},Ms={display:"none"},qf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Ii="react-flow__node-desc",Ti="react-flow__edge-desc",Kf="react-flow__aria-live",Zf=e=>e.ariaLiveMessage;function Qf({rfId:e}){const t=he(Zf);return A.createElement("div",{id:`${Kf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:qf},t)}function Jf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${Ii}-${e}`,style:Ms},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Ti}-${e}`,style:Ms},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Qf,{rfId:e}))}var nn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=w.useState(!1),s=w.useRef(!1),o=w.useRef(new Set([])),[i,a]=w.useMemo(()=>{if(e!==null){const u=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),l=u.reduce((d,m)=>d.concat(...m),[]);return[u,l]}return[[],[]]},[e]);return w.useEffect(()=>{const c=typeof document<"u"?document:null,u=(t==null?void 0:t.target)||c;if(e!==null){const l=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&vr(f))return!1;const x=As(f.code,a);o.current.add(f[x]),$s(i,o.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&vr(f))return!1;const x=As(f.code,a);$s(i,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(f[x]),f.key==="Meta"&&o.current.clear(),s.current=!1},m=()=>{o.current.clear(),r(!1)};return u==null||u.addEventListener("keydown",l),u==null||u.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{u==null||u.removeEventListener("keydown",l),u==null||u.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function As(e,t){return t.includes(e)?"code":"key"}function Oi(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const o=t.get(s),i=_t(o,r);return Oi(o,t,{x:(n.x??0)+i.x,y:(n.y??0)+i.y,z:(((a=o[be])==null?void 0:a.z)??0)>(n.z??0)?((c=o[be])==null?void 0:c.z)??0:n.z??0},r)}function Li(e,t,n){e.forEach(r=>{var o;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:i,y:a,z:c}=Oi(r,e,{...r.position,z:((o=r[be])==null?void 0:o.z)??0},t);r.positionAbsolute={x:i,y:a},r[be].z=c,n!=null&&n[r.id]&&(r[be].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,o={},i=r?1e3:0;return e.forEach(a=>{var f;const c=(Ve(a.zIndex)?a.zIndex:0)+(a.selected?i:0),u=t.get(a.id),l={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(o[d]=!0);const m=(u==null?void 0:u.type)&&(u==null?void 0:u.type)!==a.type;Object.defineProperty(l,be,{enumerable:!1,value:{handleBounds:m||(f=u==null?void 0:u[be])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,l)}),Li(s,n,o),s}function Di(e,t={}){const{getNodes:n,width:r,height:s,minZoom:o,maxZoom:i,d3Zoom:a,d3Selection:c,fitViewOnInitDone:u,fitViewOnInit:l,nodeOrigin:d}=e(),m=t.initial&&!u&&l;if(a&&c&&(m||!t.initial)){const p=n().filter(v=>{var E;const g=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?g&&t.nodes.some(M=>M.id===v.id):g}),x=p.every(v=>v.width&&v.height);if(p.length>0&&x){const v=an(p,d),{x:g,y:E,zoom:M}=_i(v,r,s,t.minZoom??o,t.maxZoom??i,t.padding??.1),b=ot.translate(g,E).scale(M);return typeof t.duration=="number"&&t.duration>0?a.transform(xt(c,t.duration),b):a.transform(c,b),!0}}return!1}function eh(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[be]:r[be],selected:n.selected})}),new Map(t)}function th(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function yn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:o,onNodesChange:i,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:u}=n();e!=null&&e.length&&(c&&r({nodeInternals:eh(e,s)}),i==null||i(e)),t!=null&&t.length&&(u&&r({edges:th(t,o)}),a==null||a(t))}const jt=()=>{},nh={zoomIn:jt,zoomOut:jt,zoomTo:jt,getZoom:()=>1,setViewport:jt,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:jt,fitBounds:jt,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),sh=()=>{const e=Se(),{d3Zoom:t,d3Selection:n}=he(rh,Ce);return w.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(xt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(xt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,o)=>t.scaleTo(xt(n,o==null?void 0:o.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,o)=>{const[i,a,c]=e.getState().transform,u=ot.translate(s.x??i,s.y??a).scale(s.zoom??c);t.transform(xt(n,o==null?void 0:o.duration),u)},getViewport:()=>{const[s,o,i]=e.getState().transform;return{x:s,y:o,zoom:i}},fitView:s=>Di(e.getState,s),setCenter:(s,o,i)=>{const{width:a,height:c,maxZoom:u}=e.getState(),l=typeof(i==null?void 0:i.zoom)<"u"?i.zoom:u,d=a/2-s*l,m=c/2-o*l,f=ot.translate(d,m).scale(l);t.transform(xt(n,i==null?void 0:i.duration),f)},fitBounds:(s,o)=>{const{width:i,height:a,minZoom:c,maxZoom:u}=e.getState(),{x:l,y:d,zoom:m}=_i(s,i,a,c,u,(o==null?void 0:o.padding)??.1),f=ot.translate(l,d).scale(m);t.transform(xt(n,o==null?void 0:o.duration),f)},project:s=>{const{transform:o,snapToGrid:i,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),Er(s,o,i,a)},screenToFlowPosition:s=>{const{transform:o,snapToGrid:i,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:u,y:l}=c.getBoundingClientRect(),d={x:s.x-u,y:s.y-l};return Er(d,o,i,a)},flowToScreenPosition:s=>{const{transform:o,domNode:i}=e.getState();if(!i)return s;const{x:a,y:c}=i.getBoundingClientRect(),u=wi(s,o);return{x:u.x+a,y:u.y+c}},viewportInitialized:!0}:nh,[t,n])};function cn(){const e=sh(),t=Se(),n=w.useCallback(()=>t.getState().getNodes().map(x=>({...x})),[]),r=w.useCallback(x=>t.getState().nodeInternals.get(x),[]),s=w.useCallback(()=>{const{edges:x=[]}=t.getState();return x.map(v=>({...v}))},[]),o=w.useCallback(x=>{const{edges:v=[]}=t.getState();return v.find(g=>g.id===x)},[]),i=w.useCallback(x=>{const{getNodes:v,setNodes:g,hasDefaultNodes:E,onNodesChange:M}=t.getState(),b=v(),$=typeof x=="function"?x(b):x;if(E)g($);else if(M){const j=$.length===0?b.map(_=>({type:"remove",id:_.id})):$.map(_=>({item:_,type:"reset"}));M(j)}},[]),a=w.useCallback(x=>{const{edges:v=[],setEdges:g,hasDefaultEdges:E,onEdgesChange:M}=t.getState(),b=typeof x=="function"?x(v):x;if(E)g(b);else if(M){const $=b.length===0?v.map(j=>({type:"remove",id:j.id})):b.map(j=>({item:j,type:"reset"}));M($)}},[]),c=w.useCallback(x=>{const v=Array.isArray(x)?x:[x],{getNodes:g,setNodes:E,hasDefaultNodes:M,onNodesChange:b}=t.getState();if(M){const j=[...g(),...v];E(j)}else if(b){const $=v.map(j=>({item:j,type:"add"}));b($)}},[]),u=w.useCallback(x=>{const v=Array.isArray(x)?x:[x],{edges:g=[],setEdges:E,hasDefaultEdges:M,onEdgesChange:b}=t.getState();if(M)E([...g,...v]);else if(b){const $=v.map(j=>({item:j,type:"add"}));b($)}},[]),l=w.useCallback(()=>{const{getNodes:x,edges:v=[],transform:g}=t.getState(),[E,M,b]=g;return{nodes:x().map($=>({...$})),edges:v.map($=>({...$})),viewport:{x:E,y:M,zoom:b}}},[]),d=w.useCallback(({nodes:x,edges:v})=>{const{nodeInternals:g,getNodes:E,edges:M,hasDefaultNodes:b,hasDefaultEdges:$,onNodesDelete:j,onEdgesDelete:_,onNodesChange:R,onEdgesChange:N}=t.getState(),I=(x||[]).map(C=>C.id),L=(v||[]).map(C=>C.id),V=E().reduce((C,S)=>{const O=S.parentNode||S.parentId,D=!I.includes(S.id)&&O&&C.find(T=>T.id===O);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(I.includes(S.id)||D)&&C.push(S),C},[]),F=M.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),y=F.filter(C=>L.includes(C.id));if(V||y){const C=vi(V,F),S=[...y,...C],O=S.reduce((D,k)=>(D.includes(k.id)||D.push(k.id),D),[]);if(($||b)&&($&&t.setState({edges:M.filter(D=>!O.includes(D.id))}),b&&(V.forEach(D=>{g.delete(D.id)}),t.setState({nodeInternals:new Map(g)}))),O.length>0&&(_==null||_(S),N&&N(O.map(D=>({id:D,type:"remove"})))),V.length>0&&(j==null||j(V),R)){const D=V.map(k=>({id:k.id,type:"remove"}));R(D)}}},[]),m=w.useCallback(x=>{const v=Ef(x),g=v?null:t.getState().nodeInternals.get(x.id);return!v&&!g?[null,null,v]:[v?x:_s(g),g,v]},[]),f=w.useCallback((x,v=!0,g)=>{const[E,M,b]=m(x);return E?(g||t.getState().getNodes()).filter($=>{if(!b&&($.id===M.id||!$.positionAbsolute))return!1;const j=_s($),_=br(j,E);return v&&_>0||_>=E.width*E.height}):[]},[]),p=w.useCallback((x,v,g=!0)=>{const[E]=m(x);if(!E)return!1;const M=br(E,v);return g&&M>0||M>=E.width*E.height},[]);return w.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:o,setNodes:i,setEdges:a,addNodes:c,addEdges:u,toObject:l,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:p}),[e,n,r,s,o,i,a,c,u,l,d,f,p])}const oh={actInsideInputWithModifier:!1};var ih=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Se(),{deleteElements:r}=cn(),s=nn(e,oh),o=nn(t);w.useEffect(()=>{if(s){const{edges:i,getNodes:a}=n.getState(),c=a().filter(l=>l.selected),u=i.filter(l=>l.selected);r({nodes:c,edges:u}),n.setState({nodesSelectionActive:!1})}},[s]),w.useEffect(()=>{n.setState({multiSelectionActive:o})},[o])};function ah(e){const t=Se();w.useEffect(()=>{let n;const r=()=>{var o,i;if(!e.current)return;const s=Lr(e.current);(s.height===0||s.width===0)&&((i=(o=t.getState()).onError)==null||i.call(o,"004",at.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Gr={position:"absolute",width:"100%",height:"100%",top:0,left:0},ch=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,xn=e=>({x:e.x,y:e.y,zoom:e.k}),Ct=(e,t)=>e.target.closest(`.${t}`),Rs=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Is=e=>{const t=e.ctrlKey&&$n()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},lh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),uh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:o=!0,panOnScroll:i=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=bt.Free,zoomOnDoubleClick:u=!0,elementsSelectable:l,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:p,maxZoom:x,zoomActivationKeyCode:v,preventScrolling:g=!0,children:E,noWheelClassName:M,noPanClassName:b})=>{const $=w.useRef(),j=Se(),_=w.useRef(!1),R=w.useRef(!1),N=w.useRef(null),I=w.useRef({x:0,y:0,zoom:0}),{d3Zoom:L,d3Selection:V,d3ZoomHandler:F,userSelectionActive:y}=he(lh,Ce),C=nn(v),S=w.useRef(0),O=w.useRef(!1),D=w.useRef();return ah(N),w.useEffect(()=>{if(N.current){const k=N.current.getBoundingClientRect(),T=ai().scaleExtent([p,x]).translateExtent(f),P=Fe(N.current).call(T),z=ot.translate(m.x,m.y).scale(Pt(m.zoom,p,x)),U=[[0,0],[k.width,k.height]],X=T.constrain()(z,U,f);T.transform(P,X),T.wheelDelta(Is),j.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[X.x,X.y,X.k],domNode:N.current.closest(".react-flow")})}},[]),w.useEffect(()=>{V&&L&&(i&&!C&&!y?V.on("wheel.zoom",k=>{if(Ct(k,M))return!1;k.preventDefault(),k.stopImmediatePropagation();const T=V.property("__zoom").k||1;if(k.ctrlKey&&o){const ee=Ye(k),oe=Is(k),ce=T*Math.pow(2,oe);L.scaleTo(V,ce,ee,k);return}const P=k.deltaMode===1?20:1;let z=c===bt.Vertical?0:k.deltaX*P,U=c===bt.Horizontal?0:k.deltaY*P;!$n()&&k.shiftKey&&c!==bt.Vertical&&(z=k.deltaY*P,U=0),L.translateBy(V,-(z/T)*a,-(U/T)*a,{internal:!0});const X=xn(V.property("__zoom")),{onViewportChangeStart:Z,onViewportChange:J,onViewportChangeEnd:se}=j.getState();clearTimeout(D.current),O.current||(O.current=!0,t==null||t(k,X),Z==null||Z(X)),O.current&&(e==null||e(k,X),J==null||J(X),D.current=setTimeout(()=>{n==null||n(k,X),se==null||se(X),O.current=!1},150))},{passive:!1}):typeof F<"u"&&V.on("wheel.zoom",function(k,T){if(!g&&k.type==="wheel"&&!k.ctrlKey||Ct(k,M))return null;k.preventDefault(),F.call(this,k,T)},{passive:!1}))},[y,i,c,V,L,F,C,o,g,M,t,e,n]),w.useEffect(()=>{L&&L.on("start",k=>{var z,U;if(!k.sourceEvent||k.sourceEvent.internal)return null;S.current=(z=k.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=j.getState(),P=xn(k.transform);_.current=!0,I.current=P,((U=k.sourceEvent)==null?void 0:U.type)==="mousedown"&&j.setState({paneDragging:!0}),T==null||T(P),t==null||t(k.sourceEvent,P)})},[L,t]),w.useEffect(()=>{L&&(y&&!_.current?L.on("zoom",null):y||L.on("zoom",k=>{var P;const{onViewportChange:T}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),R.current=!!(r&&Rs(d,S.current??0)),(e||T)&&!((P=k.sourceEvent)!=null&&P.internal)){const z=xn(k.transform);T==null||T(z),e==null||e(k.sourceEvent,z)}}))},[y,L,e,d,r]),w.useEffect(()=>{L&&L.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=j.getState();if(_.current=!1,j.setState({paneDragging:!1}),r&&Rs(d,S.current??0)&&!R.current&&r(k.sourceEvent),R.current=!1,(n||T)&&ch(I.current,k.transform)){const P=xn(k.transform);I.current=P,clearTimeout($.current),$.current=setTimeout(()=>{T==null||T(P),n==null||n(k.sourceEvent,P)},i?150:0)}})},[L,i,d,n,r]),w.useEffect(()=>{L&&L.filter(k=>{const T=C||s,P=o&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(Ct(k,"react-flow__node")||Ct(k,"react-flow__edge")))return!0;if(!d&&!T&&!i&&!u&&!o||y||!u&&k.type==="dblclick"||Ct(k,M)&&k.type==="wheel"||Ct(k,b)&&(k.type!=="wheel"||i&&k.type==="wheel"&&!C)||!o&&k.ctrlKey&&k.type==="wheel"||!T&&!i&&!P&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&z})},[y,L,s,o,i,u,d,l,C]),A.createElement("div",{className:"react-flow__renderer",ref:N,style:Gr},E)},dh=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function fh(){const{userSelectionActive:e,userSelectionRect:t}=he(dh,Ce);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Ts(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,o=t.position.y+t.height-r.height;if(s>0||o>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),o>0&&(r.style.height+=o),t.position.x<0){const i=Math.abs(t.position.x);r.position.x=r.position.x-i,r.style.width+=i,t.position.x=0}if(t.position.y<0){const i=Math.abs(t.position.y);r.position.y=r.position.y-i,r.style.height+=i,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function hh(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const o=e.filter(a=>a.id===s.id);if(o.length===0)return r.push(s),r;const i={...s};for(const a of o)if(a)switch(a.type){case"select":{i.selected=a.selected;break}case"position":{typeof a.position<"u"&&(i.position=a.position),typeof a.positionAbsolute<"u"&&(i.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(i.dragging=a.dragging),i.expandParent&&Ts(r,i);break}case"dimensions":{typeof a.dimensions<"u"&&(i.width=a.dimensions.width,i.height=a.dimensions.height),typeof a.updateStyle<"u"&&(i.style={...i.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(i.resizing=a.resizing),i.expandParent&&Ts(r,i);break}case"remove":return r}return r.push(i),r},n)}function mh(e,t){return hh(e,t)}const ft=(e,t)=>({id:e,type:"select",selected:t});function $t(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ft(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ft(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},ph=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Pi=w.memo(({isSelecting:e,selectionMode:t=tn.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:o,onPaneContextMenu:i,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:u,onPaneMouseLeave:l,children:d})=>{const m=w.useRef(null),f=Se(),p=w.useRef(0),x=w.useRef(0),v=w.useRef(),{userSelectionActive:g,elementsSelectable:E,dragging:M}=he(ph,Ce),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),p.current=0,x.current=0},$=F=>{o==null||o(F),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=F=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){F.preventDefault();return}i==null||i(F)},_=a?F=>a(F):void 0,R=F=>{const{resetSelectedElements:y,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||F.button!==0||F.target!==m.current||!v.current)return;const{x:S,y:O}=gt(F,v.current);y(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:O,x:S,y:O}}),r==null||r(F)},N=F=>{const{userSelectionRect:y,nodeInternals:C,edges:S,transform:O,onNodesChange:D,onEdgesChange:k,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!y)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=gt(F,v.current),U=y.startX??0,X=y.startY??0,Z={...y,x:z.xce.id),oe=se.map(ce=>ce.id);if(p.current!==oe.length){p.current=oe.length;const ce=$t(J,oe);ce.length&&(D==null||D(ce))}if(x.current!==ee.length){x.current=ee.length;const ce=$t(S,ee);ce.length&&(k==null||k(ce))}f.setState({userSelectionRect:Z})},I=F=>{if(F.button!==0)return;const{userSelectionRect:y}=f.getState();!g&&y&&F.target===m.current&&($==null||$(F)),f.setState({nodesSelectionActive:p.current>0}),b(),s==null||s(F)},L=F=>{g&&(f.setState({nodesSelectionActive:p.current>0}),s==null||s(F)),b()},V=E&&(e||g);return A.createElement("div",{className:Re(["react-flow__pane",{dragging:M,selection:e}]),onClick:V?void 0:er($,m),onContextMenu:er(j,m),onWheel:er(_,m),onMouseEnter:V?void 0:c,onMouseDown:V?R:void 0,onMouseMove:V?N:u,onMouseUp:V?I:void 0,onMouseLeave:V?L:l,ref:m,style:Gr},d,A.createElement(fh,null))});Pi.displayName="Pane";function zi(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:zi(r,t):!1}function Os(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function gh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!zi(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var o,i;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((o=s.positionAbsolute)==null?void 0:o.x)??0),y:n.y-(((i=s.positionAbsolute)==null?void 0:i.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function yh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function Hi(e,t,n,r,s=[0,0],o){const i=yh(e,e.extent||r);let a=i;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=_t(d,s).positionAbsolute;a=d&&Ve(m)&&Ve(f)&&Ve(d.width)&&Ve(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else o==null||o("005",at.error005()),a=i;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=_t(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let u={x:0,y:0};if(c){const d=n.get(c);u=_t(d,s).positionAbsolute}const l=a&&a!=="parent"?Dr(t,a):t;return{position:{x:l.x-u.x,y:l.y-u.y},positionAbsolute:l}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Ls=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const o=Array.from(s),i=t.getBoundingClientRect(),a={x:i.width*r[0],y:i.height*r[1]};return o.map(c=>{const u=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(u.left-i.left-a.x)/n,y:(u.top-i.top-a.y)/n,...Lr(c)}})};function Bt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Sr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:o,multiSelectionActive:i,nodeInternals:a,onError:c}=t.getState(),u=a.get(e);if(!u){c==null||c("012",at.error012(e));return}t.setState({nodesSelectionActive:!1}),u.selected?(n||u.selected&&i)&&(o({nodes:[u],edges:[]}),requestAnimationFrame(()=>{var l;return(l=r==null?void 0:r.current)==null?void 0:l.blur()})):s([e])}function xh(){const e=Se();return w.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:o}=e.getState(),i=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(i-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:o?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:o?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Fi({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:o,selectNodesOnDrag:i}){const a=Se(),[c,u]=w.useState(!1),l=w.useRef([]),d=w.useRef({x:null,y:null}),m=w.useRef(0),f=w.useRef(null),p=w.useRef({x:0,y:0}),x=w.useRef(null),v=w.useRef(!1),g=w.useRef(!1),E=w.useRef(!1),M=xh();return w.useEffect(()=>{if(e!=null&&e.current){const b=Fe(e.current),$=({x:R,y:N})=>{const{nodeInternals:I,onNodeDrag:L,onSelectionDrag:V,updateNodePositions:F,nodeExtent:y,snapGrid:C,snapToGrid:S,nodeOrigin:O,onError:D}=a.getState();d.current={x:R,y:N};let k=!1,T={x:0,y:0,x2:0,y2:0};if(l.current.length>1&&y){const z=an(l.current,O);T=en(z)}if(l.current=l.current.map(z=>{const U={x:R-z.distance.x,y:N-z.distance.y};S&&(U.x=C[0]*Math.round(U.x/C[0]),U.y=C[1]*Math.round(U.y/C[1]));const X=[[y[0][0],y[0][1]],[y[1][0],y[1][1]]];l.current.length>1&&y&&!z.extent&&(X[0][0]=z.positionAbsolute.x-T.x+y[0][0],X[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+y[1][0],X[0][1]=z.positionAbsolute.y-T.y+y[0][1],X[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+y[1][1]);const Z=Hi(z,U,I,X,O,D);return k=k||z.position.x!==Z.position.x||z.position.y!==Z.position.y,z.position=Z.position,z.positionAbsolute=Z.positionAbsolute,z}),!k)return;F(l.current,!0,!0),u(!0);const P=s?L:nr(V);if(P&&x.current){const[z,U]=tr({nodeId:s,dragItems:l.current,nodeInternals:I});P(x.current,z,U)}},j=()=>{if(!f.current)return;const[R,N]=li(p.current,f.current);if(R!==0||N!==0){const{transform:I,panBy:L}=a.getState();d.current.x=(d.current.x??0)-R/I[2],d.current.y=(d.current.y??0)-N/I[2],L({x:R,y:N})&&$(d.current)}m.current=requestAnimationFrame(j)},_=R=>{var O;const{nodeInternals:N,multiSelectionActive:I,nodesDraggable:L,unselectNodesAndEdges:V,onNodeDragStart:F,onSelectionDragStart:y}=a.getState();g.current=!0;const C=s?F:nr(y);(!i||!o)&&!I&&s&&((O=N.get(s))!=null&&O.selected||V()),s&&o&&i&&Sr({id:s,store:a,nodeRef:e});const S=M(R);if(d.current=S,l.current=gh(N,L,S,s),C&&l.current){const[D,k]=tr({nodeId:s,dragItems:l.current,nodeInternals:N});C(R.sourceEvent,D,k)}};if(t)b.on(".drag",null);else{const R=ku().on("start",N=>{const{domNode:I,nodeDragThreshold:L}=a.getState();L===0&&_(N),E.current=!1;const V=M(N);d.current=V,f.current=(I==null?void 0:I.getBoundingClientRect())||null,p.current=gt(N.sourceEvent,f.current)}).on("drag",N=>{var F,y;const I=M(N),{autoPanOnNodeDrag:L,nodeDragThreshold:V}=a.getState();if(N.sourceEvent.type==="touchmove"&&N.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&g.current&&L&&(v.current=!0,j()),!g.current){const C=I.xSnapped-(((F=d==null?void 0:d.current)==null?void 0:F.x)??0),S=I.ySnapped-(((y=d==null?void 0:d.current)==null?void 0:y.y)??0);Math.sqrt(C*C+S*S)>V&&_(N)}(d.current.x!==I.xSnapped||d.current.y!==I.ySnapped)&&l.current&&g.current&&(x.current=N.sourceEvent,p.current=gt(N.sourceEvent,f.current),$(I))}}).on("end",N=>{if(!(!g.current||E.current)&&(u(!1),v.current=!1,g.current=!1,cancelAnimationFrame(m.current),l.current)){const{updateNodePositions:I,nodeInternals:L,onNodeDragStop:V,onSelectionDragStop:F}=a.getState(),y=s?V:nr(F);if(I(l.current,!1,!1),y){const[C,S]=tr({nodeId:s,dragItems:l.current,nodeInternals:L});y(N.sourceEvent,C,S)}}}).filter(N=>{const I=N.target;return!N.button&&(!n||!Os(I,`.${n}`,e))&&(!r||Os(I,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,o,a,s,i,M]),c}function Vi(){const e=Se();return w.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:o,getNodes:i,snapToGrid:a,snapGrid:c,onError:u,nodesDraggable:l}=e.getState(),d=i().filter(E=>E.selected&&(E.draggable||l&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,p=n.isShiftPressed?4:1,x=n.x*m*p,v=n.y*f*p,g=d.map(E=>{if(E.positionAbsolute){const M={x:E.positionAbsolute.x+x,y:E.positionAbsolute.y+v};a&&(M.x=c[0]*Math.round(M.x/c[0]),M.y=c[1]*Math.round(M.y/c[1]));const{positionAbsolute:b,position:$}=Hi(E,M,r,s,void 0,u);E.position=$,E.positionAbsolute=b}return E});o(g,!0,!1)},[])}const Tt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Gt=e=>{const t=({id:n,type:r,data:s,xPos:o,yPos:i,xPosOrigin:a,yPosOrigin:c,selected:u,onClick:l,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:p,onDoubleClick:x,style:v,className:g,isDraggable:E,isSelectable:M,isConnectable:b,isFocusable:$,selectNodesOnDrag:j,sourcePosition:_,targetPosition:R,hidden:N,resizeObserver:I,dragHandle:L,zIndex:V,isParent:F,noDragClassName:y,noPanClassName:C,initialized:S,disableKeyboardA11y:O,ariaLabel:D,rfId:k,hasHandleBounds:T})=>{const P=Se(),z=w.useRef(null),U=w.useRef(null),X=w.useRef(_),Z=w.useRef(R),J=w.useRef(r),se=M||E||l||d||m||f,ee=Vi(),oe=Bt(n,P.getState,d),ce=Bt(n,P.getState,m),we=Bt(n,P.getState,f),ye=Bt(n,P.getState,p),me=Bt(n,P.getState,x),pe=ae=>{const{nodeDragThreshold:q}=P.getState();if(M&&(!j||!E||q>0)&&Sr({id:n,store:P,nodeRef:z}),l){const xe=P.getState().nodeInternals.get(n);xe&&l(ae,{...xe})}},ge=ae=>{if(!vr(ae)&&!O)if(hi.includes(ae.key)&&M){const q=ae.key==="Escape";Sr({id:n,store:P,unselect:q,nodeRef:z})}else E&&u&&Object.prototype.hasOwnProperty.call(Tt,ae.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${ae.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~o}, y: ${~~i}`}),ee({x:Tt[ae.key].x,y:Tt[ae.key].y,isShiftPressed:ae.shiftKey}))};w.useEffect(()=>()=>{U.current&&(I==null||I.unobserve(U.current),U.current=null)},[]),w.useEffect(()=>{if(z.current&&!N){const ae=z.current;(!S||!T||U.current!==ae)&&(U.current&&(I==null||I.unobserve(U.current)),I==null||I.observe(ae),U.current=ae)}},[N,S,T]),w.useEffect(()=>{const ae=J.current!==r,q=X.current!==_,xe=Z.current!==R;z.current&&(ae||q||xe)&&(ae&&(J.current=r),q&&(X.current=_),xe&&(Z.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const Ne=Fi({nodeRef:z,disabled:N||!E,noDragClassName:y,handleSelector:L,nodeId:n,isSelectable:M,selectNodesOnDrag:j});return N?null:A.createElement("div",{className:Re(["react-flow__node",`react-flow__node-${r}`,{[C]:E},g,{selected:u,selectable:M,parent:F,dragging:Ne}]),ref:z,style:{zIndex:V,transform:`translate(${a}px,${c}px)`,pointerEvents:se?"all":"none",visibility:S?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:oe,onMouseMove:ce,onMouseLeave:we,onContextMenu:ye,onClick:pe,onDoubleClick:me,onKeyDown:$?ge:void 0,tabIndex:$?0:void 0,role:$?"button":void 0,"aria-describedby":O?void 0:`${Ii}-${k}`,"aria-label":D},A.createElement($f,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:o,yPos:i,selected:u,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:Ne,dragHandle:L,zIndex:V})))};return t.displayName="NodeWrapper",w.memo(t)};const wh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...an(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function bh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Se(),{width:s,height:o,x:i,y:a,transformString:c,userSelectionActive:u}=he(wh,Ce),l=Vi(),d=w.useRef(null);if(w.useEffect(()=>{var p;n||(p=d.current)==null||p.focus({preventScroll:!0})},[n]),Fi({nodeRef:d}),u||!s||!o)return null;const m=e?p=>{const x=r.getState().getNodes().filter(v=>v.selected);e(p,x)}:void 0,f=p=>{Object.prototype.hasOwnProperty.call(Tt,p.key)&&l({x:Tt[p.key].x,y:Tt[p.key].y,isShiftPressed:p.shiftKey})};return A.createElement("div",{className:Re(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:o,top:a,left:i}}))}var vh=w.memo(bh);const _h=e=>e.nodesSelectionActive,Bi=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:i,deleteKeyCode:a,onMove:c,onMoveStart:u,onMoveEnd:l,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:p,onSelectionEnd:x,multiSelectionKeyCode:v,panActivationKeyCode:g,zoomActivationKeyCode:E,elementsSelectable:M,zoomOnScroll:b,zoomOnPinch:$,panOnScroll:j,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:N,panOnDrag:I,defaultViewport:L,translateExtent:V,minZoom:F,maxZoom:y,preventScrolling:C,onSelectionContextMenu:S,noWheelClassName:O,noPanClassName:D,disableKeyboardA11y:k})=>{const T=he(_h),P=nn(d),z=nn(g),U=z||I,X=z||j,Z=P||m&&U!==!0;return ih({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(uh,{onMove:c,onMoveStart:u,onMoveEnd:l,onPaneContextMenu:o,elementsSelectable:M,zoomOnScroll:b,zoomOnPinch:$,panOnScroll:X,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:N,panOnDrag:!P&&U,defaultViewport:L,translateExtent:V,minZoom:F,maxZoom:y,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:O,noPanClassName:D},A.createElement(Pi,{onSelectionStart:p,onSelectionEnd:x,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:i,panOnDrag:U,isSelecting:!!Z,selectionMode:f},e,T&&A.createElement(vh,{onSelectionContextMenu:S,noPanClassName:D,disableKeyboardA11y:k})))};Bi.displayName="FlowRenderer";var Eh=w.memo(Bi);function Nh(e){return he(w.useCallback(n=>e?bi(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function Sh(e){const t={input:Gt(e.input||Mi),default:Gt(e.default||Nr),output:Gt(e.output||Ai),group:Gt(e.group||Br)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,o)=>(s[o]=Gt(e[o]||Nr),s),n);return{...t,...r}}const kh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},jh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Gi=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:o,onError:i}=he(jh,Ce),a=Nh(e.onlyRenderVisibleElements),c=w.useRef(),u=w.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const l=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));o(m)});return c.current=l,l},[]);return w.useEffect(()=>()=>{var l;(l=c==null?void 0:c.current)==null||l.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Gr},a.map(l=>{var $,j,_;let d=l.type||"default";e.nodeTypes[d]||(i==null||i("003",at.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(l.draggable||t&&typeof l.draggable>"u"),p=!!(l.selectable||s&&typeof l.selectable>"u"),x=!!(l.connectable||n&&typeof l.connectable>"u"),v=!!(l.focusable||r&&typeof l.focusable>"u"),g=e.nodeExtent?Dr(l.positionAbsolute,e.nodeExtent):l.positionAbsolute,E=(g==null?void 0:g.x)??0,M=(g==null?void 0:g.y)??0,b=kh({x:E,y:M,width:l.width??0,height:l.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:l.id,id:l.id,className:l.className,style:l.style,type:d,data:l.data,sourcePosition:l.sourcePosition||K.Bottom,targetPosition:l.targetPosition||K.Top,hidden:l.hidden,xPos:E,yPos:M,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!l.selected,isDraggable:f,isSelectable:p,isConnectable:x,isFocusable:v,resizeObserver:u,dragHandle:l.dragHandle,zIndex:(($=l[be])==null?void 0:$.z)??0,isParent:!!((j=l[be])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!l.width&&!!l.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:l.ariaLabel,hasHandleBounds:!!((_=l[be])!=null&&_.handleBounds)})}))};Gi.displayName="NodeRenderer";var Ch=w.memo(Gi);const Mh=(e,t,n)=>n===K.Left?e-t:n===K.Right?e+t:e,$h=(e,t,n)=>n===K.Top?e-t:n===K.Bottom?e+t:e,Ds="react-flow__edgeupdater",Ps=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:o,onMouseOut:i,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:o,onMouseOut:i,className:Re([Ds,`${Ds}-${a}`]),cx:Mh(t,r,e),cy:$h(n,r,e),r,stroke:"transparent",fill:"transparent"}),Ah=()=>!0;var Mt=e=>{const t=({id:n,className:r,type:s,data:o,onClick:i,onEdgeDoubleClick:a,selected:c,animated:u,label:l,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:x,style:v,source:g,target:E,sourceX:M,sourceY:b,targetX:$,targetY:j,sourcePosition:_,targetPosition:R,elementsSelectable:N,hidden:I,sourceHandleId:L,targetHandleId:V,onContextMenu:F,onMouseEnter:y,onMouseMove:C,onMouseLeave:S,reconnectRadius:O,onReconnect:D,onReconnectStart:k,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:U,ariaLabel:X,isFocusable:Z,isReconnectable:J,pathOptions:se,interactionWidth:ee,disableKeyboardA11y:oe})=>{const ce=w.useRef(null),[we,ye]=w.useState(!1),[me,pe]=w.useState(!1),ge=Se(),Ne=w.useMemo(()=>`url('#${_r(z,U)}')`,[z,U]),ae=w.useMemo(()=>`url('#${_r(P,U)}')`,[P,U]);if(I)return null;const q=W=>{var de;const{edges:ie,addSelectedEdges:re,unselectNodesAndEdges:Q,multiSelectionActive:le}=ge.getState(),ne=ie.find(je=>je.id===n);ne&&(N&&(ge.setState({nodesSelectionActive:!1}),ne.selected&&le?(Q({nodes:[],edges:[ne]}),(de=ce.current)==null||de.blur()):re([n])),i&&i(W,ne))},xe=Vt(n,ge.getState,a),Te=Vt(n,ge.getState,F),ze=Vt(n,ge.getState,y),qe=Vt(n,ge.getState,C),ke=Vt(n,ge.getState,S),Me=(W,ie)=>{if(W.button!==0)return;const{edges:re,isValidConnection:Q}=ge.getState(),le=ie?E:g,ne=(ie?V:L)||null,de=ie?"target":"source",je=Q||Ah,Le=ie,$e=re.find(Ae=>Ae.id===n);pe(!0),k==null||k(W,$e,de);const Ie=Ae=>{pe(!1),T==null||T(Ae,$e,de)};Si({event:W,handleId:ne,nodeId:le,onConnect:Ae=>D==null?void 0:D($e,Ae),isTarget:Le,getState:ge.getState,setState:ge.setState,isValidConnection:je,edgeUpdaterType:de,onReconnectEnd:Ie})},Oe=W=>Me(W,!0),H=W=>Me(W,!1),Y=()=>ye(!0),B=()=>ye(!1),te=!N&&!i,G=W=>{var ie;if(!oe&&hi.includes(W.key)&&N){const{unselectNodesAndEdges:re,addSelectedEdges:Q,edges:le}=ge.getState();W.key==="Escape"?((ie=ce.current)==null||ie.blur(),re({edges:[le.find(de=>de.id===n)]})):Q([n])}};return A.createElement("g",{className:Re(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:u,inactive:te,updating:we}]),onClick:q,onDoubleClick:xe,onContextMenu:Te,onMouseEnter:ze,onMouseMove:qe,onMouseLeave:ke,onKeyDown:Z?G:void 0,tabIndex:Z?0:void 0,role:Z?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":X===null?void 0:X||`Edge from ${g} to ${E}`,"aria-describedby":Z?`${Ti}-${U}`:void 0,ref:ce},!me&&A.createElement(e,{id:n,source:g,target:E,selected:c,animated:u,label:l,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:x,data:o,style:v,sourceX:M,sourceY:b,targetX:$,targetY:j,sourcePosition:_,targetPosition:R,sourceHandleId:L,targetHandleId:V,markerStart:Ne,markerEnd:ae,pathOptions:se,interactionWidth:ee}),J&&A.createElement(A.Fragment,null,(J==="source"||J===!0)&&A.createElement(Ps,{position:_,centerX:M,centerY:b,radius:O,onMouseDown:Oe,onMouseEnter:Y,onMouseOut:B,type:"source"}),(J==="target"||J===!0)&&A.createElement(Ps,{position:R,centerX:$,centerY:j,radius:O,onMouseDown:H,onMouseEnter:Y,onMouseOut:B,type:"target"})))};return t.displayName="EdgeWrapper",w.memo(t)};function Rh(e){const t={default:Mt(e.default||In),straight:Mt(e.bezier||Hr),step:Mt(e.step||zr),smoothstep:Mt(e.step||Bn),simplebezier:Mt(e.simplebezier||Pr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,o)=>(s[o]=Mt(e[o]||In),s),n);return{...t,...r}}function zs(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,o=(n==null?void 0:n.width)||t.width,i=(n==null?void 0:n.height)||t.height;switch(e){case K.Top:return{x:r+o/2,y:s};case K.Right:return{x:r+o,y:s+i/2};case K.Bottom:return{x:r+o/2,y:s+i};case K.Left:return{x:r,y:s+i/2}}}function Hs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const Ih=(e,t,n,r,s,o)=>{const i=zs(n,e,t),a=zs(o,r,s);return{sourceX:i.x,sourceY:i.y,targetX:a.x,targetY:a.y}};function Th({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:o,width:i,height:a,transform:c}){const u={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+o)};u.x===u.x2&&(u.x2+=1),u.y===u.y2&&(u.y2+=1);const l=en({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:i/c[2],height:a/c[2]}),d=Math.max(0,Math.min(l.x2,u.x2)-Math.max(l.x,u.x)),m=Math.max(0,Math.min(l.y2,u.y2)-Math.max(l.y,u.y));return Math.ceil(d*m)>0}function Fs(e){var r,s,o,i,a;const t=((r=e==null?void 0:e[be])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.y)<"u";return[{x:((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const Oh=[{level:0,isMaxLevel:!0,edges:[]}];function Lh(e,t,n=!1){let r=-1;const s=e.reduce((i,a)=>{var l,d;const c=Ve(a.zIndex);let u=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),p=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),x=Math.max(((l=f==null?void 0:f[be])==null?void 0:l.z)||0,((d=m==null?void 0:m[be])==null?void 0:d.z)||0,1e3);u=(c?a.zIndex:0)+(p?x:0)}return i[u]?i[u].push(a):i[u]=[a],r=u>r?u:r,i},{}),o=Object.entries(s).map(([i,a])=>{const c=+i;return{edges:a,level:c,isMaxLevel:c===r}});return o.length===0?Oh:o}function Dh(e,t,n){const r=he(w.useCallback(s=>e?s.edges.filter(o=>{const i=t.get(o.source),a=t.get(o.target);return(i==null?void 0:i.width)&&(i==null?void 0:i.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Th({sourcePos:i.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:i.width,sourceHeight:i.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Lh(r,t,n)}const Ph=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),zh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Vs={[An.Arrow]:Ph,[An.ArrowClosed]:zh};function Hh(e){const t=Se();return w.useMemo(()=>{var s,o;return Object.prototype.hasOwnProperty.call(Vs,e)?Vs[e]:((o=(s=t.getState()).onError)==null||o.call(s,"009",at.error009(e)),null)},[e])}const Fh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:o="strokeWidth",strokeWidth:i,orient:a="auto-start-reverse"})=>{const c=Hh(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:i})):null},Vh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,o)=>([o.markerStart,o.markerEnd].forEach(i=>{if(i&&typeof i=="object"){const a=_r(i,t);r.includes(a)||(s.push({id:a,color:i.color||e,...i}),r.push(a))}}),s),[]).sort((s,o)=>s.id.localeCompare(o.id))},Yi=({defaultColor:e,rfId:t})=>{const n=he(w.useCallback(Vh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((o,i)=>o.id!==s[i].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Fh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};Yi.displayName="MarkerDefinitions";var Bh=w.memo(Yi);const Gh=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Xi=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:o,onEdgeContextMenu:i,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:u,onEdgeClick:l,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:x,children:v,disableKeyboardA11y:g})=>{const{edgesFocusable:E,edgesUpdatable:M,elementsSelectable:b,width:$,height:j,connectionMode:_,nodeInternals:R,onError:N}=he(Gh,Ce),I=Dh(t,R,n);return $?A.createElement(A.Fragment,null,I.map(({level:L,edges:V,isMaxLevel:F})=>A.createElement("svg",{key:L,style:{zIndex:L},width:$,height:j,className:"react-flow__edges react-flow__container"},F&&A.createElement(Bh,{defaultColor:e,rfId:r}),A.createElement("g",null,V.map(y=>{const[C,S,O]=Fs(R.get(y.source)),[D,k,T]=Fs(R.get(y.target));if(!O||!T)return null;let P=y.type||"default";s[P]||(N==null||N("011",at.error011(P)),P="default");const z=s[P]||s.default,U=_===Nt.Strict?k.target:(k.target??[]).concat(k.source??[]),X=Hs(S.source,y.sourceHandle),Z=Hs(U,y.targetHandle),J=(X==null?void 0:X.position)||K.Bottom,se=(Z==null?void 0:Z.position)||K.Top,ee=!!(y.focusable||E&&typeof y.focusable>"u"),oe=y.reconnectable||y.updatable,ce=typeof m<"u"&&(oe||M&&typeof oe>"u");if(!X||!Z)return N==null||N("008",at.error008(X,y)),null;const{sourceX:we,sourceY:ye,targetX:me,targetY:pe}=Ih(C,X,J,D,Z,se);return A.createElement(z,{key:y.id,id:y.id,className:Re([y.className,o]),type:P,data:y.data,selected:!!y.selected,animated:!!y.animated,hidden:!!y.hidden,label:y.label,labelStyle:y.labelStyle,labelShowBg:y.labelShowBg,labelBgStyle:y.labelBgStyle,labelBgPadding:y.labelBgPadding,labelBgBorderRadius:y.labelBgBorderRadius,style:y.style,source:y.source,target:y.target,sourceHandleId:y.sourceHandle,targetHandleId:y.targetHandle,markerEnd:y.markerEnd,markerStart:y.markerStart,sourceX:we,sourceY:ye,targetX:me,targetY:pe,sourcePosition:J,targetPosition:se,elementsSelectable:b,onContextMenu:i,onMouseEnter:a,onMouseMove:c,onMouseLeave:u,onClick:l,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:x,rfId:r,ariaLabel:y.ariaLabel,isFocusable:ee,isReconnectable:ce,pathOptions:"pathOptions"in y?y.pathOptions:void 0,interactionWidth:y.interactionWidth,disableKeyboardA11y:g})})))),v):null};Xi.displayName="EdgeRenderer";var Yh=w.memo(Xi);const Xh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Wh({children:e}){const t=he(Xh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Uh(e){const t=cn(),n=w.useRef(!1);w.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const qh={[K.Left]:K.Right,[K.Right]:K.Left,[K.Top]:K.Bottom,[K.Bottom]:K.Top},Wi=({nodeId:e,handleType:t,style:n,type:r=ht.Bezier,CustomComponent:s,connectionStatus:o})=>{var j,_,R;const{fromNode:i,handleId:a,toX:c,toY:u,connectionMode:l}=he(w.useCallback(N=>({fromNode:N.nodeInternals.get(e),handleId:N.connectionHandleId,toX:(N.connectionPosition.x-N.transform[0])/N.transform[2],toY:(N.connectionPosition.y-N.transform[1])/N.transform[2],connectionMode:N.connectionMode}),[e]),Ce),d=(j=i==null?void 0:i[be])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(l===Nt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!i||!m)return null;const f=a?m.find(N=>N.id===a):m[0],p=f?f.x+f.width/2:(i.width??0)/2,x=f?f.y+f.height/2:i.height??0,v=(((_=i.positionAbsolute)==null?void 0:_.x)??0)+p,g=(((R=i.positionAbsolute)==null?void 0:R.y)??0)+x,E=f==null?void 0:f.position,M=E?qh[E]:null;if(!E||!M)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:i,fromHandle:f,fromX:v,fromY:g,toX:c,toY:u,fromPosition:E,toPosition:M,connectionStatus:o});let b="";const $={sourceX:v,sourceY:g,sourcePosition:E,targetX:c,targetY:u,targetPosition:M};return r===ht.Bezier?[b]=xi($):r===ht.Step?[b]=Rn({...$,borderRadius:0}):r===ht.SmoothStep?[b]=Rn($):r===ht.SimpleBezier?[b]=yi($):b=`M${v},${g} ${c},${u}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Wi.displayName="ConnectionLine";const Kh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Zh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:o,nodesConnectable:i,width:a,height:c,connectionStatus:u}=he(Kh,Ce);return!(s&&o&&a&&i)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:Re(["react-flow__connection",u])},A.createElement(Wi,{nodeId:s,handleType:o,style:t,type:n,CustomComponent:r,connectionStatus:u})))}function Bs(e,t){return w.useRef(null),Se(),w.useMemo(()=>t(e),[e])}const Ui=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:o,onNodeClick:i,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:u,onNodeMouseEnter:l,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:p,onSelectionStart:x,onSelectionEnd:v,connectionLineType:g,connectionLineStyle:E,connectionLineComponent:M,connectionLineContainerStyle:b,selectionKeyCode:$,selectionOnDrag:j,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:N,zoomActivationKeyCode:I,deleteKeyCode:L,onlyRenderVisibleElements:V,elementsSelectable:F,selectNodesOnDrag:y,defaultViewport:C,translateExtent:S,minZoom:O,maxZoom:D,preventScrolling:k,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:U,panOnScrollSpeed:X,panOnScrollMode:Z,zoomOnDoubleClick:J,panOnDrag:se,onPaneClick:ee,onPaneMouseEnter:oe,onPaneMouseMove:ce,onPaneMouseLeave:we,onPaneScroll:ye,onPaneContextMenu:me,onEdgeContextMenu:pe,onEdgeMouseEnter:ge,onEdgeMouseMove:Ne,onEdgeMouseLeave:ae,onReconnect:q,onReconnectStart:xe,onReconnectEnd:Te,reconnectRadius:ze,noDragClassName:qe,noWheelClassName:ke,noPanClassName:Me,elevateEdgesOnSelect:Oe,disableKeyboardA11y:H,nodeOrigin:Y,nodeExtent:B,rfId:te})=>{const G=Bs(e,Sh),W=Bs(t,Rh);return Uh(o),A.createElement(Eh,{onPaneClick:ee,onPaneMouseEnter:oe,onPaneMouseMove:ce,onPaneMouseLeave:we,onPaneContextMenu:me,onPaneScroll:ye,deleteKeyCode:L,selectionKeyCode:$,selectionOnDrag:j,selectionMode:_,onSelectionStart:x,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:N,zoomActivationKeyCode:I,elementsSelectable:F,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:J,panOnScroll:U,panOnScrollSpeed:X,panOnScrollMode:Z,panOnDrag:se,defaultViewport:C,translateExtent:S,minZoom:O,maxZoom:D,onSelectionContextMenu:p,preventScrolling:k,noDragClassName:qe,noWheelClassName:ke,noPanClassName:Me,disableKeyboardA11y:H},A.createElement(Wh,null,A.createElement(Yh,{edgeTypes:W,onEdgeClick:a,onEdgeDoubleClick:u,onlyRenderVisibleElements:V,onEdgeContextMenu:pe,onEdgeMouseEnter:ge,onEdgeMouseMove:Ne,onEdgeMouseLeave:ae,onReconnect:q,onReconnectStart:xe,onReconnectEnd:Te,reconnectRadius:ze,defaultMarkerColor:T,noPanClassName:Me,elevateEdgesOnSelect:!!Oe,disableKeyboardA11y:H,rfId:te},A.createElement(Zh,{style:E,type:g,component:M,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(Ch,{nodeTypes:G,onNodeClick:i,onNodeDoubleClick:c,onNodeMouseEnter:l,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:y,onlyRenderVisibleElements:V,noPanClassName:Me,noDragClassName:qe,disableKeyboardA11y:H,nodeOrigin:Y,nodeExtent:B,rfId:te})))};Ui.displayName="GraphView";var Qh=w.memo(Ui);const kr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],lt={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:kr,nodeExtent:kr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:Nt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:Nf,isValidConnection:void 0},Jh=()=>Pc((e,t)=>({...lt,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:o}=t();e({nodeInternals:Jn(n,r,s,o)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",o=typeof r<"u",i=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:i,edges:o?r:[],hasDefaultNodes:s,hasDefaultEdges:o})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:o,fitViewOnInitDone:i,fitViewOnInitOptions:a,domNode:c,nodeOrigin:u}=t(),l=c==null?void 0:c.querySelector(".react-flow__viewport");if(!l)return;const d=window.getComputedStyle(l),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((x,v)=>{const g=s.get(v.id);if(g!=null&&g.hidden)s.set(g.id,{...g,[be]:{...g[be],handleBounds:void 0}});else if(g){const E=Lr(v.nodeElement);!!(E.width&&E.height&&(g.width!==E.width||g.height!==E.height||v.forceUpdate))&&(s.set(g.id,{...g,[be]:{...g[be],handleBounds:{source:Ls(".source",v.nodeElement,m,u),target:Ls(".target",v.nodeElement,m,u)}},...E}),x.push({id:g.id,type:"dimensions",dimensions:E}))}return x},[]);Li(s,u);const p=i||o&&!i&&Di(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:p}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:o}=t(),i=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});o(i)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:o,nodeOrigin:i,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(o){const u=mh(n,a()),l=Jn(u,s,i,c);e({nodeInternals:l})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:o}=t();let i,a=null;r?i=n.map(c=>ft(c,!0)):(i=$t(o(),n),a=$t(s,[])),yn({changedNodes:i,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:o}=t();let i,a=null;r?i=n.map(c=>ft(c,!0)):(i=$t(s,n),a=$t(o(),[])),yn({changedNodes:a,changedEdges:i,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:o}=t(),i=n||o(),a=r||s,c=i.map(l=>(l.selected=!1,ft(l.id,!1))),u=a.map(l=>ft(l.id,!1));yn({changedNodes:c,changedEdges:u,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),o=r().filter(a=>a.selected).map(a=>ft(a.id,!1)),i=n.filter(a=>a.selected).map(a=>ft(a.id,!1));yn({changedNodes:o,changedEdges:i,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Dr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:o,d3Zoom:i,d3Selection:a,translateExtent:c}=t();if(!i||!a||!n.x&&!n.y)return!1;const u=ot.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),l=[[0,0],[s,o]],d=i==null?void 0:i.constrain()(u,l,c);return i.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:lt.connectionNodeId,connectionHandleId:lt.connectionHandleId,connectionHandleType:lt.connectionHandleType,connectionStatus:lt.connectionStatus,connectionStartHandle:lt.connectionStartHandle,connectionEndHandle:lt.connectionEndHandle}),reset:()=>e({...lt})}),Object.is),qi=({children:e})=>{const t=w.useRef(null);return t.current||(t.current=Jh()),A.createElement(yf,{value:t.current},e)};qi.displayName="ReactFlowProvider";const Ki=({children:e})=>w.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(qi,null,e);Ki.displayName="ReactFlowWrapper";const em={input:Mi,default:Nr,output:Ai,group:Br},tm={default:In,straight:Hr,step:zr,smoothstep:Bn,simplebezier:Pr},nm=[0,0],rm=[15,15],sm={x:0,y:0,zoom:1},om={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Zi=w.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:o=em,edgeTypes:i=tm,onNodeClick:a,onEdgeClick:c,onInit:u,onMove:l,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:p,onConnectEnd:x,onClickConnectStart:v,onClickConnectEnd:g,onNodeMouseEnter:E,onNodeMouseMove:M,onNodeMouseLeave:b,onNodeContextMenu:$,onNodeDoubleClick:j,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:N,onNodesDelete:I,onEdgesDelete:L,onSelectionChange:V,onSelectionDragStart:F,onSelectionDrag:y,onSelectionDragStop:C,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,connectionMode:k=Nt.Strict,connectionLineType:T=ht.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:U,deleteKeyCode:X="Backspace",selectionKeyCode:Z="Shift",selectionOnDrag:J=!1,selectionMode:se=tn.Full,panActivationKeyCode:ee="Space",multiSelectionKeyCode:oe=$n()?"Meta":"Control",zoomActivationKeyCode:ce=$n()?"Meta":"Control",snapToGrid:we=!1,snapGrid:ye=rm,onlyRenderVisibleElements:me=!1,selectNodesOnDrag:pe=!0,nodesDraggable:ge,nodesConnectable:Ne,nodesFocusable:ae,nodeOrigin:q=nm,edgesFocusable:xe,edgesUpdatable:Te,elementsSelectable:ze,defaultViewport:qe=sm,minZoom:ke=.5,maxZoom:Me=2,translateExtent:Oe=kr,preventScrolling:H=!0,nodeExtent:Y,defaultMarkerColor:B="#b1b1b7",zoomOnScroll:te=!0,zoomOnPinch:G=!0,panOnScroll:W=!1,panOnScrollSpeed:ie=.5,panOnScrollMode:re=bt.Free,zoomOnDoubleClick:Q=!0,panOnDrag:le=!0,onPaneClick:ne,onPaneMouseEnter:de,onPaneMouseMove:je,onPaneMouseLeave:Le,onPaneScroll:$e,onPaneContextMenu:Ie,children:He,onEdgeContextMenu:Ae,onEdgeDoubleClick:Ke,onEdgeMouseEnter:fe,onEdgeMouseMove:et,onEdgeMouseLeave:zt,onEdgeUpdate:La,onEdgeUpdateStart:Da,onEdgeUpdateEnd:Pa,onReconnect:za,onReconnectStart:Ha,onReconnectEnd:Fa,reconnectRadius:Va=10,edgeUpdaterRadius:Ba=10,onNodesChange:Ga,onEdgesChange:Ya,noDragClassName:Xa="nodrag",noWheelClassName:Wa="nowheel",noPanClassName:Qr="nopan",fitView:Ua=!1,fitViewOptions:qa,connectOnClick:Ka=!0,attributionPosition:Za,proOptions:Qa,defaultEdgeOptions:Ja,elevateNodesOnSelect:ec=!0,elevateEdgesOnSelect:tc=!1,disableKeyboardA11y:Jr=!1,autoPanOnConnect:nc=!0,autoPanOnNodeDrag:rc=!0,connectionRadius:sc=20,isValidConnection:oc,onError:ic,style:ac,id:es,nodeDragThreshold:cc,...lc},uc)=>{const Xn=es||"1";return A.createElement("div",{...lc,style:{...ac,...om},ref:uc,className:Re(["react-flow",s]),"data-testid":"rf__wrapper",id:es},A.createElement(Ki,null,A.createElement(Qh,{onInit:u,onMove:l,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:M,onNodeMouseLeave:b,onNodeContextMenu:$,onNodeDoubleClick:j,nodeTypes:o,edgeTypes:i,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:U,selectionKeyCode:Z,selectionOnDrag:J,selectionMode:se,deleteKeyCode:X,multiSelectionKeyCode:oe,panActivationKeyCode:ee,zoomActivationKeyCode:ce,onlyRenderVisibleElements:me,selectNodesOnDrag:pe,defaultViewport:qe,translateExtent:Oe,minZoom:ke,maxZoom:Me,preventScrolling:H,zoomOnScroll:te,zoomOnPinch:G,zoomOnDoubleClick:Q,panOnScroll:W,panOnScrollSpeed:ie,panOnScrollMode:re,panOnDrag:le,onPaneClick:ne,onPaneMouseEnter:de,onPaneMouseMove:je,onPaneMouseLeave:Le,onPaneScroll:$e,onPaneContextMenu:Ie,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,onEdgeContextMenu:Ae,onEdgeDoubleClick:Ke,onEdgeMouseEnter:fe,onEdgeMouseMove:et,onEdgeMouseLeave:zt,onReconnect:za??La,onReconnectStart:Ha??Da,onReconnectEnd:Fa??Pa,reconnectRadius:Va??Ba,defaultMarkerColor:B,noDragClassName:Xa,noWheelClassName:Wa,noPanClassName:Qr,elevateEdgesOnSelect:tc,rfId:Xn,disableKeyboardA11y:Jr,nodeOrigin:q,nodeExtent:Y}),A.createElement(Uf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:p,onConnectEnd:x,onClickConnectStart:v,onClickConnectEnd:g,nodesDraggable:ge,nodesConnectable:Ne,nodesFocusable:ae,edgesFocusable:xe,edgesUpdatable:Te,elementsSelectable:ze,elevateNodesOnSelect:ec,minZoom:ke,maxZoom:Me,nodeExtent:Y,onNodesChange:Ga,onEdgesChange:Ya,snapToGrid:we,snapGrid:ye,connectionMode:k,translateExtent:Oe,connectOnClick:Ka,defaultEdgeOptions:Ja,fitView:Ua,fitViewOptions:qa,onNodesDelete:I,onEdgesDelete:L,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:N,onSelectionDrag:y,onSelectionDragStart:F,onSelectionDragStop:C,noPanClassName:Qr,nodeOrigin:q,rfId:Xn,autoPanOnConnect:nc,autoPanOnNodeDrag:rc,onError:ic,connectionRadius:sc,isValidConnection:oc,nodeDragThreshold:cc}),A.createElement(Xf,{onSelectionChange:V}),He,A.createElement(wf,{proOptions:Qa,position:Za}),A.createElement(Jf,{rfId:Xn,disableKeyboardA11y:Jr})))});Zi.displayName="ReactFlow";const Qi=({id:e,x:t,y:n,width:r,height:s,style:o,color:i,strokeColor:a,strokeWidth:c,className:u,borderRadius:l,shapeRendering:d,onClick:m,selected:f})=>{const{background:p,backgroundColor:x}=o||{},v=i||p||x;return A.createElement("rect",{className:Re(["react-flow__minimap-node",{selected:f},u]),x:t,y:n,rx:l,ry:l,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?g=>m(g,e):void 0})};Qi.displayName="MiniMapNode";var im=w.memo(Qi);const am=e=>e.nodeOrigin,cm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function lm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:o=im,onClick:i}){const a=he(cm,Ce),c=he(am),u=rr(t),l=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:p,y:x}=_t(f,c).positionAbsolute;return A.createElement(o,{key:f.id,x:p,y:x,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:u(f),borderRadius:r,strokeColor:l(f),strokeWidth:s,shapeRendering:m,onClick:i,id:f.id})}))}var um=w.memo(lm);const dm=200,fm=150,hm=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?_f(an(t,e.nodeOrigin),n):n,rfId:e.rfId}},mm="react-flow__minimap-desc";function Ji({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:o=5,nodeStrokeWidth:i=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:u="none",maskStrokeWidth:l=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:p=!1,zoomable:x=!1,ariaLabel:v="React Flow mini map",inversePan:g=!1,zoomStep:E=10,offsetScale:M=5}){const b=Se(),$=w.useRef(null),{boundingRect:j,viewBB:_,rfId:R}=he(hm,Ce),N=(e==null?void 0:e.width)??dm,I=(e==null?void 0:e.height)??fm,L=j.width/N,V=j.height/I,F=Math.max(L,V),y=F*N,C=F*I,S=M*F,O=j.x-(y-j.width)/2-S,D=j.y-(C-j.height)/2-S,k=y+S*2,T=C+S*2,P=`${mm}-${R}`,z=w.useRef(0);z.current=F,w.useEffect(()=>{if($.current){const Z=Fe($.current),J=oe=>{const{transform:ce,d3Selection:we,d3Zoom:ye}=b.getState();if(oe.sourceEvent.type!=="wheel"||!we||!ye)return;const me=-oe.sourceEvent.deltaY*(oe.sourceEvent.deltaMode===1?.05:oe.sourceEvent.deltaMode?1:.002)*E,pe=ce[2]*Math.pow(2,me);ye.scaleTo(we,pe)},se=oe=>{const{transform:ce,d3Selection:we,d3Zoom:ye,translateExtent:me,width:pe,height:ge}=b.getState();if(oe.sourceEvent.type!=="mousemove"||!we||!ye)return;const Ne=z.current*Math.max(1,ce[2])*(g?-1:1),ae={x:ce[0]-oe.sourceEvent.movementX*Ne,y:ce[1]-oe.sourceEvent.movementY*Ne},q=[[0,0],[pe,ge]],xe=ot.translate(ae.x,ae.y).scale(ce[2]),Te=ye.constrain()(xe,q,me);ye.transform(we,Te)},ee=ai().on("zoom",p?se:null).on("zoom.wheel",x?J:null);return Z.call(ee),()=>{Z.on("zoom",null)}}},[p,x,g,E]);const U=m?Z=>{const J=Ye(Z);m(Z,{x:J[0],y:J[1]})}:void 0,X=f?(Z,J)=>{const se=b.getState().nodeInternals.get(J);f(Z,se)}:void 0;return A.createElement(Or,{position:d,style:e,className:Re(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:N,height:I,viewBox:`${O} ${D} ${k} ${T}`,role:"img","aria-labelledby":P,ref:$,onClick:U},v&&A.createElement("title",{id:P},v),A.createElement(um,{onClick:X,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:o,nodeClassName:s,nodeStrokeWidth:i,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${O-S},${D-S}h${k+S*2}v${T+S*2}h${-k-S*2}z + M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:u,strokeWidth:l,pointerEvents:"none"})))}Ji.displayName="MiniMap";var pm=w.memo(Ji);function gm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function ym(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function xm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function wm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function bm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Wt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:Re(["react-flow__controls-button",t]),...n},e);Wt.displayName="ControlButton";const vm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),ea=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:o,onZoomOut:i,onFitView:a,onInteractiveChange:c,className:u,children:l,position:d="bottom-left"})=>{const m=Se(),[f,p]=w.useState(!1),{isInteractive:x,minZoomReached:v,maxZoomReached:g}=he(vm,Ce),{zoomIn:E,zoomOut:M,fitView:b}=cn();if(w.useEffect(()=>{p(!0)},[]),!f)return null;const $=()=>{E(),o==null||o()},j=()=>{M(),i==null||i()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!x,nodesConnectable:!x,elementsSelectable:!x}),c==null||c(!x)};return A.createElement(Or,{className:Re(["react-flow__controls",u]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Wt,{onClick:$,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:g},A.createElement(gm,null)),A.createElement(Wt,{onClick:j,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(ym,null))),n&&A.createElement(Wt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(xm,null)),r&&A.createElement(Wt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},x?A.createElement(bm,null):A.createElement(wm,null)),l)};ea.displayName="Controls";var _m=w.memo(ea),Be;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Be||(Be={}));function Em({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function Nm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const Sm={[Be.Dots]:"#91919a",[Be.Lines]:"#eee",[Be.Cross]:"#e2e2e2"},km={[Be.Dots]:1,[Be.Lines]:1,[Be.Cross]:6},jm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function ta({id:e,variant:t=Be.Dots,gap:n=20,size:r,lineWidth:s=1,offset:o=2,color:i,style:a,className:c}){const u=w.useRef(null),{transform:l,patternId:d}=he(jm,Ce),m=i||Sm[t],f=r||km[t],p=t===Be.Dots,x=t===Be.Cross,v=Array.isArray(n)?n:[n,n],g=[v[0]*l[2]||1,v[1]*l[2]||1],E=f*l[2],M=x?[E,E]:g,b=p?[E/o,E/o]:[M[0]/o,M[1]/o];return A.createElement("svg",{className:Re(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:u,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:l[0]%g[0],y:l[1]%g[1],width:g[0],height:g[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},p?A.createElement(Nm,{color:m,radius:E/o}):A.createElement(Em,{dimensions:M,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}ta.displayName="Background";var Cm=w.memo(ta);const Yr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Yr+e}async function ve(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function ct(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new na(r.error??`${e}: ${n.status}`,n.status);return r}class na extends Error{constructor(n,r){super(n);_e(this,"status");this.status=r}}const zx=e=>ve(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),Hx=()=>ve("/api/diagnostics"),ra=(e,t)=>ve(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),sa=()=>ve("/api/ontology/ontologies"),Mm=e=>ve(`/api/ontology/term?ref=${encodeURIComponent(e)}`),$m=()=>ve("/api/ontology/stack"),Am=()=>ve("/api/ontology/coverage"),Rm=(e,t,n)=>ct("/api/command",{op:e,payload:t,fingerprint:n??""}),Im=()=>ve("/api/git/status"),Tm=()=>ve("/api/git/diff"),Om=e=>ct("/api/git/commit",{message:e}),Lm=()=>ct("/api/git/discard",{}),Dm=()=>ve("/api/decisions"),Gs=(e,t)=>ct(`/api/decisions/${e}/verdict`,{verdict:t}),Fx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),ve(`/api/glossary/terms?${t.toString()}`)},Vx=()=>ve("/api/glossary/config"),Bx=e=>ct("/api/git/propose",e),Gx=(e="HEAD")=>ve(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Yx=(e="HEAD")=>ve(`/api/git/classify?base=${encodeURIComponent(e)}`),Xx=e=>ct("/api/git/classify",{changes:e}),Wx=e=>ve(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Ux=(e="")=>ve(`/api/git/context?user=${encodeURIComponent(e)}`),qx=(e="")=>ve(`/api/git/proposals?user=${encodeURIComponent(e)}`),Pm=()=>ve("/api/export"),zm=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Yr}/api/export/${encodeURIComponent(e)}${n}`},Hm=(e,t,n)=>ct("/api/import",{format:e,content:t,dialect:n}),Fm=(e,t)=>ct("/api/import/preview",{format:e,content:t}),Kx=e=>ve(`/api/import/stash/${encodeURIComponent(e)}`),Zx=async(e,t=!1)=>{for(const n of e)try{await Rm(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Qx=(e,t,n)=>fetch(`${Yr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new na(await r.text(),r.status);return await r.json()}),Jx=()=>ve("/api/glossary/subject-areas"),ew=e=>ve(`/api/glossary/subject-area/${e}`),tw=(e,t)=>ct(`/api/glossary/subject-area/${e}/expand`,t);function nw(){return{async load(e){try{const t=await ve(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Vm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Bm(e){return e??""}const Xr="__entity_source",Wr="__entity_target",Gm=w.memo(function({data:t,selected:n}){var j;const{entity:r,color:s,dimmed:o,highlighted:i,showTypes:a,collapseDetail:c,expanded:u,onToggleExpand:l,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:p}=t,x=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>x(_.a)-x(R.a)||_.i-R.i).map(_=>_.a),g=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const M=!!c&&!u;let b=0;if(M){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const $=(_,R)=>{const N="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:N,onMouseEnter:p?()=>p(_.id):void 0,onMouseLeave:p?()=>p(null):void 0,children:[h.jsx(mt,{id:_.id,type:"target",position:K.Left,className:"port attr-port"}),h.jsx(mt,{id:_.id,type:"source",position:K.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Vm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Bm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(o?" dimmed":"")+(i?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(mt,{id:Wr,type:"target",position:K.Left,className:"port"}),h.jsx(mt,{id:Xr,type:"source",position:K.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((j=r.conceptual)==null?void 0:j.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var N;const _=(((N=r.conceptual)==null?void 0:N.ontology_refs)??[]).filter(I=>I.uri);if(_.length===0)return null;const R=_.map(I=>I.uri).join(` +`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),g.length>0&&h.jsx("div",{className:"attr-section keys",children:g.map(_=>$(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>$(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:l?()=>l(r.id):void 0,children:`+${b} more`}),u&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:l?()=>l(r.id):void 0,children:"− collapse"})]})]})}),Ym=["string","integer","bigint","decimal","boolean","date","timestamp"];function Xm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:o,onAlign:i,onEditMapping:a}){var m,f,p,x,v,g,E,M,b,$,j,_,R;const c=!n.canEdit,u=e.conceptual,l=t.relationships.filter(N=>N.from.entity===e.id||N.to.entity===e.id),d=N=>{var I;return((I=t.entities.find(L=>L.id===N))==null?void 0:I.name)??N};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(nt,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,name:N})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(nt,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,physical_name:N})})]}),h.jsxs("div",{children:[h.jsx(Um,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Km,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(nt,{value:((m=u==null?void 0:u.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:N=>r("set_definition",{id:e.id,definition:N})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>i(e),children:(((f=u==null?void 0:u.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((p=u==null?void 0:u.ontology_refs)==null?void 0:p.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(u==null?void 0:u.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${u.ontology_layer}`,children:u.ontology_layer}),u.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Wm,{entityId:e.id,refs:(u==null?void 0:u.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(x=e.term_map)!=null&&x.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((g=e.term_map)==null?void 0:g.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),(M=e.term_map)!=null&&M.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[(($=e.term_map)==null?void 0:$.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(nt,{value:((_=u==null?void 0:u.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:N=>{var I;return r("set_stewardship",{id:e.id,owner:N,steward:((I=u==null?void 0:u.stewardship)==null?void 0:I.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(nt,{value:((R=u==null?void 0:u.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:N=>{var I;return r("set_stewardship",{id:e.id,owner:((I=u==null?void 0:u.stewardship)==null?void 0:I.owner)??null,steward:N})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(N=>h.jsx(Qm,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(Jm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(N=>{const I=N.members.map(L=>{var V;return((V=e.attributes.find(F=>F.id===L))==null?void 0:V.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+N.type,children:N.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:N.name}),h.jsx("span",{className:"key-cols",children:I})]},N.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([N,I])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:N}),h.jsx("td",{className:"udp-val",children:String(I)})]},N))})})]}),l.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",l.length,")"]}),l.map(N=>{const I=N.from.entity===e.id?N.to.entity:N.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>o(I),children:[h.jsx("span",{className:"rel-card",children:ep(N,e.id)}),d(I)]}),(N.verb_phrase||N.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(nt,{value:N.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:L=>r("update_relationship",{id:N.id,verb_phrase:L})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(nt,{value:N.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:L=>r("update_relationship",{id:N.id,inverse_verb_phrase:L})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${N.name}`,onClick:()=>r("delete_relationship",{id:N.id}),children:"✕"})]},N.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var N;return(N=navigator.clipboard)==null?void 0:N.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Wm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,o=t.filter(i=>i.uri);return o.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:o.map((i,a)=>{const c=i.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:i.uri??void 0,children:i.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[i.predicate&&h.jsx("span",{className:"ref-pill",children:i.predicate}),i.layer&&h.jsx("span",{className:`chip layer-${i.layer}`,children:i.layer}),i.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",i.resolved_via]}),typeof i.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(i.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:i.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:i.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${i.uri}-${a}`)})})}function nt({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:o=""}){const[i,a]=w.useState(e);w.useEffect(()=>a(e),[e]);const c=()=>{i.trim()!==e.trim()&&t(i.trim())};return n?h.jsx("span",{className:o,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${o}`,value:i,placeholder:s,rows:3,onChange:u=>a(u.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${o}`,value:i,placeholder:s,onChange:u=>a(u.target.value),onBlur:c,onKeyDown:u=>u.key==="Enter"&&u.target.blur()})}function Um({entity:e,doc:t,readOnly:n,exec:r}){var o,i,a;const s=((i=(o=e.conceptual)==null?void 0:o.subject_area)==null?void 0:i.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const qm=["","scd2","hub","link","satellite","bridge"];function Km({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:qm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Zm=["attribute","business_key","measure","surrogate_key"];function Qm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const o=i=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...i});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(nt,{value:e.name,readOnly:!1,onCommit:i=>o({name:i})}),(e.physical_name||!1)&&h.jsx(nt,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:i=>o({physical_name:i})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:i=>o({domain:i.target.value}),children:[...new Set([...Ym,...n.domains??[],e.domain??"string"])].sort().map(i=>h.jsx("option",{value:i,children:i},i))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:i=>o({role:i.target.value}),title:"role",children:Zm.map(i=>h.jsx("option",{value:i,children:i==="business_key"?"🔑 key":i==="measure"?"Σ measure":i},i))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:i=>o({nullable:!i.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Jm({entity:e,exec:t}){const[n,r]=w.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:o=>r(o.target.value),onKeyDown:o=>o.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function ep(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var tp="\0",yt="\0",Ys="";let np=class{constructor(t){_e(this,"_isDirected",!0);_e(this,"_isMultigraph",!1);_e(this,"_isCompound",!1);_e(this,"_label");_e(this,"_defaultNodeLabelFn",()=>{});_e(this,"_defaultEdgeLabelFn",()=>{});_e(this,"_nodes",{});_e(this,"_in",{});_e(this,"_preds",{});_e(this,"_out",{});_e(this,"_sucs",{});_e(this,"_edgeObjs",{});_e(this,"_edgeLabels",{});_e(this,"_nodeCount",0);_e(this,"_edgeCount",0);_e(this,"_parent");_e(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[yt]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(o){r.length>1?s.setNode(o,n):s.setNode(o)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=yt,this._children[t]={},this._children[yt][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=yt;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==yt)return n}}children(t=yt){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===yt)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([i,a]){t(i)&&n.setNode(i,a)}),Object.values(this._edgeObjs).forEach(function(i){n.hasNode(i.v)&&n.hasNode(i.w)&&n.setEdge(i,r.edge(i))});var s={};function o(i){var a=r.parent(i);return a===void 0||n.hasNode(a)?(s[i]=a,a):a in s?s[a]:o(a)}return this._isCompound&&n.nodes().forEach(i=>n.setParent(i,o(i))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(o,i){return s.length>1?r.setEdge(o,i,n):r.setEdge(o,i),i}),this}setEdge(){var t,n,r,s,o=!1,i=arguments[0];typeof i=="object"&&i!==null&&"v"in i?(t=i.v,n=i.w,r=i.name,arguments.length===2&&(s=arguments[1],o=!0)):(t=i,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],o=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Ut(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return o&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=o?s:this._defaultEdgeLabelFn(t,n,r);var c=rp(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Xs(this._preds[n],t),Xs(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r),o=this._edgeObjs[s];return o&&(t=o.v,n=o.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Ws(this._preds[n],t),Ws(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(o=>o.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(o=>o.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Xs(e,t){e[t]?e[t]++:e[t]=1}function Ws(e,t){--e[t]||delete e[t]}function Ut(e,t,n,r){var s=""+t,o=""+n;if(!e&&s>o){var i=s;s=o,o=i}return s+Ys+o+Ys+(r===void 0?tp:r)}function rp(e,t,n,r){var s=""+t,o=""+n;if(!e&&s>o){var i=s;s=o,o=i}var a={v:s,w:o};return r&&(a.name=r),a}function sr(e,t){return Ut(e,t.v,t.w,t.name)}var Ur=np,sp="2.2.4",op={Graph:Ur,version:sp},ip=Ur,ap={write:cp,read:dp};function cp(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:lp(e),edges:up(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function lp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function up(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function dp(e){var t=new ip(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var fp=hp;function hp(e){var t={},n=[],r;function s(o){Object.hasOwn(t,o)||(t[o]=!0,r.push(o),e.successors(o).forEach(s),e.predecessors(o).forEach(s))}return e.nodes().forEach(function(o){r=[],s(o),r.length&&n.push(r)}),n}let mp=class{constructor(){_e(this,"_arr",[]);_e(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,o=s.length;return r[t]=o,s.push({key:t,priority:n}),this._decrease(o),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,o=t;r>1,!(n[s].priority1;function yp(e,t,n,r){return xp(e,String(t),n||gp,r||function(s){return e.outEdges(s)})}function xp(e,t,n,r){var s={},o=new pp,i,a,c=function(u){var l=u.v!==i?u.v:u.w,d=s[l],m=n(u),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+u+" Weight: "+m);f0&&(i=o.removeMin(),a=s[i],a.distance!==Number.POSITIVE_INFINITY);)r(i).forEach(c);return s}var wp=ia,bp=vp;function vp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=wp(e,s,t,n),r},{})}var aa=_p;function _p(e){var t=0,n=[],r={},s=[];function o(i){var a=r[i]={onStack:!0,lowlink:t,index:t++};if(n.push(i),e.successors(i).forEach(function(l){Object.hasOwn(r,l)?r[l].onStack&&(a.lowlink=Math.min(a.lowlink,r[l].index)):(o(l),a.lowlink=Math.min(a.lowlink,r[l].lowlink))}),a.lowlink===a.index){var c=[],u;do u=n.pop(),r[u].onStack=!1,c.push(u);while(i!==u);s.push(c)}}return e.nodes().forEach(function(i){Object.hasOwn(r,i)||o(i)}),s}var Ep=aa,Np=Sp;function Sp(e){return Ep(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var kp=Cp,jp=()=>1;function Cp(e,t,n){return Mp(e,t||jp,n||function(r){return e.outEdges(r)})}function Mp(e,t,n){var r={},s=e.nodes();return s.forEach(function(o){r[o]={},r[o][o]={distance:0},s.forEach(function(i){o!==i&&(r[o][i]={distance:Number.POSITIVE_INFINITY})}),n(o).forEach(function(i){var a=i.v===o?i.w:i.v,c=t(i);r[o][a]={distance:c,predecessor:o}})}),s.forEach(function(o){var i=r[o];s.forEach(function(a){var c=r[a];s.forEach(function(u){var l=c[o],d=i[u],m=c[u],f=l.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?Ip:Tp,o=[],i={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,i,o)}),o}function Ip(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var o=s.pop();o[1]?r.push(o[0]):Object.hasOwn(n,o[0])||(n[o[0]]=!0,s.push([o[0],!0]),da(t(o[0]),i=>s.push([i,!1])))}}function Tp(e,t,n,r){for(var s=[e];s.length>0;){var o=s.pop();Object.hasOwn(n,o)||(n[o]=!0,r.push(o),da(t(o),i=>s.push(i)))}}function da(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var Op=ua,Lp=Dp;function Dp(e,t){return Op(e,t,"post")}var Pp=ua,zp=Hp;function Hp(e,t){return Pp(e,t,"pre")}var Fp=Ur,Vp=oa,Bp=Gp;function Gp(e,t){var n=new Fp,r={},s=new Vp,o;function i(c){var u=c.v===o?c.w:c.v,l=s.priority(u);if(l!==void 0){var d=t(c);d0;){if(o=s.removeMin(),Object.hasOwn(r,o))n.setEdge(o,r[o]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(o).forEach(i)}return n}var Yp={components:fp,dijkstra:ia,dijkstraAll:bp,findCycles:Np,floydWarshall:kp,isAcyclic:$p,postorder:Lp,preorder:zp,prim:Bp,tarjan:aa,topsort:la},qs=op,Ue={Graph:qs.Graph,json:ap,alg:Yp,version:qs.version};let Xp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Ks(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Ks(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Wp)),r=r._prev;return"["+t.join(", ")+"]"}};function Ks(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Wp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Up=Xp;let qp=Ue.Graph,Kp=Up;var Zp=Jp;let Qp=()=>1;function Jp(e,t){if(e.nodeCount()<=1)return[];let n=tg(e,t||Qp);return eg(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function eg(e,t,n){let r=[],s=t[t.length-1],o=t[0],i;for(;e.nodeCount();){for(;i=o.dequeue();)or(e,t,n,i);for(;i=s.dequeue();)or(e,t,n,i);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(i=t[a].dequeue(),i){r=r.concat(or(e,t,n,i,!0));break}}}return r}function or(e,t,n,r,s){let o=s?[]:void 0;return e.inEdges(r.v).forEach(i=>{let a=e.edge(i),c=e.node(i.v);s&&o.push({v:i.v,w:i.w}),c.out-=a,Cr(t,n,c)}),e.outEdges(r.v).forEach(i=>{let a=e.edge(i),c=i.w,u=e.node(c);u.in-=a,Cr(t,n,u)}),e.removeNode(r.v),o}function tg(e,t){let n=new qp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,u=t(a),l=c+u;n.setEdge(a.v,a.w,l),s=Math.max(s,n.node(a.v).out+=u),r=Math.max(r,n.node(a.w).in+=u)});let o=ng(s+r+3).map(()=>new Kp),i=r+1;return n.nodes().forEach(a=>{Cr(o,i,n.node(a))}),{graph:n,buckets:o,zeroIdx:i}}function Cr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function ng(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function sg(e){let t=new fa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function og(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return qr(e.nodes(),t)}function ig(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return qr(e.nodes(),t)}function ag(e,t){let n=e.x,r=e.y,s=t.x-n,o=t.y-r,i=e.width/2,a=e.height/2;if(!s&&!o)throw new Error("Not possible to find intersection inside of the rectangle");let c,u;return Math.abs(o)*i>Math.abs(s)*a?(o<0&&(a=-a),c=a*s/o,u=a):(s<0&&(i=-i),c=i,u=i*o/s),{x:n+c,y:r+u}}function cg(e){let t=ya(pa(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function lg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function ug(e){let t=e.nodes().map(i=>e.node(i).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(i=>{let a=e.node(i).rank-n;r[a]||(r[a]=[]),r[a].push(i)});let s=0,o=e.graph().nodeRankFactor;Array.from(r).forEach((i,a)=>{i===void 0&&a%o!==0?--s:i!==void 0&&s&&i.forEach(c=>e.node(c).rank+=s)})}function dg(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),ha(e,"border",s,t)}function fg(e,t=ma){const n=[];for(let r=0;rma){const n=fg(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function pa(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function hg(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function mg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function pg(e,t){return t()}let gg=0;function ga(e){var t=++gg;return e+(""+t)}function ya(e,t,n=1){t==null&&(t=e,e=0);let r=o=>otr[t]),Object.entries(e).reduce((r,[s,o])=>(r[s]=n(o,s),r),{})}function qr(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let wg=Zp,bg=Ee.uniqueId;var vg={run:_g,undo:Ng};function _g(e){(e.graph().acyclicer==="greedy"?wg(e,n(e)):Eg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,bg("rev"))});function n(r){return s=>r.edge(s).weight}}function Eg(e){let t=[],n={},r={};function s(o){Object.hasOwn(r,o)||(r[o]=!0,n[o]=!0,e.outEdges(o).forEach(i=>{Object.hasOwn(n,i.w)?t.push(i):s(i.w)}),delete n[o])}return e.nodes().forEach(s),t}function Ng(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let Sg=Ee;var kg={run:jg,undo:Mg};function jg(e){e.graph().dummyChains=[],e.edges().forEach(t=>Cg(e,t))}function Cg(e,t){let n=t.v,r=e.node(n).rank,s=t.w,o=e.node(s).rank,i=t.name,a=e.edge(t),c=a.labelRank;if(o===r+1)return;e.removeEdge(t);let u,l,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:$g}=Ee;var Yn={longestPath:Ag,slack:Rg};function Ag(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let o=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var i=$g(Math.min,o);return i===Number.POSITIVE_INFINITY&&(i=0),s.rank=i}e.sources().forEach(n)}function Rg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var Ig=Ue.Graph,On=Yn.slack,xa=Tg;function Tg(e){var t=new Ig({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,o;Og(t,e){var o=s.v,i=r===o?s.w:o;!e.hasNode(i)&&!On(t,s)&&(e.setNode(i,{}),e.setEdge(r,i,{}),n(i))})}return e.nodes().forEach(n),e.nodeCount()}function Lg(e,t){return t.edges().reduce((r,s)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(o=On(t,s)),ot.node(r).rank+=n)}var Pg=xa,Zs=Yn.slack,zg=Yn.longestPath,Hg=Ue.alg.preorder,Fg=Ue.alg.postorder,Vg=Ee.simplify,Bg=St;St.initLowLimValues=Zr;St.initCutValues=Kr;St.calcCutValue=wa;St.leaveEdge=va;St.enterEdge=_a;St.exchangeEdges=Ea;function St(e){e=Vg(e),zg(e);var t=Pg(e);Zr(t),Kr(t,e);for(var n,r;n=va(t);)r=_a(t,e,n),Ea(t,e,n,r)}function Kr(e,t){var n=Fg(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Gg(e,t,r))}function Gg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=wa(e,t,n)}function wa(e,t,n){var r=e.node(n),s=r.parent,o=!0,i=t.edge(n,s),a=0;return i||(o=!1,i=t.edge(s,n)),a=i.weight,t.nodeEdges(n).forEach(c=>{var u=c.v===n,l=u?c.w:c.v;if(l!==s){var d=u===o,m=t.edge(c).weight;if(a+=d?m:-m,Xg(e,n,l)){var f=e.edge(n,l).cutvalue;a+=d?-f:f}}}),a}function Zr(e,t){arguments.length<2&&(t=e.nodes()[0]),ba(e,{},1,t)}function ba(e,t,n,r,s){var o=n,i=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ba(e,t,n,a,r))}),i.low=o,i.lim=n++,s?i.parent=s:delete i.parent,n}function va(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function _a(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var o=e.node(r),i=e.node(s),a=o,c=!1;o.lim>i.lim&&(a=i,c=!0);var u=t.edges().filter(l=>c===Qs(e,e.node(l.v),a)&&c!==Qs(e,e.node(l.w),a));return u.reduce((l,d)=>Zs(t,d)!t.node(s).parent),r=Hg(e,n);r=r.slice(1),r.forEach(s=>{var o=e.node(s).parent,i=t.edge(s,o),a=!1;i||(i=t.edge(o,s),a=!0),t.node(s).rank=t.node(o).rank+(a?i.minlen:-i.minlen)})}function Xg(e,t,n){return e.hasEdge(t,n)}function Qs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Wg=Yn,Na=Wg.longestPath,Ug=xa,qg=Bg,Kg=Zg;function Zg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Js(e);break;case"tight-tree":Jg(e);break;case"longest-path":Qg(e);break;case"none":break;default:Js(e)}}var Qg=Na;function Jg(e){Na(e),Ug(e)}function Js(e){qg(e)}var ey=ty;function ty(e){let t=ry(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,o=ny(e,t,s.v,s.w),i=o.path,a=o.lca,c=0,u=i[c],l=!0;for(;n!==s.w;){if(r=e.node(n),l){for(;(u=i[c])!==a&&e.node(u).maxRanki||a>t[c].lim));for(u=c,c=r;(c=e.parent(c))!==u;)o.push(c);return{path:s.concat(o.reverse()),lca:u}}function ry(e){let t={},n=0;function r(s){let o=n;e.children(s).forEach(r),t[s]={low:o,lim:n++}}return e.children().forEach(r),t}let Ln=Ee;var sy={run:oy,cleanup:cy};function oy(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=iy(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,o=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=o);let i=ay(e)+1;e.children().forEach(a=>Sa(e,t,o,i,s,n,a)),e.graph().nodeRankFactor=o}function Sa(e,t,n,r,s,o,i){let a=e.children(i);if(!a.length){i!==t&&e.setEdge(t,i,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),u=Ln.addBorderNode(e,"_bb"),l=e.node(i);e.setParent(c,i),l.borderTop=c,e.setParent(u,i),l.borderBottom=u,a.forEach(d=>{Sa(e,t,n,r,s,o,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,p=m.borderBottom?m.borderBottom:d,x=m.borderTop?r:2*r,v=f!==p?1:s-o[i]+1;e.setEdge(c,f,{weight:x,minlen:v,nestingEdge:!0}),e.setEdge(p,u,{weight:x,minlen:v,nestingEdge:!0})}),e.parent(i)||e.setEdge(t,c,{weight:0,minlen:s+o[i]})}function iy(e){var t={};function n(r,s){var o=e.children(r);o&&o.length&&o.forEach(i=>n(i,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function ay(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function cy(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let ly=Ee;var uy=dy;function dy(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let o=s.minRank,i=s.maxRank+1;oto(e.node(t))),e.edges().forEach(t=>to(e.edge(t)))}function to(e){let t=e.width;e.width=e.height,e.height=t}function py(e){e.nodes().forEach(t=>ir(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ir),Object.hasOwn(n,"y")&&ir(n)})}function ir(e){e.y=-e.y}function gy(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let no=Ee;var yy=xy;function xy(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=no.applyWithChunking(Math.max,r),o=no.range(s+1).map(()=>[]);function i(c){if(t[c])return;t[c]=!0;let u=e.node(c);o[u.rank].push(c),e.successors(c).forEach(i)}return n.sort((c,u)=>e.node(c).rank-e.node(u).rank).forEach(i),o}let wy=Ee.zipObject;var by=vy;function vy(e,t){let n=0;for(let r=1;rl)),s=t.flatMap(u=>e.outEdges(u).map(l=>({pos:r[l.w],weight:e.edge(l).weight})).sort((l,d)=>l.pos-d.pos)),o=1;for(;o{let l=u.pos+o;a[l]+=u.weight;let d=0;for(;l>0;)l%2&&(d+=a[l+1]),l=l-1>>1,a[l]+=u.weight;c+=u.weight*d}),c}var Ey=Ny;function Ny(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((o,i)=>{let a=e.edge(i),c=e.node(i.v);return{sum:o.sum+a.weight*c.order,weight:o.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let Sy=Ee;var ky=jy;function jy(e,t){let n={};e.forEach((s,o)=>{let i=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i:o};s.barycenter!==void 0&&(i.barycenter=s.barycenter,i.weight=s.weight)}),t.edges().forEach(s=>{let o=n[s.v],i=n[s.w];o!==void 0&&i!==void 0&&(i.indegree++,o.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return Cy(r)}function Cy(e){let t=[];function n(s){return o=>{o.merged||(o.barycenter===void 0||s.barycenter===void 0||o.barycenter>=s.barycenter)&&My(s,o)}}function r(s){return o=>{o.in.push(s),--o.indegree===0&&e.push(o)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>Sy.pick(s,["vs","i","barycenter","weight"]))}function My(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let $y=Ee;var Ay=Ry;function Ry(e,t){let n=$y.partition(e,l=>Object.hasOwn(l,"barycenter")),r=n.lhs,s=n.rhs.sort((l,d)=>d.i-l.i),o=[],i=0,a=0,c=0;r.sort(Iy(!!t)),c=ro(o,s,c),r.forEach(l=>{c+=l.vs.length,o.push(l.vs),i+=l.barycenter*l.weight,a+=l.weight,c=ro(o,s,c)});let u={vs:o.flat(!0)};return a&&(u.barycenter=i/a,u.weight=a),u}function ro(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function Iy(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Ty=Ey,Oy=ky,Ly=Ay;var Dy=ja;function ja(e,t,n,r){let s=e.children(t),o=e.node(t),i=o?o.borderLeft:void 0,a=o?o.borderRight:void 0,c={};i&&(s=s.filter(m=>m!==i&&m!==a));let u=Ty(e,s);u.forEach(m=>{if(e.children(m.v).length){let f=ja(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&zy(m,f)}});let l=Oy(u,n);Py(l,c);let d=Ly(l,r);if(i&&(d.vs=[i,d.vs,a].flat(!0),e.predecessors(i).length)){let m=e.node(e.predecessors(i)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function Py(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function zy(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let Hy=Ue.Graph,Fy=Ee;var Vy=By;function By(e,t,n,r){r||(r=e.nodes());let s=Gy(e),o=new Hy({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(i=>e.node(i));return r.forEach(i=>{let a=e.node(i),c=e.parent(i);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(o.setNode(i),o.setParent(i,c||s),e[n](i).forEach(u=>{let l=u.v===i?u.w:u.v,d=o.edge(l,i),m=d!==void 0?d.weight:0;o.setEdge(l,i,{weight:e.edge(u).weight+m})}),Object.hasOwn(a,"minRank")&&o.setNode(i,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),o}function Gy(e){for(var t;e.hasNode(t=Fy.uniqueId("_root")););return t}var Yy=Xy;function Xy(e,t,n){let r={},s;n.forEach(o=>{let i=e.parent(o),a,c;for(;i;){if(a=e.parent(i),a?(c=r[a],r[a]=i):(c=s,s=i),c&&c!==i){t.setEdge(c,i);return}i=a}})}let Wy=yy,Uy=by,qy=Dy,Ky=Vy,Zy=Yy,Qy=Ue.Graph,wn=Ee;var Jy=Ca;function Ca(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,Ca);return}let n=wn.maxRank(e),r=so(e,wn.range(1,n+1),"inEdges"),s=so(e,wn.range(n-1,-1,-1),"outEdges"),o=Wy(e);if(oo(e,o),t&&t.disableOptimalOrderHeuristic)return;let i=Number.POSITIVE_INFINITY,a;for(let c=0,u=0;u<4;++c,++u){e0(c%2?r:s,c%4>=2),o=wn.buildLayerMatrix(e);let l=Uy(e,o);l{r.has(o)||r.set(o,[]),r.get(o).push(i)};for(const o of e.nodes()){const i=e.node(o);if(typeof i.rank=="number"&&s(i.rank,o),typeof i.minRank=="number"&&typeof i.maxRank=="number")for(let a=i.minRank;a<=i.maxRank;a++)a!==i.rank&&s(a,o)}return t.map(function(o){return Ky(e,o,n,r.get(o)||[])})}function e0(e,t){let n=new Qy;e.forEach(function(r){let s=r.graph().root,o=qy(r,s,n,t);o.vs.forEach((i,a)=>r.node(i).order=a),Zy(r,n,o.vs)})}function oo(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let t0=Ue.Graph,rt=Ee;var n0={positionX:h0};function r0(e,t){let n={};function r(s,o){let i=0,a=0,c=s.length,u=o[o.length-1];return o.forEach((l,d)=>{let m=o0(e,l),f=m?e.node(m).order:c;(m||l===u)&&(o.slice(a,d+1).forEach(p=>{e.predecessors(p).forEach(x=>{let v=e.node(x),g=v.order;(g{l=o[d],e.node(l).dummy&&e.predecessors(l).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderu)&&Ma(n,m,l)})})}function s(o,i){let a=-1,c,u=0;return i.forEach((l,d)=>{if(e.node(l).dummy==="border"){let m=e.predecessors(l);m.length&&(c=e.node(m[0]).order,r(i,u,d,a,c),u=d,a=c)}r(i,u,i.length,c,o.length)}),i}return t.length&&t.reduce(s),n}function o0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ma(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function i0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function a0(e,t,n,r){let s={},o={},i={};return t.forEach(a=>{a.forEach((c,u)=>{s[c]=c,o[c]=c,i[c]=u})}),t.forEach(a=>{let c=-1;a.forEach(u=>{let l=r(u);if(l.length){l=l.sort((m,f)=>i[m]-i[f]);let d=(l.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let p=l[m];o[u]===u&&cMath.max(m,o[f.v]+i.edge(f)),0)}function l(d){let m=i.outEdges(d).reduce((p,x)=>Math.min(p,o[x.w]-i.edge(x)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(o[d]=Math.max(o[d],m))}return c(u,i.predecessors.bind(i)),c(l,i.successors.bind(i)),Object.keys(r).forEach(d=>o[d]=o[n[d]]),o}function l0(e,t,n,r){let s=new t0,o=e.graph(),i=m0(o.nodesep,o.edgesep,r);return t.forEach(a=>{let c;a.forEach(u=>{let l=n[u];if(s.setNode(l),c){var d=n[c],m=s.edge(d,l);s.setEdge(d,l,Math.max(i(e,u,c),m||0))}c=u})}),s}function u0(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let u=p0(e,a)/2;s=Math.max(c+u,s),o=Math.min(c-u,o)});const i=s-o;return i{["l","r"].forEach(i=>{let a=o+i,c=e[a];if(c===t)return;let u=Object.values(c),l=r-rt.applyWithChunking(Math.min,u);i!=="l"&&(l=s-rt.applyWithChunking(Math.max,u)),l&&(e[a]=rt.mapValues(c,d=>d+l))})})}function f0(e,t){return rt.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(o=>o[r]).sort((o,i)=>o-i);return(s[1]+s[2])/2}})}function h0(e){let t=rt.buildLayerMatrix(e),n=Object.assign(r0(e,t),s0(e,t)),r={},s;["u","d"].forEach(i=>{s=i==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(i==="u"?e.predecessors:e.successors).bind(e),u=a0(e,s,n,c),l=c0(e,s,u.root,u.align,a==="r");a==="r"&&(l=rt.mapValues(l,d=>-d)),r[i+a]=l})});let o=u0(e,r);return d0(r,o),f0(r,e.graph().align)}function m0(e,t,n){return(r,s,o)=>{let i=r.node(s),a=r.node(o),c=0,u;if(c+=i.width/2,Object.hasOwn(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":u=-i.width/2;break;case"r":u=i.width/2;break}if(u&&(c+=n?u:-u),u=0,c+=(i.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":u=a.width/2;break;case"r":u=-a.width/2;break}return u&&(c+=n?u:-u),u=0,c}}function p0(e,t){return e.node(t).width}let $a=Ee,g0=n0.positionX;var y0=x0;function x0(e){e=$a.asNonCompoundGraph(e),w0(e),Object.entries(g0(e)).forEach(([t,n])=>e.node(t).x=n)}function w0(e){let t=$a.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const o=s.reduce((i,a)=>{const c=e.node(a).height;return i>c?i:c},0);s.forEach(i=>e.node(i).y=r+o/2),r+=o+n})}let io=vg,ao=kg,b0=Kg,v0=Ee.normalizeRanks,_0=ey,E0=Ee.removeEmptyRanks,co=sy,N0=uy,lo=fy,S0=Jy,k0=y0,Ge=Ee,j0=Ue.Graph;var C0=M0;function M0(e,t){let n=t&&t.debugTiming?Ge.time:Ge.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>z0(e));n(" runLayout",()=>$0(r,n,t)),n(" updateInputGraph",()=>A0(e,r))})}function $0(e,t,n){t(" makeSpaceForEdgeLabels",()=>H0(e)),t(" removeSelfEdges",()=>q0(e)),t(" acyclic",()=>io.run(e)),t(" nestingGraph.run",()=>co.run(e)),t(" rank",()=>b0(Ge.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>F0(e)),t(" removeEmptyRanks",()=>E0(e)),t(" nestingGraph.cleanup",()=>co.cleanup(e)),t(" normalizeRanks",()=>v0(e)),t(" assignRankMinMax",()=>V0(e)),t(" removeEdgeLabelProxies",()=>B0(e)),t(" normalize.run",()=>ao.run(e)),t(" parentDummyChains",()=>_0(e)),t(" addBorderSegments",()=>N0(e)),t(" order",()=>S0(e,n)),t(" insertSelfEdges",()=>K0(e)),t(" adjustCoordinateSystem",()=>lo.adjust(e)),t(" position",()=>k0(e)),t(" positionSelfEdges",()=>Z0(e)),t(" removeBorderNodes",()=>U0(e)),t(" normalize.undo",()=>ao.undo(e)),t(" fixupEdgeLabelCoords",()=>X0(e)),t(" undoCoordinateSystem",()=>lo.undo(e)),t(" translateGraph",()=>G0(e)),t(" assignNodeIntersects",()=>Y0(e)),t(" reversePoints",()=>W0(e)),t(" acyclic.undo",()=>io.undo(e))}function A0(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let R0=["nodesep","edgesep","ranksep","marginx","marginy"],I0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},T0=["acyclicer","ranker","rankdir","align"],O0=["width","height","rank"],uo={width:0,height:0},L0=["minlen","weight","width","height","labeloffset"],D0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},P0=["labelpos"];function z0(e){let t=new j0({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},I0,cr(n,R0),Ge.pick(n,T0))),e.nodes().forEach(r=>{let s=lr(e.node(r));const o=cr(s,O0);Object.keys(uo).forEach(i=>{o[i]===void 0&&(o[i]=uo[i])}),t.setNode(r,o),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},D0,cr(s,L0),Ge.pick(s,P0)))}),t}function H0(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function F0(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),o={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};Ge.addDummyNode(e,"edge-proxy",o,"_ep")}})}function V0(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function B0(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function G0(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,o=e.graph(),i=o.marginx||0,a=o.marginy||0;function c(u){let l=u.x,d=u.y,m=u.width,f=u.height;t=Math.min(t,l-m/2),n=Math.max(n,l+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(u=>c(e.node(u))),e.edges().forEach(u=>{let l=e.edge(u);Object.hasOwn(l,"x")&&c(l)}),t-=i,r-=a,e.nodes().forEach(u=>{let l=e.node(u);l.x-=t,l.y-=r}),e.edges().forEach(u=>{let l=e.edge(u);l.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(l,"x")&&(l.x-=t),Object.hasOwn(l,"y")&&(l.y-=r)}),o.width=n-t+i,o.height=s-r+a}function Y0(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),o,i;n.points?(o=n.points[0],i=n.points[n.points.length-1]):(n.points=[],o=s,i=r),n.points.unshift(Ge.intersectRect(r,o)),n.points.push(Ge.intersectRect(s,i))})}function X0(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function W0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function U0(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),o=e.node(n.borderLeft[n.borderLeft.length-1]),i=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(i.x-o.x),n.height=Math.abs(s.y-r.y),n.x=o.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function q0(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function K0(e){var t=Ge.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,o)=>{var i=e.node(s);i.order=o+r,(i.selfEdges||[]).forEach(a=>{Ge.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:i.rank,order:o+ ++r,e:a.e,label:a.label},"_se")}),delete i.selfEdges})})}function Z0(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,o=r.y,i=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*i/3,y:o-a},{x:s+5*i/6,y:o-a},{x:s+i,y:o},{x:s+5*i/6,y:o+a},{x:s+2*i/3,y:o+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return Ge.mapValues(Ge.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Q0=Ee,J0=Ue.Graph;var ex={debugOrdering:tx};function tx(e){let t=Q0.buildLayerMatrix(e),n=new J0({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let o="layer"+s;n.setNode(o,{rank:"same"}),r.reduce((i,a)=>(n.setEdge(i,a,{style:"invis"}),a))}),n}var nx="1.1.8",rx={graphlib:Ue,layout:C0,debug:ex,util:{time:Ee.time,notime:Ee.notime},version:nx};const fo=Co(rx),Qe=264,sx=44,ox=26,ix=14;function pt(e){const t=Math.max(e.attributes.length,1);return sx+t*ox+ix}const ax=40;function ur(e,t,n,r="auto",s,o="LR"){const i=cx(n,s);return r==="grid"?go(e,n,i):r==="clustered"?po(e,t,n,i,o):r==="hierarchical"||e.length<=ax?ho(e,t,n,o):new Set(e.map(c=>i(c.id)).filter(Boolean)).size>1?po(e,t,n,i,o):go(e,n,i)}function cx(e,t){return n=>{var r,s,o;if(t){const i=t.get(n);if(i)return i.name}return((o=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:o.name)??""}}function Aa(e,t,n,r=!1,s="LR"){const o=new fo.graphlib.Graph;o.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),o.setDefaultEdgeLabel(()=>({}));const i=new Set(e.map(l=>l.id));for(const l of e){const d=n.get(l.id);o.setNode(l.id,{width:Qe,height:d?pt(d):120})}for(const l of t)i.has(l.source)&&i.has(l.target)&&o.setEdge(l.source,l.target,{minlen:1,weight:2});fo.layout(o);let a=0,c=0;return{nodes:e.map(l=>{const d=o.node(l.id),m=n.get(l.id),f=m?pt(m):120,p=d.x-Qe/2,x=d.y-f/2;return a=Math.max(a,p+Qe),c=Math.max(c,x+f),{...l,position:{x:p,y:x}}}),width:a,height:c}}function ho(e,t,n,r="LR"){return Aa(e,t,n,!1,r).nodes}function lx(e,t){const n=a=>{const c=t.get(a);return c?pt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let o=0,i=0;for(let a=0;a{const d=l*(Qe+Ra);s.push({...u,position:{x:d,y:o}}),i=Math.max(i,d+Qe)}),o+=Math.max(...c.map(u=>n(u.id)))+Ia}return{nodes:s,width:i,height:o}}const mo=120;function po(e,t,n,r,s="LR"){const o=new Map;for(const m of e){const f=r(m.id);(o.get(f)??o.set(f,[]).get(f)).push(m)}const a=[...o.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=o.get(m),p=new Set(f.map(E=>E.id));let x=0;for(const E of t)p.has(E.source)&&p.has(E.target)&&x++;const g=f.length<=8&&x>=f.length-1?Aa(f,t,n,!0,s):lx(f,n);return{name:m,...g}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),u=[];let l=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const Ra=40,Ia=40;function go(e,t,n){const r=u=>{const l=t.get(u);return l?pt(l):120},s=[...e].sort((u,l)=>{var x,v;const d=n(u.id),m=n(l.id);if(d!==m)return d.localeCompare(m);const f=((x=t.get(u.id))==null?void 0:x.name)??u.id,p=((v=t.get(l.id))==null?void 0:v.name)??l.id;return f.localeCompare(p)}),o=Math.max(1,Math.round(Math.sqrt(s.length))),i=Array.from({length:o},(u,l)=>l*(Qe+Ra)),a=new Map;let c=0;for(let u=0;ua.set(m.id,{x:i[f],y:c}));const d=Math.max(...l.map(m=>r(m.id)));c+=d+Ia}return e.map(u=>({...u,position:a.get(u.id)??u.position}))}function ln({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const ux=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ta=["industry","core","domain","specialised"];function dx({entity:e,exec:t,onClose:n}){var b,$;const[r,s]=w.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[o,i]=w.useState([]),[a,c]=w.useState(null),[u,l]=w.useState(null),[d,m]=w.useState("skos:exactMatch"),[f,p]=w.useState((($=e.conceptual)==null?void 0:$.ontology_layer)??"core"),[x,v]=w.useState([]),[g,E]=w.useState("");w.useEffect(()=>{sa().then(j=>v(j.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return i([]);ra(r,g||void 0).then(_=>{i(_.results),c(_.loaded_terms)}).catch(()=>i([]))},200);return()=>clearTimeout(j)},[r,g]);const M=()=>{u&&t("set_alignment",{id:e.id,aligns_to:u.prefixed,alignment:d,layer:f,resolved_via:u.source}).then(n)};return h.jsxs(ln,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[x.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(g===""?" active":""),onClick:()=>E(""),children:"all sources"}),x.map(j=>h.jsx("button",{className:"src-chip"+(g===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:g?`Search within ${g}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&x.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[o.map(j=>h.jsxs("button",{className:"term-card"+((u==null?void 0:u.iri)===j.iri?" picked":""),onClick:()=>l(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&o.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:ux.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>p(j.target.value),children:Ta.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!u,onClick:M,children:["Align",u?` to ${u.label}`:""]})]})]})}function fx({entity:e,doc:t,exec:n,onClose:r}){var b,$,j;const[s,o]=w.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[i,a]=w.useState((($=e.term_map)==null?void 0:$.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),l=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=l.length===0&&d(i),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:i.trim()||null}).then(r)},p=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",x=t.project.kg_base_iri||`urn:${p}:`,v=(j=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:j.members.map(_=>{var R;return(R=e.attributes.find(N=>N.id===_))==null?void 0:R.name}).filter(Boolean),g=v&&v.length?`${x}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=i.trim()||`${x}${e.id}`,M=s.trim()||g;return h.jsxs(ln,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:i,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(i)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>o(_.target.value)}),l.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",l.length>1?"s":"",": ",l.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",M]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function hx({doc:e,exec:t,onClose:n,onCreated:r}){const[s,o]=w.useState(""),[i,a]=w.useState(""),[c,u]=w.useState(""),[l,d]=w.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:i||null,subject_area:c||null,layer:l||null}).then(f=>{const p=f==null?void 0:f.created_id;n(),p&&r(p)})};return h.jsxs(ln,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>o(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:i,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>u(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:l,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ta.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const Oa=["many_to_one","one_to_many","one_to_one","many_to_many"];function mx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:o,onClose:i}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),u=w.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[l,d]=w.useState(r??""),[m,f]=w.useState(s??(u==null?void 0:u.id)??""),[p,x]=w.useState("many_to_one"),[v,g]=w.useState("mandatory");if(!a||!c)return null;const E=l==="__new__",M=()=>o("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:l||null,to_attribute:m||null,create_from_fk:E,cardinality:p,optionality:v}).then(i);return h.jsxs(ln,{title:`${a.name} → ${c.name}`,onClose:i,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:p,onChange:b=>x(b.target.value),children:Oa.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:l,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",u?` "${u.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>g(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:M,children:"Create relationship"})})]})}function px({rel:e,doc:t,exec:n,onClose:r}){const s=g=>{var E;return((E=t.entities.find(M=>M.id===g))==null?void 0:E.name)??"?"},[o,i]=w.useState(e.name),[a,c]=w.useState(e.cardinality),[u,l]=w.useState(e.optionality),[d,m]=w.useState(e.identifying),[f,p]=w.useState(!1),x=async()=>{o.trim()&&o.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:o.trim()}),(a!==e.cardinality||u!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:u,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(ln,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:o,onChange:g=>i(g.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:g=>c(g.target.value),children:Oa.map(g=>h.jsx("option",{children:g},g))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:u,onChange:g=>l(g.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:g=>m(g.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>p(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:x,children:"Save"})]})]})}const yo=10,gx=6,At=24;function yx(e,t){return t?e:Math.round(e/yo)*yo}function xx(e,t,n){const r=[...t];for(const i of n)r.push(i.left-At,i.right+At);let s=e,o=gx;for(const i of r){const a=Math.abs(i-e);at.left&&ei.left&&no.left&&n=i.right?(l.push({x:n,y:t.y},{x:i.right,y:t.y}),m={ox:1,oy:0}):(l.push({x:n,y:t.y},{x:i.left,y:t.y}),m={ox:-1,oy:0});return{path:Ex(l),sourceOut:d,targetOut:m}}const ut=8;function Sx(e,t,n){const r=Math.abs(e-n.left),s=Math.abs(e-n.right),o=Math.abs(t-n.top),i=Math.abs(t-n.bottom),a=Math.min(r,s,o,i),c=(u,l,d)=>Math.min(Math.max(u,l),d);return a===r?{side:"left",x:n.left,y:c(t,n.top+ut,n.bottom-ut)}:a===s?{side:"right",x:n.right,y:c(t,n.top+ut,n.bottom-ut)}:a===o?{side:"top",x:c(e,n.left+ut,n.right-ut),y:n.top}:{side:"bottom",x:c(e,n.left+ut,n.right-ut),y:n.bottom}}function wo(e,t){const n=(r,s,o)=>Math.min(Math.max(r,s),o);switch(e.side){case"left":return{x:t.left,y:n(e.y,t.top,t.bottom),out:{ox:-1,oy:0}};case"right":return{x:t.right,y:n(e.y,t.top,t.bottom),out:{ox:1,oy:0}};case"top":return{x:n(e.x??(t.left+t.right)/2,t.left,t.right),y:t.top,out:{ox:0,oy:-1}};default:return{x:n(e.x??(t.left+t.right)/2,t.left,t.right),y:t.bottom,out:{ox:0,oy:1}}}}const dr=3,kx=w.memo(function({id:t,source:n,target:r,sourceX:s,sourceY:o,targetX:i,targetY:a,sourcePosition:c,targetPosition:u,data:l,selected:d}){const{screenToFlowPosition:m}=cn(),f=he(re=>re.transform[2]),p=he(re=>vo(re.nodeInternals.get(n)),bo),x=he(re=>vo(re.nodeInternals.get(r)),bo),[v,g]=w.useState(null),[E,M]=w.useState(null),b=w.useRef(!1),$=w.useRef(0),j=l==null?void 0:l.onRouteChange,_=!!j,R=v??(l==null?void 0:l.routeX),N=p??(l==null?void 0:l.sourceCard),I=x??(l==null?void 0:l.targetCard),L=(E==null?void 0:E.end)==="source"?E.a:l==null?void 0:l.sourceAnchor,V=(E==null?void 0:E.end)==="target"?E.a:l==null?void 0:l.targetAnchor,F=L&&N?wo(L,N):{x:s,y:o,out:null},y=V&&I?wo(V,I):{x:i,y:a,out:null},C=F.x,S=F.y,O=y.x,D=y.y,k=(L==null?void 0:L.side)==="right"?K.Right:(L==null?void 0:L.side)==="left"?K.Left:c,T=(V==null?void 0:V.side)==="right"?K.Right:(V==null?void 0:V.side)==="left"?K.Left:u,[P,z,U]=Rn({sourceX:C,sourceY:S,sourcePosition:k,targetX:O,targetY:D,targetPosition:T,borderRadius:10,...R!=null?{centerX:R}:{}}),X=N,Z=I,J=R!=null&&X&&Z?Nx({x:C,y:S},{y:D},R,k===K.Left?-1:1,T===K.Left?-1:1,X,Z):null,se=J?J.path:P,ee=l==null?void 0:l.relationship,oe=(l==null?void 0:l.dimmed)??!1,ce=(ee==null?void 0:ee.cardinality)??"many_to_one",we=(ee==null?void 0:ee.optionality)==="optional",ye=(ee==null?void 0:ee.identifying)??!1,me=ce==="many_to_one"||ce==="many_to_many",pe=ce==="one_to_many"||ce==="many_to_many",ge="rel-edge"+(d?" selected":"")+(oe?" dimmed":""),Ne=((l==null?void 0:l.memberCount)??0)>1,ae=l==null?void 0:l.onHoverEdge,q=R??z,xe=U,Te=q,ze=xe,qe=J?J.sourceOut:F.out??{ox:k===K.Left?-1:1,oy:0},ke=J?J.targetOut:y.out??{ox:T===K.Left?-1:1,oy:0},Me={x:C,y:S},Oe=J&&Z?ke.oy!==0?{x:R,y:ke.oy<0?Z.top:Z.bottom}:{x:ke.ox>0?Z.right:Z.left,y:D}:{x:O,y:D},H=w.useCallback(re=>j&&ee&&j(ee.id,re),[j,ee]),Y=w.useCallback(re=>{var $e,Ie;if(!_||re.button!==0)return;re.stopPropagation(),(Ie=($e=re.target).setPointerCapture)==null||Ie.call($e,re.pointerId),b.current=!0,$.current=0;const le=m({x:re.clientX,y:re.clientY}).x;let ne=0,de=R??q;const je=He=>{const Ae=m({x:He.clientX,y:He.clientY});$.current=Math.max($.current,Math.abs(Ae.x-le)),de=bx(Ae.x,{shift:He.shiftKey,source:(l==null?void 0:l.sourceCard)??{left:s,right:s},target:(l==null?void 0:l.targetCard)??{left:i,right:i}}),ne||(ne=requestAnimationFrame(()=>{ne=0,g(de)}))},Le=()=>{window.removeEventListener("pointermove",je),window.removeEventListener("pointerup",Le),ne&&cancelAnimationFrame(ne),b.current=!1,g(null),$.current>=dr&&H(de)};window.addEventListener("pointermove",je),window.addEventListener("pointerup",Le)},[_,m,R,q,l,s,i,H]),B=w.useCallback(re=>{$.current>=dr&&(re.stopPropagation(),$.current=0)},[]),te=w.useCallback(re=>{_&&(re.stopPropagation(),H(null))},[_,H]),G=l==null?void 0:l.onAnchorChange,W=w.useCallback(re=>Q=>{var Ie,He;const le=re==="source"?N:I;if(!G||!ee||!le||Q.button!==0)return;Q.stopPropagation(),(He=(Ie=Q.target).setPointerCapture)==null||He.call(Ie,Q.pointerId),$.current=0;const ne=m({x:Q.clientX,y:Q.clientY});let de=0,je=null;const Le=Ae=>{const Ke=m({x:Ae.clientX,y:Ae.clientY});$.current=Math.max($.current,Math.hypot(Ke.x-ne.x,Ke.y-ne.y)),je=Sx(Ke.x,Ke.y,le),de||(de=requestAnimationFrame(()=>{de=0,M({end:re,a:je})}))},$e=()=>{window.removeEventListener("pointermove",Le),window.removeEventListener("pointerup",$e),de&&cancelAnimationFrame(de),M(null),$.current>=dr&&je&&G(ee.id,re,je)};window.addEventListener("pointermove",Le),window.addEventListener("pointerup",$e)},[G,ee,N,I,m]),ie=w.useCallback(re=>Q=>{!G||!ee||(Q.stopPropagation(),G(ee.id,re,null))},[G,ee]);return h.jsxs("g",{className:ge,onMouseEnter:ae?()=>ae(ee.id):void 0,onMouseLeave:ae?()=>ae(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:se,fill:"none",strokeDasharray:ye?void 0:"6 4"}),h.jsx("path",{d:se,fill:"none",strokeWidth:16/f,stroke:"transparent"}),h.jsx(Eo,{x:Me.x,y:Me.y,out:qe,many:me,optional:we}),h.jsx(Eo,{x:Oe.x,y:Oe.y,out:ke,many:pe,optional:!1}),!!G&&((l==null?void 0:l.hovered)||d||E!=null)&&h.jsxs(h.Fragment,{children:[h.jsx(_o,{x:Me.x,y:Me.y,zoom:f,onPointerDown:W("source"),onDoubleClick:ie("source")}),h.jsx(_o,{x:Oe.x,y:Oe.y,zoom:f,onPointerDown:W("target"),onDoubleClick:ie("target")})]}),_&&((l==null?void 0:l.hovered)||d||v!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:Y,onClickCapture:B,onDoubleClick:te,children:[h.jsx("rect",{x:q-20/f,y:Math.min(S,D),width:40/f,height:Math.max(Math.abs(D-S),24/f),fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:q-5.5/f,y:xe-11/f,width:11/f,height:22/f,rx:5/f,strokeWidth:1.5/f}),h.jsx("circle",{className:"rel-grip-dot",cx:q,cy:xe-4.5/f,r:1.1/f}),h.jsx("circle",{className:"rel-grip-dot",cx:q,cy:xe,r:1.1/f}),h.jsx("circle",{className:"rel-grip-dot",cx:q,cy:xe+4.5/f,r:1.1/f})]}),(d||Ne)&&ee&&h.jsxs("text",{className:"rel-label",x:Te,y:ze-8,children:[d?ee.verb_phrase||ee.name:"",Ne?`${d?" ":""}(${l.memberCount})`:""]})]})});function bo(e,t){return e===t?!0:!e||!t?!1:e.left===t.left&&e.right===t.right&&e.top===t.top&&e.bottom===t.bottom}function vo(e){if(!(e!=null&&e.positionAbsolute)||e.width==null||e.height==null)return null;const{x:t,y:n}=e.positionAbsolute;return{left:t,right:t+e.width,top:n,bottom:n+e.height}}function _o({x:e,y:t,zoom:n,onPointerDown:r,onDoubleClick:s}){return h.jsxs("g",{className:"rel-endpoint",style:{cursor:"move"},onPointerDown:r,onDoubleClick:s,children:[h.jsx("circle",{cx:e,cy:t,r:10/n,fill:"transparent"}),h.jsx("circle",{className:"rel-endpoint-dot",cx:e,cy:t,r:3.5/n,strokeWidth:1.5/n})]})}function Eo({x:e,y:t,out:n,many:r,optional:s}){const{ox:a,oy:c}=n,u=-c,l=a,d=p=>({x:e+a*p,y:t+c*p}),m=(p,x)=>({x:e+a*p+u*x,y:t+c*p+l*x}),f=[];if(r){const p=d(12),x=m(0,-7),v=d(0),g=m(0,7);f.push(h.jsx("path",{className:"rel-glyph",d:`M ${p.x} ${p.y} L ${x.x} ${x.y} M ${p.x} ${p.y} L ${v.x} ${v.y} M ${p.x} ${p.y} L ${g.x} ${g.y}`,fill:"none"},"foot"))}else{const p=m(9,-7),x=m(9,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:x.x,y2:x.y},"one"))}if(s){const p=d(18);f.push(h.jsx("circle",{className:"rel-glyph ring",cx:p.x,cy:p.y,r:4},"opt"))}else{const p=m(17,-7),x=m(17,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:x.x,y2:x.y},"mand"))}return h.jsx(h.Fragment,{children:f})}const jx={entity:Gm},Cx={relationship:kx},No=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],So="#8a7d6a";function ko(e){return{side:e.side,y:Math.round(e.y),...e.x!=null?{x:Math.round(e.x)}:{}}}function Mx(e,t,n){const s=Qe;let{x:o,y:i}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const u of n)ou.x&&iu.y&&(i=u.y+u.h+16,a=!0)}return{x:o,y:i}}function $x(e,t){const n=(o,i)=>{var a;return!!i&&!!((a=t.get(o))!=null&&a.attributes.some(c=>c.id===i))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Xr,targetHandle:n(e.to.entity,s)?s:Wr}}function iw({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:o="",showTypes:i=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:u,activeAreas:l,onError:d,handleRef:m,layoutStore:f}){const{fitView:p,fitBounds:x,getNodes:v}=cn(),[g,E]=w.useState([]),[M,b]=w.useState([]),$=w.useRef(!1),j=w.useMemo(()=>{const H=l&&l.size>0?[...l].sort():null;return H?"sa:"+H.join("+"):"__all__"},[l]),_=w.useRef(null),[R,N]=w.useState(0),I=w.useRef(new Map),L=w.useRef(null);w.useEffect(()=>{if(!f){_.current=null;return}const H=I.current.get(j);if(H){_.current=H,$.current=!1,N(B=>B+1);return}let Y=!1;return f.load(j).then(B=>{Y||(I.current.set(j,B),_.current=B,$.current=!1,N(te=>te+1))}),()=>{Y=!0}},[f,j]);const[V,F]=w.useState(null),[y,C]=w.useState(null),[S,O]=w.useState(!1),[D,k]=w.useState(null),[T,P]=w.useState(null),[z,U]=w.useState(null),[X,Z]=w.useState(null),J=w.useRef({}),se=!t.canEdit,ee=w.useRef(null),oe=w.useCallback(()=>{f&&(ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{const H={};for(const te of v())te.hidden||(H[te.id]={x:Math.round(te.position.x),y:Math.round(te.position.y)});const Y={};for(const[te,G]of Object.entries(J.current)){const W={};G.routeX!=null&&(W.routeX=Math.round(G.routeX)),G.sourceAnchor&&(W.sourceAnchor=ko(G.sourceAnchor)),G.targetAnchor&&(W.targetAnchor=ko(G.targetAnchor)),(W.routeX!=null||W.sourceAnchor||W.targetAnchor)&&(Y[te]=W)}const B={nodes:H,edges:Y};I.current.set(j,B),_.current=B,f.save(j,B)},800))},[f,v,j]),ce=w.useCallback((H,Y)=>{const B=J.current[H]??{};Y==null?delete B.routeX:B.routeX=Y,J.current[H]=B,b(te=>te.map(G=>G.id===H?{...G,data:{...G.data,routeX:Y??void 0}}:G)),oe()},[oe]),we=w.useCallback((H,Y,B)=>{const te=J.current[H]??{},G=Y==="source"?"sourceAnchor":"targetAnchor";B==null?delete te[G]:te[G]=B,J.current[H]=te,b(W=>W.map(ie=>ie.id===H?{...ie,data:{...ie.data,[G]:B??void 0}}:ie)),oe()},[oe]),ye=w.useMemo(()=>{const H=new Map;return e.subject_areas.forEach((Y,B)=>H.set(Y.id,No[B%No.length])),H},[e]),me=w.useMemo(()=>{const H=new Map;return e.entities.forEach(Y=>H.set(Y.id,Y)),H},[e]),pe=w.useMemo(()=>{const H=new Map,Y=new Map;return e.subject_areas.forEach(B=>{(B.members??[]).forEach(te=>Y.set(te,{id:B.id,name:B.name}))}),e.entities.forEach(B=>{var ie,re;const te=(ie=B.conceptual)!=null&&ie.id?Y.get(B.conceptual.id):void 0,G=(re=B.conceptual)==null?void 0:re.subject_area,W=te??(G?{id:G.id,name:G.name??G.id}:void 0);W&&H.set(B.id,W)}),H},[e]),ge=w.useCallback(H=>{var B;if(!l||l.size===0)return!1;const Y=(B=pe.get(H))==null?void 0:B.id;return!(Y&&l.has(Y))},[l,pe]),Ne=w.useMemo(()=>{const H=new Map,Y=(B,te)=>{if(!te.length)return;const G=H.get(B)??new Set;te.forEach(W=>G.add(W)),H.set(B,G)};for(const B of e.relationships)Y(B.from.entity,B.from.attributes),Y(B.to.entity,B.to.attributes);return H},[e]);w.useEffect(()=>{var re;const H=o.trim().toLowerCase(),Y=new Set;if(H)for(const Q of e.entities)(Q.name.toLowerCase()+" "+(((re=Q.conceptual)==null?void 0:re.name.toLowerCase())??"")+" "+Q.attributes.map(ne=>ne.name.toLowerCase()).join(" ")).includes(H)&&Y.add(Q.id);const B=new Set;if(r){B.add(r);for(const Q of e.relationships)Q.from.entity===r&&B.add(Q.to.entity),Q.to.entity===r&&B.add(Q.from.entity)}const te=e.entities.map(Q=>{const le=H!==""&&!Y.has(Q.id),ne=r!==null&&!B.has(Q.id);return{id:Q.id,type:"entity",position:{x:0,y:0},hidden:ge(Q.id),data:{entity:Q,color:(()=>{const de=pe.get(Q.id);return de?ye.get(de.id)??So:So})(),dimmed:le||ne,highlighted:H!==""&&Y.has(Q.id),showTypes:i,collapseDetail:a,expanded:(c==null?void 0:c.has(Q.id))??!1,onToggleExpand:u,endpointAttrs:Ne.get(Q.id),highlightAttrs:void 0,onHoverAttr:U}}}),G=e.relationships.filter(Q=>me.has(Q.from.entity)&&me.has(Q.to.entity)).map(Q=>{const{sourceHandle:le,targetHandle:ne}=$x(Q,me),de=r!==null&&Q.from.entity!==r&&Q.to.entity!==r;return{id:Q.id,source:Q.from.entity,target:Q.to.entity,sourceHandle:le,targetHandle:ne,type:"relationship",data:{relationship:Q,dimmed:de,memberCount:Math.max(Q.from.attributes.length,Q.to.attributes.length),onHoverEdge:Z}}}),W=_.current;if(J.current={},W)for(const[Q,le]of Object.entries(W.edges))J.current[Q]={...le.routeX!=null?{routeX:le.routeX}:{},...le.sourceAnchor?{sourceAnchor:le.sourceAnchor}:{},...le.targetAnchor?{targetAnchor:le.targetAnchor}:{}};const ie=Q=>{const le=new Map;for(const ne of Q)le.set(ne.id,{left:ne.position.x,right:ne.position.x+Qe,top:ne.position.y,bottom:ne.position.y+pt(ne.data.entity)});b(G.map(ne=>{const de=J.current[ne.id]??{};return{...ne,data:{...ne.data,routeX:de.routeX,sourceAnchor:de.sourceAnchor,targetAnchor:de.targetAnchor,onRouteChange:f?ce:void 0,onAnchorChange:f?we:void 0,sourceCard:le.get(ne.source),targetCard:le.get(ne.target)}}}))};E(Q=>{const le=new Map(Q.map(fe=>[fe.id,fe.position])),ne=te.every(fe=>le.has(fe.id)),de=((l==null?void 0:l.size)??0)>0;if($.current&&ne&&Q.length>=te.length&&!de){const fe=te.map(et=>({...et,position:le.get(et.id)??et.position}));return ie(fe),fe}const je=de?te.filter(fe=>!fe.hidden):te,Le=ur(je,G,me,"auto",pe),$e=new Map(Le.map(fe=>[fe.id,fe.position])),Ie=(W==null?void 0:W.nodes)??{},He=Object.keys(Ie).length>0,Ae=[],Ke=te.map(fe=>{const et=Ie[fe.id];if(et){const zt={x:et.x,y:et.y};return Ae.push({x:zt.x,y:zt.y,w:Qe,h:pt(fe.data.entity)}),{...fe,position:zt}}return $e.has(fe.id)?{...fe,position:$e.get(fe.id)}:le.has(fe.id)&&$.current?{...fe,position:le.get(fe.id)}:fe});if(He)for(const fe of Ke)Ie[fe.id]||fe.hidden||(fe.position=Mx(fe.position,pt(fe.data.entity),Ae),Ae.push({x:fe.position.x,y:fe.position.y,w:Qe,h:pt(fe.data.entity)}));return $.current=!0,He||requestAnimationFrame(()=>p({padding:.15,duration:300})),ie(Ke),Ke})},[e,o,r,i,a,c,u,ye,me,pe,ge,l,Ne,p,f,ce,we,R]);const ae=w.useMemo(()=>{const H=new Set,Y=new Set,B=new Map,te=(G,W)=>{if(!W.length)return;const ie=B.get(G)??new Set;W.forEach(re=>ie.add(re)),B.set(G,ie)};if(z)for(const G of e.relationships)(G.from.attributes.includes(z)||G.to.attributes.includes(z))&&(H.add(G.id),Y.add(G.from.entity),Y.add(G.to.entity),te(G.from.entity,G.from.attributes),te(G.to.entity,G.to.attributes));if(X){const G=e.relationships.find(W=>W.id===X);G&&(te(G.from.entity,G.from.attributes),te(G.to.entity,G.to.attributes))}return{active:z!==null,relsForAttr:H,entsForAttr:Y,hitAttrsByEntity:B}},[e,z,X]);w.useEffect(()=>{var te;const H=o.trim().toLowerCase(),Y=new Set;if(H)for(const G of e.entities)(G.name.toLowerCase()+" "+(((te=G.conceptual)==null?void 0:te.name.toLowerCase())??"")+" "+G.attributes.map(ie=>ie.name.toLowerCase()).join(" ")).includes(H)&&Y.add(G.id);const B=new Set;if(r){B.add(r);for(const G of e.relationships)G.from.entity===r&&B.add(G.to.entity),G.to.entity===r&&B.add(G.from.entity)}E(G=>G.map(W=>{const ie=H!==""&&!Y.has(W.id),re=r!==null&&!B.has(W.id),Q=ae.active&&!ae.entsForAttr.has(W.id),le=ie||re||Q,ne=H!==""&&Y.has(W.id)||ae.active&&ae.entsForAttr.has(W.id),de=ae.hitAttrsByEntity.get(W.id);return W.data.dimmed===le&&W.data.highlighted===ne&&W.data.highlightAttrs===de?W:{...W,data:{...W.data,dimmed:le,highlighted:ne,highlightAttrs:de}}})),b(G=>G.map(W=>{var Le,$e,Ie;const ie=(Le=W.data)==null?void 0:Le.relationship,re=r!==null&&ie!==void 0&&ie.from.entity!==r&&ie.to.entity!==r,Q=ae.active&&!ae.relsForAttr.has(W.id),le=re||Q,ne=X===W.id,de=r!==null&&ie!==void 0&&(ie.from.entity===r||ie.to.entity===r),je=ne||de?1e3:0;return(($e=W.data)==null?void 0:$e.dimmed)===le&&((Ie=W.data)==null?void 0:Ie.hovered)===ne&&W.zIndex===je?W:{...W,zIndex:je,data:{...W.data,dimmed:le,hovered:ne}}}))},[ae,X,o,r,e]),w.useEffect(()=>{var te;const H=o.trim().toLowerCase();if(!H)return;const Y=new Set;for(const G of e.entities)(G.name.toLowerCase()+" "+(((te=G.conceptual)==null?void 0:te.name.toLowerCase())??"")+" "+G.attributes.map(ie=>ie.name.toLowerCase()).join(" ")).includes(H)&&Y.add(G.id);if(!Y.size)return;const B=requestAnimationFrame(()=>{const G=v().filter(ie=>Y.has(ie.id));if(!G.length)return;const W=Lf(G);x(W,{padding:.35,duration:400})});return()=>cancelAnimationFrame(B)},[o,e,v,x]);const q=w.useCallback((H="auto",Y="LR")=>{L.current=Object.fromEntries(v().map(B=>[B.id,{x:B.position.x,y:B.position.y}])),E(B=>ur(B,M,me,H,pe,Y)),requestAnimationFrame(()=>p({padding:.15,duration:300})),oe()},[M,me,pe,p,v,oe]),xe=w.useCallback(()=>{const H=L.current;H&&(E(Y=>Y.map(B=>H[B.id]?{...B,position:H[B.id]}:B)),L.current=null,oe())},[oe]),Te=w.useCallback(()=>{f==null||f.reset(j),I.current.delete(j),_.current=null,J.current={},$.current=!1,b(H=>H.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(H=>{const Y=ur(H,M,me,"auto",pe);return requestAnimationFrame(()=>p({padding:.15,duration:300})),Y})},[f,j,M,me,pe,p]),ze=w.useCallback(H=>{s(H),E(Y=>(Y.find(te=>te.id===H)&&requestAnimationFrame(()=>p({nodes:[{id:H}],padding:.4,duration:400})),Y))},[p,s]);w.useImperativeHandle(m,()=>({relayout:q,fitView:()=>p({padding:.15,duration:300}),focusEntity:ze,newEntity:()=>O(!0),resetLayout:Te,undoRelayout:xe}),[q,p,ze,Te,xe]);const qe=w.useCallback(H=>{if(se||!H.source||!H.target||H.source===H.target)return;const Y=H.sourceHandle&&H.sourceHandle!==Xr?H.sourceHandle:void 0,B=H.targetHandle&&H.targetHandle!==Wr?H.targetHandle:void 0;k({from:H.source,to:H.target,fromAttr:Y,toAttr:B})},[se]),ke=w.useCallback(async(H,Y)=>{try{return await n(H,Y)}catch(B){throw d==null||d(B instanceof Error?B.message:String(B)),B}},[n,d]),Me=r?me.get(r)??null:null,Oe=e.relationships.find(H=>H.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Zi,{nodes:g,edges:M,nodeTypes:jx,edgeTypes:Cx,onNodeClick:(H,Y)=>s(Y.id),onEdgeDoubleClick:(H,Y)=>!se&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(H,Y)=>{E(B=>B.map(te=>te.id===Y.id?{...te,position:Y.position}:te)),oe()},onConnect:qe,nodesConnectable:!se,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(Cm,{variant:Be.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(pm,{pannable:!0,zoomable:!0,nodeColor:H=>{var Y;return((Y=H.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(_m,{showInteractive:!1})]}),Me&&h.jsx(Xm,{entity:Me,doc:e,caps:t,exec:ke,onClose:()=>s(null),onFocusEntity:ze,onAlign:F,onEditMapping:C}),V&&h.jsx(dx,{entity:V,exec:ke,onClose:()=>F(null)}),y&&h.jsx(fx,{entity:y,doc:e,exec:ke,onClose:()=>C(null)}),S&&h.jsx(hx,{doc:e,exec:ke,onClose:()=>O(!1),onCreated:ze}),D&&h.jsx(mx,{doc:e,fromId:D.from,toId:D.to,initialFromAttr:D.fromAttr,initialToAttr:D.toAttr,exec:ke,onClose:()=>k(null)}),Oe&&h.jsx(px,{rel:Oe,doc:e,exec:ke,onClose:()=>P(null)})]})}function aw({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:o}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(Ax,{}),e==="layers"&&h.jsx(Ix,{refreshKey:r,onFocusEntity:o}),e==="changes"&&h.jsx(Tx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Ox,{readOnly:n})]})}function Ax(){const[e,t]=w.useState(""),[n,r]=w.useState([]),[s,o]=w.useState({loaded:0,vocabs:[]}),[i,a]=w.useState(null),[c,u]=w.useState([]),[l,d]=w.useState("");w.useEffect(()=>{sa().then(f=>u(f.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const f=setTimeout(()=>{ra(e||"a",l||void 0).then(p=>{r(e?p.results:[]),o({loaded:p.loaded_terms,vocabs:p.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,l]);const m=w.useCallback(f=>{Mm(f).then(a).catch(()=>{})},[]);return i?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:i.label}),h.jsx("code",{className:"term-iri",children:i.prefixed}),i.definition&&h.jsx("p",{className:"term-def",children:i.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:i.source})]}),i.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),i.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),i.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),i.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(l===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(l===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:l?`Search within ${l}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const Rx=["industry","core","domain","specialised"];function Ix({refreshKey:e,onFocusEntity:t}){const[n,r]=w.useState(null),[s,o]=w.useState(null);if(w.useEffect(()=>{$m().then(r).catch(()=>{}),Am().then(o).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const i=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),Rx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var u;return h.jsxs("button",{className:"stack-term"+(i.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((l,d)=>h.jsxs("span",{className:"align-arrow"+(l.resolved?"":" unresolved")+(l.status==="proposed"?" proposed":""),title:l.ref+(l.resolved_via?` (via ${l.resolved_via})`:""),children:["↑ ",l.label,l.status==="proposed"?" ·prop":""]},`${l.ref}-${d}`)),!c.aligned_to&&(((u=c.aligned_refs)==null?void 0:u.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Tx({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=w.useState(null),[o,i]=w.useState(""),[a,c]=w.useState(""),[u,l]=w.useState(!1),d=w.useCallback(()=>{Im().then(s).catch(()=>s(null)),Tm().then(m=>i([m.diff,...m.untracked].filter(Boolean).join(` + +`))).catch(()=>i(""))},[]);return w.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:o.split(` +`).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` +`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:u,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(l(!0),Lm().then(()=>{l(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:u||!a.trim(),onClick:()=>{l(!0),Om(a).then(()=>{l(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Ox({readOnly:e}){const[t,n]=w.useState([]),r=w.useCallback(()=>{Dm().then(o=>n(o.decisions)).catch(()=>n([]))},[]);if(w.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(o=>h.jsxs("div",{className:"decision "+o.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[o.verdict]}),h.jsx("span",{className:"chip",children:o.confidence}),h.jsx("span",{className:"chip",children:o.signal})]}),h.jsx("p",{className:"decision-subject",children:o.subject}),!e&&o.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Gs(o.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Gs(o.signal_key,"rejected").then(r),children:"Reject"})]})]},o.signal_key))})}function cw({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:o,openImport:i=!1,prefillImport:a="",onPreview:c}){const[u,l]=w.useState(i&&t?"import":null),[d,m]=w.useState([]),[f,p]=w.useState("postgres"),x=w.useRef(null);w.useEffect(()=>{Pm().then(g=>m(g.formats)).catch(()=>m([]))},[]),w.useEffect(()=>{if(!u)return;const g=E=>{x.current&&!x.current.contains(E.target)&&l(null)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[u]);const v=d.find(g=>g.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:x,children:[h.jsxs("button",{className:s+(u==="export"?" on":""),onClick:()=>l(u==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(u==="import"?" on":""),onClick:()=>l(u==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),u==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(v==null?void 0:v.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:g=>p(g.target.value),children:v.dialects.map(g=>h.jsx("option",{value:g,children:g},g))})]}),d.map(g=>h.jsx("a",{className:"ie-item",href:zm(g.id,g.id==="sql"?f:void 0),download:!0,onClick:()=>l(null),children:g.label},g.id))]}),u==="import"&&h.jsx(Lx,{exec:e,submitLabel:r,buttonClass:s,applyBatch:o,onClose:()=>l(null),onImported:g=>{l(null),n==null||n(g)},onPreview:c,prefillImport:a})]})}const jo=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function Lx({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:o,onPreview:i,prefillImport:a}){var j;const[c,u]=w.useState(i?"erwin":"sql"),[l,d]=w.useState("postgres"),[m,f]=w.useState(a??""),[p,x]=w.useState(!1),[v,g]=w.useState(null),[E,M]=w.useState([]);w.useEffect(()=>{a&&f(a)},[a]);const b=_=>{_&&_.text().then(f).catch(()=>g("could not read that file"))},$=async()=>{x(!0),g(null),M([]);try{if(i&&c==="erwin"){const R=await Fm(c,m);if(!R.changes.length){g(R.warnings[0]??"nothing to import from that document"),x(!1);return}s(),i(R),x(!1);return}const _=await Hm(c,m,c==="sql"?l:void 0);if(!_.changes.length){g(_.warnings[0]??"nothing to import from that document"),x(!1);return}if(r)await r(_.changes);else for(const R of _.changes)await e(R.op,R.payload);M(_.warnings),o(_.tables)}catch(_){g(_ instanceof Error?_.message:String(_))}finally{x(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:jo.map(_=>h.jsx("button",{className:"ie-tab"+(c===_.id?" active":""),onClick:()=>u(_.id),children:_.label},_.id))}),h.jsx("p",{className:"ie-hint",children:(j=jo.find(_=>_.id===c))==null?void 0:j.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:l,onChange:_=>d(_.target.value),children:["postgres","snowflake","mysql","duckdb"].map(_=>h.jsx("option",{children:_},_))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:_=>f(_.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:_=>{var R;return b(((R=_.target.files)==null?void 0:R[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((_,R)=>h.jsx("p",{className:"ie-warn",children:_},R)),v&&h.jsx("p",{className:"ie-error",children:v}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:p||!m.trim(),onClick:$,children:p?"Importing…":t})]})]})}export{na as A,Cm as B,_m as C,Gm as E,cw as I,Ix as L,iw as M,Ax as O,No as P,qi as R,aw as S,Hx as a,Zx as b,Ux as c,Jx as d,ew as e,zx as f,Im as g,nw as h,tw as i,qx as j,Bx as k,Gx as l,Yx as m,Wx as n,ra as o,Qx as p,Kx as q,Xx as r,Rm as s,Fx as t,Vx as u,ur as v,Zi as w,kx as x,pm as y}; diff --git a/packages/server/src/mdl_server/static/assets/styles-Dfh1I8li.js b/packages/server/src/mdl_server/static/assets/styles-Dfh1I8li.js deleted file mode 100644 index 861a234..0000000 --- a/packages/server/src/mdl_server/static/assets/styles-Dfh1I8li.js +++ /dev/null @@ -1,23 +0,0 @@ -var lc=Object.defineProperty;var uc=(e,t,n)=>t in e?lc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _e=(e,t,n)=>uc(e,typeof t!="symbol"?t+"":t,n);import{r as w,g as ko,R as A,j as h}from"./client-DOmNpTln.js";function Me(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?xc:yc;$o.useSyncExternalStore=It.useSyncExternalStore!==void 0?It.useSyncExternalStore:wc;Mo.exports=$o;var bc=Mo.exports;/** - * @license React - * use-sync-external-store-shim/with-selector.production.js - * - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var Dn=w,vc=bc;function _c(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var Ec=typeof Object.is=="function"?Object.is:_c,Nc=vc.useSyncExternalStore,Sc=Dn.useRef,kc=Dn.useEffect,jc=Dn.useMemo,Cc=Dn.useDebugValue;Co.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var o=Sc(null);if(o.current===null){var i={hasValue:!1,value:null};o.current=i}else i=o.current;o=jc(function(){function c(f){if(!l){if(l=!0,u=f,f=r(f),s!==void 0&&i.hasValue){var p=i.value;if(s(p,f))return d=p}return d=f}if(p=d,Ec(u,f))return p;var x=r(f);return s!==void 0&&s(p,x)?(u=f,p):(u=f,d=x)}var l=!1,u,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=Nc(e,o[0],o[1]);return kc(function(){i.hasValue=!0,i.value=a},[a]),Cc(a),a};jo.exports=Co;var Mc=jo.exports;const $c=ko(Mc),Ac={},ts=e=>{let t;const n=new Set,r=(u,d)=>{const m=typeof u=="function"?u(t):u;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(p=>p(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(Ac?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(r,s,c);return c},Rc=e=>e?ts(e):ts,{useDebugValue:Ic}=A,{useSyncExternalStoreWithSelector:Tc}=$c,Oc=e=>e;function Ao(e,t=Oc,n){const r=Tc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Ic(r),r}const ns=(e,t)=>{const n=Rc(e),r=(s,o=t)=>Ao(n,s,o);return Object.assign(r,n),r},Lc=(e,t)=>e?ns(e,t):ns;function ke(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var Dc={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Pc(e+"",n),s,o=-1,i=r.length;if(arguments.length<2){for(;++o0)for(var n=new Array(s),r=0,s,o;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),ss.hasOwnProperty(t)?{space:ss[t],local:e}:e}function Hc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===fr&&t.documentElement.namespaceURI===fr?t.createElement(e):t.createElementNS(n,e)}}function Fc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Ro(e){var t=zn(e);return(t.local?Fc:Hc)(t)}function Vc(){}function Mr(e){return e==null?Vc:function(){return this.querySelector(e)}}function Bc(e){typeof e!="function"&&(e=Mr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=C&&(C=E+1);!($=_[C])&&++C=0;)(i=r[s])&&(o&&i.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(i,o),o=i);return this}function ml(e){e||(e=pl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),o=0;ot?1:e>=t?0:NaN}function gl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function yl(){return Array.from(this)}function xl(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Ml:typeof t=="function"?Al:$l)(e,t,n??"")):Tt(this.node(),e)}function Tt(e,t){return e.style.getPropertyValue(t)||Do(e).getComputedStyle(e,null).getPropertyValue(t)}function Il(e){return function(){delete this[e]}}function Tl(e,t){return function(){this[e]=t}}function Ol(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Ll(e,t){return arguments.length>1?this.each((t==null?Il:typeof t=="function"?Ol:Tl)(e,t)):this.node()[e]}function Po(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new zo(e)}function zo(e){this._node=e,this._names=Po(e.getAttribute("class")||"")}zo.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Ho(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function uu(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,o;n()=>e;function hr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:o,x:i,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}hr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function bu(e){return!e.ctrlKey&&!e.button}function vu(){return this.parentNode}function _u(e,t){return t??{x:e.x,y:e.y}}function Eu(){return navigator.maxTouchPoints||"ontouchstart"in this}function Nu(){var e=bu,t=vu,n=_u,r=Eu,s={},o=Pn("start","drag","end"),i=0,a,c,l,u,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",_).on("touchmove.drag",g,wu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,$){if(!(u||!e.call(this,b,$))){var j=C(this,t.call(this,b,$),b,$,"mouse");j&&(Pe(b.view).on("mousemove.drag",p,qt).on("mouseup.drag",x,qt),Go(b.view),Un(b),l=!1,a=b.clientX,c=b.clientY,j("start",b))}}function p(b){if($t(b),!l){var $=b.clientX-a,j=b.clientY-c;l=$*$+j*j>d}s.mouse("drag",b)}function x(b){Pe(b.view).on("mousemove.drag mouseup.drag",null),Yo(b.view,l),$t(b),s.mouse("end",b)}function _(b,$){if(e.call(this,b,$)){var j=b.changedTouches,v=t.call(this,b,$),R=j.length,N,T;for(N=0;N>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?dn(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?dn(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=ku.exec(e))?new Oe(t[1],t[2],t[3],1):(t=ju.exec(e))?new Oe(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Cu.exec(e))?dn(t[1],t[2],t[3],t[4]):(t=Mu.exec(e))?dn(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=$u.exec(e))?ds(t[1],t[2]/100,t[3]/100,1):(t=Au.exec(e))?ds(t[1],t[2]/100,t[3]/100,t[4]):os.hasOwnProperty(e)?cs(os[e]):e==="transparent"?new Oe(NaN,NaN,NaN,0):null}function cs(e){return new Oe(e>>16&255,e>>8&255,e&255,1)}function dn(e,t,n,r){return r<=0&&(e=t=n=NaN),new Oe(e,t,n,r)}function Tu(e){return e instanceof sn||(e=Qt(e)),e?(e=e.rgb(),new Oe(e.r,e.g,e.b,e.opacity)):new Oe}function mr(e,t,n,r){return arguments.length===1?Tu(e):new Oe(e,t,n,r??1)}function Oe(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Ar(Oe,mr,Xo(sn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Oe(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Kt:Math.pow(Kt,e),new Oe(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Oe(wt(this.r),wt(this.g),wt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:ls,formatHex:ls,formatHex8:Ou,formatRgb:us,toString:us}));function ls(){return`#${yt(this.r)}${yt(this.g)}${yt(this.b)}`}function Ou(){return`#${yt(this.r)}${yt(this.g)}${yt(this.b)}${yt((isNaN(this.opacity)?1:this.opacity)*255)}`}function us(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${wt(this.r)}, ${wt(this.g)}, ${wt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function wt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function yt(e){return e=wt(e),(e<16?"0":"")+e.toString(16)}function ds(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ye(e,t,n,r)}function Wo(e){if(e instanceof Ye)return new Ye(e.h,e.s,e.l,e.opacity);if(e instanceof sn||(e=Qt(e)),!e)return new Ye;if(e instanceof Ye)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),o=Math.max(t,n,r),i=NaN,a=o-s,c=(o+s)/2;return a?(t===o?i=(n-r)/a+(n0&&c<1?0:i,new Ye(i,a,c,e.opacity)}function Lu(e,t,n,r){return arguments.length===1?Wo(e):new Ye(e,t,n,r??1)}function Ye(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Ar(Ye,Lu,Xo(sn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Ye(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Kt:Math.pow(Kt,e),new Ye(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Oe(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Ye(fs(this.h),fn(this.s),fn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${fs(this.h)}, ${fn(this.s)*100}%, ${fn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function fs(e){return e=(e||0)%360,e<0?e+360:e}function fn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Uo=e=>()=>e;function Du(e,t){return function(n){return e+n*t}}function Pu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function zu(e){return(e=+e)==1?qo:function(t,n){return n-t?Pu(t,n,e):Uo(isNaN(t)?n:t)}}function qo(e,t){var n=t-e;return n?Du(e,n):Uo(isNaN(e)?t:e)}const hs=function e(t){var n=zu(t);function r(s,o){var i=n((s=mr(s)).r,(o=mr(o)).r),a=n(s.g,o.g),c=n(s.b,o.b),l=qo(s.opacity,o.opacity);return function(u){return s.r=i(u),s.g=a(u),s.b=c(u),s.opacity=l(u),s+""}}return r.gamma=e,r}(1);function lt(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var pr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(pr.source,"g");function Hu(e){return function(){return e}}function Fu(e){return function(t){return e(t)+""}}function Vu(e,t){var n=pr.lastIndex=Kn.lastIndex=0,r,s,o,i=-1,a=[],c=[];for(e=e+"",t=t+"";(r=pr.exec(e))&&(s=Kn.exec(t));)(o=s.index)>n&&(o=t.slice(n,o),a[i]?a[i]+=o:a[++i]=o),(r=r[0])===(s=s[0])?a[i]?a[i]+=s:a[++i]=s:(a[++i]=null,c.push({i,x:lt(r,s)})),n=Kn.lastIndex;return n180?u+=360:u-l>180&&(l+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:lt(l,u)})):u&&d.push(s(d)+"rotate("+u+r)}function a(l,u,d,m){l!==u?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:lt(l,u)}):u&&d.push(s(d)+"skewX("+u+r)}function c(l,u,d,m,f,p){if(l!==d||u!==m){var x=f.push(s(f)+"scale(",null,",",null,")");p.push({i:x-4,x:lt(l,d)},{i:x-2,x:lt(u,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(l,u){var d=[],m=[];return l=e(l),u=e(u),o(l.translateX,l.translateY,u.translateX,u.translateY,d,m),i(l.rotate,u.rotate,d,m),a(l.skewX,u.skewX,d,m),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,d,m),l=u=null,function(f){for(var p=-1,x=m.length,_;++p=0&&e._call.call(void 0,t),e=e._next;--Ot}function gs(){vt=(Cn=Jt.now())+Hn,Ot=Yt=0;try{Qu()}finally{Ot=0,ed(),vt=0}}function Ju(){var e=Jt.now(),t=e-Cn;t>Qo&&(Hn-=t,Cn=e)}function ed(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Xt=e,yr(r)}function yr(e){if(!Ot){Yt&&(Yt=clearTimeout(Yt));var t=e-vt;t>24?(e<1/0&&(Yt=setTimeout(gs,e-Jt.now()-Hn)),Ht&&(Ht=clearInterval(Ht))):(Ht||(Cn=Jt.now(),Ht=setInterval(Ju,Qo)),Ot=1,Jo(gs))}}function ys(e,t,n){var r=new Mn;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var td=Pn("start","end","cancel","interrupt"),nd=[],ti=0,xs=1,xr=2,vn=3,ws=4,wr=5,_n=6;function Fn(e,t,n,r,s,o){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;rd(e,n,{name:t,index:r,group:s,on:td,tween:nd,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:ti})}function Ir(e,t){var n=Xe(e,t);if(n.state>ti)throw new Error("too late; already scheduled");return n}function Ze(e,t){var n=Xe(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function Xe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function rd(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=ei(o,0,n.time);function o(l){n.state=xs,n.timer.restart(i,n.delay,n.time),n.delay<=l&&i(l-n.delay)}function i(l){var u,d,m,f;if(n.state!==xs)return c();for(u in r)if(f=r[u],f.name===n.name){if(f.state===vn)return ys(i);f.state===ws?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[u]):+uxr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function Id(e,t,n){var r,s,o=Rd(t)?Ir:Ze;return function(){var i=o(this,e),a=i.on;a!==r&&(s=(r=a).copy()).on(t,n),i.on=s}}function Td(e,t){var n=this._id;return arguments.length<2?Xe(this.node(),n).on.on(e):this.each(Id(n,e,t))}function Od(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Ld(){return this.on("end.remove",Od(this._id))}function Dd(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Mr(e));for(var r=this._groups,s=r.length,o=new Array(s),i=0;i()=>e;function lf(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function nt(e,t,n){this.k=e,this.x=t,this.y=n}nt.prototype={constructor:nt,scale:function(e){return e===1?this:new nt(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new nt(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var rt=new nt(1,0,0);nt.prototype;function Zn(e){e.stopImmediatePropagation()}function Ft(e){e.preventDefault(),e.stopImmediatePropagation()}function uf(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function df(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function bs(){return this.__zoom||rt}function ff(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function hf(){return navigator.maxTouchPoints||"ontouchstart"in this}function mf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),i>o?(o+i)/2:Math.min(0,o)||Math.max(0,i))}function oi(){var e=uf,t=df,n=mf,r=ff,s=hf,o=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Ku,l=Pn("start","zoom","end"),u,d,m,f=500,p=150,x=0,_=10;function g(y){y.property("__zoom",bs).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",T).filter(s).on("touchstart.zoom",P).on("touchmove.zoom",G).on("touchend.zoom touchcancel.zoom",V).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(y,M,S,O){var z=y.selection?y.selection():y;z.property("__zoom",bs),y!==z?$(y,M,S,O):z.interrupt().each(function(){j(this,arguments).event(O).start().zoom(null,typeof M=="function"?M.apply(this,arguments):M).end()})},g.scaleBy=function(y,M,S,O){g.scaleTo(y,function(){var z=this.__zoom.k,k=typeof M=="function"?M.apply(this,arguments):M;return z*k},S,O)},g.scaleTo=function(y,M,S,O){g.transform(y,function(){var z=t.apply(this,arguments),k=this.__zoom,I=S==null?b(z):typeof S=="function"?S.apply(this,arguments):S,L=k.invert(I),D=typeof M=="function"?M.apply(this,arguments):M;return n(C(E(k,D),I,L),z,i)},S,O)},g.translateBy=function(y,M,S,O){g.transform(y,function(){return n(this.__zoom.translate(typeof M=="function"?M.apply(this,arguments):M,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),i)},null,O)},g.translateTo=function(y,M,S,O,z){g.transform(y,function(){var k=t.apply(this,arguments),I=this.__zoom,L=O==null?b(k):typeof O=="function"?O.apply(this,arguments):O;return n(rt.translate(L[0],L[1]).scale(I.k).translate(typeof M=="function"?-M.apply(this,arguments):-M,typeof S=="function"?-S.apply(this,arguments):-S),k,i)},O,z)};function E(y,M){return M=Math.max(o[0],Math.min(o[1],M)),M===y.k?y:new nt(M,y.x,y.y)}function C(y,M,S){var O=M[0]-S[0]*y.k,z=M[1]-S[1]*y.k;return O===y.x&&z===y.y?y:new nt(y.k,O,z)}function b(y){return[(+y[0][0]+ +y[1][0])/2,(+y[0][1]+ +y[1][1])/2]}function $(y,M,S,O){y.on("start.zoom",function(){j(this,arguments).event(O).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(O).end()}).tween("zoom",function(){var z=this,k=arguments,I=j(z,k).event(O),L=t.apply(z,k),D=S==null?b(L):typeof S=="function"?S.apply(z,k):S,q=Math.max(L[1][0]-L[0][0],L[1][1]-L[0][1]),F=z.__zoom,J=typeof M=="function"?M.apply(z,k):M,ee=c(F.invert(D).concat(q/F.k),J.invert(D).concat(q/J.k));return function(se){if(se===1)se=J;else{var le=ee(se),ne=q/le[2];se=new nt(ne,D[0]-le[0]*ne,D[1]-le[1]*ne)}I.zoom(null,se)}})}function j(y,M,S){return!S&&y.__zooming||new v(y,M)}function v(y,M){this.that=y,this.args=M,this.active=0,this.sourceEvent=null,this.extent=t.apply(y,M),this.taps=0}v.prototype={event:function(y){return y&&(this.sourceEvent=y),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(y,M){return this.mouse&&y!=="mouse"&&(this.mouse[1]=M.invert(this.mouse[0])),this.touch0&&y!=="touch"&&(this.touch0[1]=M.invert(this.touch0[0])),this.touch1&&y!=="touch"&&(this.touch1[1]=M.invert(this.touch1[0])),this.that.__zoom=M,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(y){var M=Pe(this.that).datum();l.call(y,this.that,new lf(y,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:l}),M)}};function R(y,...M){if(!e.apply(this,arguments))return;var S=j(this,M).event(y),O=this.__zoom,z=Math.max(o[0],Math.min(o[1],O.k*Math.pow(2,r.apply(this,arguments)))),k=Ge(y);if(S.wheel)(S.mouse[0][0]!==k[0]||S.mouse[0][1]!==k[1])&&(S.mouse[1]=O.invert(S.mouse[0]=k)),clearTimeout(S.wheel);else{if(O.k===z)return;S.mouse=[k,O.invert(k)],En(this),S.start()}Ft(y),S.wheel=setTimeout(I,p),S.zoom("mouse",n(C(E(O,z),S.mouse[0],S.mouse[1]),S.extent,i));function I(){S.wheel=null,S.end()}}function N(y,...M){if(m||!e.apply(this,arguments))return;var S=y.currentTarget,O=j(this,M,!0).event(y),z=Pe(y.view).on("mousemove.zoom",D,!0).on("mouseup.zoom",q,!0),k=Ge(y,S),I=y.clientX,L=y.clientY;Go(y.view),Zn(y),O.mouse=[k,this.__zoom.invert(k)],En(this),O.start();function D(F){if(Ft(F),!O.moved){var J=F.clientX-I,ee=F.clientY-L;O.moved=J*J+ee*ee>x}O.event(F).zoom("mouse",n(C(O.that.__zoom,O.mouse[0]=Ge(F,S),O.mouse[1]),O.extent,i))}function q(F){z.on("mousemove.zoom mouseup.zoom",null),Yo(F.view,O.moved),Ft(F),O.event(F).end()}}function T(y,...M){if(e.apply(this,arguments)){var S=this.__zoom,O=Ge(y.changedTouches?y.changedTouches[0]:y,this),z=S.invert(O),k=S.k*(y.shiftKey?.5:2),I=n(C(E(S,k),O,z),t.apply(this,M),i);Ft(y),a>0?Pe(this).transition().duration(a).call($,I,O,y):Pe(this).call(g.transform,I,O,y)}}function P(y,...M){if(e.apply(this,arguments)){var S=y.touches,O=S.length,z=j(this,M,y.changedTouches.length===O).event(y),k,I,L,D;for(Zn(y),I=0;I"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},ii=ot.error001();function ge(e,t){const n=w.useContext(Vn);if(n===null)throw new Error(ii);return Ao(n,e,t)}const Ne=()=>{const e=w.useContext(Vn);if(e===null)throw new Error(ii);return w.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},gf=e=>e.userSelectionActive?"none":"all";function Or({position:e,children:t,className:n,style:r,...s}){const o=ge(gf),i=`${e}`.split("-");return A.createElement("div",{className:Me(["react-flow__panel",n,...i]),style:{...r,pointerEvents:o},...s},t)}function yf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Or,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const xf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:o={},labelBgPadding:i=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u})=>{const d=w.useRef(null),[m,f]=w.useState({x:0,y:0,width:0,height:0}),p=Me(["react-flow__edge-textwrapper",l]);return w.useEffect(()=>{if(d.current){const x=d.current.getBBox();f({x:x.x,y:x.y,width:x.width,height:x.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:p,visibility:m.width?"visible":"hidden",...u},s&&A.createElement("rect",{width:m.width+2*i[0],x:-i[0],y:-i[1],height:m.height+2*i[1],className:"react-flow__edge-textbg",style:o,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var wf=w.memo(xf);const Lr=e=>({width:e.offsetWidth,height:e.offsetHeight}),Lt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Dr=(e={x:0,y:0},t)=>({x:Lt(e.x,t[0][0],t[1][0]),y:Lt(e.y,t[0][1],t[1][1])}),vs=(e,t,n)=>en?-Lt(Math.abs(e-n),1,50)/50:0,ai=(e,t)=>{const n=vs(e.x,35,t.width-35)*20,r=vs(e.y,35,t.height-35)*20;return[n,r]},ci=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},li=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),en=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),ui=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),_s=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),bf=(e,t)=>ui(li(en(e),en(t))),br=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},vf=e=>ze(e.width)&&ze(e.height)&&ze(e.x)&&ze(e.y),ze=e=>!isNaN(e)&&isFinite(e),be=Symbol.for("internals"),di=["Enter"," ","Escape"],_f=(e,t)=>{},Ef=e=>"nativeEvent"in e;function vr(e){var s,o;const t=Ef(e)?e.nativeEvent:e,n=((o=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:o[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const fi=e=>"clientX"in e,mt=(e,t)=>{var o,i;const n=fi(e),r=n?e.clientX:(o=e.touches)==null?void 0:o[0].clientX,s=n?e.clientY:(i=e.touches)==null?void 0:i[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},$n=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},on=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:u,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&ze(n)&&ze(r)?A.createElement(wf,{x:n,y:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null);on.displayName="BaseEdge";function Vt(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(o=>o.id===e);s&&n(r,{...s})}}function hi({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,o=n{const[_,g,E]=pi({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:o});return A.createElement(on,{path:_,labelX:g,labelY:E,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:x})});Pr.displayName="SimpleBezierEdge";const Ns={[K.Left]:{x:-1,y:0},[K.Right]:{x:1,y:0},[K.Top]:{x:0,y:-1},[K.Bottom]:{x:0,y:1}},Nf=({source:e,sourcePosition:t=K.Bottom,target:n})=>t===K.Left||t===K.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function Sf({source:e,sourcePosition:t=K.Bottom,target:n,targetPosition:r=K.Top,center:s,offset:o}){const i=Ns[t],a=Ns[r],c={x:e.x+i.x*o,y:e.y+i.y*o},l={x:n.x+a.x*o,y:n.y+a.y*o},u=Nf({source:c,sourcePosition:t,target:l}),d=u.x!==0?"x":"y",m=u[d];let f=[],p,x;const _={x:0,y:0},g={x:0,y:0},[E,C,b,$]=hi({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(i[d]*a[d]===-1){p=s.x??E,x=s.y??C;const v=[{x:p,y:c.y},{x:p,y:l.y}],R=[{x:c.x,y:x},{x:l.x,y:x}];i[d]===m?f=d==="x"?v:R:f=d==="x"?R:v}else{const v=[{x:c.x,y:l.y}],R=[{x:l.x,y:c.y}];if(d==="x"?f=i.x===m?R:v:f=i.y===m?v:R,t===r){const V=Math.abs(e[d]-n[d]);if(V<=o){const y=Math.min(o-1,o-V);i[d]===m?_[d]=(c[d]>e[d]?-1:1)*y:g[d]=(l[d]>n[d]?-1:1)*y}}if(t!==r){const V=d==="x"?"y":"x",y=i[d]===a[V],M=c[V]>l[V],S=c[V]=G?(p=(N.x+T.x)/2,x=f[0].y):(p=f[0].x,x=(N.y+T.y)/2)}return[[e,{x:c.x+_.x,y:c.y+_.y},...f,{x:l.x+g.x,y:l.y+g.y},n],p,x,b,$]}function kf(e,t,n,r){const s=Math.min(Ss(e,t)/2,Ss(t,n)/2,r),{x:o,y:i}=t;if(e.x===o&&o===n.x||e.y===i&&i===n.y)return`L${o} ${i}`;if(e.y===i){const l=e.x{let C="";return E>0&&E{const[g,E,C]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:x==null?void 0:x.borderRadius,offset:x==null?void 0:x.offset});return A.createElement(on,{path:g,labelX:E,labelY:C,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:f,markerStart:p,interactionWidth:_})});Bn.displayName="SmoothStepEdge";const zr=w.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:w.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});zr.displayName="StepEdge";function jf({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,o,i,a]=hi({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,o,i,a]}const Hr=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[p,x,_]=jf({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(on,{path:p,labelX:x,labelY:_,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l,style:u,markerEnd:d,markerStart:m,interactionWidth:f})});Hr.displayName="StraightEdge";function pn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function ks({pos:e,x1:t,y1:n,x2:r,y2:s,c:o}){switch(e){case K.Left:return[t-pn(t-r,o),n];case K.Right:return[t+pn(r-t,o),n];case K.Top:return[t,n-pn(n-s,o)];case K.Bottom:return[t,n+pn(s-n,o)]}}function gi({sourceX:e,sourceY:t,sourcePosition:n=K.Bottom,targetX:r,targetY:s,targetPosition:o=K.Top,curvature:i=.25}){const[a,c]=ks({pos:n,x1:e,y1:t,x2:r,y2:s,c:i}),[l,u]=ks({pos:o,x1:r,y1:s,x2:e,y2:t,c:i}),[d,m,f,p]=mi({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${r},${s}`,d,m,f,p]}const In=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=K.Bottom,targetPosition:o=K.Top,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,pathOptions:x,interactionWidth:_})=>{const[g,E,C]=gi({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:o,curvature:x==null?void 0:x.curvature});return A.createElement(on,{path:g,labelX:E,labelY:C,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:_})});In.displayName="BezierEdge";const Fr=w.createContext(null),Cf=Fr.Provider;Fr.Consumer;const Mf=()=>w.useContext(Fr),$f=e=>"id"in e&&"source"in e&&"target"in e,Af=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,_r=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Rf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),If=(e,t)=>{if(!e.source||!e.target)return t;let n;return $f(e)?n={...e}:n={...e,id:Af(e)},Rf(n,t)?t:t.concat(n)},Er=({x:e,y:t},[n,r,s],o,[i,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return o?{x:i*Math.round(c.x/i),y:a*Math.round(c.y/a)}:c},yi=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),bt=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},an=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:o,y:i}=bt(s,t).positionAbsolute;return li(r,en({x:o,y:i,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return ui(n)},Tf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),an(e,t)),xi=(e,t,[n,r,s]=[0,0,1],o=!1,i=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},l=[];return e.forEach(u=>{const{width:d,height:m,selectable:f=!0,hidden:p=!1}=u;if(i&&!f||p)return!1;const{positionAbsolute:x}=bt(u,a),_={x:x.x,y:x.y,width:d||0,height:m||0},g=br(c,_),E=typeof d>"u"||typeof m>"u"||d===null||m===null,C=o&&g>0,b=(d||0)*(m||0);(E||C||g>=b||u.dragging)&&l.push(u)}),l},wi=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},bi=(e,t,n,r,s,o=.1)=>{const i=t/(e.width*(1+o)),a=n/(e.height*(1+o)),c=Math.min(i,a),l=Lt(c,r,s),u=e.x+e.width/2,d=e.y+e.height/2,m=t/2-u*l,f=n/2-d*l;return{x:m,y:f,zoom:l}},gt=(e,t=0)=>e.transition().duration(t);function js(e,t,n,r){return(t[n]||[]).reduce((s,o)=>{var i,a;return`${e.id}-${o.id}-${n}`!==r&&s.push({id:o.id||null,type:n,nodeId:e.id,x:(((i=e.positionAbsolute)==null?void 0:i.x)??0)+o.x+o.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+o.y+o.height/2}),s},[])}function Of(e,t,n,r,s,o){const{x:i,y:a}=mt(e),l=t.elementsFromPoint(i,a).find(p=>p.classList.contains("react-flow__handle"));if(l){const p=l.getAttribute("data-nodeid");if(p){const x=Vr(void 0,l),_=l.getAttribute("data-handleid"),g=o({nodeId:p,id:_,type:x});if(g){const E=s.find(C=>C.nodeId===p&&C.type===x&&C.id===_);return{handle:{id:_,type:x,nodeId:p,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:g}}}}let u=[],d=1/0;if(s.forEach(p=>{const x=Math.sqrt((p.x-n.x)**2+(p.y-n.y)**2);if(x<=r){const _=o(p);x<=d&&(xp.isValid),f=u.some(({handle:p})=>p.type==="target");return u.find(({handle:p,validHandleResult:x})=>f?p.type==="target":m?x.isValid:!0)||u[0]}const Lf={source:null,target:null,sourceHandle:null,targetHandle:null},vi=()=>({handleDomNode:null,isValid:!1,connection:Lf,endHandle:null});function _i(e,t,n,r,s,o,i){const a=s==="target",c=i.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),l={...vi(),handleDomNode:c};if(c){const u=Vr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),p=c.classList.contains("connectableend"),x={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};l.connection=x,f&&p&&(t===_t.Strict?a&&u==="source"||!a&&u==="target":d!==n||m!==r)&&(l.endHandle={nodeId:d,handleId:m,type:u},l.isValid=o(x))}return l}function Df({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,o)=>{if(o[be]){const{handleBounds:i}=o[be];let a=[],c=[];i&&(a=js(o,i,"source",`${t}-${n}-${r}`),c=js(o,i,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Vr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Pf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function Ei({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:o,setState:i,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:l}){const u=ci(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:p,onConnectStart:x,panBy:_,getNodes:g,cancelConnection:E}=o();let C=0,b;const{x:$,y:j}=mt(e),v=u==null?void 0:u.elementFromPoint($,j),R=Vr(c,v),N=m==null?void 0:m.getBoundingClientRect();if(!N||!R)return;let T,P=mt(e,N),G=!1,V=null,y=!1,M=null;const S=Df({nodes:g(),nodeId:n,handleId:t,handleType:R}),O=()=>{if(!f)return;const[I,L]=ai(P,N);_({x:I,y:L}),C=requestAnimationFrame(O)};i({connectionPosition:P,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),x==null||x(e,{nodeId:n,handleId:t,handleType:R});function z(I){const{transform:L}=o();P=mt(I,N);const{handle:D,validHandleResult:q}=Of(I,u,Er(P,L,!1,[1,1]),p,S,F=>_i(F,d,n,t,s?"target":"source",a,u));if(b=D,G||(O(),G=!0),M=q.handleDomNode,V=q.connection,y=q.isValid,i({connectionPosition:b&&y?yi({x:b.x,y:b.y},L):P,connectionStatus:Pf(!!b,y),connectionEndHandle:q.endHandle}),!b&&!y&&!M)return Qn(T);V.source!==V.target&&M&&(Qn(T),T=M,M.classList.add("connecting","react-flow__handle-connecting"),M.classList.toggle("valid",y),M.classList.toggle("react-flow__handle-valid",y))}function k(I){var L,D;(b||M)&&V&&y&&(r==null||r(V)),(D=(L=o()).onConnectEnd)==null||D.call(L,I),c&&(l==null||l(I)),Qn(T),E(),cancelAnimationFrame(C),G=!1,y=!1,V=null,M=null,u.removeEventListener("mousemove",z),u.removeEventListener("mouseup",k),u.removeEventListener("touchmove",z),u.removeEventListener("touchend",k)}u.addEventListener("mousemove",z),u.addEventListener("mouseup",k),u.addEventListener("touchmove",z),u.addEventListener("touchend",k)}const Cs=()=>!0,zf=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Hf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:o,connectionClickStartHandle:i}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n,clickConnecting:(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n}},Ni=w.forwardRef(({type:e="source",position:t=K.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:o=!0,id:i,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},f)=>{var N,T;const p=i||null,x=e==="target",_=Ne(),g=Mf(),{connectOnClick:E,noPanClassName:C}=ge(zf,ke),{connecting:b,clickConnecting:$}=ge(Hf(g,p,e),ke);g||(T=(N=_.getState()).onError)==null||T.call(N,"010",ot.error010());const j=P=>{const{defaultEdgeOptions:G,onConnect:V,hasDefaultEdges:y}=_.getState(),M={...G,...P};if(y){const{edges:S,setEdges:O}=_.getState();O(If(M,S))}V==null||V(M),a==null||a(M)},v=P=>{if(!g)return;const G=fi(P);s&&(G&&P.button===0||!G)&&Ei({event:P,handleId:p,nodeId:g,onConnect:j,isTarget:x,getState:_.getState,setState:_.setState,isValidConnection:n||_.getState().isValidConnection||Cs}),G?u==null||u(P):d==null||d(P)},R=P=>{const{onClickConnectStart:G,onClickConnectEnd:V,connectionClickStartHandle:y,connectionMode:M,isValidConnection:S}=_.getState();if(!g||!y&&!s)return;if(!y){G==null||G(P,{nodeId:g,handleId:p,handleType:e}),_.setState({connectionClickStartHandle:{nodeId:g,type:e,handleId:p}});return}const O=ci(P.target),z=n||S||Cs,{connection:k,isValid:I}=_i({nodeId:g,id:p,type:e},M,y.nodeId,y.handleId||null,y.type,z,O);I&&j(k),V==null||V(P),_.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":p,"data-nodeid":g,"data-handlepos":t,"data-id":`${g}-${p}-${e}`,className:Me(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",C,l,{source:!x,target:x,connectable:r,connectablestart:s,connectableend:o,connecting:$,connectionindicator:r&&(s&&!b||o&&b)}]),onMouseDown:v,onTouchStart:v,onClick:E?R:void 0,ref:f,...m},c)});Ni.displayName="Handle";var ft=w.memo(Ni);const Si=({data:e,isConnectable:t,targetPosition:n=K.Top,sourcePosition:r=K.Bottom})=>A.createElement(A.Fragment,null,A.createElement(ft,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(ft,{type:"source",position:r,isConnectable:t}));Si.displayName="DefaultNode";var Nr=w.memo(Si);const ki=({data:e,isConnectable:t,sourcePosition:n=K.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(ft,{type:"source",position:n,isConnectable:t}));ki.displayName="InputNode";var ji=w.memo(ki);const Ci=({data:e,isConnectable:t,targetPosition:n=K.Top})=>A.createElement(A.Fragment,null,A.createElement(ft,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);Ci.displayName="OutputNode";var Mi=w.memo(Ci);const Br=()=>null;Br.displayName="GroupNode";const Ff=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),gn=e=>e.id;function Vf(e,t){return ke(e.selectedNodes.map(gn),t.selectedNodes.map(gn))&&ke(e.selectedEdges.map(gn),t.selectedEdges.map(gn))}const $i=w.memo(({onSelectionChange:e})=>{const t=Ne(),{selectedNodes:n,selectedEdges:r}=ge(Ff,Vf);return w.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(o=>o(s))},[n,r,e]),null});$i.displayName="SelectionListener";const Bf=e=>!!e.onSelectionChange;function Gf({onSelectionChange:e}){const t=ge(Bf);return e||t?A.createElement($i,{onSelectionChange:e}):null}const Yf=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Nt(e,t){w.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ae(e,t,n){w.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Xf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:o,onConnectEnd:i,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:l,nodesConnectable:u,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:p,minZoom:x,maxZoom:_,nodeExtent:g,onNodesChange:E,onEdgesChange:C,elementsSelectable:b,connectionMode:$,snapGrid:j,snapToGrid:v,translateExtent:R,connectOnClick:N,defaultEdgeOptions:T,fitView:P,fitViewOptions:G,onNodesDelete:V,onEdgesDelete:y,onNodeDrag:M,onNodeDragStart:S,onNodeDragStop:O,onSelectionDrag:z,onSelectionDragStart:k,onSelectionDragStop:I,noPanClassName:L,nodeOrigin:D,rfId:q,autoPanOnConnect:F,autoPanOnNodeDrag:J,onError:ee,connectionRadius:se,isValidConnection:le,nodeDragThreshold:ne})=>{const{setNodes:ce,setEdges:we,setDefaultNodesAndEdges:ye,setMinZoom:he,setMaxZoom:ue,setTranslateExtent:me,setNodeExtent:Se,reset:ie}=ge(Yf,ke),Z=Ne();return w.useEffect(()=>{const xe=r==null?void 0:r.map(je=>({...je,...T}));return ye(n,xe),()=>{ie()}},[]),ae("defaultEdgeOptions",T,Z.setState),ae("connectionMode",$,Z.setState),ae("onConnect",s,Z.setState),ae("onConnectStart",o,Z.setState),ae("onConnectEnd",i,Z.setState),ae("onClickConnectStart",a,Z.setState),ae("onClickConnectEnd",c,Z.setState),ae("nodesDraggable",l,Z.setState),ae("nodesConnectable",u,Z.setState),ae("nodesFocusable",d,Z.setState),ae("edgesFocusable",m,Z.setState),ae("edgesUpdatable",f,Z.setState),ae("elementsSelectable",b,Z.setState),ae("elevateNodesOnSelect",p,Z.setState),ae("snapToGrid",v,Z.setState),ae("snapGrid",j,Z.setState),ae("onNodesChange",E,Z.setState),ae("onEdgesChange",C,Z.setState),ae("connectOnClick",N,Z.setState),ae("fitViewOnInit",P,Z.setState),ae("fitViewOnInitOptions",G,Z.setState),ae("onNodesDelete",V,Z.setState),ae("onEdgesDelete",y,Z.setState),ae("onNodeDrag",M,Z.setState),ae("onNodeDragStart",S,Z.setState),ae("onNodeDragStop",O,Z.setState),ae("onSelectionDrag",z,Z.setState),ae("onSelectionDragStart",k,Z.setState),ae("onSelectionDragStop",I,Z.setState),ae("noPanClassName",L,Z.setState),ae("nodeOrigin",D,Z.setState),ae("rfId",q,Z.setState),ae("autoPanOnConnect",F,Z.setState),ae("autoPanOnNodeDrag",J,Z.setState),ae("onError",ee,Z.setState),ae("connectionRadius",se,Z.setState),ae("isValidConnection",le,Z.setState),ae("nodeDragThreshold",ne,Z.setState),Nt(e,ce),Nt(t,we),Nt(x,he),Nt(_,ue),Nt(R,me),Nt(g,Se),null},Ms={display:"none"},Wf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Ai="react-flow__node-desc",Ri="react-flow__edge-desc",Uf="react-flow__aria-live",qf=e=>e.ariaLiveMessage;function Kf({rfId:e}){const t=ge(qf);return A.createElement("div",{id:`${Uf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Wf},t)}function Zf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${Ai}-${e}`,style:Ms},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Ri}-${e}`,style:Ms},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Kf,{rfId:e}))}var nn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=w.useState(!1),s=w.useRef(!1),o=w.useRef(new Set([])),[i,a]=w.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),u=l.reduce((d,m)=>d.concat(...m),[]);return[l,u]}return[[],[]]},[e]);return w.useEffect(()=>{const c=typeof document<"u"?document:null,l=(t==null?void 0:t.target)||c;if(e!==null){const u=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&vr(f))return!1;const x=As(f.code,a);o.current.add(f[x]),$s(i,o.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&vr(f))return!1;const x=As(f.code,a);$s(i,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(f[x]),f.key==="Meta"&&o.current.clear(),s.current=!1},m=()=>{o.current.clear(),r(!1)};return l==null||l.addEventListener("keydown",u),l==null||l.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{l==null||l.removeEventListener("keydown",u),l==null||l.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function As(e,t){return t.includes(e)?"code":"key"}function Ii(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const o=t.get(s),i=bt(o,r);return Ii(o,t,{x:(n.x??0)+i.x,y:(n.y??0)+i.y,z:(((a=o[be])==null?void 0:a.z)??0)>(n.z??0)?((c=o[be])==null?void 0:c.z)??0:n.z??0},r)}function Ti(e,t,n){e.forEach(r=>{var o;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:i,y:a,z:c}=Ii(r,e,{...r.position,z:((o=r[be])==null?void 0:o.z)??0},t);r.positionAbsolute={x:i,y:a},r[be].z=c,n!=null&&n[r.id]&&(r[be].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,o={},i=r?1e3:0;return e.forEach(a=>{var f;const c=(ze(a.zIndex)?a.zIndex:0)+(a.selected?i:0),l=t.get(a.id),u={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(o[d]=!0);const m=(l==null?void 0:l.type)&&(l==null?void 0:l.type)!==a.type;Object.defineProperty(u,be,{enumerable:!1,value:{handleBounds:m||(f=l==null?void 0:l[be])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,u)}),Ti(s,n,o),s}function Oi(e,t={}){const{getNodes:n,width:r,height:s,minZoom:o,maxZoom:i,d3Zoom:a,d3Selection:c,fitViewOnInitDone:l,fitViewOnInit:u,nodeOrigin:d}=e(),m=t.initial&&!l&&u;if(a&&c&&(m||!t.initial)){const p=n().filter(_=>{var E;const g=t.includeHiddenNodes?_.width&&_.height:!_.hidden;return(E=t.nodes)!=null&&E.length?g&&t.nodes.some(C=>C.id===_.id):g}),x=p.every(_=>_.width&&_.height);if(p.length>0&&x){const _=an(p,d),{x:g,y:E,zoom:C}=bi(_,r,s,t.minZoom??o,t.maxZoom??i,t.padding??.1),b=rt.translate(g,E).scale(C);return typeof t.duration=="number"&&t.duration>0?a.transform(gt(c,t.duration),b):a.transform(c,b),!0}}return!1}function Qf(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[be]:r[be],selected:n.selected})}),new Map(t)}function Jf(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function yn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:o,onNodesChange:i,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:l}=n();e!=null&&e.length&&(c&&r({nodeInternals:Qf(e,s)}),i==null||i(e)),t!=null&&t.length&&(l&&r({edges:Jf(t,o)}),a==null||a(t))}const St=()=>{},eh={zoomIn:St,zoomOut:St,zoomTo:St,getZoom:()=>1,setViewport:St,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:St,fitBounds:St,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},th=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),nh=()=>{const e=Ne(),{d3Zoom:t,d3Selection:n}=ge(th,ke);return w.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(gt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(gt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,o)=>t.scaleTo(gt(n,o==null?void 0:o.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,o)=>{const[i,a,c]=e.getState().transform,l=rt.translate(s.x??i,s.y??a).scale(s.zoom??c);t.transform(gt(n,o==null?void 0:o.duration),l)},getViewport:()=>{const[s,o,i]=e.getState().transform;return{x:s,y:o,zoom:i}},fitView:s=>Oi(e.getState,s),setCenter:(s,o,i)=>{const{width:a,height:c,maxZoom:l}=e.getState(),u=typeof(i==null?void 0:i.zoom)<"u"?i.zoom:l,d=a/2-s*u,m=c/2-o*u,f=rt.translate(d,m).scale(u);t.transform(gt(n,i==null?void 0:i.duration),f)},fitBounds:(s,o)=>{const{width:i,height:a,minZoom:c,maxZoom:l}=e.getState(),{x:u,y:d,zoom:m}=bi(s,i,a,c,l,(o==null?void 0:o.padding)??.1),f=rt.translate(u,d).scale(m);t.transform(gt(n,o==null?void 0:o.duration),f)},project:s=>{const{transform:o,snapToGrid:i,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),Er(s,o,i,a)},screenToFlowPosition:s=>{const{transform:o,snapToGrid:i,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:l,y:u}=c.getBoundingClientRect(),d={x:s.x-l,y:s.y-u};return Er(d,o,i,a)},flowToScreenPosition:s=>{const{transform:o,domNode:i}=e.getState();if(!i)return s;const{x:a,y:c}=i.getBoundingClientRect(),l=yi(s,o);return{x:l.x+a,y:l.y+c}},viewportInitialized:!0}:eh,[t,n])};function cn(){const e=nh(),t=Ne(),n=w.useCallback(()=>t.getState().getNodes().map(x=>({...x})),[]),r=w.useCallback(x=>t.getState().nodeInternals.get(x),[]),s=w.useCallback(()=>{const{edges:x=[]}=t.getState();return x.map(_=>({..._}))},[]),o=w.useCallback(x=>{const{edges:_=[]}=t.getState();return _.find(g=>g.id===x)},[]),i=w.useCallback(x=>{const{getNodes:_,setNodes:g,hasDefaultNodes:E,onNodesChange:C}=t.getState(),b=_(),$=typeof x=="function"?x(b):x;if(E)g($);else if(C){const j=$.length===0?b.map(v=>({type:"remove",id:v.id})):$.map(v=>({item:v,type:"reset"}));C(j)}},[]),a=w.useCallback(x=>{const{edges:_=[],setEdges:g,hasDefaultEdges:E,onEdgesChange:C}=t.getState(),b=typeof x=="function"?x(_):x;if(E)g(b);else if(C){const $=b.length===0?_.map(j=>({type:"remove",id:j.id})):b.map(j=>({item:j,type:"reset"}));C($)}},[]),c=w.useCallback(x=>{const _=Array.isArray(x)?x:[x],{getNodes:g,setNodes:E,hasDefaultNodes:C,onNodesChange:b}=t.getState();if(C){const j=[...g(),..._];E(j)}else if(b){const $=_.map(j=>({item:j,type:"add"}));b($)}},[]),l=w.useCallback(x=>{const _=Array.isArray(x)?x:[x],{edges:g=[],setEdges:E,hasDefaultEdges:C,onEdgesChange:b}=t.getState();if(C)E([...g,..._]);else if(b){const $=_.map(j=>({item:j,type:"add"}));b($)}},[]),u=w.useCallback(()=>{const{getNodes:x,edges:_=[],transform:g}=t.getState(),[E,C,b]=g;return{nodes:x().map($=>({...$})),edges:_.map($=>({...$})),viewport:{x:E,y:C,zoom:b}}},[]),d=w.useCallback(({nodes:x,edges:_})=>{const{nodeInternals:g,getNodes:E,edges:C,hasDefaultNodes:b,hasDefaultEdges:$,onNodesDelete:j,onEdgesDelete:v,onNodesChange:R,onEdgesChange:N}=t.getState(),T=(x||[]).map(M=>M.id),P=(_||[]).map(M=>M.id),G=E().reduce((M,S)=>{const O=S.parentNode||S.parentId,z=!T.includes(S.id)&&O&&M.find(I=>I.id===O);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(T.includes(S.id)||z)&&M.push(S),M},[]),V=C.filter(M=>typeof M.deletable=="boolean"?M.deletable:!0),y=V.filter(M=>P.includes(M.id));if(G||y){const M=wi(G,V),S=[...y,...M],O=S.reduce((z,k)=>(z.includes(k.id)||z.push(k.id),z),[]);if(($||b)&&($&&t.setState({edges:C.filter(z=>!O.includes(z.id))}),b&&(G.forEach(z=>{g.delete(z.id)}),t.setState({nodeInternals:new Map(g)}))),O.length>0&&(v==null||v(S),N&&N(O.map(z=>({id:z,type:"remove"})))),G.length>0&&(j==null||j(G),R)){const z=G.map(k=>({id:k.id,type:"remove"}));R(z)}}},[]),m=w.useCallback(x=>{const _=vf(x),g=_?null:t.getState().nodeInternals.get(x.id);return!_&&!g?[null,null,_]:[_?x:_s(g),g,_]},[]),f=w.useCallback((x,_=!0,g)=>{const[E,C,b]=m(x);return E?(g||t.getState().getNodes()).filter($=>{if(!b&&($.id===C.id||!$.positionAbsolute))return!1;const j=_s($),v=br(j,E);return _&&v>0||v>=E.width*E.height}):[]},[]),p=w.useCallback((x,_,g=!0)=>{const[E]=m(x);if(!E)return!1;const C=br(E,_);return g&&C>0||C>=E.width*E.height},[]);return w.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:o,setNodes:i,setEdges:a,addNodes:c,addEdges:l,toObject:u,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:p}),[e,n,r,s,o,i,a,c,l,u,d,f,p])}const rh={actInsideInputWithModifier:!1};var sh=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Ne(),{deleteElements:r}=cn(),s=nn(e,rh),o=nn(t);w.useEffect(()=>{if(s){const{edges:i,getNodes:a}=n.getState(),c=a().filter(u=>u.selected),l=i.filter(u=>u.selected);r({nodes:c,edges:l}),n.setState({nodesSelectionActive:!1})}},[s]),w.useEffect(()=>{n.setState({multiSelectionActive:o})},[o])};function oh(e){const t=Ne();w.useEffect(()=>{let n;const r=()=>{var o,i;if(!e.current)return;const s=Lr(e.current);(s.height===0||s.width===0)&&((i=(o=t.getState()).onError)==null||i.call(o,"004",ot.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Gr={position:"absolute",width:"100%",height:"100%",top:0,left:0},ih=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,xn=e=>({x:e.x,y:e.y,zoom:e.k}),kt=(e,t)=>e.target.closest(`.${t}`),Rs=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Is=e=>{const t=e.ctrlKey&&$n()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},ah=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),ch=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:o=!0,panOnScroll:i=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=xt.Free,zoomOnDoubleClick:l=!0,elementsSelectable:u,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:p,maxZoom:x,zoomActivationKeyCode:_,preventScrolling:g=!0,children:E,noWheelClassName:C,noPanClassName:b})=>{const $=w.useRef(),j=Ne(),v=w.useRef(!1),R=w.useRef(!1),N=w.useRef(null),T=w.useRef({x:0,y:0,zoom:0}),{d3Zoom:P,d3Selection:G,d3ZoomHandler:V,userSelectionActive:y}=ge(ah,ke),M=nn(_),S=w.useRef(0),O=w.useRef(!1),z=w.useRef();return oh(N),w.useEffect(()=>{if(N.current){const k=N.current.getBoundingClientRect(),I=oi().scaleExtent([p,x]).translateExtent(f),L=Pe(N.current).call(I),D=rt.translate(m.x,m.y).scale(Lt(m.zoom,p,x)),q=[[0,0],[k.width,k.height]],F=I.constrain()(D,q,f);I.transform(L,F),I.wheelDelta(Is),j.setState({d3Zoom:I,d3Selection:L,d3ZoomHandler:L.on("wheel.zoom"),transform:[F.x,F.y,F.k],domNode:N.current.closest(".react-flow")})}},[]),w.useEffect(()=>{G&&P&&(i&&!M&&!y?G.on("wheel.zoom",k=>{if(kt(k,C))return!1;k.preventDefault(),k.stopImmediatePropagation();const I=G.property("__zoom").k||1;if(k.ctrlKey&&o){const le=Ge(k),ne=Is(k),ce=I*Math.pow(2,ne);P.scaleTo(G,ce,le,k);return}const L=k.deltaMode===1?20:1;let D=c===xt.Vertical?0:k.deltaX*L,q=c===xt.Horizontal?0:k.deltaY*L;!$n()&&k.shiftKey&&c!==xt.Vertical&&(D=k.deltaY*L,q=0),P.translateBy(G,-(D/I)*a,-(q/I)*a,{internal:!0});const F=xn(G.property("__zoom")),{onViewportChangeStart:J,onViewportChange:ee,onViewportChangeEnd:se}=j.getState();clearTimeout(z.current),O.current||(O.current=!0,t==null||t(k,F),J==null||J(F)),O.current&&(e==null||e(k,F),ee==null||ee(F),z.current=setTimeout(()=>{n==null||n(k,F),se==null||se(F),O.current=!1},150))},{passive:!1}):typeof V<"u"&&G.on("wheel.zoom",function(k,I){if(!g&&k.type==="wheel"&&!k.ctrlKey||kt(k,C))return null;k.preventDefault(),V.call(this,k,I)},{passive:!1}))},[y,i,c,G,P,V,M,o,g,C,t,e,n]),w.useEffect(()=>{P&&P.on("start",k=>{var D,q;if(!k.sourceEvent||k.sourceEvent.internal)return null;S.current=(D=k.sourceEvent)==null?void 0:D.button;const{onViewportChangeStart:I}=j.getState(),L=xn(k.transform);v.current=!0,T.current=L,((q=k.sourceEvent)==null?void 0:q.type)==="mousedown"&&j.setState({paneDragging:!0}),I==null||I(L),t==null||t(k.sourceEvent,L)})},[P,t]),w.useEffect(()=>{P&&(y&&!v.current?P.on("zoom",null):y||P.on("zoom",k=>{var L;const{onViewportChange:I}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),R.current=!!(r&&Rs(d,S.current??0)),(e||I)&&!((L=k.sourceEvent)!=null&&L.internal)){const D=xn(k.transform);I==null||I(D),e==null||e(k.sourceEvent,D)}}))},[y,P,e,d,r]),w.useEffect(()=>{P&&P.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:I}=j.getState();if(v.current=!1,j.setState({paneDragging:!1}),r&&Rs(d,S.current??0)&&!R.current&&r(k.sourceEvent),R.current=!1,(n||I)&&ih(T.current,k.transform)){const L=xn(k.transform);T.current=L,clearTimeout($.current),$.current=setTimeout(()=>{I==null||I(L),n==null||n(k.sourceEvent,L)},i?150:0)}})},[P,i,d,n,r]),w.useEffect(()=>{P&&P.filter(k=>{const I=M||s,L=o&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(kt(k,"react-flow__node")||kt(k,"react-flow__edge")))return!0;if(!d&&!I&&!i&&!l&&!o||y||!l&&k.type==="dblclick"||kt(k,C)&&k.type==="wheel"||kt(k,b)&&(k.type!=="wheel"||i&&k.type==="wheel"&&!M)||!o&&k.ctrlKey&&k.type==="wheel"||!I&&!i&&!L&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const D=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&D})},[y,P,s,o,i,l,d,u,M]),A.createElement("div",{className:"react-flow__renderer",ref:N,style:Gr},E)},lh=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function uh(){const{userSelectionActive:e,userSelectionRect:t}=ge(lh,ke);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Ts(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,o=t.position.y+t.height-r.height;if(s>0||o>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),o>0&&(r.style.height+=o),t.position.x<0){const i=Math.abs(t.position.x);r.position.x=r.position.x-i,r.style.width+=i,t.position.x=0}if(t.position.y<0){const i=Math.abs(t.position.y);r.position.y=r.position.y-i,r.style.height+=i,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function dh(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const o=e.filter(a=>a.id===s.id);if(o.length===0)return r.push(s),r;const i={...s};for(const a of o)if(a)switch(a.type){case"select":{i.selected=a.selected;break}case"position":{typeof a.position<"u"&&(i.position=a.position),typeof a.positionAbsolute<"u"&&(i.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(i.dragging=a.dragging),i.expandParent&&Ts(r,i);break}case"dimensions":{typeof a.dimensions<"u"&&(i.width=a.dimensions.width,i.height=a.dimensions.height),typeof a.updateStyle<"u"&&(i.style={...i.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(i.resizing=a.resizing),i.expandParent&&Ts(r,i);break}case"remove":return r}return r.push(i),r},n)}function fh(e,t){return dh(e,t)}const ut=(e,t)=>({id:e,type:"select",selected:t});function Ct(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ut(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ut(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},hh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Li=w.memo(({isSelecting:e,selectionMode:t=tn.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:o,onPaneContextMenu:i,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:l,onPaneMouseLeave:u,children:d})=>{const m=w.useRef(null),f=Ne(),p=w.useRef(0),x=w.useRef(0),_=w.useRef(),{userSelectionActive:g,elementsSelectable:E,dragging:C}=ge(hh,ke),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),p.current=0,x.current=0},$=V=>{o==null||o(V),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=V=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){V.preventDefault();return}i==null||i(V)},v=a?V=>a(V):void 0,R=V=>{const{resetSelectedElements:y,domNode:M}=f.getState();if(_.current=M==null?void 0:M.getBoundingClientRect(),!E||!e||V.button!==0||V.target!==m.current||!_.current)return;const{x:S,y:O}=mt(V,_.current);y(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:O,x:S,y:O}}),r==null||r(V)},N=V=>{const{userSelectionRect:y,nodeInternals:M,edges:S,transform:O,onNodesChange:z,onEdgesChange:k,nodeOrigin:I,getNodes:L}=f.getState();if(!e||!_.current||!y)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const D=mt(V,_.current),q=y.startX??0,F=y.startY??0,J={...y,x:D.xce.id),ne=se.map(ce=>ce.id);if(p.current!==ne.length){p.current=ne.length;const ce=Ct(ee,ne);ce.length&&(z==null||z(ce))}if(x.current!==le.length){x.current=le.length;const ce=Ct(S,le);ce.length&&(k==null||k(ce))}f.setState({userSelectionRect:J})},T=V=>{if(V.button!==0)return;const{userSelectionRect:y}=f.getState();!g&&y&&V.target===m.current&&($==null||$(V)),f.setState({nodesSelectionActive:p.current>0}),b(),s==null||s(V)},P=V=>{g&&(f.setState({nodesSelectionActive:p.current>0}),s==null||s(V)),b()},G=E&&(e||g);return A.createElement("div",{className:Me(["react-flow__pane",{dragging:C,selection:e}]),onClick:G?void 0:er($,m),onContextMenu:er(j,m),onWheel:er(v,m),onMouseEnter:G?void 0:c,onMouseDown:G?R:void 0,onMouseMove:G?N:l,onMouseUp:G?T:void 0,onMouseLeave:G?P:u,ref:m,style:Gr},d,A.createElement(uh,null))});Li.displayName="Pane";function Di(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Di(r,t):!1}function Os(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function mh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Di(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var o,i;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((o=s.positionAbsolute)==null?void 0:o.x)??0),y:n.y-(((i=s.positionAbsolute)==null?void 0:i.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function ph(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function Pi(e,t,n,r,s=[0,0],o){const i=ph(e,e.extent||r);let a=i;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=bt(d,s).positionAbsolute;a=d&&ze(m)&&ze(f)&&ze(d.width)&&ze(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else o==null||o("005",ot.error005()),a=i;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=bt(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let l={x:0,y:0};if(c){const d=n.get(c);l=bt(d,s).positionAbsolute}const u=a&&a!=="parent"?Dr(t,a):t;return{position:{x:u.x-l.x,y:u.y-l.y},positionAbsolute:u}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Ls=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const o=Array.from(s),i=t.getBoundingClientRect(),a={x:i.width*r[0],y:i.height*r[1]};return o.map(c=>{const l=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(l.left-i.left-a.x)/n,y:(l.top-i.top-a.y)/n,...Lr(c)}})};function Bt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Sr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:o,multiSelectionActive:i,nodeInternals:a,onError:c}=t.getState(),l=a.get(e);if(!l){c==null||c("012",ot.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&i)&&(o({nodes:[l],edges:[]}),requestAnimationFrame(()=>{var u;return(u=r==null?void 0:r.current)==null?void 0:u.blur()})):s([e])}function gh(){const e=Ne();return w.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:o}=e.getState(),i=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(i-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:o?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:o?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function zi({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:o,selectNodesOnDrag:i}){const a=Ne(),[c,l]=w.useState(!1),u=w.useRef([]),d=w.useRef({x:null,y:null}),m=w.useRef(0),f=w.useRef(null),p=w.useRef({x:0,y:0}),x=w.useRef(null),_=w.useRef(!1),g=w.useRef(!1),E=w.useRef(!1),C=gh();return w.useEffect(()=>{if(e!=null&&e.current){const b=Pe(e.current),$=({x:R,y:N})=>{const{nodeInternals:T,onNodeDrag:P,onSelectionDrag:G,updateNodePositions:V,nodeExtent:y,snapGrid:M,snapToGrid:S,nodeOrigin:O,onError:z}=a.getState();d.current={x:R,y:N};let k=!1,I={x:0,y:0,x2:0,y2:0};if(u.current.length>1&&y){const D=an(u.current,O);I=en(D)}if(u.current=u.current.map(D=>{const q={x:R-D.distance.x,y:N-D.distance.y};S&&(q.x=M[0]*Math.round(q.x/M[0]),q.y=M[1]*Math.round(q.y/M[1]));const F=[[y[0][0],y[0][1]],[y[1][0],y[1][1]]];u.current.length>1&&y&&!D.extent&&(F[0][0]=D.positionAbsolute.x-I.x+y[0][0],F[1][0]=D.positionAbsolute.x+(D.width??0)-I.x2+y[1][0],F[0][1]=D.positionAbsolute.y-I.y+y[0][1],F[1][1]=D.positionAbsolute.y+(D.height??0)-I.y2+y[1][1]);const J=Pi(D,q,T,F,O,z);return k=k||D.position.x!==J.position.x||D.position.y!==J.position.y,D.position=J.position,D.positionAbsolute=J.positionAbsolute,D}),!k)return;V(u.current,!0,!0),l(!0);const L=s?P:nr(G);if(L&&x.current){const[D,q]=tr({nodeId:s,dragItems:u.current,nodeInternals:T});L(x.current,D,q)}},j=()=>{if(!f.current)return;const[R,N]=ai(p.current,f.current);if(R!==0||N!==0){const{transform:T,panBy:P}=a.getState();d.current.x=(d.current.x??0)-R/T[2],d.current.y=(d.current.y??0)-N/T[2],P({x:R,y:N})&&$(d.current)}m.current=requestAnimationFrame(j)},v=R=>{var O;const{nodeInternals:N,multiSelectionActive:T,nodesDraggable:P,unselectNodesAndEdges:G,onNodeDragStart:V,onSelectionDragStart:y}=a.getState();g.current=!0;const M=s?V:nr(y);(!i||!o)&&!T&&s&&((O=N.get(s))!=null&&O.selected||G()),s&&o&&i&&Sr({id:s,store:a,nodeRef:e});const S=C(R);if(d.current=S,u.current=mh(N,P,S,s),M&&u.current){const[z,k]=tr({nodeId:s,dragItems:u.current,nodeInternals:N});M(R.sourceEvent,z,k)}};if(t)b.on(".drag",null);else{const R=Nu().on("start",N=>{const{domNode:T,nodeDragThreshold:P}=a.getState();P===0&&v(N),E.current=!1;const G=C(N);d.current=G,f.current=(T==null?void 0:T.getBoundingClientRect())||null,p.current=mt(N.sourceEvent,f.current)}).on("drag",N=>{var V,y;const T=C(N),{autoPanOnNodeDrag:P,nodeDragThreshold:G}=a.getState();if(N.sourceEvent.type==="touchmove"&&N.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!_.current&&g.current&&P&&(_.current=!0,j()),!g.current){const M=T.xSnapped-(((V=d==null?void 0:d.current)==null?void 0:V.x)??0),S=T.ySnapped-(((y=d==null?void 0:d.current)==null?void 0:y.y)??0);Math.sqrt(M*M+S*S)>G&&v(N)}(d.current.x!==T.xSnapped||d.current.y!==T.ySnapped)&&u.current&&g.current&&(x.current=N.sourceEvent,p.current=mt(N.sourceEvent,f.current),$(T))}}).on("end",N=>{if(!(!g.current||E.current)&&(l(!1),_.current=!1,g.current=!1,cancelAnimationFrame(m.current),u.current)){const{updateNodePositions:T,nodeInternals:P,onNodeDragStop:G,onSelectionDragStop:V}=a.getState(),y=s?G:nr(V);if(T(u.current,!1,!1),y){const[M,S]=tr({nodeId:s,dragItems:u.current,nodeInternals:P});y(N.sourceEvent,M,S)}}}).filter(N=>{const T=N.target;return!N.button&&(!n||!Os(T,`.${n}`,e))&&(!r||Os(T,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,o,a,s,i,C]),c}function Hi(){const e=Ne();return w.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:o,getNodes:i,snapToGrid:a,snapGrid:c,onError:l,nodesDraggable:u}=e.getState(),d=i().filter(E=>E.selected&&(E.draggable||u&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,p=n.isShiftPressed?4:1,x=n.x*m*p,_=n.y*f*p,g=d.map(E=>{if(E.positionAbsolute){const C={x:E.positionAbsolute.x+x,y:E.positionAbsolute.y+_};a&&(C.x=c[0]*Math.round(C.x/c[0]),C.y=c[1]*Math.round(C.y/c[1]));const{positionAbsolute:b,position:$}=Pi(E,C,r,s,void 0,l);E.position=$,E.positionAbsolute=b}return E});o(g,!0,!1)},[])}const Rt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Gt=e=>{const t=({id:n,type:r,data:s,xPos:o,yPos:i,xPosOrigin:a,yPosOrigin:c,selected:l,onClick:u,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:p,onDoubleClick:x,style:_,className:g,isDraggable:E,isSelectable:C,isConnectable:b,isFocusable:$,selectNodesOnDrag:j,sourcePosition:v,targetPosition:R,hidden:N,resizeObserver:T,dragHandle:P,zIndex:G,isParent:V,noDragClassName:y,noPanClassName:M,initialized:S,disableKeyboardA11y:O,ariaLabel:z,rfId:k,hasHandleBounds:I})=>{const L=Ne(),D=w.useRef(null),q=w.useRef(null),F=w.useRef(v),J=w.useRef(R),ee=w.useRef(r),se=C||E||u||d||m||f,le=Hi(),ne=Bt(n,L.getState,d),ce=Bt(n,L.getState,m),we=Bt(n,L.getState,f),ye=Bt(n,L.getState,p),he=Bt(n,L.getState,x),ue=ie=>{const{nodeDragThreshold:Z}=L.getState();if(C&&(!j||!E||Z>0)&&Sr({id:n,store:L,nodeRef:D}),u){const xe=L.getState().nodeInternals.get(n);xe&&u(ie,{...xe})}},me=ie=>{if(!vr(ie)&&!O)if(di.includes(ie.key)&&C){const Z=ie.key==="Escape";Sr({id:n,store:L,unselect:Z,nodeRef:D})}else E&&l&&Object.prototype.hasOwnProperty.call(Rt,ie.key)&&(L.setState({ariaLiveMessage:`Moved selected node ${ie.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~o}, y: ${~~i}`}),le({x:Rt[ie.key].x,y:Rt[ie.key].y,isShiftPressed:ie.shiftKey}))};w.useEffect(()=>()=>{q.current&&(T==null||T.unobserve(q.current),q.current=null)},[]),w.useEffect(()=>{if(D.current&&!N){const ie=D.current;(!S||!I||q.current!==ie)&&(q.current&&(T==null||T.unobserve(q.current)),T==null||T.observe(ie),q.current=ie)}},[N,S,I]),w.useEffect(()=>{const ie=ee.current!==r,Z=F.current!==v,xe=J.current!==R;D.current&&(ie||Z||xe)&&(ie&&(ee.current=r),Z&&(F.current=v),xe&&(J.current=R),L.getState().updateNodeDimensions([{id:n,nodeElement:D.current,forceUpdate:!0}]))},[n,r,v,R]);const Se=zi({nodeRef:D,disabled:N||!E,noDragClassName:y,handleSelector:P,nodeId:n,isSelectable:C,selectNodesOnDrag:j});return N?null:A.createElement("div",{className:Me(["react-flow__node",`react-flow__node-${r}`,{[M]:E},g,{selected:l,selectable:C,parent:V,dragging:Se}]),ref:D,style:{zIndex:G,transform:`translate(${a}px,${c}px)`,pointerEvents:se?"all":"none",visibility:S?"visible":"hidden",..._},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ne,onMouseMove:ce,onMouseLeave:we,onContextMenu:ye,onClick:ue,onDoubleClick:he,onKeyDown:$?me:void 0,tabIndex:$?0:void 0,role:$?"button":void 0,"aria-describedby":O?void 0:`${Ai}-${k}`,"aria-label":z},A.createElement(Cf,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:o,yPos:i,selected:l,isConnectable:b,sourcePosition:v,targetPosition:R,dragging:Se,dragHandle:P,zIndex:G})))};return t.displayName="NodeWrapper",w.memo(t)};const yh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...an(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function xh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Ne(),{width:s,height:o,x:i,y:a,transformString:c,userSelectionActive:l}=ge(yh,ke),u=Hi(),d=w.useRef(null);if(w.useEffect(()=>{var p;n||(p=d.current)==null||p.focus({preventScroll:!0})},[n]),zi({nodeRef:d}),l||!s||!o)return null;const m=e?p=>{const x=r.getState().getNodes().filter(_=>_.selected);e(p,x)}:void 0,f=p=>{Object.prototype.hasOwnProperty.call(Rt,p.key)&&u({x:Rt[p.key].x,y:Rt[p.key].y,isShiftPressed:p.shiftKey})};return A.createElement("div",{className:Me(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:o,top:a,left:i}}))}var wh=w.memo(xh);const bh=e=>e.nodesSelectionActive,Fi=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:i,deleteKeyCode:a,onMove:c,onMoveStart:l,onMoveEnd:u,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:p,onSelectionEnd:x,multiSelectionKeyCode:_,panActivationKeyCode:g,zoomActivationKeyCode:E,elementsSelectable:C,zoomOnScroll:b,zoomOnPinch:$,panOnScroll:j,panOnScrollSpeed:v,panOnScrollMode:R,zoomOnDoubleClick:N,panOnDrag:T,defaultViewport:P,translateExtent:G,minZoom:V,maxZoom:y,preventScrolling:M,onSelectionContextMenu:S,noWheelClassName:O,noPanClassName:z,disableKeyboardA11y:k})=>{const I=ge(bh),L=nn(d),D=nn(g),q=D||T,F=D||j,J=L||m&&q!==!0;return sh({deleteKeyCode:a,multiSelectionKeyCode:_}),A.createElement(ch,{onMove:c,onMoveStart:l,onMoveEnd:u,onPaneContextMenu:o,elementsSelectable:C,zoomOnScroll:b,zoomOnPinch:$,panOnScroll:F,panOnScrollSpeed:v,panOnScrollMode:R,zoomOnDoubleClick:N,panOnDrag:!L&&q,defaultViewport:P,translateExtent:G,minZoom:V,maxZoom:y,zoomActivationKeyCode:E,preventScrolling:M,noWheelClassName:O,noPanClassName:z},A.createElement(Li,{onSelectionStart:p,onSelectionEnd:x,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:i,panOnDrag:q,isSelecting:!!J,selectionMode:f},e,I&&A.createElement(wh,{onSelectionContextMenu:S,noPanClassName:z,disableKeyboardA11y:k})))};Fi.displayName="FlowRenderer";var vh=w.memo(Fi);function _h(e){return ge(w.useCallback(n=>e?xi(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function Eh(e){const t={input:Gt(e.input||ji),default:Gt(e.default||Nr),output:Gt(e.output||Mi),group:Gt(e.group||Br)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,o)=>(s[o]=Gt(e[o]||Nr),s),n);return{...t,...r}}const Nh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},Sh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Vi=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:o,onError:i}=ge(Sh,ke),a=_h(e.onlyRenderVisibleElements),c=w.useRef(),l=w.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const u=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));o(m)});return c.current=u,u},[]);return w.useEffect(()=>()=>{var u;(u=c==null?void 0:c.current)==null||u.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Gr},a.map(u=>{var $,j,v;let d=u.type||"default";e.nodeTypes[d]||(i==null||i("003",ot.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(u.draggable||t&&typeof u.draggable>"u"),p=!!(u.selectable||s&&typeof u.selectable>"u"),x=!!(u.connectable||n&&typeof u.connectable>"u"),_=!!(u.focusable||r&&typeof u.focusable>"u"),g=e.nodeExtent?Dr(u.positionAbsolute,e.nodeExtent):u.positionAbsolute,E=(g==null?void 0:g.x)??0,C=(g==null?void 0:g.y)??0,b=Nh({x:E,y:C,width:u.width??0,height:u.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:u.id,id:u.id,className:u.className,style:u.style,type:d,data:u.data,sourcePosition:u.sourcePosition||K.Bottom,targetPosition:u.targetPosition||K.Top,hidden:u.hidden,xPos:E,yPos:C,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!u.selected,isDraggable:f,isSelectable:p,isConnectable:x,isFocusable:_,resizeObserver:l,dragHandle:u.dragHandle,zIndex:(($=u[be])==null?void 0:$.z)??0,isParent:!!((j=u[be])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!u.width&&!!u.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:u.ariaLabel,hasHandleBounds:!!((v=u[be])!=null&&v.handleBounds)})}))};Vi.displayName="NodeRenderer";var kh=w.memo(Vi);const jh=(e,t,n)=>n===K.Left?e-t:n===K.Right?e+t:e,Ch=(e,t,n)=>n===K.Top?e-t:n===K.Bottom?e+t:e,Ds="react-flow__edgeupdater",Ps=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:o,onMouseOut:i,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:o,onMouseOut:i,className:Me([Ds,`${Ds}-${a}`]),cx:jh(t,r,e),cy:Ch(n,r,e),r,stroke:"transparent",fill:"transparent"}),Mh=()=>!0;var jt=e=>{const t=({id:n,className:r,type:s,data:o,onClick:i,onEdgeDoubleClick:a,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:x,style:_,source:g,target:E,sourceX:C,sourceY:b,targetX:$,targetY:j,sourcePosition:v,targetPosition:R,elementsSelectable:N,hidden:T,sourceHandleId:P,targetHandleId:G,onContextMenu:V,onMouseEnter:y,onMouseMove:M,onMouseLeave:S,reconnectRadius:O,onReconnect:z,onReconnectStart:k,onReconnectEnd:I,markerEnd:L,markerStart:D,rfId:q,ariaLabel:F,isFocusable:J,isReconnectable:ee,pathOptions:se,interactionWidth:le,disableKeyboardA11y:ne})=>{const ce=w.useRef(null),[we,ye]=w.useState(!1),[he,ue]=w.useState(!1),me=Ne(),Se=w.useMemo(()=>`url('#${_r(D,q)}')`,[D,q]),ie=w.useMemo(()=>`url('#${_r(L,q)}')`,[L,q]);if(T)return null;const Z=W=>{var fe;const{edges:te,addSelectedEdges:pe,unselectNodesAndEdges:Q,multiSelectionActive:oe}=me.getState(),re=te.find(Ce=>Ce.id===n);re&&(N&&(me.setState({nodesSelectionActive:!1}),re.selected&&oe?(Q({nodes:[],edges:[re]}),(fe=ce.current)==null||fe.blur()):pe([n])),i&&i(W,re))},xe=Vt(n,me.getState,a),je=Vt(n,me.getState,V),Ae=Vt(n,me.getState,y),Le=Vt(n,me.getState,M),Re=Vt(n,me.getState,S),Ie=(W,te)=>{if(W.button!==0)return;const{edges:pe,isValidConnection:Q}=me.getState(),oe=te?E:g,re=(te?G:P)||null,fe=te?"target":"source",Ce=Q||Mh,Te=te,$e=pe.find(Be=>Be.id===n);ue(!0),k==null||k(W,$e,fe);const Ue=Be=>{ue(!1),I==null||I(Be,$e,fe)};Ei({event:W,handleId:re,nodeId:oe,onConnect:Be=>z==null?void 0:z($e,Be),isTarget:Te,getState:me.getState,setState:me.setState,isValidConnection:Ce,edgeUpdaterType:fe,onReconnectEnd:Ue})},Ve=W=>Ie(W,!0),H=W=>Ie(W,!1),X=()=>ye(!0),B=()=>ye(!1),U=!N&&!i,Y=W=>{var te;if(!ne&&di.includes(W.key)&&N){const{unselectNodesAndEdges:pe,addSelectedEdges:Q,edges:oe}=me.getState();W.key==="Escape"?((te=ce.current)==null||te.blur(),pe({edges:[oe.find(fe=>fe.id===n)]})):Q([n])}};return A.createElement("g",{className:Me(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:l,inactive:U,updating:we}]),onClick:Z,onDoubleClick:xe,onContextMenu:je,onMouseEnter:Ae,onMouseMove:Le,onMouseLeave:Re,onKeyDown:J?Y:void 0,tabIndex:J?0:void 0,role:J?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":F===null?void 0:F||`Edge from ${g} to ${E}`,"aria-describedby":J?`${Ri}-${q}`:void 0,ref:ce},!he&&A.createElement(e,{id:n,source:g,target:E,selected:c,animated:l,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:x,data:o,style:_,sourceX:C,sourceY:b,targetX:$,targetY:j,sourcePosition:v,targetPosition:R,sourceHandleId:P,targetHandleId:G,markerStart:Se,markerEnd:ie,pathOptions:se,interactionWidth:le}),ee&&A.createElement(A.Fragment,null,(ee==="source"||ee===!0)&&A.createElement(Ps,{position:v,centerX:C,centerY:b,radius:O,onMouseDown:Ve,onMouseEnter:X,onMouseOut:B,type:"source"}),(ee==="target"||ee===!0)&&A.createElement(Ps,{position:R,centerX:$,centerY:j,radius:O,onMouseDown:H,onMouseEnter:X,onMouseOut:B,type:"target"})))};return t.displayName="EdgeWrapper",w.memo(t)};function $h(e){const t={default:jt(e.default||In),straight:jt(e.bezier||Hr),step:jt(e.step||zr),smoothstep:jt(e.step||Bn),simplebezier:jt(e.simplebezier||Pr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,o)=>(s[o]=jt(e[o]||In),s),n);return{...t,...r}}function zs(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,o=(n==null?void 0:n.width)||t.width,i=(n==null?void 0:n.height)||t.height;switch(e){case K.Top:return{x:r+o/2,y:s};case K.Right:return{x:r+o,y:s+i/2};case K.Bottom:return{x:r+o/2,y:s+i};case K.Left:return{x:r,y:s+i/2}}}function Hs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const Ah=(e,t,n,r,s,o)=>{const i=zs(n,e,t),a=zs(o,r,s);return{sourceX:i.x,sourceY:i.y,targetX:a.x,targetY:a.y}};function Rh({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:o,width:i,height:a,transform:c}){const l={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+o)};l.x===l.x2&&(l.x2+=1),l.y===l.y2&&(l.y2+=1);const u=en({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:i/c[2],height:a/c[2]}),d=Math.max(0,Math.min(u.x2,l.x2)-Math.max(u.x,l.x)),m=Math.max(0,Math.min(u.y2,l.y2)-Math.max(u.y,l.y));return Math.ceil(d*m)>0}function Fs(e){var r,s,o,i,a;const t=((r=e==null?void 0:e[be])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.y)<"u";return[{x:((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const Ih=[{level:0,isMaxLevel:!0,edges:[]}];function Th(e,t,n=!1){let r=-1;const s=e.reduce((i,a)=>{var u,d;const c=ze(a.zIndex);let l=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),p=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),x=Math.max(((u=f==null?void 0:f[be])==null?void 0:u.z)||0,((d=m==null?void 0:m[be])==null?void 0:d.z)||0,1e3);l=(c?a.zIndex:0)+(p?x:0)}return i[l]?i[l].push(a):i[l]=[a],r=l>r?l:r,i},{}),o=Object.entries(s).map(([i,a])=>{const c=+i;return{edges:a,level:c,isMaxLevel:c===r}});return o.length===0?Ih:o}function Oh(e,t,n){const r=ge(w.useCallback(s=>e?s.edges.filter(o=>{const i=t.get(o.source),a=t.get(o.target);return(i==null?void 0:i.width)&&(i==null?void 0:i.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Rh({sourcePos:i.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:i.width,sourceHeight:i.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Th(r,t,n)}const Lh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),Dh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Vs={[An.Arrow]:Lh,[An.ArrowClosed]:Dh};function Ph(e){const t=Ne();return w.useMemo(()=>{var s,o;return Object.prototype.hasOwnProperty.call(Vs,e)?Vs[e]:((o=(s=t.getState()).onError)==null||o.call(s,"009",ot.error009(e)),null)},[e])}const zh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:o="strokeWidth",strokeWidth:i,orient:a="auto-start-reverse"})=>{const c=Ph(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:i})):null},Hh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,o)=>([o.markerStart,o.markerEnd].forEach(i=>{if(i&&typeof i=="object"){const a=_r(i,t);r.includes(a)||(s.push({id:a,color:i.color||e,...i}),r.push(a))}}),s),[]).sort((s,o)=>s.id.localeCompare(o.id))},Bi=({defaultColor:e,rfId:t})=>{const n=ge(w.useCallback(Hh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((o,i)=>o.id!==s[i].id)));return A.createElement("defs",null,n.map(r=>A.createElement(zh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};Bi.displayName="MarkerDefinitions";var Fh=w.memo(Bi);const Vh=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Gi=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:o,onEdgeContextMenu:i,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:x,children:_,disableKeyboardA11y:g})=>{const{edgesFocusable:E,edgesUpdatable:C,elementsSelectable:b,width:$,height:j,connectionMode:v,nodeInternals:R,onError:N}=ge(Vh,ke),T=Oh(t,R,n);return $?A.createElement(A.Fragment,null,T.map(({level:P,edges:G,isMaxLevel:V})=>A.createElement("svg",{key:P,style:{zIndex:P},width:$,height:j,className:"react-flow__edges react-flow__container"},V&&A.createElement(Fh,{defaultColor:e,rfId:r}),A.createElement("g",null,G.map(y=>{const[M,S,O]=Fs(R.get(y.source)),[z,k,I]=Fs(R.get(y.target));if(!O||!I)return null;let L=y.type||"default";s[L]||(N==null||N("011",ot.error011(L)),L="default");const D=s[L]||s.default,q=v===_t.Strict?k.target:(k.target??[]).concat(k.source??[]),F=Hs(S.source,y.sourceHandle),J=Hs(q,y.targetHandle),ee=(F==null?void 0:F.position)||K.Bottom,se=(J==null?void 0:J.position)||K.Top,le=!!(y.focusable||E&&typeof y.focusable>"u"),ne=y.reconnectable||y.updatable,ce=typeof m<"u"&&(ne||C&&typeof ne>"u");if(!F||!J)return N==null||N("008",ot.error008(F,y)),null;const{sourceX:we,sourceY:ye,targetX:he,targetY:ue}=Ah(M,F,ee,z,J,se);return A.createElement(D,{key:y.id,id:y.id,className:Me([y.className,o]),type:L,data:y.data,selected:!!y.selected,animated:!!y.animated,hidden:!!y.hidden,label:y.label,labelStyle:y.labelStyle,labelShowBg:y.labelShowBg,labelBgStyle:y.labelBgStyle,labelBgPadding:y.labelBgPadding,labelBgBorderRadius:y.labelBgBorderRadius,style:y.style,source:y.source,target:y.target,sourceHandleId:y.sourceHandle,targetHandleId:y.targetHandle,markerEnd:y.markerEnd,markerStart:y.markerStart,sourceX:we,sourceY:ye,targetX:he,targetY:ue,sourcePosition:ee,targetPosition:se,elementsSelectable:b,onContextMenu:i,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:x,rfId:r,ariaLabel:y.ariaLabel,isFocusable:le,isReconnectable:ce,pathOptions:"pathOptions"in y?y.pathOptions:void 0,interactionWidth:y.interactionWidth,disableKeyboardA11y:g})})))),_):null};Gi.displayName="EdgeRenderer";var Bh=w.memo(Gi);const Gh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Yh({children:e}){const t=ge(Gh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Xh(e){const t=cn(),n=w.useRef(!1);w.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Wh={[K.Left]:K.Right,[K.Right]:K.Left,[K.Top]:K.Bottom,[K.Bottom]:K.Top},Yi=({nodeId:e,handleType:t,style:n,type:r=dt.Bezier,CustomComponent:s,connectionStatus:o})=>{var j,v,R;const{fromNode:i,handleId:a,toX:c,toY:l,connectionMode:u}=ge(w.useCallback(N=>({fromNode:N.nodeInternals.get(e),handleId:N.connectionHandleId,toX:(N.connectionPosition.x-N.transform[0])/N.transform[2],toY:(N.connectionPosition.y-N.transform[1])/N.transform[2],connectionMode:N.connectionMode}),[e]),ke),d=(j=i==null?void 0:i[be])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(u===_t.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!i||!m)return null;const f=a?m.find(N=>N.id===a):m[0],p=f?f.x+f.width/2:(i.width??0)/2,x=f?f.y+f.height/2:i.height??0,_=(((v=i.positionAbsolute)==null?void 0:v.x)??0)+p,g=(((R=i.positionAbsolute)==null?void 0:R.y)??0)+x,E=f==null?void 0:f.position,C=E?Wh[E]:null;if(!E||!C)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:i,fromHandle:f,fromX:_,fromY:g,toX:c,toY:l,fromPosition:E,toPosition:C,connectionStatus:o});let b="";const $={sourceX:_,sourceY:g,sourcePosition:E,targetX:c,targetY:l,targetPosition:C};return r===dt.Bezier?[b]=gi($):r===dt.Step?[b]=Rn({...$,borderRadius:0}):r===dt.SmoothStep?[b]=Rn($):r===dt.SimpleBezier?[b]=pi($):b=`M${_},${g} ${c},${l}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Yi.displayName="ConnectionLine";const Uh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function qh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:o,nodesConnectable:i,width:a,height:c,connectionStatus:l}=ge(Uh,ke);return!(s&&o&&a&&i)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:Me(["react-flow__connection",l])},A.createElement(Yi,{nodeId:s,handleType:o,style:t,type:n,CustomComponent:r,connectionStatus:l})))}function Bs(e,t){return w.useRef(null),Ne(),w.useMemo(()=>t(e),[e])}const Xi=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:o,onNodeClick:i,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:l,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:p,onSelectionStart:x,onSelectionEnd:_,connectionLineType:g,connectionLineStyle:E,connectionLineComponent:C,connectionLineContainerStyle:b,selectionKeyCode:$,selectionOnDrag:j,selectionMode:v,multiSelectionKeyCode:R,panActivationKeyCode:N,zoomActivationKeyCode:T,deleteKeyCode:P,onlyRenderVisibleElements:G,elementsSelectable:V,selectNodesOnDrag:y,defaultViewport:M,translateExtent:S,minZoom:O,maxZoom:z,preventScrolling:k,defaultMarkerColor:I,zoomOnScroll:L,zoomOnPinch:D,panOnScroll:q,panOnScrollSpeed:F,panOnScrollMode:J,zoomOnDoubleClick:ee,panOnDrag:se,onPaneClick:le,onPaneMouseEnter:ne,onPaneMouseMove:ce,onPaneMouseLeave:we,onPaneScroll:ye,onPaneContextMenu:he,onEdgeContextMenu:ue,onEdgeMouseEnter:me,onEdgeMouseMove:Se,onEdgeMouseLeave:ie,onReconnect:Z,onReconnectStart:xe,onReconnectEnd:je,reconnectRadius:Ae,noDragClassName:Le,noWheelClassName:Re,noPanClassName:Ie,elevateEdgesOnSelect:Ve,disableKeyboardA11y:H,nodeOrigin:X,nodeExtent:B,rfId:U})=>{const Y=Bs(e,Eh),W=Bs(t,$h);return Xh(o),A.createElement(vh,{onPaneClick:le,onPaneMouseEnter:ne,onPaneMouseMove:ce,onPaneMouseLeave:we,onPaneContextMenu:he,onPaneScroll:ye,deleteKeyCode:P,selectionKeyCode:$,selectionOnDrag:j,selectionMode:v,onSelectionStart:x,onSelectionEnd:_,multiSelectionKeyCode:R,panActivationKeyCode:N,zoomActivationKeyCode:T,elementsSelectable:V,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:L,zoomOnPinch:D,zoomOnDoubleClick:ee,panOnScroll:q,panOnScrollSpeed:F,panOnScrollMode:J,panOnDrag:se,defaultViewport:M,translateExtent:S,minZoom:O,maxZoom:z,onSelectionContextMenu:p,preventScrolling:k,noDragClassName:Le,noWheelClassName:Re,noPanClassName:Ie,disableKeyboardA11y:H},A.createElement(Yh,null,A.createElement(Bh,{edgeTypes:W,onEdgeClick:a,onEdgeDoubleClick:l,onlyRenderVisibleElements:G,onEdgeContextMenu:ue,onEdgeMouseEnter:me,onEdgeMouseMove:Se,onEdgeMouseLeave:ie,onReconnect:Z,onReconnectStart:xe,onReconnectEnd:je,reconnectRadius:Ae,defaultMarkerColor:I,noPanClassName:Ie,elevateEdgesOnSelect:!!Ve,disableKeyboardA11y:H,rfId:U},A.createElement(qh,{style:E,type:g,component:C,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(kh,{nodeTypes:Y,onNodeClick:i,onNodeDoubleClick:c,onNodeMouseEnter:u,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:y,onlyRenderVisibleElements:G,noPanClassName:Ie,noDragClassName:Le,disableKeyboardA11y:H,nodeOrigin:X,nodeExtent:B,rfId:U})))};Xi.displayName="GraphView";var Kh=w.memo(Xi);const kr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],at={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:kr,nodeExtent:kr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:_t.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:_f,isValidConnection:void 0},Zh=()=>Lc((e,t)=>({...at,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:o}=t();e({nodeInternals:Jn(n,r,s,o)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",o=typeof r<"u",i=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:i,edges:o?r:[],hasDefaultNodes:s,hasDefaultEdges:o})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:o,fitViewOnInitDone:i,fitViewOnInitOptions:a,domNode:c,nodeOrigin:l}=t(),u=c==null?void 0:c.querySelector(".react-flow__viewport");if(!u)return;const d=window.getComputedStyle(u),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((x,_)=>{const g=s.get(_.id);if(g!=null&&g.hidden)s.set(g.id,{...g,[be]:{...g[be],handleBounds:void 0}});else if(g){const E=Lr(_.nodeElement);!!(E.width&&E.height&&(g.width!==E.width||g.height!==E.height||_.forceUpdate))&&(s.set(g.id,{...g,[be]:{...g[be],handleBounds:{source:Ls(".source",_.nodeElement,m,l),target:Ls(".target",_.nodeElement,m,l)}},...E}),x.push({id:g.id,type:"dimensions",dimensions:E}))}return x},[]);Ti(s,l);const p=i||o&&!i&&Oi(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:p}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:o}=t(),i=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});o(i)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:o,nodeOrigin:i,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(o){const l=fh(n,a()),u=Jn(l,s,i,c);e({nodeInternals:u})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:o}=t();let i,a=null;r?i=n.map(c=>ut(c,!0)):(i=Ct(o(),n),a=Ct(s,[])),yn({changedNodes:i,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:o}=t();let i,a=null;r?i=n.map(c=>ut(c,!0)):(i=Ct(s,n),a=Ct(o(),[])),yn({changedNodes:a,changedEdges:i,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:o}=t(),i=n||o(),a=r||s,c=i.map(u=>(u.selected=!1,ut(u.id,!1))),l=a.map(u=>ut(u.id,!1));yn({changedNodes:c,changedEdges:l,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),o=r().filter(a=>a.selected).map(a=>ut(a.id,!1)),i=n.filter(a=>a.selected).map(a=>ut(a.id,!1));yn({changedNodes:o,changedEdges:i,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Dr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:o,d3Zoom:i,d3Selection:a,translateExtent:c}=t();if(!i||!a||!n.x&&!n.y)return!1;const l=rt.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),u=[[0,0],[s,o]],d=i==null?void 0:i.constrain()(l,u,c);return i.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:at.connectionNodeId,connectionHandleId:at.connectionHandleId,connectionHandleType:at.connectionHandleType,connectionStatus:at.connectionStatus,connectionStartHandle:at.connectionStartHandle,connectionEndHandle:at.connectionEndHandle}),reset:()=>e({...at})}),Object.is),Wi=({children:e})=>{const t=w.useRef(null);return t.current||(t.current=Zh()),A.createElement(pf,{value:t.current},e)};Wi.displayName="ReactFlowProvider";const Ui=({children:e})=>w.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(Wi,null,e);Ui.displayName="ReactFlowWrapper";const Qh={input:ji,default:Nr,output:Mi,group:Br},Jh={default:In,straight:Hr,step:zr,smoothstep:Bn,simplebezier:Pr},em=[0,0],tm=[15,15],nm={x:0,y:0,zoom:1},rm={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},qi=w.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:o=Qh,edgeTypes:i=Jh,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:p,onConnectEnd:x,onClickConnectStart:_,onClickConnectEnd:g,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:b,onNodeContextMenu:$,onNodeDoubleClick:j,onNodeDragStart:v,onNodeDrag:R,onNodeDragStop:N,onNodesDelete:T,onEdgesDelete:P,onSelectionChange:G,onSelectionDragStart:V,onSelectionDrag:y,onSelectionDragStop:M,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:z,connectionMode:k=_t.Strict,connectionLineType:I=dt.Bezier,connectionLineStyle:L,connectionLineComponent:D,connectionLineContainerStyle:q,deleteKeyCode:F="Backspace",selectionKeyCode:J="Shift",selectionOnDrag:ee=!1,selectionMode:se=tn.Full,panActivationKeyCode:le="Space",multiSelectionKeyCode:ne=$n()?"Meta":"Control",zoomActivationKeyCode:ce=$n()?"Meta":"Control",snapToGrid:we=!1,snapGrid:ye=tm,onlyRenderVisibleElements:he=!1,selectNodesOnDrag:ue=!0,nodesDraggable:me,nodesConnectable:Se,nodesFocusable:ie,nodeOrigin:Z=em,edgesFocusable:xe,edgesUpdatable:je,elementsSelectable:Ae,defaultViewport:Le=nm,minZoom:Re=.5,maxZoom:Ie=2,translateExtent:Ve=kr,preventScrolling:H=!0,nodeExtent:X,defaultMarkerColor:B="#b1b1b7",zoomOnScroll:U=!0,zoomOnPinch:Y=!0,panOnScroll:W=!1,panOnScrollSpeed:te=.5,panOnScrollMode:pe=xt.Free,zoomOnDoubleClick:Q=!0,panOnDrag:oe=!0,onPaneClick:re,onPaneMouseEnter:fe,onPaneMouseMove:Ce,onPaneMouseLeave:Te,onPaneScroll:$e,onPaneContextMenu:Ue,children:Dt,onEdgeContextMenu:Be,onEdgeDoubleClick:Pt,onEdgeMouseEnter:de,onEdgeMouseMove:Qe,onEdgeMouseLeave:zt,onEdgeUpdate:Ta,onEdgeUpdateStart:Oa,onEdgeUpdateEnd:La,onReconnect:Da,onReconnectStart:Pa,onReconnectEnd:za,reconnectRadius:Ha=10,edgeUpdaterRadius:Fa=10,onNodesChange:Va,onEdgesChange:Ba,noDragClassName:Ga="nodrag",noWheelClassName:Ya="nowheel",noPanClassName:Qr="nopan",fitView:Xa=!1,fitViewOptions:Wa,connectOnClick:Ua=!0,attributionPosition:qa,proOptions:Ka,defaultEdgeOptions:Za,elevateNodesOnSelect:Qa=!0,elevateEdgesOnSelect:Ja=!1,disableKeyboardA11y:Jr=!1,autoPanOnConnect:ec=!0,autoPanOnNodeDrag:tc=!0,connectionRadius:nc=20,isValidConnection:rc,onError:sc,style:oc,id:es,nodeDragThreshold:ic,...ac},cc)=>{const Xn=es||"1";return A.createElement("div",{...ac,style:{...oc,...rm},ref:cc,className:Me(["react-flow",s]),"data-testid":"rf__wrapper",id:es},A.createElement(Ui,null,A.createElement(Kh,{onInit:l,onMove:u,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:C,onNodeMouseLeave:b,onNodeContextMenu:$,onNodeDoubleClick:j,nodeTypes:o,edgeTypes:i,connectionLineType:I,connectionLineStyle:L,connectionLineComponent:D,connectionLineContainerStyle:q,selectionKeyCode:J,selectionOnDrag:ee,selectionMode:se,deleteKeyCode:F,multiSelectionKeyCode:ne,panActivationKeyCode:le,zoomActivationKeyCode:ce,onlyRenderVisibleElements:he,selectNodesOnDrag:ue,defaultViewport:Le,translateExtent:Ve,minZoom:Re,maxZoom:Ie,preventScrolling:H,zoomOnScroll:U,zoomOnPinch:Y,zoomOnDoubleClick:Q,panOnScroll:W,panOnScrollSpeed:te,panOnScrollMode:pe,panOnDrag:oe,onPaneClick:re,onPaneMouseEnter:fe,onPaneMouseMove:Ce,onPaneMouseLeave:Te,onPaneScroll:$e,onPaneContextMenu:Ue,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:z,onEdgeContextMenu:Be,onEdgeDoubleClick:Pt,onEdgeMouseEnter:de,onEdgeMouseMove:Qe,onEdgeMouseLeave:zt,onReconnect:Da??Ta,onReconnectStart:Pa??Oa,onReconnectEnd:za??La,reconnectRadius:Ha??Fa,defaultMarkerColor:B,noDragClassName:Ga,noWheelClassName:Ya,noPanClassName:Qr,elevateEdgesOnSelect:Ja,rfId:Xn,disableKeyboardA11y:Jr,nodeOrigin:Z,nodeExtent:X}),A.createElement(Xf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:p,onConnectEnd:x,onClickConnectStart:_,onClickConnectEnd:g,nodesDraggable:me,nodesConnectable:Se,nodesFocusable:ie,edgesFocusable:xe,edgesUpdatable:je,elementsSelectable:Ae,elevateNodesOnSelect:Qa,minZoom:Re,maxZoom:Ie,nodeExtent:X,onNodesChange:Va,onEdgesChange:Ba,snapToGrid:we,snapGrid:ye,connectionMode:k,translateExtent:Ve,connectOnClick:Ua,defaultEdgeOptions:Za,fitView:Xa,fitViewOptions:Wa,onNodesDelete:T,onEdgesDelete:P,onNodeDragStart:v,onNodeDrag:R,onNodeDragStop:N,onSelectionDrag:y,onSelectionDragStart:V,onSelectionDragStop:M,noPanClassName:Qr,nodeOrigin:Z,rfId:Xn,autoPanOnConnect:ec,autoPanOnNodeDrag:tc,onError:sc,connectionRadius:nc,isValidConnection:rc,nodeDragThreshold:ic}),A.createElement(Gf,{onSelectionChange:G}),Dt,A.createElement(yf,{proOptions:Ka,position:qa}),A.createElement(Zf,{rfId:Xn,disableKeyboardA11y:Jr})))});qi.displayName="ReactFlow";const Ki=({id:e,x:t,y:n,width:r,height:s,style:o,color:i,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,onClick:m,selected:f})=>{const{background:p,backgroundColor:x}=o||{},_=i||p||x;return A.createElement("rect",{className:Me(["react-flow__minimap-node",{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:s,fill:_,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?g=>m(g,e):void 0})};Ki.displayName="MiniMapNode";var sm=w.memo(Ki);const om=e=>e.nodeOrigin,im=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function am({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:o=sm,onClick:i}){const a=ge(im,ke),c=ge(om),l=rr(t),u=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:p,y:x}=bt(f,c).positionAbsolute;return A.createElement(o,{key:f.id,x:p,y:x,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:l(f),borderRadius:r,strokeColor:u(f),strokeWidth:s,shapeRendering:m,onClick:i,id:f.id})}))}var cm=w.memo(am);const lm=200,um=150,dm=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?bf(an(t,e.nodeOrigin),n):n,rfId:e.rfId}},fm="react-flow__minimap-desc";function Zi({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:o=5,nodeStrokeWidth:i=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:l="none",maskStrokeWidth:u=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:p=!1,zoomable:x=!1,ariaLabel:_="React Flow mini map",inversePan:g=!1,zoomStep:E=10,offsetScale:C=5}){const b=Ne(),$=w.useRef(null),{boundingRect:j,viewBB:v,rfId:R}=ge(dm,ke),N=(e==null?void 0:e.width)??lm,T=(e==null?void 0:e.height)??um,P=j.width/N,G=j.height/T,V=Math.max(P,G),y=V*N,M=V*T,S=C*V,O=j.x-(y-j.width)/2-S,z=j.y-(M-j.height)/2-S,k=y+S*2,I=M+S*2,L=`${fm}-${R}`,D=w.useRef(0);D.current=V,w.useEffect(()=>{if($.current){const J=Pe($.current),ee=ne=>{const{transform:ce,d3Selection:we,d3Zoom:ye}=b.getState();if(ne.sourceEvent.type!=="wheel"||!we||!ye)return;const he=-ne.sourceEvent.deltaY*(ne.sourceEvent.deltaMode===1?.05:ne.sourceEvent.deltaMode?1:.002)*E,ue=ce[2]*Math.pow(2,he);ye.scaleTo(we,ue)},se=ne=>{const{transform:ce,d3Selection:we,d3Zoom:ye,translateExtent:he,width:ue,height:me}=b.getState();if(ne.sourceEvent.type!=="mousemove"||!we||!ye)return;const Se=D.current*Math.max(1,ce[2])*(g?-1:1),ie={x:ce[0]-ne.sourceEvent.movementX*Se,y:ce[1]-ne.sourceEvent.movementY*Se},Z=[[0,0],[ue,me]],xe=rt.translate(ie.x,ie.y).scale(ce[2]),je=ye.constrain()(xe,Z,he);ye.transform(we,je)},le=oi().on("zoom",p?se:null).on("zoom.wheel",x?ee:null);return J.call(le),()=>{J.on("zoom",null)}}},[p,x,g,E]);const q=m?J=>{const ee=Ge(J);m(J,{x:ee[0],y:ee[1]})}:void 0,F=f?(J,ee)=>{const se=b.getState().nodeInternals.get(ee);f(J,se)}:void 0;return A.createElement(Or,{position:d,style:e,className:Me(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:N,height:T,viewBox:`${O} ${z} ${k} ${I}`,role:"img","aria-labelledby":L,ref:$,onClick:q},_&&A.createElement("title",{id:L},_),A.createElement(cm,{onClick:F,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:o,nodeClassName:s,nodeStrokeWidth:i,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${O-S},${z-S}h${k+S*2}v${I+S*2}h${-k-S*2}z - M${v.x},${v.y}h${v.width}v${v.height}h${-v.width}z`,fill:c,fillRule:"evenodd",stroke:l,strokeWidth:u,pointerEvents:"none"})))}Zi.displayName="MiniMap";var hm=w.memo(Zi);function mm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function pm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function gm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function ym(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function xm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Wt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:Me(["react-flow__controls-button",t]),...n},e);Wt.displayName="ControlButton";const wm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Qi=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:o,onZoomOut:i,onFitView:a,onInteractiveChange:c,className:l,children:u,position:d="bottom-left"})=>{const m=Ne(),[f,p]=w.useState(!1),{isInteractive:x,minZoomReached:_,maxZoomReached:g}=ge(wm,ke),{zoomIn:E,zoomOut:C,fitView:b}=cn();if(w.useEffect(()=>{p(!0)},[]),!f)return null;const $=()=>{E(),o==null||o()},j=()=>{C(),i==null||i()},v=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!x,nodesConnectable:!x,elementsSelectable:!x}),c==null||c(!x)};return A.createElement(Or,{className:Me(["react-flow__controls",l]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Wt,{onClick:$,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:g},A.createElement(mm,null)),A.createElement(Wt,{onClick:j,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:_},A.createElement(pm,null))),n&&A.createElement(Wt,{className:"react-flow__controls-fitview",onClick:v,title:"fit view","aria-label":"fit view"},A.createElement(gm,null)),r&&A.createElement(Wt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},x?A.createElement(xm,null):A.createElement(ym,null)),u)};Qi.displayName="Controls";var bm=w.memo(Qi),He;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(He||(He={}));function vm({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function _m({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const Em={[He.Dots]:"#91919a",[He.Lines]:"#eee",[He.Cross]:"#e2e2e2"},Nm={[He.Dots]:1,[He.Lines]:1,[He.Cross]:6},Sm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Ji({id:e,variant:t=He.Dots,gap:n=20,size:r,lineWidth:s=1,offset:o=2,color:i,style:a,className:c}){const l=w.useRef(null),{transform:u,patternId:d}=ge(Sm,ke),m=i||Em[t],f=r||Nm[t],p=t===He.Dots,x=t===He.Cross,_=Array.isArray(n)?n:[n,n],g=[_[0]*u[2]||1,_[1]*u[2]||1],E=f*u[2],C=x?[E,E]:g,b=p?[E/o,E/o]:[C[0]/o,C[1]/o];return A.createElement("svg",{className:Me(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:l,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:u[0]%g[0],y:u[1]%g[1],width:g[0],height:g[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},p?A.createElement(_m,{color:m,radius:E/o}):A.createElement(vm,{dimensions:C,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}Ji.displayName="Background";var km=w.memo(Ji);const Yr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Yr+e}async function ve(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function it(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new ea(r.error??`${e}: ${n.status}`,n.status);return r}class ea extends Error{constructor(n,r){super(n);_e(this,"status");this.status=r}}const Dx=e=>ve(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),Px=()=>ve("/api/diagnostics"),ta=(e,t)=>ve(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),na=()=>ve("/api/ontology/ontologies"),jm=e=>ve(`/api/ontology/term?ref=${encodeURIComponent(e)}`),Cm=()=>ve("/api/ontology/stack"),Mm=()=>ve("/api/ontology/coverage"),$m=(e,t,n)=>it("/api/command",{op:e,payload:t,fingerprint:n??""}),Am=()=>ve("/api/git/status"),Rm=()=>ve("/api/git/diff"),Im=e=>it("/api/git/commit",{message:e}),Tm=()=>it("/api/git/discard",{}),Om=()=>ve("/api/decisions"),Gs=(e,t)=>it(`/api/decisions/${e}/verdict`,{verdict:t}),zx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),ve(`/api/glossary/terms?${t.toString()}`)},Hx=()=>ve("/api/glossary/config"),Fx=e=>it("/api/git/propose",e),Vx=(e="HEAD")=>ve(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Bx=(e="HEAD")=>ve(`/api/git/classify?base=${encodeURIComponent(e)}`),Gx=e=>it("/api/git/classify",{changes:e}),Yx=e=>ve(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Xx=(e="")=>ve(`/api/git/context?user=${encodeURIComponent(e)}`),Wx=(e="")=>ve(`/api/git/proposals?user=${encodeURIComponent(e)}`),Lm=()=>ve("/api/export"),Dm=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Yr}/api/export/${encodeURIComponent(e)}${n}`},Pm=(e,t,n)=>it("/api/import",{format:e,content:t,dialect:n}),zm=(e,t)=>it("/api/import/preview",{format:e,content:t}),Ux=e=>ve(`/api/import/stash/${encodeURIComponent(e)}`),qx=async(e,t=!1)=>{for(const n of e)try{await $m(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Kx=(e,t,n)=>fetch(`${Yr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new ea(await r.text(),r.status);return await r.json()}),Zx=()=>ve("/api/glossary/subject-areas"),Qx=e=>ve(`/api/glossary/subject-area/${e}`),Jx=(e,t)=>it(`/api/glossary/subject-area/${e}/expand`,t);function ew(){return{async load(e){try{const t=await ve(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Hm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Fm(e){return e??""}const Xr="__entity_source",Wr="__entity_target",Vm=w.memo(function({data:t,selected:n}){var j;const{entity:r,color:s,dimmed:o,highlighted:i,showTypes:a,collapseDetail:c,expanded:l,onToggleExpand:u,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:p}=t,x=v=>v.role==="business_key"?0:d!=null&&d.has(v.id)?1:2,_=[...r.attributes].map((v,R)=>({a:v,i:R})).sort((v,R)=>x(v.a)-x(R.a)||v.i-R.i).map(v=>v.a),g=_.filter(v=>v.role==="business_key");let E=_.filter(v=>v.role!=="business_key");const C=!!c&&!l;let b=0;if(C){const v=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-v.length,E=v}const $=(v,R)=>{const N="attr-row"+(m!=null&&m.has(v.id)?" rel-hit":"")+(f!=null&&f.has(v.id)?" rel-dim":"")+(d!=null&&d.has(v.id)?" endpoint":"");return h.jsxs("div",{className:N,onMouseEnter:p?()=>p(v.id):void 0,onMouseLeave:p?()=>p(null):void 0,children:[h.jsx(ft,{id:v.id,type:"target",position:K.Left,className:"port attr-port"}),h.jsx(ft,{id:v.id,type:"source",position:K.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Hm[v.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:v.name}),a&&h.jsx("span",{className:"attr-type",children:Fm(v.domain)}),!v.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},v.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(o?" dimmed":"")+(i?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(ft,{id:Wr,type:"target",position:K.Left,className:"port"}),h.jsx(ft,{id:Xr,type:"source",position:K.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((j=r.conceptual)==null?void 0:j.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var N;const v=(((N=r.conceptual)==null?void 0:N.ontology_refs)??[]).filter(T=>T.uri);if(v.length===0)return null;const R=v.map(T=>T.uri).join(` -`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",v.length>1?` ${v.length}`:""]})})()]})]}),g.length>0&&h.jsx("div",{className:"attr-section keys",children:g.map(v=>$(v,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(v=>$(v,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:u?()=>u(r.id):void 0,children:`+${b} more`}),l&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:u?()=>u(r.id):void 0,children:"− collapse"})]})]})}),Bm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Gm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:o,onAlign:i,onEditMapping:a}){var m,f,p,x,_,g,E,C,b,$,j,v,R;const c=!n.canEdit,l=e.conceptual,u=t.relationships.filter(N=>N.from.entity===e.id||N.to.entity===e.id),d=N=>{var T;return((T=t.entities.find(P=>P.id===N))==null?void 0:T.name)??N};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(et,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,name:N})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(et,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,physical_name:N})})]}),h.jsxs("div",{children:[h.jsx(Xm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Um,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(et,{value:((m=l==null?void 0:l.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:N=>r("set_definition",{id:e.id,definition:N})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>i(e),children:(((f=l==null?void 0:l.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((p=l==null?void 0:l.ontology_refs)==null?void 0:p.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(l==null?void 0:l.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${l.ontology_layer}`,children:l.ontology_layer}),l.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Ym,{entityId:e.id,refs:(l==null?void 0:l.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(x=e.term_map)!=null&&x.subject_template||(_=e.term_map)!=null&&_.class_iri?"Edit mapping…":"Map…"}),(((g=e.term_map)==null?void 0:g.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),(C=e.term_map)!=null&&C.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[(($=e.term_map)==null?void 0:$.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(et,{value:((v=l==null?void 0:l.stewardship)==null?void 0:v.owner)??"",placeholder:"—",readOnly:c,onCommit:N=>{var T;return r("set_stewardship",{id:e.id,owner:N,steward:((T=l==null?void 0:l.stewardship)==null?void 0:T.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(et,{value:((R=l==null?void 0:l.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:N=>{var T;return r("set_stewardship",{id:e.id,owner:((T=l==null?void 0:l.stewardship)==null?void 0:T.owner)??null,steward:N})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(N=>h.jsx(Km,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(Zm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(N=>{const T=N.members.map(P=>{var G;return((G=e.attributes.find(V=>V.id===P))==null?void 0:G.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+N.type,children:N.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:N.name}),h.jsx("span",{className:"key-cols",children:T})]},N.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([N,T])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:N}),h.jsx("td",{className:"udp-val",children:String(T)})]},N))})})]}),u.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",u.length,")"]}),u.map(N=>{const T=N.from.entity===e.id?N.to.entity:N.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>o(T),children:[h.jsx("span",{className:"rel-card",children:Qm(N,e.id)}),d(T)]}),(N.verb_phrase||N.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(et,{value:N.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,verb_phrase:P})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(et,{value:N.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:P=>r("update_relationship",{id:N.id,inverse_verb_phrase:P})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${N.name}`,onClick:()=>r("delete_relationship",{id:N.id}),children:"✕"})]},N.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var N;return(N=navigator.clipboard)==null?void 0:N.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Ym({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,o=t.filter(i=>i.uri);return o.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:o.map((i,a)=>{const c=i.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:i.uri??void 0,children:i.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[i.predicate&&h.jsx("span",{className:"ref-pill",children:i.predicate}),i.layer&&h.jsx("span",{className:`chip layer-${i.layer}`,children:i.layer}),i.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",i.resolved_via]}),typeof i.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(i.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:i.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:i.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${i.uri}-${a}`)})})}function et({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:o=""}){const[i,a]=w.useState(e);w.useEffect(()=>a(e),[e]);const c=()=>{i.trim()!==e.trim()&&t(i.trim())};return n?h.jsx("span",{className:o,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${o}`,value:i,placeholder:s,rows:3,onChange:l=>a(l.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${o}`,value:i,placeholder:s,onChange:l=>a(l.target.value),onBlur:c,onKeyDown:l=>l.key==="Enter"&&l.target.blur()})}function Xm({entity:e,doc:t,readOnly:n,exec:r}){var o,i,a;const s=((i=(o=e.conceptual)==null?void 0:o.subject_area)==null?void 0:i.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const Wm=["","scd2","hub","link","satellite","bridge"];function Um({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:Wm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const qm=["attribute","business_key","measure","surrogate_key"];function Km({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const o=i=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...i});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(et,{value:e.name,readOnly:!1,onCommit:i=>o({name:i})}),(e.physical_name||!1)&&h.jsx(et,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:i=>o({physical_name:i})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:i=>o({domain:i.target.value}),children:[...new Set([...Bm,...n.domains??[],e.domain??"string"])].sort().map(i=>h.jsx("option",{value:i,children:i},i))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:i=>o({role:i.target.value}),title:"role",children:qm.map(i=>h.jsx("option",{value:i,children:i==="business_key"?"🔑 key":i==="measure"?"Σ measure":i},i))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:i=>o({nullable:!i.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Zm({entity:e,exec:t}){const[n,r]=w.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:o=>r(o.target.value),onKeyDown:o=>o.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function Qm(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var Jm="\0",pt="\0",Ys="";let ep=class{constructor(t){_e(this,"_isDirected",!0);_e(this,"_isMultigraph",!1);_e(this,"_isCompound",!1);_e(this,"_label");_e(this,"_defaultNodeLabelFn",()=>{});_e(this,"_defaultEdgeLabelFn",()=>{});_e(this,"_nodes",{});_e(this,"_in",{});_e(this,"_preds",{});_e(this,"_out",{});_e(this,"_sucs",{});_e(this,"_edgeObjs",{});_e(this,"_edgeLabels",{});_e(this,"_nodeCount",0);_e(this,"_edgeCount",0);_e(this,"_parent");_e(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[pt]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(o){r.length>1?s.setNode(o,n):s.setNode(o)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=pt,this._children[t]={},this._children[pt][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=pt;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==pt)return n}}children(t=pt){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===pt)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([i,a]){t(i)&&n.setNode(i,a)}),Object.values(this._edgeObjs).forEach(function(i){n.hasNode(i.v)&&n.hasNode(i.w)&&n.setEdge(i,r.edge(i))});var s={};function o(i){var a=r.parent(i);return a===void 0||n.hasNode(a)?(s[i]=a,a):a in s?s[a]:o(a)}return this._isCompound&&n.nodes().forEach(i=>n.setParent(i,o(i))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(o,i){return s.length>1?r.setEdge(o,i,n):r.setEdge(o,i),i}),this}setEdge(){var t,n,r,s,o=!1,i=arguments[0];typeof i=="object"&&i!==null&&"v"in i?(t=i.v,n=i.w,r=i.name,arguments.length===2&&(s=arguments[1],o=!0)):(t=i,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],o=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Ut(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return o&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=o?s:this._defaultEdgeLabelFn(t,n,r);var c=tp(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Xs(this._preds[n],t),Xs(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r),o=this._edgeObjs[s];return o&&(t=o.v,n=o.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Ws(this._preds[n],t),Ws(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(o=>o.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(o=>o.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Xs(e,t){e[t]?e[t]++:e[t]=1}function Ws(e,t){--e[t]||delete e[t]}function Ut(e,t,n,r){var s=""+t,o=""+n;if(!e&&s>o){var i=s;s=o,o=i}return s+Ys+o+Ys+(r===void 0?Jm:r)}function tp(e,t,n,r){var s=""+t,o=""+n;if(!e&&s>o){var i=s;s=o,o=i}var a={v:s,w:o};return r&&(a.name=r),a}function sr(e,t){return Ut(e,t.v,t.w,t.name)}var Ur=ep,np="2.2.4",rp={Graph:Ur,version:np},sp=Ur,op={write:ip,read:lp};function ip(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:ap(e),edges:cp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function ap(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function cp(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function lp(e){var t=new sp(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var up=dp;function dp(e){var t={},n=[],r;function s(o){Object.hasOwn(t,o)||(t[o]=!0,r.push(o),e.successors(o).forEach(s),e.predecessors(o).forEach(s))}return e.nodes().forEach(function(o){r=[],s(o),r.length&&n.push(r)}),n}let fp=class{constructor(){_e(this,"_arr",[]);_e(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,o=s.length;return r[t]=o,s.push({key:t,priority:n}),this._decrease(o),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,o=t;r>1,!(n[s].priority1;function pp(e,t,n,r){return gp(e,String(t),n||mp,r||function(s){return e.outEdges(s)})}function gp(e,t,n,r){var s={},o=new hp,i,a,c=function(l){var u=l.v!==i?l.v:l.w,d=s[u],m=n(l),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+m);f0&&(i=o.removeMin(),a=s[i],a.distance!==Number.POSITIVE_INFINITY);)r(i).forEach(c);return s}var yp=sa,xp=wp;function wp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=yp(e,s,t,n),r},{})}var oa=bp;function bp(e){var t=0,n=[],r={},s=[];function o(i){var a=r[i]={onStack:!0,lowlink:t,index:t++};if(n.push(i),e.successors(i).forEach(function(u){Object.hasOwn(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(o(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var c=[],l;do l=n.pop(),r[l].onStack=!1,c.push(l);while(i!==l);s.push(c)}}return e.nodes().forEach(function(i){Object.hasOwn(r,i)||o(i)}),s}var vp=oa,_p=Ep;function Ep(e){return vp(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var Np=kp,Sp=()=>1;function kp(e,t,n){return jp(e,t||Sp,n||function(r){return e.outEdges(r)})}function jp(e,t,n){var r={},s=e.nodes();return s.forEach(function(o){r[o]={},r[o][o]={distance:0},s.forEach(function(i){o!==i&&(r[o][i]={distance:Number.POSITIVE_INFINITY})}),n(o).forEach(function(i){var a=i.v===o?i.w:i.v,c=t(i);r[o][a]={distance:c,predecessor:o}})}),s.forEach(function(o){var i=r[o];s.forEach(function(a){var c=r[a];s.forEach(function(l){var u=c[o],d=i[l],m=c[l],f=u.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?Ap:Rp,o=[],i={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,i,o)}),o}function Ap(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var o=s.pop();o[1]?r.push(o[0]):Object.hasOwn(n,o[0])||(n[o[0]]=!0,s.push([o[0],!0]),la(t(o[0]),i=>s.push([i,!1])))}}function Rp(e,t,n,r){for(var s=[e];s.length>0;){var o=s.pop();Object.hasOwn(n,o)||(n[o]=!0,r.push(o),la(t(o),i=>s.push(i)))}}function la(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var Ip=ca,Tp=Op;function Op(e,t){return Ip(e,t,"post")}var Lp=ca,Dp=Pp;function Pp(e,t){return Lp(e,t,"pre")}var zp=Ur,Hp=ra,Fp=Vp;function Vp(e,t){var n=new zp,r={},s=new Hp,o;function i(c){var l=c.v===o?c.w:c.v,u=s.priority(l);if(u!==void 0){var d=t(c);d0;){if(o=s.removeMin(),Object.hasOwn(r,o))n.setEdge(o,r[o]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(o).forEach(i)}return n}var Bp={components:up,dijkstra:sa,dijkstraAll:xp,findCycles:_p,floydWarshall:Np,isAcyclic:Cp,postorder:Tp,preorder:Dp,prim:Fp,tarjan:oa,topsort:aa},qs=rp,We={Graph:qs.Graph,json:op,alg:Bp,version:qs.version};let Gp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Ks(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Ks(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Yp)),r=r._prev;return"["+t.join(", ")+"]"}};function Ks(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Yp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Xp=Gp;let Wp=We.Graph,Up=Xp;var qp=Zp;let Kp=()=>1;function Zp(e,t){if(e.nodeCount()<=1)return[];let n=Jp(e,t||Kp);return Qp(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function Qp(e,t,n){let r=[],s=t[t.length-1],o=t[0],i;for(;e.nodeCount();){for(;i=o.dequeue();)or(e,t,n,i);for(;i=s.dequeue();)or(e,t,n,i);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(i=t[a].dequeue(),i){r=r.concat(or(e,t,n,i,!0));break}}}return r}function or(e,t,n,r,s){let o=s?[]:void 0;return e.inEdges(r.v).forEach(i=>{let a=e.edge(i),c=e.node(i.v);s&&o.push({v:i.v,w:i.w}),c.out-=a,Cr(t,n,c)}),e.outEdges(r.v).forEach(i=>{let a=e.edge(i),c=i.w,l=e.node(c);l.in-=a,Cr(t,n,l)}),e.removeNode(r.v),o}function Jp(e,t){let n=new Wp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,l=t(a),u=c+l;n.setEdge(a.v,a.w,u),s=Math.max(s,n.node(a.v).out+=l),r=Math.max(r,n.node(a.w).in+=l)});let o=eg(s+r+3).map(()=>new Up),i=r+1;return n.nodes().forEach(a=>{Cr(o,i,n.node(a))}),{graph:n,buckets:o,zeroIdx:i}}function Cr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function eg(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function ng(e){let t=new ua({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function rg(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return qr(e.nodes(),t)}function sg(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return qr(e.nodes(),t)}function og(e,t){let n=e.x,r=e.y,s=t.x-n,o=t.y-r,i=e.width/2,a=e.height/2;if(!s&&!o)throw new Error("Not possible to find intersection inside of the rectangle");let c,l;return Math.abs(o)*i>Math.abs(s)*a?(o<0&&(a=-a),c=a*s/o,l=a):(s<0&&(i=-i),c=i,l=i*o/s),{x:n+c,y:r+l}}function ig(e){let t=pa(ha(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function ag(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function cg(e){let t=e.nodes().map(i=>e.node(i).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(i=>{let a=e.node(i).rank-n;r[a]||(r[a]=[]),r[a].push(i)});let s=0,o=e.graph().nodeRankFactor;Array.from(r).forEach((i,a)=>{i===void 0&&a%o!==0?--s:i!==void 0&&s&&i.forEach(c=>e.node(c).rank+=s)})}function lg(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),da(e,"border",s,t)}function ug(e,t=fa){const n=[];for(let r=0;rfa){const n=ug(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function ha(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function dg(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function fg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function hg(e,t){return t()}let mg=0;function ma(e){var t=++mg;return e+(""+t)}function pa(e,t,n=1){t==null&&(t=e,e=0);let r=o=>otr[t]),Object.entries(e).reduce((r,[s,o])=>(r[s]=n(o,s),r),{})}function qr(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let yg=qp,xg=Ee.uniqueId;var wg={run:bg,undo:_g};function bg(e){(e.graph().acyclicer==="greedy"?yg(e,n(e)):vg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,xg("rev"))});function n(r){return s=>r.edge(s).weight}}function vg(e){let t=[],n={},r={};function s(o){Object.hasOwn(r,o)||(r[o]=!0,n[o]=!0,e.outEdges(o).forEach(i=>{Object.hasOwn(n,i.w)?t.push(i):s(i.w)}),delete n[o])}return e.nodes().forEach(s),t}function _g(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let Eg=Ee;var Ng={run:Sg,undo:jg};function Sg(e){e.graph().dummyChains=[],e.edges().forEach(t=>kg(e,t))}function kg(e,t){let n=t.v,r=e.node(n).rank,s=t.w,o=e.node(s).rank,i=t.name,a=e.edge(t),c=a.labelRank;if(o===r+1)return;e.removeEdge(t);let l,u,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:Cg}=Ee;var Yn={longestPath:Mg,slack:$g};function Mg(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let o=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var i=Cg(Math.min,o);return i===Number.POSITIVE_INFINITY&&(i=0),s.rank=i}e.sources().forEach(n)}function $g(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var Ag=We.Graph,On=Yn.slack,ga=Rg;function Rg(e){var t=new Ag({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,o;Ig(t,e){var o=s.v,i=r===o?s.w:o;!e.hasNode(i)&&!On(t,s)&&(e.setNode(i,{}),e.setEdge(r,i,{}),n(i))})}return e.nodes().forEach(n),e.nodeCount()}function Tg(e,t){return t.edges().reduce((r,s)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(o=On(t,s)),ot.node(r).rank+=n)}var Lg=ga,Zs=Yn.slack,Dg=Yn.longestPath,Pg=We.alg.preorder,zg=We.alg.postorder,Hg=Ee.simplify,Fg=Et;Et.initLowLimValues=Zr;Et.initCutValues=Kr;Et.calcCutValue=ya;Et.leaveEdge=wa;Et.enterEdge=ba;Et.exchangeEdges=va;function Et(e){e=Hg(e),Dg(e);var t=Lg(e);Zr(t),Kr(t,e);for(var n,r;n=wa(t);)r=ba(t,e,n),va(t,e,n,r)}function Kr(e,t){var n=zg(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Vg(e,t,r))}function Vg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=ya(e,t,n)}function ya(e,t,n){var r=e.node(n),s=r.parent,o=!0,i=t.edge(n,s),a=0;return i||(o=!1,i=t.edge(s,n)),a=i.weight,t.nodeEdges(n).forEach(c=>{var l=c.v===n,u=l?c.w:c.v;if(u!==s){var d=l===o,m=t.edge(c).weight;if(a+=d?m:-m,Gg(e,n,u)){var f=e.edge(n,u).cutvalue;a+=d?-f:f}}}),a}function Zr(e,t){arguments.length<2&&(t=e.nodes()[0]),xa(e,{},1,t)}function xa(e,t,n,r,s){var o=n,i=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=xa(e,t,n,a,r))}),i.low=o,i.lim=n++,s?i.parent=s:delete i.parent,n}function wa(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ba(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var o=e.node(r),i=e.node(s),a=o,c=!1;o.lim>i.lim&&(a=i,c=!0);var l=t.edges().filter(u=>c===Qs(e,e.node(u.v),a)&&c!==Qs(e,e.node(u.w),a));return l.reduce((u,d)=>Zs(t,d)!t.node(s).parent),r=Pg(e,n);r=r.slice(1),r.forEach(s=>{var o=e.node(s).parent,i=t.edge(s,o),a=!1;i||(i=t.edge(o,s),a=!0),t.node(s).rank=t.node(o).rank+(a?i.minlen:-i.minlen)})}function Gg(e,t,n){return e.hasEdge(t,n)}function Qs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Yg=Yn,_a=Yg.longestPath,Xg=ga,Wg=Fg,Ug=qg;function qg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Js(e);break;case"tight-tree":Zg(e);break;case"longest-path":Kg(e);break;case"none":break;default:Js(e)}}var Kg=_a;function Zg(e){_a(e),Xg(e)}function Js(e){Wg(e)}var Qg=Jg;function Jg(e){let t=ty(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,o=ey(e,t,s.v,s.w),i=o.path,a=o.lca,c=0,l=i[c],u=!0;for(;n!==s.w;){if(r=e.node(n),u){for(;(l=i[c])!==a&&e.node(l).maxRanki||a>t[c].lim));for(l=c,c=r;(c=e.parent(c))!==l;)o.push(c);return{path:s.concat(o.reverse()),lca:l}}function ty(e){let t={},n=0;function r(s){let o=n;e.children(s).forEach(r),t[s]={low:o,lim:n++}}return e.children().forEach(r),t}let Ln=Ee;var ny={run:ry,cleanup:iy};function ry(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=sy(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,o=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=o);let i=oy(e)+1;e.children().forEach(a=>Ea(e,t,o,i,s,n,a)),e.graph().nodeRankFactor=o}function Ea(e,t,n,r,s,o,i){let a=e.children(i);if(!a.length){i!==t&&e.setEdge(t,i,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),l=Ln.addBorderNode(e,"_bb"),u=e.node(i);e.setParent(c,i),u.borderTop=c,e.setParent(l,i),u.borderBottom=l,a.forEach(d=>{Ea(e,t,n,r,s,o,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,p=m.borderBottom?m.borderBottom:d,x=m.borderTop?r:2*r,_=f!==p?1:s-o[i]+1;e.setEdge(c,f,{weight:x,minlen:_,nestingEdge:!0}),e.setEdge(p,l,{weight:x,minlen:_,nestingEdge:!0})}),e.parent(i)||e.setEdge(t,c,{weight:0,minlen:s+o[i]})}function sy(e){var t={};function n(r,s){var o=e.children(r);o&&o.length&&o.forEach(i=>n(i,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function oy(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function iy(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let ay=Ee;var cy=ly;function ly(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let o=s.minRank,i=s.maxRank+1;oto(e.node(t))),e.edges().forEach(t=>to(e.edge(t)))}function to(e){let t=e.width;e.width=e.height,e.height=t}function hy(e){e.nodes().forEach(t=>ir(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ir),Object.hasOwn(n,"y")&&ir(n)})}function ir(e){e.y=-e.y}function my(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let no=Ee;var py=gy;function gy(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=no.applyWithChunking(Math.max,r),o=no.range(s+1).map(()=>[]);function i(c){if(t[c])return;t[c]=!0;let l=e.node(c);o[l.rank].push(c),e.successors(c).forEach(i)}return n.sort((c,l)=>e.node(c).rank-e.node(l).rank).forEach(i),o}let yy=Ee.zipObject;var xy=wy;function wy(e,t){let n=0;for(let r=1;ru)),s=t.flatMap(l=>e.outEdges(l).map(u=>({pos:r[u.w],weight:e.edge(u).weight})).sort((u,d)=>u.pos-d.pos)),o=1;for(;o{let u=l.pos+o;a[u]+=l.weight;let d=0;for(;u>0;)u%2&&(d+=a[u+1]),u=u-1>>1,a[u]+=l.weight;c+=l.weight*d}),c}var vy=_y;function _y(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((o,i)=>{let a=e.edge(i),c=e.node(i.v);return{sum:o.sum+a.weight*c.order,weight:o.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let Ey=Ee;var Ny=Sy;function Sy(e,t){let n={};e.forEach((s,o)=>{let i=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i:o};s.barycenter!==void 0&&(i.barycenter=s.barycenter,i.weight=s.weight)}),t.edges().forEach(s=>{let o=n[s.v],i=n[s.w];o!==void 0&&i!==void 0&&(i.indegree++,o.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return ky(r)}function ky(e){let t=[];function n(s){return o=>{o.merged||(o.barycenter===void 0||s.barycenter===void 0||o.barycenter>=s.barycenter)&&jy(s,o)}}function r(s){return o=>{o.in.push(s),--o.indegree===0&&e.push(o)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>Ey.pick(s,["vs","i","barycenter","weight"]))}function jy(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let Cy=Ee;var My=$y;function $y(e,t){let n=Cy.partition(e,u=>Object.hasOwn(u,"barycenter")),r=n.lhs,s=n.rhs.sort((u,d)=>d.i-u.i),o=[],i=0,a=0,c=0;r.sort(Ay(!!t)),c=ro(o,s,c),r.forEach(u=>{c+=u.vs.length,o.push(u.vs),i+=u.barycenter*u.weight,a+=u.weight,c=ro(o,s,c)});let l={vs:o.flat(!0)};return a&&(l.barycenter=i/a,l.weight=a),l}function ro(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function Ay(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Ry=vy,Iy=Ny,Ty=My;var Oy=Sa;function Sa(e,t,n,r){let s=e.children(t),o=e.node(t),i=o?o.borderLeft:void 0,a=o?o.borderRight:void 0,c={};i&&(s=s.filter(m=>m!==i&&m!==a));let l=Ry(e,s);l.forEach(m=>{if(e.children(m.v).length){let f=Sa(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&Dy(m,f)}});let u=Iy(l,n);Ly(u,c);let d=Ty(u,r);if(i&&(d.vs=[i,d.vs,a].flat(!0),e.predecessors(i).length)){let m=e.node(e.predecessors(i)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function Ly(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function Dy(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let Py=We.Graph,zy=Ee;var Hy=Fy;function Fy(e,t,n,r){r||(r=e.nodes());let s=Vy(e),o=new Py({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(i=>e.node(i));return r.forEach(i=>{let a=e.node(i),c=e.parent(i);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(o.setNode(i),o.setParent(i,c||s),e[n](i).forEach(l=>{let u=l.v===i?l.w:l.v,d=o.edge(u,i),m=d!==void 0?d.weight:0;o.setEdge(u,i,{weight:e.edge(l).weight+m})}),Object.hasOwn(a,"minRank")&&o.setNode(i,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),o}function Vy(e){for(var t;e.hasNode(t=zy.uniqueId("_root")););return t}var By=Gy;function Gy(e,t,n){let r={},s;n.forEach(o=>{let i=e.parent(o),a,c;for(;i;){if(a=e.parent(i),a?(c=r[a],r[a]=i):(c=s,s=i),c&&c!==i){t.setEdge(c,i);return}i=a}})}let Yy=py,Xy=xy,Wy=Oy,Uy=Hy,qy=By,Ky=We.Graph,wn=Ee;var Zy=ka;function ka(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,ka);return}let n=wn.maxRank(e),r=so(e,wn.range(1,n+1),"inEdges"),s=so(e,wn.range(n-1,-1,-1),"outEdges"),o=Yy(e);if(oo(e,o),t&&t.disableOptimalOrderHeuristic)return;let i=Number.POSITIVE_INFINITY,a;for(let c=0,l=0;l<4;++c,++l){Qy(c%2?r:s,c%4>=2),o=wn.buildLayerMatrix(e);let u=Xy(e,o);u{r.has(o)||r.set(o,[]),r.get(o).push(i)};for(const o of e.nodes()){const i=e.node(o);if(typeof i.rank=="number"&&s(i.rank,o),typeof i.minRank=="number"&&typeof i.maxRank=="number")for(let a=i.minRank;a<=i.maxRank;a++)a!==i.rank&&s(a,o)}return t.map(function(o){return Uy(e,o,n,r.get(o)||[])})}function Qy(e,t){let n=new Ky;e.forEach(function(r){let s=r.graph().root,o=Wy(r,s,n,t);o.vs.forEach((i,a)=>r.node(i).order=a),qy(r,n,o.vs)})}function oo(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let Jy=We.Graph,tt=Ee;var e0={positionX:d0};function t0(e,t){let n={};function r(s,o){let i=0,a=0,c=s.length,l=o[o.length-1];return o.forEach((u,d)=>{let m=r0(e,u),f=m?e.node(m).order:c;(m||u===l)&&(o.slice(a,d+1).forEach(p=>{e.predecessors(p).forEach(x=>{let _=e.node(x),g=_.order;(g{u=o[d],e.node(u).dummy&&e.predecessors(u).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderl)&&ja(n,m,u)})})}function s(o,i){let a=-1,c,l=0;return i.forEach((u,d)=>{if(e.node(u).dummy==="border"){let m=e.predecessors(u);m.length&&(c=e.node(m[0]).order,r(i,l,d,a,c),l=d,a=c)}r(i,l,i.length,c,o.length)}),i}return t.length&&t.reduce(s),n}function r0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function ja(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function s0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function o0(e,t,n,r){let s={},o={},i={};return t.forEach(a=>{a.forEach((c,l)=>{s[c]=c,o[c]=c,i[c]=l})}),t.forEach(a=>{let c=-1;a.forEach(l=>{let u=r(l);if(u.length){u=u.sort((m,f)=>i[m]-i[f]);let d=(u.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let p=u[m];o[l]===l&&cMath.max(m,o[f.v]+i.edge(f)),0)}function u(d){let m=i.outEdges(d).reduce((p,x)=>Math.min(p,o[x.w]-i.edge(x)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(o[d]=Math.max(o[d],m))}return c(l,i.predecessors.bind(i)),c(u,i.successors.bind(i)),Object.keys(r).forEach(d=>o[d]=o[n[d]]),o}function a0(e,t,n,r){let s=new Jy,o=e.graph(),i=f0(o.nodesep,o.edgesep,r);return t.forEach(a=>{let c;a.forEach(l=>{let u=n[l];if(s.setNode(u),c){var d=n[c],m=s.edge(d,u);s.setEdge(d,u,Math.max(i(e,l,c),m||0))}c=l})}),s}function c0(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let l=h0(e,a)/2;s=Math.max(c+l,s),o=Math.min(c-l,o)});const i=s-o;return i{["l","r"].forEach(i=>{let a=o+i,c=e[a];if(c===t)return;let l=Object.values(c),u=r-tt.applyWithChunking(Math.min,l);i!=="l"&&(u=s-tt.applyWithChunking(Math.max,l)),u&&(e[a]=tt.mapValues(c,d=>d+u))})})}function u0(e,t){return tt.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(o=>o[r]).sort((o,i)=>o-i);return(s[1]+s[2])/2}})}function d0(e){let t=tt.buildLayerMatrix(e),n=Object.assign(t0(e,t),n0(e,t)),r={},s;["u","d"].forEach(i=>{s=i==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(i==="u"?e.predecessors:e.successors).bind(e),l=o0(e,s,n,c),u=i0(e,s,l.root,l.align,a==="r");a==="r"&&(u=tt.mapValues(u,d=>-d)),r[i+a]=u})});let o=c0(e,r);return l0(r,o),u0(r,e.graph().align)}function f0(e,t,n){return(r,s,o)=>{let i=r.node(s),a=r.node(o),c=0,l;if(c+=i.width/2,Object.hasOwn(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":l=-i.width/2;break;case"r":l=i.width/2;break}if(l&&(c+=n?l:-l),l=0,c+=(i.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(c+=n?l:-l),l=0,c}}function h0(e,t){return e.node(t).width}let Ca=Ee,m0=e0.positionX;var p0=g0;function g0(e){e=Ca.asNonCompoundGraph(e),y0(e),Object.entries(m0(e)).forEach(([t,n])=>e.node(t).x=n)}function y0(e){let t=Ca.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const o=s.reduce((i,a)=>{const c=e.node(a).height;return i>c?i:c},0);s.forEach(i=>e.node(i).y=r+o/2),r+=o+n})}let io=wg,ao=Ng,x0=Ug,w0=Ee.normalizeRanks,b0=Qg,v0=Ee.removeEmptyRanks,co=ny,_0=cy,lo=uy,E0=Zy,N0=p0,Fe=Ee,S0=We.Graph;var k0=j0;function j0(e,t){let n=t&&t.debugTiming?Fe.time:Fe.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>D0(e));n(" runLayout",()=>C0(r,n,t)),n(" updateInputGraph",()=>M0(e,r))})}function C0(e,t,n){t(" makeSpaceForEdgeLabels",()=>P0(e)),t(" removeSelfEdges",()=>W0(e)),t(" acyclic",()=>io.run(e)),t(" nestingGraph.run",()=>co.run(e)),t(" rank",()=>x0(Fe.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>z0(e)),t(" removeEmptyRanks",()=>v0(e)),t(" nestingGraph.cleanup",()=>co.cleanup(e)),t(" normalizeRanks",()=>w0(e)),t(" assignRankMinMax",()=>H0(e)),t(" removeEdgeLabelProxies",()=>F0(e)),t(" normalize.run",()=>ao.run(e)),t(" parentDummyChains",()=>b0(e)),t(" addBorderSegments",()=>_0(e)),t(" order",()=>E0(e,n)),t(" insertSelfEdges",()=>U0(e)),t(" adjustCoordinateSystem",()=>lo.adjust(e)),t(" position",()=>N0(e)),t(" positionSelfEdges",()=>q0(e)),t(" removeBorderNodes",()=>X0(e)),t(" normalize.undo",()=>ao.undo(e)),t(" fixupEdgeLabelCoords",()=>G0(e)),t(" undoCoordinateSystem",()=>lo.undo(e)),t(" translateGraph",()=>V0(e)),t(" assignNodeIntersects",()=>B0(e)),t(" reversePoints",()=>Y0(e)),t(" acyclic.undo",()=>io.undo(e))}function M0(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let $0=["nodesep","edgesep","ranksep","marginx","marginy"],A0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},R0=["acyclicer","ranker","rankdir","align"],I0=["width","height","rank"],uo={width:0,height:0},T0=["minlen","weight","width","height","labeloffset"],O0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},L0=["labelpos"];function D0(e){let t=new S0({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},A0,cr(n,$0),Fe.pick(n,R0))),e.nodes().forEach(r=>{let s=lr(e.node(r));const o=cr(s,I0);Object.keys(uo).forEach(i=>{o[i]===void 0&&(o[i]=uo[i])}),t.setNode(r,o),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},O0,cr(s,T0),Fe.pick(s,L0)))}),t}function P0(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function z0(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),o={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};Fe.addDummyNode(e,"edge-proxy",o,"_ep")}})}function H0(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function F0(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function V0(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,o=e.graph(),i=o.marginx||0,a=o.marginy||0;function c(l){let u=l.x,d=l.y,m=l.width,f=l.height;t=Math.min(t,u-m/2),n=Math.max(n,u+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(l=>c(e.node(l))),e.edges().forEach(l=>{let u=e.edge(l);Object.hasOwn(u,"x")&&c(u)}),t-=i,r-=a,e.nodes().forEach(l=>{let u=e.node(l);u.x-=t,u.y-=r}),e.edges().forEach(l=>{let u=e.edge(l);u.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=r)}),o.width=n-t+i,o.height=s-r+a}function B0(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),o,i;n.points?(o=n.points[0],i=n.points[n.points.length-1]):(n.points=[],o=s,i=r),n.points.unshift(Fe.intersectRect(r,o)),n.points.push(Fe.intersectRect(s,i))})}function G0(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Y0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function X0(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),o=e.node(n.borderLeft[n.borderLeft.length-1]),i=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(i.x-o.x),n.height=Math.abs(s.y-r.y),n.x=o.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function W0(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function U0(e){var t=Fe.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,o)=>{var i=e.node(s);i.order=o+r,(i.selfEdges||[]).forEach(a=>{Fe.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:i.rank,order:o+ ++r,e:a.e,label:a.label},"_se")}),delete i.selfEdges})})}function q0(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,o=r.y,i=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*i/3,y:o-a},{x:s+5*i/6,y:o-a},{x:s+i,y:o},{x:s+5*i/6,y:o+a},{x:s+2*i/3,y:o+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return Fe.mapValues(Fe.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let K0=Ee,Z0=We.Graph;var Q0={debugOrdering:J0};function J0(e){let t=K0.buildLayerMatrix(e),n=new Z0({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let o="layer"+s;n.setNode(o,{rank:"same"}),r.reduce((i,a)=>(n.setEdge(i,a,{style:"invis"}),a))}),n}var ex="1.1.8",tx={graphlib:We,layout:k0,debug:Q0,util:{time:Ee.time,notime:Ee.notime},version:ex};const fo=ko(tx),Ke=264,nx=44,rx=26,sx=14;function ht(e){const t=Math.max(e.attributes.length,1);return nx+t*rx+sx}const ox=40;function ur(e,t,n,r="auto",s,o="LR"){const i=ix(n,s);return r==="grid"?go(e,n,i):r==="clustered"?po(e,t,n,i,o):r==="hierarchical"||e.length<=ox?ho(e,t,n,o):new Set(e.map(c=>i(c.id)).filter(Boolean)).size>1?po(e,t,n,i,o):go(e,n,i)}function ix(e,t){return n=>{var r,s,o;if(t){const i=t.get(n);if(i)return i.name}return((o=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:o.name)??""}}function Ma(e,t,n,r=!1,s="LR"){const o=new fo.graphlib.Graph;o.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),o.setDefaultEdgeLabel(()=>({}));const i=new Set(e.map(u=>u.id));for(const u of e){const d=n.get(u.id);o.setNode(u.id,{width:Ke,height:d?ht(d):120})}for(const u of t)i.has(u.source)&&i.has(u.target)&&o.setEdge(u.source,u.target,{minlen:1,weight:2});fo.layout(o);let a=0,c=0;return{nodes:e.map(u=>{const d=o.node(u.id),m=n.get(u.id),f=m?ht(m):120,p=d.x-Ke/2,x=d.y-f/2;return a=Math.max(a,p+Ke),c=Math.max(c,x+f),{...u,position:{x:p,y:x}}}),width:a,height:c}}function ho(e,t,n,r="LR"){return Ma(e,t,n,!1,r).nodes}function ax(e,t){const n=a=>{const c=t.get(a);return c?ht(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let o=0,i=0;for(let a=0;a{const d=u*(Ke+$a);s.push({...l,position:{x:d,y:o}}),i=Math.max(i,d+Ke)}),o+=Math.max(...c.map(l=>n(l.id)))+Aa}return{nodes:s,width:i,height:o}}const mo=120;function po(e,t,n,r,s="LR"){const o=new Map;for(const m of e){const f=r(m.id);(o.get(f)??o.set(f,[]).get(f)).push(m)}const a=[...o.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=o.get(m),p=new Set(f.map(E=>E.id));let x=0;for(const E of t)p.has(E.source)&&p.has(E.target)&&x++;const g=f.length<=8&&x>=f.length-1?Ma(f,t,n,!0,s):ax(f,n);return{name:m,...g}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),l=[];let u=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const $a=40,Aa=40;function go(e,t,n){const r=l=>{const u=t.get(l);return u?ht(u):120},s=[...e].sort((l,u)=>{var x,_;const d=n(l.id),m=n(u.id);if(d!==m)return d.localeCompare(m);const f=((x=t.get(l.id))==null?void 0:x.name)??l.id,p=((_=t.get(u.id))==null?void 0:_.name)??u.id;return f.localeCompare(p)}),o=Math.max(1,Math.round(Math.sqrt(s.length))),i=Array.from({length:o},(l,u)=>u*(Ke+$a)),a=new Map;let c=0;for(let l=0;la.set(m.id,{x:i[f],y:c}));const d=Math.max(...u.map(m=>r(m.id)));c+=d+Aa}return e.map(l=>({...l,position:a.get(l.id)??l.position}))}function ln({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const cx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ra=["industry","core","domain","specialised"];function lx({entity:e,exec:t,onClose:n}){var b,$;const[r,s]=w.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[o,i]=w.useState([]),[a,c]=w.useState(null),[l,u]=w.useState(null),[d,m]=w.useState("skos:exactMatch"),[f,p]=w.useState((($=e.conceptual)==null?void 0:$.ontology_layer)??"core"),[x,_]=w.useState([]),[g,E]=w.useState("");w.useEffect(()=>{na().then(j=>_(j.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return i([]);ta(r,g||void 0).then(v=>{i(v.results),c(v.loaded_terms)}).catch(()=>i([]))},200);return()=>clearTimeout(j)},[r,g]);const C=()=>{l&&t("set_alignment",{id:e.id,aligns_to:l.prefixed,alignment:d,layer:f,resolved_via:l.source}).then(n)};return h.jsxs(ln,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[x.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(g===""?" active":""),onClick:()=>E(""),children:"all sources"}),x.map(j=>h.jsx("button",{className:"src-chip"+(g===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:g?`Search within ${g}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&x.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[o.map(j=>h.jsxs("button",{className:"term-card"+((l==null?void 0:l.iri)===j.iri?" picked":""),onClick:()=>u(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&o.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:cx.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>p(j.target.value),children:Ra.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!l,onClick:C,children:["Align",l?` to ${l.label}`:""]})]})]})}function ux({entity:e,doc:t,exec:n,onClose:r}){var b,$,j;const[s,o]=w.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[i,a]=w.useState((($=e.term_map)==null?void 0:$.class_iri)??""),c=new Set(e.attributes.map(v=>v.name)),u=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(v=>v[1]).filter(v=>!c.has(v)),d=v=>!v||v.startsWith("http://")||v.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(v),m=u.length===0&&d(i),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:i.trim()||null}).then(r)},p=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",x=t.project.kg_base_iri||`urn:${p}:`,_=(j=(e.key_groups??[]).find(v=>v.type==="pk"))==null?void 0:j.members.map(v=>{var R;return(R=e.attributes.find(N=>N.id===v))==null?void 0:R.name}).filter(Boolean),g=_&&_.length?`${x}${e.id}/${_.map(v=>`{${v}}`).join("_")}`:"(blank-node: entity has no primary key)",E=i.trim()||`${x}${e.id}`,C=s.trim()||g;return h.jsxs(ln,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:i,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:v=>a(v.target.value)}),d(i)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:v=>o(v.target.value)}),u.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",u.length>1?"s":"",": ",u.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",C]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((_==null?void 0:_[0])??"id")+"}",". Columns:"," ",e.attributes.map(v=>v.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function dx({doc:e,exec:t,onClose:n,onCreated:r}){const[s,o]=w.useState(""),[i,a]=w.useState(""),[c,l]=w.useState(""),[u,d]=w.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:i||null,subject_area:c||null,layer:u||null}).then(f=>{const p=f==null?void 0:f.created_id;n(),p&&r(p)})};return h.jsxs(ln,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>o(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:i,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>l(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:u,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ra.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const Ia=["many_to_one","one_to_many","one_to_one","many_to_many"];function fx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:o,onClose:i}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),l=w.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[u,d]=w.useState(r??""),[m,f]=w.useState(s??(l==null?void 0:l.id)??""),[p,x]=w.useState("many_to_one"),[_,g]=w.useState("mandatory");if(!a||!c)return null;const E=u==="__new__",C=()=>o("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:u||null,to_attribute:m||null,create_from_fk:E,cardinality:p,optionality:_}).then(i);return h.jsxs(ln,{title:`${a.name} → ${c.name}`,onClose:i,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:p,onChange:b=>x(b.target.value),children:Ia.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:u,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",l?` "${l.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:_,onChange:b=>g(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:C,children:"Create relationship"})})]})}function hx({rel:e,doc:t,exec:n,onClose:r}){const s=g=>{var E;return((E=t.entities.find(C=>C.id===g))==null?void 0:E.name)??"?"},[o,i]=w.useState(e.name),[a,c]=w.useState(e.cardinality),[l,u]=w.useState(e.optionality),[d,m]=w.useState(e.identifying),[f,p]=w.useState(!1),x=async()=>{o.trim()&&o.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:o.trim()}),(a!==e.cardinality||l!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:l,identifying:d}),r()},_=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(ln,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:o,onChange:g=>i(g.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:g=>c(g.target.value),children:Ia.map(g=>h.jsx("option",{children:g},g))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:l,onChange:g=>u(g.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:g=>m(g.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:_,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>p(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:x,children:"Save"})]})]})}const yo=10,mx=6,Mt=24;function px(e,t){return t?e:Math.round(e/yo)*yo}function gx(e,t,n){const r=[...t];for(const i of n)r.push(i.left-Mt,i.right+Mt);let s=e,o=mx;for(const i of r){const a=Math.abs(i-e);at.left&&ei.left&&no.left&&n=i.right?(u.push({x:n,y:t.y},{x:i.right,y:t.y}),m={ox:1,oy:0}):(u.push({x:n,y:t.y},{x:i.left,y:t.y}),m={ox:-1,oy:0});return{path:vx(u),sourceOut:d,targetOut:m}}const ct=8;function Ex(e,t,n){const r=Math.abs(e-n.left),s=Math.abs(e-n.right),o=Math.abs(t-n.top),i=Math.abs(t-n.bottom),a=Math.min(r,s,o,i),c=(l,u,d)=>Math.min(Math.max(l,u),d);return a===r?{side:"left",x:n.left,y:c(t,n.top+ct,n.bottom-ct)}:a===s?{side:"right",x:n.right,y:c(t,n.top+ct,n.bottom-ct)}:a===o?{side:"top",x:c(e,n.left+ct,n.right-ct),y:n.top}:{side:"bottom",x:c(e,n.left+ct,n.right-ct),y:n.bottom}}function wo(e,t){const n=(r,s,o)=>Math.min(Math.max(r,s),o);switch(e.side){case"left":return{x:t.left,y:n(e.y,t.top,t.bottom),out:{ox:-1,oy:0}};case"right":return{x:t.right,y:n(e.y,t.top,t.bottom),out:{ox:1,oy:0}};case"top":return{x:n(e.x??(t.left+t.right)/2,t.left,t.right),y:t.top,out:{ox:0,oy:-1}};default:return{x:n(e.x??(t.left+t.right)/2,t.left,t.right),y:t.bottom,out:{ox:0,oy:1}}}}const dr=3,Nx=w.memo(function({id:t,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:i,targetPosition:a,data:c,selected:l}){const{screenToFlowPosition:u}=cn(),d=ge(U=>U.transform[2]),[m,f]=w.useState(null),[p,x]=w.useState(null),_=w.useRef(!1),g=w.useRef(0),E=c==null?void 0:c.onRouteChange,C=!!E,b=m??(c==null?void 0:c.routeX),$=c==null?void 0:c.sourceCard,j=c==null?void 0:c.targetCard,v=(p==null?void 0:p.end)==="source"?p.a:c==null?void 0:c.sourceAnchor,R=(p==null?void 0:p.end)==="target"?p.a:c==null?void 0:c.targetAnchor,N=v&&$?wo(v,$):{x:n,y:r,out:null},T=R&&j?wo(R,j):{x:s,y:o,out:null},P=N.x,G=N.y,V=T.x,y=T.y,M=(v==null?void 0:v.side)==="right"?K.Right:(v==null?void 0:v.side)==="left"?K.Left:i,S=(R==null?void 0:R.side)==="right"?K.Right:(R==null?void 0:R.side)==="left"?K.Left:a,[O,z,k]=Rn({sourceX:P,sourceY:G,sourcePosition:M,targetX:V,targetY:y,targetPosition:S,borderRadius:10,...b!=null?{centerX:b}:{}}),I=c==null?void 0:c.sourceCard,L=c==null?void 0:c.targetCard,D=b!=null&&I&&L?_x({x:P,y:G},{y},b,M===K.Left?-1:1,S===K.Left?-1:1,I,L):null,q=D?D.path:O,F=c==null?void 0:c.relationship,J=(c==null?void 0:c.dimmed)??!1,ee=(F==null?void 0:F.cardinality)??"many_to_one",se=(F==null?void 0:F.optionality)==="optional",le=(F==null?void 0:F.identifying)??!1,ne=ee==="many_to_one"||ee==="many_to_many",ce=ee==="one_to_many"||ee==="many_to_many",we="rel-edge"+(l?" selected":"")+(J?" dimmed":""),ye=((c==null?void 0:c.memberCount)??0)>1,he=c==null?void 0:c.onHoverEdge,ue=b??z,me=k,Se=ue,ie=me,Z=D?D.sourceOut:N.out??{ox:M===K.Left?-1:1,oy:0},xe=D?D.targetOut:T.out??{ox:S===K.Left?-1:1,oy:0},je={x:P,y:G},Ae=D&&L?xe.oy!==0?{x:b,y:xe.oy<0?L.top:L.bottom}:{x:xe.ox>0?L.right:L.left,y}:{x:V,y},Le=w.useCallback(U=>E&&F&&E(F.id,U),[E,F]),Re=w.useCallback(U=>{var re,fe;if(!C||U.button!==0)return;U.stopPropagation(),(fe=(re=U.target).setPointerCapture)==null||fe.call(re,U.pointerId),_.current=!0,g.current=0;const W=u({x:U.clientX,y:U.clientY}).x;let te=0,pe=b??ue;const Q=Ce=>{const Te=u({x:Ce.clientX,y:Ce.clientY});g.current=Math.max(g.current,Math.abs(Te.x-W)),pe=xx(Te.x,{shift:Ce.shiftKey,source:(c==null?void 0:c.sourceCard)??{left:n,right:n},target:(c==null?void 0:c.targetCard)??{left:s,right:s}}),te||(te=requestAnimationFrame(()=>{te=0,f(pe)}))},oe=()=>{window.removeEventListener("pointermove",Q),window.removeEventListener("pointerup",oe),te&&cancelAnimationFrame(te),_.current=!1,f(null),g.current>=dr&&Le(pe)};window.addEventListener("pointermove",Q),window.addEventListener("pointerup",oe)},[C,u,b,ue,c,n,s,Le]),Ie=w.useCallback(U=>{g.current>=dr&&(U.stopPropagation(),g.current=0)},[]),Ve=w.useCallback(U=>{C&&(U.stopPropagation(),Le(null))},[C,Le]),H=c==null?void 0:c.onAnchorChange,X=w.useCallback(U=>Y=>{var fe,Ce;const W=U==="source"?c==null?void 0:c.sourceCard:c==null?void 0:c.targetCard;if(!H||!F||!W||Y.button!==0)return;Y.stopPropagation(),(Ce=(fe=Y.target).setPointerCapture)==null||Ce.call(fe,Y.pointerId),g.current=0;const te=u({x:Y.clientX,y:Y.clientY});let pe=0,Q=null;const oe=Te=>{const $e=u({x:Te.clientX,y:Te.clientY});g.current=Math.max(g.current,Math.hypot($e.x-te.x,$e.y-te.y)),Q=Ex($e.x,$e.y,W),pe||(pe=requestAnimationFrame(()=>{pe=0,x({end:U,a:Q})}))},re=()=>{window.removeEventListener("pointermove",oe),window.removeEventListener("pointerup",re),pe&&cancelAnimationFrame(pe),x(null),g.current>=dr&&Q&&H(F.id,U,Q)};window.addEventListener("pointermove",oe),window.addEventListener("pointerup",re)},[H,F,c,u]),B=w.useCallback(U=>Y=>{!H||!F||(Y.stopPropagation(),H(F.id,U,null))},[H,F]);return h.jsxs("g",{className:we,onMouseEnter:he?()=>he(F.id):void 0,onMouseLeave:he?()=>he(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:q,fill:"none",strokeDasharray:le?void 0:"6 4"}),h.jsx("path",{d:q,fill:"none",strokeWidth:16/d,stroke:"transparent"}),h.jsx(vo,{x:je.x,y:je.y,out:Z,many:ne,optional:se}),h.jsx(vo,{x:Ae.x,y:Ae.y,out:xe,many:ce,optional:!1}),!!H&&((c==null?void 0:c.hovered)||l||p!=null)&&h.jsxs(h.Fragment,{children:[h.jsx(bo,{x:je.x,y:je.y,zoom:d,onPointerDown:X("source"),onDoubleClick:B("source")}),h.jsx(bo,{x:Ae.x,y:Ae.y,zoom:d,onPointerDown:X("target"),onDoubleClick:B("target")})]}),C&&((c==null?void 0:c.hovered)||l||m!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:Re,onClickCapture:Ie,onDoubleClick:Ve,children:[h.jsx("rect",{x:ue-20/d,y:Math.min(G,y),width:40/d,height:Math.max(Math.abs(y-G),24/d),fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:ue-5.5/d,y:me-11/d,width:11/d,height:22/d,rx:5/d,strokeWidth:1.5/d}),h.jsx("circle",{className:"rel-grip-dot",cx:ue,cy:me-4.5/d,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:ue,cy:me,r:1.1/d}),h.jsx("circle",{className:"rel-grip-dot",cx:ue,cy:me+4.5/d,r:1.1/d})]}),(l||ye)&&F&&h.jsxs("text",{className:"rel-label",x:Se,y:ie-8,children:[l?F.verb_phrase||F.name:"",ye?`${l?" ":""}(${c.memberCount})`:""]})]})});function bo({x:e,y:t,zoom:n,onPointerDown:r,onDoubleClick:s}){return h.jsxs("g",{className:"rel-endpoint",style:{cursor:"move"},onPointerDown:r,onDoubleClick:s,children:[h.jsx("circle",{cx:e,cy:t,r:10/n,fill:"transparent"}),h.jsx("circle",{className:"rel-endpoint-dot",cx:e,cy:t,r:3.5/n,strokeWidth:1.5/n})]})}function vo({x:e,y:t,out:n,many:r,optional:s}){const{ox:a,oy:c}=n,l=-c,u=a,d=p=>({x:e+a*p,y:t+c*p}),m=(p,x)=>({x:e+a*p+l*x,y:t+c*p+u*x}),f=[];if(r){const p=d(12),x=m(0,-7),_=d(0),g=m(0,7);f.push(h.jsx("path",{className:"rel-glyph",d:`M ${p.x} ${p.y} L ${x.x} ${x.y} M ${p.x} ${p.y} L ${_.x} ${_.y} M ${p.x} ${p.y} L ${g.x} ${g.y}`,fill:"none"},"foot"))}else{const p=m(9,-7),x=m(9,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:x.x,y2:x.y},"one"))}if(s){const p=d(18);f.push(h.jsx("circle",{className:"rel-glyph ring",cx:p.x,cy:p.y,r:4},"opt"))}else{const p=m(17,-7),x=m(17,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:x.x,y2:x.y},"mand"))}return h.jsx(h.Fragment,{children:f})}const Sx={entity:Vm},kx={relationship:Nx},_o=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],Eo="#8a7d6a";function No(e){return{side:e.side,y:Math.round(e.y),...e.x!=null?{x:Math.round(e.x)}:{}}}function jx(e,t,n){const s=Ke;let{x:o,y:i}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const l of n)ol.x&&il.y&&(i=l.y+l.h+16,a=!0)}return{x:o,y:i}}function Cx(e,t){const n=(o,i)=>{var a;return!!i&&!!((a=t.get(o))!=null&&a.attributes.some(c=>c.id===i))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Xr,targetHandle:n(e.to.entity,s)?s:Wr}}function sw({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:o="",showTypes:i=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:l,activeAreas:u,onError:d,handleRef:m,layoutStore:f}){const{fitView:p,fitBounds:x,getNodes:_}=cn(),[g,E]=w.useState([]),[C,b]=w.useState([]),$=w.useRef(!1),j=w.useMemo(()=>{const H=u&&u.size>0?[...u].sort():null;return H?"sa:"+H.join("+"):"__all__"},[u]),v=w.useRef(null),[R,N]=w.useState(0),T=w.useRef(new Map),P=w.useRef(null);w.useEffect(()=>{if(!f){v.current=null;return}const H=T.current.get(j);if(H){v.current=H,$.current=!1,N(B=>B+1);return}let X=!1;return f.load(j).then(B=>{X||(T.current.set(j,B),v.current=B,$.current=!1,N(U=>U+1))}),()=>{X=!0}},[f,j]);const[G,V]=w.useState(null),[y,M]=w.useState(null),[S,O]=w.useState(!1),[z,k]=w.useState(null),[I,L]=w.useState(null),[D,q]=w.useState(null),[F,J]=w.useState(null),ee=w.useRef({}),se=!t.canEdit,le=w.useRef(null),ne=w.useCallback(()=>{f&&(le.current&&clearTimeout(le.current),le.current=setTimeout(()=>{const H={};for(const U of _())U.hidden||(H[U.id]={x:Math.round(U.position.x),y:Math.round(U.position.y)});const X={};for(const[U,Y]of Object.entries(ee.current)){const W={};Y.routeX!=null&&(W.routeX=Math.round(Y.routeX)),Y.sourceAnchor&&(W.sourceAnchor=No(Y.sourceAnchor)),Y.targetAnchor&&(W.targetAnchor=No(Y.targetAnchor)),(W.routeX!=null||W.sourceAnchor||W.targetAnchor)&&(X[U]=W)}const B={nodes:H,edges:X};T.current.set(j,B),v.current=B,f.save(j,B)},800))},[f,_,j]),ce=w.useCallback((H,X)=>{const B=ee.current[H]??{};X==null?delete B.routeX:B.routeX=X,ee.current[H]=B,b(U=>U.map(Y=>Y.id===H?{...Y,data:{...Y.data,routeX:X??void 0}}:Y)),ne()},[ne]),we=w.useCallback((H,X,B)=>{const U=ee.current[H]??{},Y=X==="source"?"sourceAnchor":"targetAnchor";B==null?delete U[Y]:U[Y]=B,ee.current[H]=U,b(W=>W.map(te=>te.id===H?{...te,data:{...te.data,[Y]:B??void 0}}:te)),ne()},[ne]),ye=w.useMemo(()=>{const H=new Map;return e.subject_areas.forEach((X,B)=>H.set(X.id,_o[B%_o.length])),H},[e]),he=w.useMemo(()=>{const H=new Map;return e.entities.forEach(X=>H.set(X.id,X)),H},[e]),ue=w.useMemo(()=>{const H=new Map,X=new Map;return e.subject_areas.forEach(B=>{(B.members??[]).forEach(U=>X.set(U,{id:B.id,name:B.name}))}),e.entities.forEach(B=>{var te,pe;const U=(te=B.conceptual)!=null&&te.id?X.get(B.conceptual.id):void 0,Y=(pe=B.conceptual)==null?void 0:pe.subject_area,W=U??(Y?{id:Y.id,name:Y.name??Y.id}:void 0);W&&H.set(B.id,W)}),H},[e]),me=w.useCallback(H=>{var B;if(!u||u.size===0)return!1;const X=(B=ue.get(H))==null?void 0:B.id;return!(X&&u.has(X))},[u,ue]),Se=w.useMemo(()=>{const H=new Map,X=(B,U)=>{if(!U.length)return;const Y=H.get(B)??new Set;U.forEach(W=>Y.add(W)),H.set(B,Y)};for(const B of e.relationships)X(B.from.entity,B.from.attributes),X(B.to.entity,B.to.attributes);return H},[e]);w.useEffect(()=>{var pe;const H=o.trim().toLowerCase(),X=new Set;if(H)for(const Q of e.entities)(Q.name.toLowerCase()+" "+(((pe=Q.conceptual)==null?void 0:pe.name.toLowerCase())??"")+" "+Q.attributes.map(re=>re.name.toLowerCase()).join(" ")).includes(H)&&X.add(Q.id);const B=new Set;if(r){B.add(r);for(const Q of e.relationships)Q.from.entity===r&&B.add(Q.to.entity),Q.to.entity===r&&B.add(Q.from.entity)}const U=e.entities.map(Q=>{const oe=H!==""&&!X.has(Q.id),re=r!==null&&!B.has(Q.id);return{id:Q.id,type:"entity",position:{x:0,y:0},hidden:me(Q.id),data:{entity:Q,color:(()=>{const fe=ue.get(Q.id);return fe?ye.get(fe.id)??Eo:Eo})(),dimmed:oe||re,highlighted:H!==""&&X.has(Q.id),showTypes:i,collapseDetail:a,expanded:(c==null?void 0:c.has(Q.id))??!1,onToggleExpand:l,endpointAttrs:Se.get(Q.id),highlightAttrs:void 0,onHoverAttr:q}}}),Y=e.relationships.filter(Q=>he.has(Q.from.entity)&&he.has(Q.to.entity)).map(Q=>{const{sourceHandle:oe,targetHandle:re}=Cx(Q,he),fe=r!==null&&Q.from.entity!==r&&Q.to.entity!==r;return{id:Q.id,source:Q.from.entity,target:Q.to.entity,sourceHandle:oe,targetHandle:re,type:"relationship",data:{relationship:Q,dimmed:fe,memberCount:Math.max(Q.from.attributes.length,Q.to.attributes.length),onHoverEdge:J}}}),W=v.current;if(ee.current={},W)for(const[Q,oe]of Object.entries(W.edges))ee.current[Q]={...oe.routeX!=null?{routeX:oe.routeX}:{},...oe.sourceAnchor?{sourceAnchor:oe.sourceAnchor}:{},...oe.targetAnchor?{targetAnchor:oe.targetAnchor}:{}};const te=Q=>{const oe=new Map;for(const re of Q)oe.set(re.id,{left:re.position.x,right:re.position.x+Ke,top:re.position.y,bottom:re.position.y+ht(re.data.entity)});b(Y.map(re=>{const fe=ee.current[re.id]??{};return{...re,data:{...re.data,routeX:fe.routeX,sourceAnchor:fe.sourceAnchor,targetAnchor:fe.targetAnchor,onRouteChange:f?ce:void 0,onAnchorChange:f?we:void 0,sourceCard:oe.get(re.source),targetCard:oe.get(re.target)}}}))};E(Q=>{const oe=new Map(Q.map(de=>[de.id,de.position])),re=U.every(de=>oe.has(de.id)),fe=((u==null?void 0:u.size)??0)>0;if($.current&&re&&Q.length>=U.length&&!fe){const de=U.map(Qe=>({...Qe,position:oe.get(Qe.id)??Qe.position}));return te(de),de}const Ce=fe?U.filter(de=>!de.hidden):U,Te=ur(Ce,Y,he,"auto",ue),$e=new Map(Te.map(de=>[de.id,de.position])),Ue=(W==null?void 0:W.nodes)??{},Dt=Object.keys(Ue).length>0,Be=[],Pt=U.map(de=>{const Qe=Ue[de.id];if(Qe){const zt={x:Qe.x,y:Qe.y};return Be.push({x:zt.x,y:zt.y,w:Ke,h:ht(de.data.entity)}),{...de,position:zt}}return $e.has(de.id)?{...de,position:$e.get(de.id)}:oe.has(de.id)&&$.current?{...de,position:oe.get(de.id)}:de});if(Dt)for(const de of Pt)Ue[de.id]||de.hidden||(de.position=jx(de.position,ht(de.data.entity),Be),Be.push({x:de.position.x,y:de.position.y,w:Ke,h:ht(de.data.entity)}));return $.current=!0,Dt||requestAnimationFrame(()=>p({padding:.15,duration:300})),te(Pt),Pt})},[e,o,r,i,a,c,l,ye,he,ue,me,u,Se,p,f,ce,we,R]);const ie=w.useMemo(()=>{const H=new Set,X=new Set,B=new Map,U=(Y,W)=>{if(!W.length)return;const te=B.get(Y)??new Set;W.forEach(pe=>te.add(pe)),B.set(Y,te)};if(D)for(const Y of e.relationships)(Y.from.attributes.includes(D)||Y.to.attributes.includes(D))&&(H.add(Y.id),X.add(Y.from.entity),X.add(Y.to.entity),U(Y.from.entity,Y.from.attributes),U(Y.to.entity,Y.to.attributes));if(F){const Y=e.relationships.find(W=>W.id===F);Y&&(U(Y.from.entity,Y.from.attributes),U(Y.to.entity,Y.to.attributes))}return{active:D!==null,relsForAttr:H,entsForAttr:X,hitAttrsByEntity:B}},[e,D,F]);w.useEffect(()=>{var U;const H=o.trim().toLowerCase(),X=new Set;if(H)for(const Y of e.entities)(Y.name.toLowerCase()+" "+(((U=Y.conceptual)==null?void 0:U.name.toLowerCase())??"")+" "+Y.attributes.map(te=>te.name.toLowerCase()).join(" ")).includes(H)&&X.add(Y.id);const B=new Set;if(r){B.add(r);for(const Y of e.relationships)Y.from.entity===r&&B.add(Y.to.entity),Y.to.entity===r&&B.add(Y.from.entity)}E(Y=>Y.map(W=>{const te=H!==""&&!X.has(W.id),pe=r!==null&&!B.has(W.id),Q=ie.active&&!ie.entsForAttr.has(W.id),oe=te||pe||Q,re=H!==""&&X.has(W.id)||ie.active&&ie.entsForAttr.has(W.id),fe=ie.hitAttrsByEntity.get(W.id);return W.data.dimmed===oe&&W.data.highlighted===re&&W.data.highlightAttrs===fe?W:{...W,data:{...W.data,dimmed:oe,highlighted:re,highlightAttrs:fe}}})),b(Y=>Y.map(W=>{var Te,$e,Ue;const te=(Te=W.data)==null?void 0:Te.relationship,pe=r!==null&&te!==void 0&&te.from.entity!==r&&te.to.entity!==r,Q=ie.active&&!ie.relsForAttr.has(W.id),oe=pe||Q,re=F===W.id,fe=r!==null&&te!==void 0&&(te.from.entity===r||te.to.entity===r),Ce=re||fe?1e3:0;return(($e=W.data)==null?void 0:$e.dimmed)===oe&&((Ue=W.data)==null?void 0:Ue.hovered)===re&&W.zIndex===Ce?W:{...W,zIndex:Ce,data:{...W.data,dimmed:oe,hovered:re}}}))},[ie,F,o,r,e]),w.useEffect(()=>{var U;const H=o.trim().toLowerCase();if(!H)return;const X=new Set;for(const Y of e.entities)(Y.name.toLowerCase()+" "+(((U=Y.conceptual)==null?void 0:U.name.toLowerCase())??"")+" "+Y.attributes.map(te=>te.name.toLowerCase()).join(" ")).includes(H)&&X.add(Y.id);if(!X.size)return;const B=requestAnimationFrame(()=>{const Y=_().filter(te=>X.has(te.id));if(!Y.length)return;const W=Tf(Y);x(W,{padding:.35,duration:400})});return()=>cancelAnimationFrame(B)},[o,e,_,x]);const Z=w.useCallback((H="auto",X="LR")=>{P.current=Object.fromEntries(_().map(B=>[B.id,{x:B.position.x,y:B.position.y}])),E(B=>ur(B,C,he,H,ue,X)),requestAnimationFrame(()=>p({padding:.15,duration:300})),ne()},[C,he,ue,p,_,ne]),xe=w.useCallback(()=>{const H=P.current;H&&(E(X=>X.map(B=>H[B.id]?{...B,position:H[B.id]}:B)),P.current=null,ne())},[ne]),je=w.useCallback(()=>{f==null||f.reset(j),T.current.delete(j),v.current=null,ee.current={},$.current=!1,b(H=>H.map(X=>({...X,data:{...X.data,routeX:void 0}}))),E(H=>{const X=ur(H,C,he,"auto",ue);return requestAnimationFrame(()=>p({padding:.15,duration:300})),X})},[f,j,C,he,ue,p]),Ae=w.useCallback(H=>{s(H),E(X=>(X.find(U=>U.id===H)&&requestAnimationFrame(()=>p({nodes:[{id:H}],padding:.4,duration:400})),X))},[p,s]);w.useImperativeHandle(m,()=>({relayout:Z,fitView:()=>p({padding:.15,duration:300}),focusEntity:Ae,newEntity:()=>O(!0),resetLayout:je,undoRelayout:xe}),[Z,p,Ae,je,xe]);const Le=w.useCallback(H=>{if(se||!H.source||!H.target||H.source===H.target)return;const X=H.sourceHandle&&H.sourceHandle!==Xr?H.sourceHandle:void 0,B=H.targetHandle&&H.targetHandle!==Wr?H.targetHandle:void 0;k({from:H.source,to:H.target,fromAttr:X,toAttr:B})},[se]),Re=w.useCallback(async(H,X)=>{try{return await n(H,X)}catch(B){throw d==null||d(B instanceof Error?B.message:String(B)),B}},[n,d]),Ie=r?he.get(r)??null:null,Ve=e.relationships.find(H=>H.id===I)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(qi,{nodes:g,edges:C,nodeTypes:Sx,edgeTypes:kx,onNodeClick:(H,X)=>s(X.id),onEdgeDoubleClick:(H,X)=>!se&&L(X.id),onPaneClick:()=>{s(null),L(null)},onNodeDragStop:(H,X)=>{E(B=>B.map(U=>U.id===X.id?{...U,position:X.position}:U)),ne()},onConnect:Le,nodesConnectable:!se,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(km,{variant:He.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(hm,{pannable:!0,zoomable:!0,nodeColor:H=>{var X;return((X=H.data)==null?void 0:X.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(bm,{showInteractive:!1})]}),Ie&&h.jsx(Gm,{entity:Ie,doc:e,caps:t,exec:Re,onClose:()=>s(null),onFocusEntity:Ae,onAlign:V,onEditMapping:M}),G&&h.jsx(lx,{entity:G,exec:Re,onClose:()=>V(null)}),y&&h.jsx(ux,{entity:y,doc:e,exec:Re,onClose:()=>M(null)}),S&&h.jsx(dx,{doc:e,exec:Re,onClose:()=>O(!1),onCreated:Ae}),z&&h.jsx(fx,{doc:e,fromId:z.from,toId:z.to,initialFromAttr:z.fromAttr,initialToAttr:z.toAttr,exec:Re,onClose:()=>k(null)}),Ve&&h.jsx(hx,{rel:Ve,doc:e,exec:Re,onClose:()=>L(null)})]})}function ow({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:o}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(Mx,{}),e==="layers"&&h.jsx(Ax,{refreshKey:r,onFocusEntity:o}),e==="changes"&&h.jsx(Rx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Ix,{readOnly:n})]})}function Mx(){const[e,t]=w.useState(""),[n,r]=w.useState([]),[s,o]=w.useState({loaded:0,vocabs:[]}),[i,a]=w.useState(null),[c,l]=w.useState([]),[u,d]=w.useState("");w.useEffect(()=>{na().then(f=>l(f.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const f=setTimeout(()=>{ta(e||"a",u||void 0).then(p=>{r(e?p.results:[]),o({loaded:p.loaded_terms,vocabs:p.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,u]);const m=w.useCallback(f=>{jm(f).then(a).catch(()=>{})},[]);return i?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:i.label}),h.jsx("code",{className:"term-iri",children:i.prefixed}),i.definition&&h.jsx("p",{className:"term-def",children:i.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:i.source})]}),i.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),i.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),i.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),i.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(u===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(u===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:u?`Search within ${u}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const $x=["industry","core","domain","specialised"];function Ax({refreshKey:e,onFocusEntity:t}){const[n,r]=w.useState(null),[s,o]=w.useState(null);if(w.useEffect(()=>{Cm().then(r).catch(()=>{}),Mm().then(o).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const i=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),$x.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var l;return h.jsxs("button",{className:"stack-term"+(i.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((u,d)=>h.jsxs("span",{className:"align-arrow"+(u.resolved?"":" unresolved")+(u.status==="proposed"?" proposed":""),title:u.ref+(u.resolved_via?` (via ${u.resolved_via})`:""),children:["↑ ",u.label,u.status==="proposed"?" ·prop":""]},`${u.ref}-${d}`)),!c.aligned_to&&(((l=c.aligned_refs)==null?void 0:l.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Rx({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=w.useState(null),[o,i]=w.useState(""),[a,c]=w.useState(""),[l,u]=w.useState(!1),d=w.useCallback(()=>{Am().then(s).catch(()=>s(null)),Rm().then(m=>i([m.diff,...m.untracked].filter(Boolean).join(` - -`))).catch(()=>i(""))},[]);return w.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:o.split(` -`).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` -`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:l,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(u(!0),Tm().then(()=>{u(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:l||!a.trim(),onClick:()=>{u(!0),Im(a).then(()=>{u(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Ix({readOnly:e}){const[t,n]=w.useState([]),r=w.useCallback(()=>{Om().then(o=>n(o.decisions)).catch(()=>n([]))},[]);if(w.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(o=>h.jsxs("div",{className:"decision "+o.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[o.verdict]}),h.jsx("span",{className:"chip",children:o.confidence}),h.jsx("span",{className:"chip",children:o.signal})]}),h.jsx("p",{className:"decision-subject",children:o.subject}),!e&&o.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Gs(o.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Gs(o.signal_key,"rejected").then(r),children:"Reject"})]})]},o.signal_key))})}function iw({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:o,openImport:i=!1,prefillImport:a="",onPreview:c}){const[l,u]=w.useState(i&&t?"import":null),[d,m]=w.useState([]),[f,p]=w.useState("postgres"),x=w.useRef(null);w.useEffect(()=>{Lm().then(g=>m(g.formats)).catch(()=>m([]))},[]),w.useEffect(()=>{if(!l)return;const g=E=>{x.current&&!x.current.contains(E.target)&&u(null)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[l]);const _=d.find(g=>g.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:x,children:[h.jsxs("button",{className:s+(l==="export"?" on":""),onClick:()=>u(l==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(l==="import"?" on":""),onClick:()=>u(l==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),l==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(_==null?void 0:_.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:g=>p(g.target.value),children:_.dialects.map(g=>h.jsx("option",{value:g,children:g},g))})]}),d.map(g=>h.jsx("a",{className:"ie-item",href:Dm(g.id,g.id==="sql"?f:void 0),download:!0,onClick:()=>u(null),children:g.label},g.id))]}),l==="import"&&h.jsx(Tx,{exec:e,submitLabel:r,buttonClass:s,applyBatch:o,onClose:()=>u(null),onImported:g=>{u(null),n==null||n(g)},onPreview:c,prefillImport:a})]})}const So=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function Tx({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:o,onPreview:i,prefillImport:a}){var j;const[c,l]=w.useState(i?"erwin":"sql"),[u,d]=w.useState("postgres"),[m,f]=w.useState(a??""),[p,x]=w.useState(!1),[_,g]=w.useState(null),[E,C]=w.useState([]);w.useEffect(()=>{a&&f(a)},[a]);const b=v=>{v&&v.text().then(f).catch(()=>g("could not read that file"))},$=async()=>{x(!0),g(null),C([]);try{if(i&&c==="erwin"){const R=await zm(c,m);if(!R.changes.length){g(R.warnings[0]??"nothing to import from that document"),x(!1);return}s(),i(R),x(!1);return}const v=await Pm(c,m,c==="sql"?u:void 0);if(!v.changes.length){g(v.warnings[0]??"nothing to import from that document"),x(!1);return}if(r)await r(v.changes);else for(const R of v.changes)await e(R.op,R.payload);C(v.warnings),o(v.tables)}catch(v){g(v instanceof Error?v.message:String(v))}finally{x(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:So.map(v=>h.jsx("button",{className:"ie-tab"+(c===v.id?" active":""),onClick:()=>l(v.id),children:v.label},v.id))}),h.jsx("p",{className:"ie-hint",children:(j=So.find(v=>v.id===c))==null?void 0:j.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:u,onChange:v=>d(v.target.value),children:["postgres","snowflake","mysql","duckdb"].map(v=>h.jsx("option",{children:v},v))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:v=>f(v.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:v=>{var R;return b(((R=v.target.files)==null?void 0:R[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((v,R)=>h.jsx("p",{className:"ie-warn",children:v},R)),_&&h.jsx("p",{className:"ie-error",children:_}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:p||!m.trim(),onClick:$,children:p?"Importing…":t})]})]})}export{ea as A,km as B,bm as C,Vm as E,iw as I,Ax as L,sw as M,Mx as O,_o as P,Wi as R,ow as S,Px as a,qx as b,Xx as c,Zx as d,Qx as e,Dx as f,Am as g,ew as h,Jx as i,Wx as j,Fx as k,Vx as l,Bx as m,Yx as n,ta as o,Kx as p,Ux as q,Gx as r,$m as s,zx as t,Hx as u,ur as v,qi as w,Nx as x,hm as y}; diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index a060dab..d41f5eb 100644 --- a/packages/server/src/mdl_server/static/index.html +++ b/packages/server/src/mdl_server/static/index.html @@ -4,9 +4,9 @@ Modelith - + - + diff --git a/packages/server/src/mdl_server/static/sme.html b/packages/server/src/mdl_server/static/sme.html index 6d89fa5..de81992 100644 --- a/packages/server/src/mdl_server/static/sme.html +++ b/packages/server/src/mdl_server/static/sme.html @@ -4,9 +4,9 @@ Modelith Glossary - + - + From a282c829680f40667808b51d2120aa763b2d88e0 Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Mon, 12 Oct 2026 19:30:26 +1100 Subject: [PATCH 11/14] canvas: click-to-select edges (handles stay visible); clean horizontal routing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two usability fixes from real use. 1. Handles were hard to find — they showed only while hovering the thin line, so you had to hover-fight to grab them. A single click now SELECTS the edge: its route grip and both endpoint grips stay visible (and the line glows) until you click elsewhere; double-click still opens the editor. Grips are brighter with a glow on hover. No more hover-fighting. 2. A horizontal edge (source and target at the same height) produced a degenerate orthogonal path — zero-length corner curves that could render as a kink/stray mark. polyline() now simplifies the waypoints (dropping duplicate and collinear points), so a horizontal edge is a clean straight line. Tests: a horizontal-edge path assertion (straight line, no corners) + the existing 49. Full backend suite (0 failures), ruff, and all VS Code gates green. --- canvas/src/ModelCanvas.tsx | 36 +++++++++++++------ canvas/src/RelationshipEdge.tsx | 12 +++++-- canvas/src/edgeRouting.test.ts | 10 ++++++ canvas/src/edgeRouting.ts | 34 ++++++++++++++++-- canvas/src/styles.css | 10 +++--- ...m-JUW0CWvf.js => ModelDiagram-CxAF-B4F.js} | 2 +- .../{main-BINydbdB.js => main-BiJ4Tezc.js} | 2 +- .../{sme-GKXcuii9.js => sme-B1K9phBm.js} | 4 +-- ...tyles-BzOwieT6.css => styles-D9kpX-nz.css} | 2 +- ...{styles-CY4hT8Nm.js => styles-DqoimPMg.js} | 12 +++---- .../server/src/mdl_server/static/index.html | 6 ++-- .../server/src/mdl_server/static/sme.html | 6 ++-- 12 files changed, 99 insertions(+), 37 deletions(-) rename packages/server/src/mdl_server/static/assets/{ModelDiagram-JUW0CWvf.js => ModelDiagram-CxAF-B4F.js} (97%) rename packages/server/src/mdl_server/static/assets/{main-BINydbdB.js => main-BiJ4Tezc.js} (99%) rename packages/server/src/mdl_server/static/assets/{sme-GKXcuii9.js => sme-B1K9phBm.js} (99%) rename packages/server/src/mdl_server/static/assets/{styles-BzOwieT6.css => styles-D9kpX-nz.css} (59%) rename packages/server/src/mdl_server/static/assets/{styles-CY4hT8Nm.js => styles-DqoimPMg.js} (50%) diff --git a/canvas/src/ModelCanvas.tsx b/canvas/src/ModelCanvas.tsx index fa85d6e..ff8986e 100644 --- a/canvas/src/ModelCanvas.tsx +++ b/canvas/src/ModelCanvas.tsx @@ -219,6 +219,9 @@ export function ModelCanvas({ // and canvas-local; it feeds the existing dimmed/highlighted computation. const [hoveredAttr, setHoveredAttr] = useState(null); const [hoveredEdge, setHoveredEdge] = useState(null); + // a single click SELECTS a relationship (persistently shows its drag handles, so the + // user does not have to hover-fight the thin line); double-click still opens the editor. + const [selectedEdge, setSelectedEdge] = useState(null); // committed edge routes for the current view (relId -> {routeX?, sourceAnchor?, // targetAnchor?}). The live drag is kept inside the edge component; this holds only // committed values. @@ -633,21 +636,29 @@ export function ModelCanvas({ rel.from.entity !== selectedId && rel.to.entity !== selectedId; const hoverDim = hover.active && !hover.relsForAttr.has(r.id); const dimmed = selectDim || hoverDim; - // the hovered edge shows its drag handle (so it is grabbable without a click, - // which now double-clicks to open the editor) + // Show an edge's drag handles when it is hovered OR directly selected (clicked), + // so the user can click once and keep the handles up instead of hover-fighting the + // thin line. `edgeSelected` is the clicked edge; `nearSelected` is connected to the + // selected ENTITY (for z-lift only). const hovered = hoveredEdge === r.id; - const selected = selectedId !== null && rel !== undefined && + const edgeSelected = selectedEdge === r.id; + const nearSelected = selectedId !== null && rel !== undefined && (rel.from.entity === selectedId || rel.to.entity === selectedId); // Lift the hovered/selected edge ABOVE the node cards (default edges render // behind them) so its route and crow's-foot markers are never hidden while // you work it. Other edges stay behind the cards for a clean diagram. - const zIndex = hovered || selected ? 1000 : 0; - if (r.data?.dimmed === dimmed && r.data?.hovered === hovered && r.zIndex === zIndex) + const zIndex = hovered || edgeSelected || nearSelected ? 1000 : 0; + if ( + r.data?.dimmed === dimmed && + r.data?.hovered === hovered && + r.data?.edgeSelected === edgeSelected && + r.zIndex === zIndex + ) return r; - return { ...r, zIndex, data: { ...r.data!, dimmed, hovered } }; + return { ...r, zIndex, data: { ...r.data!, dimmed, hovered, edgeSelected } }; }), ); - }, [hover, hoveredEdge, query, selectedId, doc]); + }, [hover, hoveredEdge, selectedEdge, query, selectedId, doc]); // Frame the matches. In a large model the entities a search hits may be off-screen, // so highlighting alone is not enough — pan/zoom to the matched nodes (like Fit, but @@ -790,13 +801,16 @@ export function ModelCanvas({ edges={edges} nodeTypes={nodeTypes} edgeTypes={edgeTypes} - onNodeClick={(_, n) => onSelect(n.id)} - // Double-click opens the relationship editor; single-click/hover is reserved for - // the drag handle (hovering an edge reveals its route grip, and clicking it would - // otherwise pop the editor and steal the grab). + onNodeClick={(_, n) => { + onSelect(n.id); + setSelectedEdge(null); + }} + // Single-click SELECTS the edge (its handles stay up); double-click opens the editor. + onEdgeClick={(_, e) => setSelectedEdge(e.id)} onEdgeDoubleClick={(_, e) => !readOnly && setRelEdit(e.id)} onPaneClick={() => { onSelect(null); + setSelectedEdge(null); setRelEdit(null); }} onNodeDragStop={(_, n) => { diff --git a/canvas/src/RelationshipEdge.tsx b/canvas/src/RelationshipEdge.tsx index 1c226d4..c5804ab 100644 --- a/canvas/src/RelationshipEdge.tsx +++ b/canvas/src/RelationshipEdge.tsx @@ -13,6 +13,9 @@ export interface RelationshipEdgeData { /** true while the mouse is over this edge — shows the drag handle so it is grabbable * without a click (the editor now opens on double-click) */ hovered?: boolean; + /** true when this edge was clicked (selected) — keeps its handles visible so the user + * does not have to hover the thin line to work it */ + edgeSelected?: boolean; /** the x of the vertical segment, in flow coords. Undefined = automatic routing. */ routeX?: number; /** commit a new route (or null to reset to automatic). Absent = not draggable. */ @@ -159,7 +162,10 @@ export const RelationshipEdge = memo(function RelationshipEdge({ const srcMany = cardinality === "many_to_one" || cardinality === "many_to_many"; const tgtMany = cardinality === "one_to_many" || cardinality === "many_to_many"; - const cls = "rel-edge" + (selected ? " selected" : "") + (dimmed ? " dimmed" : ""); + const cls = + "rel-edge" + + (selected || data?.edgeSelected ? " selected" : "") + + (dimmed ? " dimmed" : ""); const composite = (data?.memberCount ?? 0) > 1; const onHover = data?.onHoverEdge; @@ -327,7 +333,7 @@ export const RelationshipEdge = memo(function RelationshipEdge({ {/* endpoint handles — drag an end ALONG its entity's border. Shown on hover/select. */} - {!!onAnchorChange && (data?.hovered || selected || dragAnchor != null) && ( + {!!onAnchorChange && (data?.hovered || data?.edgeSelected || selected || dragAnchor != null) && ( <> { expect(r.y).toBe(250); // clamped to bottom }); }); + +describe("orthogonalPath degenerate cases", () => { + it("a horizontal edge (same y) is a clean straight line, no stray corners", () => { + const sCard = { left: 0, right: 264, top: 600, bottom: 860 }; + const tCard = { left: 600, right: 864, top: 600, bottom: 860 }; + const r = orthogonalPath({ x: 264, y: 700 }, { x: 600, y: 700 }, 430, 1, -1, sCard, tCard); + expect(r.path).toBe("M 264 700 L 600 700"); // no Q corners + expect(r.targetOut).toEqual({ ox: -1, oy: 0 }); + }); +}); diff --git a/canvas/src/edgeRouting.ts b/canvas/src/edgeRouting.ts index 76712ba..cf8e076 100644 --- a/canvas/src/edgeRouting.ts +++ b/canvas/src/edgeRouting.ts @@ -143,9 +143,39 @@ function corner(prev: Pt, c: Pt, next: Pt, r: number): string { return `L ${t1.x} ${t1.y} Q ${c.x} ${c.y} ${t2.x} ${t2.y} `; } +/** Drop consecutive-identical and collinear waypoints, so a degenerate run (e.g. a + * horizontal edge whose source and target share a y, giving a zero-length vertical + * segment) collapses to a clean straight line instead of emitting zero-length corner + * curves that render as a kink or a stray mark. */ +function simplify(pts: Pt[]): Pt[] { + const out: Pt[] = []; + for (const p of pts) { + const prev = out[out.length - 1]; + if (prev && Math.abs(prev.x - p.x) < 0.5 && Math.abs(prev.y - p.y) < 0.5) continue; // dup + out.push(p); + } + // remove collinear middles (a-b-c where b lies on the a→c line) + const res: Pt[] = []; + for (let i = 0; i < out.length; i++) { + const a = res[res.length - 1]; + const b = out[i]; + const c = out[i + 1]; + if (a && c) { + const abx = b.x - a.x, aby = b.y - a.y, bcx = c.x - b.x, bcy = c.y - b.y; + // both segments horizontal, or both vertical -> b is redundant + if ((Math.abs(aby) < 0.5 && Math.abs(bcy) < 0.5) || (Math.abs(abx) < 0.5 && Math.abs(bcx) < 0.5)) { + continue; + } + } + res.push(b); + } + return res; +} + /** Build an orthogonal SVG path through the given waypoints with rounded corners. */ -function polyline(pts: Pt[]): string { - if (pts.length < 2) return ""; +function polyline(raw: Pt[]): string { + const pts = simplify(raw); + if (pts.length < 2) return pts.length === 1 ? `M ${pts[0].x} ${pts[0].y}` : ""; let d = `M ${pts[0].x} ${pts[0].y} `; for (let i = 1; i < pts.length - 1; i++) d += corner(pts[i - 1], pts[i], pts[i + 1], R); const last = pts[pts.length - 1]; diff --git a/canvas/src/styles.css b/canvas/src/styles.css index 495deb6..463368c 100644 --- a/canvas/src/styles.css +++ b/canvas/src/styles.css @@ -262,13 +262,15 @@ body { font-family: var(--font); background: var(--bg); color: var(--text); } the edge's default pointer so you get drag feedback anywhere along the segment, not only on the grip pill. */ .rel-handle, .rel-handle * { cursor: ew-resize !important; } -.rel-handle .rel-grip { fill: var(--accent); stroke: var(--bg); opacity: 0.95; } +.rel-handle .rel-grip { fill: var(--accent); stroke: var(--bg); opacity: 1; } .rel-handle .rel-grip-dot { fill: var(--bg); } -.rel-handle:hover .rel-grip { fill: var(--accent); filter: brightness(1.15); } +.rel-handle:hover .rel-grip { fill: var(--accent); filter: brightness(1.25) drop-shadow(0 0 3px var(--accent)); } /* draggable endpoint grips (slide an edge end along an entity's border) */ .rel-endpoint, .rel-endpoint * { cursor: move !important; } -.rel-endpoint .rel-endpoint-dot { fill: var(--accent); stroke: var(--bg); opacity: 0.95; } -.rel-endpoint:hover .rel-endpoint-dot { filter: brightness(1.2); } +.rel-endpoint .rel-endpoint-dot { fill: var(--accent); stroke: var(--bg); opacity: 1; } +.rel-endpoint:hover .rel-endpoint-dot { filter: brightness(1.3) drop-shadow(0 0 3px var(--accent)); } +/* a clicked (selected) edge glows so it is obvious its handles are live */ +.rel-edge.selected .rel-path { stroke-width: 2.2; filter: drop-shadow(0 0 2px var(--accent)); } .layout-menu-sep { height: 1px; margin: 4px 0; background: var(--border); } /* ---------- detail panel ---------- */ diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-JUW0CWvf.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-CxAF-B4F.js similarity index 97% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-JUW0CWvf.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-CxAF-B4F.js index e777f8c..2a96951 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-JUW0CWvf.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-CxAF-B4F.js @@ -1 +1 @@ -import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-CY4hT8Nm.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; +import{r,j as s}from"./client-DOmNpTln.js";import{f as T,v as _,w as O,x as R,E as D,B as P,C as z,y as A}from"./styles-DqoimPMg.js";const V={entity:D},$={relationship:R},l={breaking:"#f87171",additive:"#34d399",cosmetic:"#fcd34d"},N=["#5eead4","#fcd34d","#a78bfa","#fb923c","#38bdf8","#f472b6","#a3e635"],d="#64748b";function Y({subjectArea:u,severityByUlid:a,focusUlid:m,onSelect:c}){const[t,g]=r.useState(null),[f,w]=r.useState(null),[h,E]=r.useState(!0);r.useEffect(()=>{g(null),T(u).then(g).catch(n=>w(String(n)))},[u]);const{nodes:k,edges:M}=r.useMemo(()=>{if(!t)return{nodes:[],edges:[]};const n=new Map;t.subject_areas.forEach(e=>{let o=2166136261;for(let i=0;i[e.id,e])),x=a&&a.size>0,C=t.entities.map(e=>{var j;const o=(a==null?void 0:a.get(e.id))??(e.conceptual?a==null?void 0:a.get(e.conceptual.id):void 0),i=x?o?l[o]??d:d:(j=e.conceptual)!=null&&j.subject_area?n.get(e.conceptual.subject_area.id)??d:d;return{id:e.id,type:"entity",position:{x:0,y:0},data:{entity:e,color:i,dimmed:!!(x&&!o),highlighted:e.id===m,showTypes:h}}}),b=t.relationships.map(e=>({id:e.id,source:e.from.entity,target:e.to.entity,type:"relationship",data:{relationship:e,dimmed:!1}}));return{nodes:_(C,b,p),edges:b}},[t,a,m,h]);return f?s.jsx("p",{className:"sme-splash error",children:f}):t?t.entities.length?s.jsxs("div",{className:"erd-wrap",children:[s.jsxs("div",{className:"erd-bar",children:[s.jsxs("span",{className:"erd-count",children:[t.entities.length," entities · ",t.relationships.length," relationships",t.scope&&" · scoped"]}),s.jsxs("label",{className:"erd-toggle",children:[s.jsx("input",{type:"checkbox",checked:h,onChange:n=>E(n.target.checked)}),"show types"]}),a&&a.size>0&&s.jsxs("span",{className:"erd-legend",children:[s.jsx("span",{className:"sw",style:{background:l.breaking}})," breaking",s.jsx("span",{className:"sw",style:{background:l.additive}})," added",s.jsx("span",{className:"sw",style:{background:l.cosmetic}})," changed",s.jsx("span",{className:"sw",style:{background:d}})," unchanged"]})]}),s.jsx("div",{className:"erd-canvas",children:s.jsxs(O,{nodes:k,edges:M,nodeTypes:V,edgeTypes:$,fitView:!0,minZoom:.1,nodesConnectable:!1,onNodeClick:(n,p)=>c==null?void 0:c(p.id),onPaneClick:()=>c==null?void 0:c(null),onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},children:[s.jsx(P,{gap:16,color:"#1f2937"}),s.jsx(z,{showInteractive:!1}),s.jsx(A,{pannable:!0,zoomable:!0})]})})]}):s.jsx("p",{className:"sme-placeholder",children:"Nothing to draw — this subject area has no entities in it yet."}):s.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"})}export{Y as ModelDiagram}; diff --git a/packages/server/src/mdl_server/static/assets/main-BINydbdB.js b/packages/server/src/mdl_server/static/assets/main-BiJ4Tezc.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-BINydbdB.js rename to packages/server/src/mdl_server/static/assets/main-BiJ4Tezc.js index 84ac676..2bc5622 100644 --- a/packages/server/src/mdl_server/static/assets/main-BINydbdB.js +++ b/packages/server/src/mdl_server/static/assets/main-BiJ4Tezc.js @@ -1,2 +1,2 @@ -import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-CY4hT8Nm.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` +import{j as e,r as a,c as ie,R as le}from"./client-DOmNpTln.js";import{I as de,R as he,P as Y,h as ue,f as J,a as Z,g as ee,s as xe,A as pe,b as je,M as me,S as fe}from"./styles-DqoimPMg.js";function ge(s){return{canEdit:!s,mode:"direct",canArbitrate:!s,canCommit:!s}}function i({size:s=16,children:l}){return e.jsx("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:l})}const ye=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M12 3l7.5 4.5v9L12 21l-7.5-4.5v-9L12 3z"})}),we=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5 9-5z"}),e.jsx("path",{d:"M3 12l9 5 9-5"}),e.jsx("path",{d:"M3 16l9 5 9-5"})]}),ve=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.4"}),e.jsx("circle",{cx:"18",cy:"18",r:"2.4"}),e.jsx("path",{d:"M6 8.4v7.2M8.4 6H14a3 3 0 0 1 3 3v6.6"})]}),Me=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4v16M6 8h12"}),e.jsx("path",{d:"M6 8l-2.5 5a2.5 2.5 0 0 0 5 0L6 8zM18 8l-2.5 5a2.5 2.5 0 0 0 5 0L18 8z"}),e.jsx("path",{d:"M9 20h6"})]}),Ce=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M8 7l-4 5 4 5M16 7l4 5-4 5"})}),Ne=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M8 8l4-4 4 4M8 16l4 4 4-4"}),e.jsx("path",{d:"M4 12h16"})]}),Ee=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"15",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"15",width:"7",height:"5",rx:"1"})]}),ke=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"})}),Se=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M20 11a8 8 0 1 0-.5 4"}),e.jsx("path",{d:"M20 4v5h-5"})]}),Ie=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("path",{d:"M4 9h16"})]}),Le=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M4 7h9a4 4 0 0 1 4 4v3"}),e.jsx("path",{d:"M14 11l3 3 3-3"})]}),Re=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M8.5 12.5l2.5 2.5 4.5-5"})]}),Te=s=>e.jsxs(i,{...s,children:[e.jsx("path",{d:"M12 4l9 16H3l9-16z"}),e.jsx("path",{d:"M12 10v4M12 17.5v.5"})]}),ze=s=>e.jsxs(i,{...s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M15 9l-6 6M9 9l6 6"})]}),De=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M4 6h16M4 12h16M4 18h16"})}),Fe=s=>e.jsxs(i,{...s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),Be=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M6 6l12 12M18 6L6 18"})}),Pe=s=>e.jsx(i,{...s,children:e.jsx("path",{d:"M5 12h14M13 6l6 6-6 6"})});function Ae({doc:s,saColors:l,countByArea:j,activeAreas:h,onSetActive:x,open:w,onClose:g}){const m=s.subject_areas,p=h.size>0,y=r=>x(new Set([r])),f=r=>{const u=new Set(h);u.has(r)?u.delete(r):u.add(r),x(u)},v=j.get("")??0;return e.jsxs("aside",{className:"canvas-drawer"+(w?" open":""),"aria-hidden":!w,children:[e.jsxs("div",{className:"drawer-header",children:[e.jsxs("h2",{children:[e.jsx(Fe,{size:16})," Subject areas"]}),e.jsx("button",{className:"icon-btn",onClick:g,title:"Close","aria-label":"Close drawer",children:e.jsx(Be,{size:16})})]}),e.jsx("div",{className:"drawer-hint",children:p?`Showing ${h.size} of ${m.length} — click a domain to focus, tick to add.`:"Click a domain to show only it. Tick several to compare."}),e.jsx("button",{className:"sa-all"+(p?"":" active"),onClick:()=>x(new Set),disabled:!p,children:"Show all"}),e.jsxs("div",{className:"sa-list",children:[m.map(r=>{const u=h.has(r.id),k=j.get(r.id)??r.member_count??0;return e.jsxs("div",{className:"sa-row"+(u?" active":""),onClick:()=>y(r.id),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),y(r.id))},title:`Focus ${r.name}`,children:[e.jsx("input",{type:"checkbox",checked:u,onClick:b=>b.stopPropagation(),onChange:()=>f(r.id),"aria-label":`Include ${r.name}`}),e.jsx("span",{className:"sa-chip",style:{background:l.get(r.id)}}),e.jsx("span",{className:"sa-name",children:r.name}),e.jsx("span",{className:"sa-count",children:k})]},r.id)}),v>0&&e.jsxs("div",{className:"sa-row muted",title:"Entities with no subject area",children:[e.jsx("span",{className:"sa-chip none"}),e.jsx("span",{className:"sa-name",children:"No subject area"}),e.jsx("span",{className:"sa-count",children:v})]})]})]})}function _e({doc:s,diagnostics:l,query:j,onQuery:h,onSubmitQuery:x,showTypes:w,onToggleTypes:g,collapseDetail:m,onToggleCollapse:p,onFitView:y,onRelayout:f,onResetLayout:v,onRefresh:r,readOnly:u,dirty:k,panelTab:b,onPanelTab:q,onNewEntity:A,exec:S,onImported:I,onImportBatch:_,openImport:$,onToggleDrawer:z,drawerOpen:D,filterCount:K}){const M=(l==null?void 0:l.items.filter(o=>o.severity==="error").length)??0,F=(l==null?void 0:l.items.filter(o=>o.severity==="warning").length)??0,E=(o,L,B,O,H)=>e.jsxs("button",{className:"grp-btn"+(b===o?" active":""),onClick:()=>q(o),title:O,children:[L,e.jsx("span",{children:B}),H&&e.jsx("span",{className:"grp-badge","aria-label":"uncommitted changes"})]});return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row context",children:[e.jsxs("button",{className:"hamburger"+(D?" active":""),onClick:z,title:D?"Hide subject areas & layout":"Subject areas & layout","aria-label":"Toggle subject-area & layout drawer","aria-expanded":D,children:[e.jsx(De,{size:18}),K>0&&e.jsx("span",{className:"hamburger-badge",children:K})]}),e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"logo",children:"◮"}),e.jsx("span",{className:"brand-name",children:"Modelith"}),e.jsx("span",{className:"project-name",children:s.project.name}),u&&e.jsx("span",{className:"chip",children:"read-only"})]}),e.jsx("input",{className:"search",type:"search",placeholder:"Search entities & attributes… ( / , Enter jumps )",value:j,onChange:o=>h(o.target.value),onKeyDown:o=>{o.key==="Enter"&&x()},id:"mdl-search"}),e.jsxs("div",{className:"stats",children:[e.jsxs("span",{className:"stat-item",title:"entities",children:[e.jsx(Ie,{size:14}),s.counts.entities]}),e.jsxs("span",{className:"stat-item",title:"relationships",children:[e.jsx(Le,{size:14}),s.counts.relationships]}),l&&e.jsx("span",{className:"diag-chip"+(M?" err":F?" warn":" ok"),title:l.items.map(o=>`${o.code} ${o.message}`).join(` `)||"model valid",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),M]}):F?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14}),F]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:14}),"valid"]})})]})]}),e.jsxs("div",{className:"topbar-row actions",children:[!u&&e.jsxs("button",{className:"tool-btn primary",onClick:A,title:"New entity (n)",children:[e.jsx(ye,{size:15}),e.jsx("span",{children:"Entity"})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Panels",children:[e.jsx("span",{className:"grp-tag",children:"Panels"}),E("ontology",e.jsx(be,{size:15}),"Ontology","Ontology browser"),E("layers",e.jsx(we,{size:15}),"Layers","Four-layer stack & coverage"),E("changes",e.jsx(ve,{size:15}),"Changes",k?"Uncommitted changes":"Changes",k),E("decisions",e.jsx(Me,{size:15}),"Decisions","Decision ledger")]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"View",children:[e.jsx("span",{className:"grp-tag",children:"View"}),e.jsx("button",{className:"grp-btn icon-only"+(w?" active":""),onClick:g,title:"Toggle data types","aria-label":"Toggle data types",children:e.jsx(Ce,{size:15})}),e.jsx("button",{className:"grp-btn icon-only"+(m?" active":""),onClick:p,title:"Collapse to keys (PK + FK only) — readable for large models","aria-label":"Collapse to keys",children:e.jsx(Ne,{size:15})}),e.jsx(Ke,{onRelayout:f,onReset:v}),e.jsx("button",{className:"grp-btn icon-only",onClick:y,title:"Fit view","aria-label":"Fit view",children:e.jsx(ke,{size:15})})]}),e.jsxs("div",{className:"btn-group",role:"group","aria-label":"Data",children:[e.jsx("span",{className:"grp-tag",children:"Data"}),e.jsx("button",{className:"grp-btn icon-only",onClick:r,title:"Refresh from disk (picks up terminal / external edits)","aria-label":"Refresh from disk",children:e.jsx(Se,{size:15})}),e.jsx(de,{exec:S,canEdit:!u,onImported:I,submitLabel:"Import",buttonClass:"grp-btn",applyBatch:_,openImport:$})]})]})]})}const U=["LR","TB","RL","BT"],$e={LR:0,TB:90,RL:180,BT:270},se={LR:"left → right",TB:"top → bottom",RL:"right → left",BT:"bottom → top"};function Ke({onRelayout:s,onReset:l}){const[j,h]=a.useState(!1),[x,w]=a.useState("LR"),[g,m]=a.useState("auto"),p=a.useRef(null);a.useEffect(()=>{if(!j)return;const r=u=>{p.current&&!p.current.contains(u.target)&&h(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[j]);const y=r=>{m(r),s(r,x)},f=r=>{y(r),h(!1)},v=()=>{const r=U[(U.indexOf(x)+1)%U.length];w(r),s(g,r)};return e.jsxs("div",{className:"layout-picker",ref:p,children:[e.jsx("button",{className:"grp-btn icon-only",onClick:()=>y("auto"),title:"Auto-layout","aria-label":"Auto-layout",children:e.jsx(Ee,{size:15})}),e.jsx("button",{className:"grp-btn icon-only caret"+(j?" active":""),onClick:()=>h(r=>!r),title:"Layout style","aria-label":"Layout style",children:"▾"}),e.jsx("button",{className:"grp-btn icon-only",onClick:v,title:`Flow direction: ${se[x]} (click to rotate)`,"aria-label":`Flow direction: ${se[x]}`,children:e.jsx("span",{className:"dir-arrow",style:{transform:`rotate(${$e[x]}deg)`},children:e.jsx(Pe,{size:15})})}),j&&e.jsxs("div",{className:"layout-menu",role:"menu",children:[e.jsx("button",{onClick:()=>f("auto"),children:"Auto (by size)"}),e.jsx("button",{onClick:()=>f("hierarchical"),children:"Hierarchical"}),e.jsx("button",{onClick:()=>f("clustered"),children:"Clustered (by area)"}),e.jsx("button",{onClick:()=>f("grid"),children:"Grid"}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"layout-menu-sep",role:"separator"}),e.jsx("button",{onClick:()=>{l(),h(!1)},title:"Clear saved positions and routes for this view",children:"Reset layout"})]})]})]})}function He(){const[s,l]=a.useState(null),[j,h]=a.useState(null),[x,w]=a.useState(null),[g,m]=a.useState(null),[p,y]=a.useState(""),[f,v]=a.useState(!0),[r,u]=a.useState(!1),[k,b]=a.useState(()=>new Set),[q,A]=a.useState(null),[S,I]=a.useState(null),[_,$]=a.useState(!1),[z,D]=a.useState(()=>new Set),[K,M]=a.useState(!1),[F,E]=a.useState(0),o=a.useRef(null),L=a.useRef(""),B=a.useRef(!1),O=a.useMemo(()=>{const t=new Map;return s==null||s.subject_areas.forEach((c,n)=>t.set(c.id,Y[n%Y.length])),t},[s]),H=a.useMemo(()=>{const t=new Map;if(!s)return t;const c=new Map;return s.subject_areas.forEach(n=>{(n.members??[]).forEach(d=>c.set(d,n.id))}),s.entities.forEach(n=>{var N,Q,X;const P=((N=n.conceptual)!=null&&N.id?c.get(n.conceptual.id):void 0)??((X=(Q=n.conceptual)==null?void 0:Q.subject_area)==null?void 0:X.id)??"";t.set(n.id,P)}),t},[s]),te=a.useMemo(()=>{const t=new Map;return H.forEach(c=>t.set(c,(t.get(c)??0)+1)),t},[H]),R=(s==null?void 0:s.read_only)??!0,ne=a.useMemo(()=>ge(R),[R]),ae=a.useMemo(()=>ue(),[]),V=a.useMemo(()=>new URLSearchParams(window.location.search),[]),T=V.get("minimal")==="1";a.useEffect(()=>{T&&u(!0)},[T]);const re=a.useCallback(t=>{b(c=>{const n=new Set(c);return n.has(t)?n.delete(t):n.add(t),n})},[]),ce=V.get("import")==="1",W=a.useRef(!1),C=a.useCallback(()=>{J().then(l).catch(t=>w(String(t))),Z().then(h).catch(()=>h(null)),ee().then(t=>M(!!(t.git&&!t.clean))).catch(()=>M(!1)),E(t=>t+1)},[]);a.useEffect(C,[C]),a.useEffect(()=>{const t=setInterval(()=>{J().then(c=>{l(n=>n&&c.fingerprint===n.fingerprint?n:(B.current||(L.current=c.fingerprint),T||(Z().then(h).catch(()=>h(null)),ee().then(d=>M(!!(d.git&&!d.clean))).catch(()=>M(!1))),E(d=>d+1),c))}).catch(()=>{})},3e3);return()=>clearInterval(t)},[T]),a.useEffect(()=>{s!=null&&s.fingerprint&&(L.current=s.fingerprint)},[s]);const G=a.useCallback(async(t,c)=>{if(s){B.current=!0;try{const n=await xe(t,c,L.current||s.fingerprint);return n!=null&&n.fingerprint&&(L.current=n.fingerprint),C(),n}catch(n){throw n instanceof pe&&n.status===409?(m("Model changed on disk — view refreshed, please retry."),C()):m(n instanceof Error?n.message:String(n)),n}finally{B.current=!1}}},[s,C]);a.useEffect(()=>{if(!g)return;const t=setTimeout(()=>m(null),5e3);return()=>clearTimeout(t)},[g]),a.useEffect(()=>{if(!s||W.current)return;const t=V.get("focus");if(!t)return;const c=s.entities.find(n=>{var d;return n.name===t||((d=n.conceptual)==null?void 0:d.name)===t});c&&(W.current=!0,requestAnimationFrame(()=>{var n;return(n=o.current)==null?void 0:n.focusEntity(c.id)}))},[s,V]);const oe=a.useCallback(()=>{var n;if(!s)return;const t=p.trim().toLowerCase();if(!t)return;const c=s.entities.find(d=>{var N;return(d.name.toLowerCase()+" "+(((N=d.conceptual)==null?void 0:N.name.toLowerCase())??"")+" "+d.attributes.map(Q=>Q.name.toLowerCase()).join(" ")).includes(t)});c&&((n=o.current)==null||n.focusEntity(c.id))},[s,p]);return a.useEffect(()=>{const t=c=>{var d,P,N;const n=(d=document.activeElement)==null?void 0:d.tagName;n==="INPUT"||n==="TEXTAREA"||n==="SELECT"||(c.key==="/"&&(c.preventDefault(),(P=document.getElementById("mdl-search"))==null||P.focus()),c.key==="n"&&!R&&((N=o.current)==null||N.newEntity()),c.key==="Escape"&&(A(null),y(""),I(null)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[R]),x?e.jsxs("div",{className:"splash error",children:[e.jsxs("h1",{children:["◮"," Modelith"]}),e.jsx("p",{children:"Could not load the model:"}),e.jsx("pre",{children:x}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl serve"})," pointed at a model directory?"]})]}):s?e.jsxs("div",{className:"app",children:[!T&&e.jsx(_e,{doc:s,diagnostics:j,query:p,onQuery:y,onSubmitQuery:oe,showTypes:f,onToggleTypes:()=>v(t=>!t),collapseDetail:r,onToggleCollapse:()=>u(t=>!t),onFitView:()=>{var t;return(t=o.current)==null?void 0:t.fitView()},onRelayout:(t,c)=>{var n;return(n=o.current)==null?void 0:n.relayout(t,c)},onResetLayout:()=>{var t;return(t=o.current)==null?void 0:t.resetLayout()},onRefresh:C,readOnly:R,dirty:K,panelTab:S,onPanelTab:t=>I(c=>c===t?null:t),onNewEntity:()=>{var t;return(t=o.current)==null?void 0:t.newEntity()},exec:G,onImported:C,onImportBatch:je,openImport:ce,onToggleDrawer:()=>$(t=>!t),drawerOpen:_,filterCount:z.size}),e.jsxs("div",{className:"canvas-wrap",children:[e.jsx(me,{doc:s,caps:ne,exec:G,selectedId:S?null:q,onSelect:A,query:p,showTypes:f,collapseDetail:r,expandedEntities:k,onToggleExpand:re,activeAreas:z,onError:m,handleRef:o,layoutStore:ae}),!T&&e.jsx(Ae,{doc:s,saColors:O,countByArea:te,activeAreas:z,onSetActive:D,open:_,onClose:()=>$(!1)}),S&&e.jsx(fe,{tab:S,onClose:()=>I(null),readOnly:R,refreshKey:F,onModelChanged:C,onFocusEntity:t=>{var c;I(null),(c=o.current)==null||c.focusEntity(t)}}),g&&e.jsx("div",{className:"toast",children:g})]})]}):e.jsxs("div",{className:"splash",children:["◮"," loading model…"]})}function Ve(){return e.jsx(he,{children:e.jsx(He,{})})}ie.createRoot(document.getElementById("root")).render(e.jsx(le.StrictMode,{children:e.jsx(Ve,{})})); diff --git a/packages/server/src/mdl_server/static/assets/sme-GKXcuii9.js b/packages/server/src/mdl_server/static/assets/sme-B1K9phBm.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-GKXcuii9.js rename to packages/server/src/mdl_server/static/assets/sme-B1K9phBm.js index a29f54c..f9f1e96 100644 --- a/packages/server/src/mdl_server/static/assets/sme-GKXcuii9.js +++ b/packages/server/src/mdl_server/static/assets/sme-B1K9phBm.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-JUW0CWvf.js","assets/client-DOmNpTln.js","assets/styles-CY4hT8Nm.js","assets/styles-BzOwieT6.css"])))=>i.map(i=>d[i]); -import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-CY4hT8Nm.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-JUW0CWvf.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-CxAF-B4F.js","assets/client-DOmNpTln.js","assets/styles-DqoimPMg.js","assets/styles-D9kpX-nz.css"])))=>i.map(i=>d[i]); +import{r as a,j as e,c as Ge,R as Ke}from"./client-DOmNpTln.js";import{p as xe,c as be,d as ge,e as Ve,i as ve,I as Ue,R as Fe,M as Te,O as Ye,L as Je,j as Qe,k as Xe,A as Ze,l as es,m as ss,n as ns,o as ts,q as as,s as rs,f as ie,r as is,t as ls,u as cs,b as os}from"./styles-DqoimPMg.js";/* empty css */const ds="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function he(s,n){let t="";for(let i=0;i>=5n;return t}function Ne(){const s=BigInt(Date.now())&(1n<<48n)-1n,n=new Uint8Array(10);crypto.getRandomValues(n);let t=0n;for(const i of n)t=t<<8n|BigInt(i);return he(s,10)+he(t,16)}const hs={create_entity:["id","conceptual_id"],create_relationship:["id","from_fk_id"],create_subject_area:["id"],create_term:["id"],create_domain:["id"],create_code_set:["id"],create_key_group:["id"],create_category:["id"],add_attribute:["id"]};function ms(s,n){const t=hs[s];if(!t)return n;const i={...n};for(const l of t)i[l]||(i[l]=Ne());return i}function ye(s,n){if(s.startsWith("create_")||s==="add_attribute")return`${s}:${n.id??n.attribute_id}`;const t=n.id??n.entity_id??"",i=n.attribute_id??"";return i?`${s}:${t}:${i}`:`${s}:${t}`}function us({subjectArea:s,describe:n}){const[t,i]=a.useState([]),[l,m]=a.useState(null),[c,r]=a.useState(!1),d=a.useRef(null),v=a.useCallback(async(o,f)=>{f=ms(o,f),o==="set_alignment"&&f.status===void 0&&(f={...f,status:"proposed"});const N=ye(o,f),{label:_,before:B,after:E}=n(o,f);return i(S=>{const C=S.filter(R=>R.key!==N);if(o.startsWith("delete_")){const R=f.id??f.entity_id;if(R&&S.some(w=>w.op.startsWith("create_")&&w.payload.id===R))return C.filter(w=>w.payload.id!==R)}return[...C,{op:o,payload:f,label:_,before:B,after:E,key:N}]}),{ok:!0,fingerprint:"",created_id:f.id??null,diagnostics:[]}},[n]);a.useEffect(()=>{if(!t.length){m(null);return}const o=setTimeout(()=>{var N;(N=d.current)==null||N.abort();const f=new AbortController;d.current=f,r(!0),xe(t.map(_=>({op:_.op,payload:_.payload})),s,f.signal).then(m).catch(_=>{_.name!=="AbortError"&&m(null)}).finally(()=>r(!1))},250);return()=>clearTimeout(o)},[t,s]);const j=a.useCallback(o=>{i(f=>f.filter(N=>N.key!==o))},[]),b=a.useCallback(()=>i([]),[]);return a.useMemo(()=>({pending:t,previewDoc:(l==null?void 0:l.model)??null,previewDiff:(l==null?void 0:l.diff)??null,diagnostics:(l==null?void 0:l.diagnostics)??[],failure:l&&l.failed_index!==null?{index:l.failed_index,error:l.error??"invalid change"}:null,busy:c,exec:v,drop:j,clear:b}),[t,l,c,v,j,b])}function ps(s){const n=new Map;for(const i of s)for(const l of["id","conceptual_id","from_fk_id"]){const m=i.payload[l];i.op.startsWith("create_")&&typeof m=="string"&&n.set(m,i.key)}if(!n.size)return new Set;const t=new Set;for(const i of s)if(!i.op.startsWith("create_"))for(const l of Object.values(i.payload))typeof l=="string"&&n.has(l)&&(t.add(i.key),t.add(n.get(l)));return t}function js({user:s}){const[n,t]=a.useState(null);return a.useEffect(()=>{be(s).then(t).catch(()=>{})},[s]),!(n!=null&&n.ok)||!n.git?null:n.read_only?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"browse only — editing is disabled on this deployment"})]}):n.dirty?e.jsxs("div",{className:"git-banner warn",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"uncommitted changes in the working tree — a proposal will be refused until they are committed or discarded"})]}):n.on_base?e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"protected — your edits become a pull request"})]}):e.jsxs("div",{className:"git-banner",children:[e.jsx("code",{children:n.branch}),e.jsx("span",{children:"your proposal branch"}),n.behind?e.jsxs("span",{className:"dim",children:["· ",n.base_branch," is ",n.behind," ahead"]}):null]})}function fs({exec:s,canEdit:n,stagedMembers:t}){const[i,l]=a.useState([]),[m,c]=a.useState(""),[r,d]=a.useState(null),[v,j]=a.useState(""),[b,o]=a.useState(new Set),[f,N]=a.useState("ancestors"),[_,B]=a.useState(1),[E,S]=a.useState(null),[C,R]=a.useState(new Set),[A,w]=a.useState(null);a.useEffect(()=>{ge().then(h=>{l(h.subject_areas),c(k=>{var D;return k||((D=h.subject_areas[0])==null?void 0:D.id)||""})}).catch(h=>w(String(h)))},[]),a.useEffect(()=>{m&&(S(null),o(new Set),Ve(m).then(d).catch(h=>w(String(h))))},[m]);const $=a.useMemo(()=>t[m]??(r==null?void 0:r.members)??[],[t,m,r]),I=a.useMemo(()=>{const h=new Map;for(const k of[...(r==null?void 0:r.included)??[],...(r==null?void 0:r.available)??[]])h.set(k.id,k);return h},[r]),g=v.trim().toLowerCase(),O=h=>!g||h.name.toLowerCase().includes(g),u=a.useMemo(()=>new Set($),[$]),M=a.useMemo(()=>$.map(h=>I.get(h)).filter(h=>!!h&&O(h)),[$,I,g]),z=a.useMemo(()=>[...I.values()].filter(h=>!u.has(h.id)&&O(h)),[I,u,g]),W=a.useCallback(h=>{if(!r)return;const k=h.filter(q=>!(r.members??[]).includes(q)).length,D=(r.members??[]).filter(q=>!h.includes(q)).length;s("set_subject_area_members",{id:r.id,members:h,__label:`${r.name}: ${h.length} objects (+${k} −${D})`})},[r,s]),H=(h,k)=>{const D=k?[...$,...h.filter(q=>!u.has(q))]:$.filter(q=>!h.includes(q));W(D),o(new Set)},G=(h,k,D)=>{const q=new Set(h);q.has(k)?q.delete(k):q.add(k),D(q)},T=()=>{if(!r)return;const h=b.size?[...b]:$;if(!h.length){w("add an object first, or select one to expand from");return}w(null),ve(r.id,{seeds:h,direction:f,levels:_}).then(k=>{S(k.hops),R(new Set(k.added))}).catch(k=>w(String(k)))},J=()=>{H([...C],!0),S(null)};if(A&&!r)return e.jsx("p",{className:"sme-splash error",children:A});if(!i.length)return e.jsx("p",{className:"sme-placeholder",children:"No subject areas yet."});const x=((r==null?void 0:r.inconsistent)??[]).filter(h=>!u.has(h));return e.jsxs("div",{className:"sa-editor",children:[e.jsx("nav",{className:"sme-nav",children:i.map(h=>e.jsxs("button",{className:"sme-sa"+(h.id===m?" active":""),onClick:()=>c(h.id),title:h.definition??void 0,children:[h.name,e.jsx("span",{className:"sme-sa-count",children:(t[h.id]??h.members).length})]},h.id))}),e.jsxs("div",{className:"sa-main",children:[e.jsxs("div",{className:"sa-head",children:[e.jsx("h2",{children:(r==null?void 0:r.name)??"…"}),(r==null?void 0:r.definition)&&e.jsx("p",{className:"sme-muted",children:r.definition}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:v,onChange:h=>j(h.target.value)})]}),x.length>0&&n&&e.jsxs("div",{className:"sa-nudge",children:[x.length," object",x.length>1?"s are":" is"," homed in this area but not included.",e.jsxs("button",{className:"sme-link",onClick:()=>H(x,!0),children:["Add ",x.length>1?"them all":"it"]})]}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${z.length})`,rows:z,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>!u.has(h)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!z.length,onClick:()=>H(z.map(h=>h.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!b.size,onClick:()=>H([...b].filter(h=>u.has(h)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!n||!M.length,onClick:()=>H(M.map(h=>h.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${M.length})`,rows:M,picked:b,onToggle:h=>G(b,h,o),homedHere:(r==null?void 0:r.homed_here)??[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:f,onChange:h=>N(h.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:_,onChange:h=>B(Math.max(1,Math.min(10,Number(h.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!n,children:"Preview"})]}),A&&e.jsx("p",{className:"sme-error-line",children:A}),E&&e.jsxs("div",{className:"sa-hops",children:[E.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),E.map(h=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:C.has(h.id),onChange:()=>G(C,h.id,R)}),e.jsx("span",{className:"sa-hop-name",children:h.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",h.via_name," · ",h.direction.replace(/s$/,""),", level ",h.level]})]},h.id)),E.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>S(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",onClick:J,disabled:!C.size,children:["Add ",C.size," object",C.size===1?"":"s"]})]})]})]})]})]})}function ee({title:s,rows:n,picked:t,onToggle:i,homedHere:l}){const m=a.useMemo(()=>new Set(l),[l]);return e.jsxs("div",{className:"sa-pane",children:[e.jsx("h3",{children:s}),e.jsxs("ul",{children:[n.map(c=>e.jsxs("li",{className:"sa-row"+(t.has(c.id)?" picked":""),onClick:()=>i(c.id),children:[e.jsx("input",{type:"checkbox",readOnly:!0,checked:t.has(c.id)}),e.jsx("span",{className:"sa-row-name",children:c.name}),m.has(c.id)?e.jsx("span",{className:"sme-badge",children:"home"}):e.jsx("span",{className:"sme-badge borrowed",children:"borrowed"})]},c.id)),!n.length&&e.jsx("li",{className:"sme-empty",children:"nothing here"})]})]})}function xs({objects:s,onCreate:n,onClose:t}){const[i,l]=a.useState(""),[m,c]=a.useState(""),[r]=a.useState(s),[d,v]=a.useState([]),[j,b]=a.useState(new Set),[o,f]=a.useState(""),[N,_]=a.useState("ancestors"),[B,E]=a.useState(1),[S,C]=a.useState(null),[R,A]=a.useState(new Set),[w,$]=a.useState(""),[I,g]=a.useState(null);a.useEffect(()=>{ge().then(x=>{x.subject_areas[0]&&$(x.subject_areas[0].id)}).catch(()=>{})},[]);const O=a.useMemo(()=>new Set(d),[d]),u=o.trim().toLowerCase(),M=x=>!u||x.name.toLowerCase().includes(u),z=a.useMemo(()=>d.map(x=>r.find(h=>h.id===x)).filter(x=>!!x&&M(x)),[d,r,u]),W=a.useMemo(()=>r.filter(x=>!O.has(x.id)&&M(x)),[r,O,u]),H=(x,h)=>{v(k=>h?[...k,...x.filter(D=>!k.includes(D))]:k.filter(D=>!x.includes(D))),b(new Set)},G=(x,h,k)=>{const D=new Set(x);D.has(h)?D.delete(h):D.add(h),k(D)},T=()=>{const x=j.size?[...j]:d;if(!x.length){g("pick an object to expand from first");return}w&&(g(null),ve(w,{seeds:x,direction:N,levels:B}).then(h=>{const k=h.hops.filter(D=>!O.has(D.id));C(k),A(new Set(k.map(D=>D.id)))}).catch(h=>g(String(h))))},J=()=>{i.trim()&&n(i.trim(),m.trim(),d)};return e.jsx("div",{className:"sme-modal-backdrop",onClick:t,children:e.jsxs("div",{className:"sme-modal sa-modal",onClick:x=>x.stopPropagation(),children:[e.jsx("h2",{children:"New subject area"}),e.jsx("p",{className:"sme-hint",children:"A subject area is a filtered view of the model. Name it and choose what it contains — both land as one proposal."}),e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{autoFocus:!0,value:i,placeholder:"e.g. UseCase-ApraStressTesting",onChange:x=>l(x.target.value),onKeyDown:x=>x.key==="Enter"&&d.length===0&&J()})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition (optional)"}),e.jsx("input",{value:m,placeholder:"what this view is for",onChange:x=>c(x.target.value)})]})]}),e.jsx("input",{className:"sme-search sa-filter",type:"search",placeholder:"Filter both lists…",value:o,onChange:x=>f(x.target.value)}),e.jsxs("div",{className:"sa-panes",children:[e.jsx(ee,{title:`Available (${W.length})`,rows:W,picked:j,onToggle:x=>G(j,x,b),homedHere:[]}),e.jsxs("div",{className:"sa-controls",children:[e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>!O.has(x)),!0),title:"Add the selected objects",children:"→"}),e.jsx("button",{className:"sme-secondary",disabled:!W.length,onClick:()=>H(W.map(x=>x.id),!0),title:"Add everything matching the filter",children:"»"}),e.jsx("button",{className:"sme-secondary",disabled:!j.size,onClick:()=>H([...j].filter(x=>O.has(x)),!1),title:"Remove the selected objects",children:"←"}),e.jsx("button",{className:"sme-secondary",disabled:!z.length,onClick:()=>H(z.map(x=>x.id),!1),title:"Remove everything matching the filter",children:"«"})]}),e.jsx(ee,{title:`Included (${z.length})`,rows:z,picked:j,onToggle:x=>G(j,x,b),homedHere:[]})]}),e.jsxs("div",{className:"sa-expand",children:[e.jsx("h3",{children:"Add related objects"}),e.jsxs("div",{className:"sa-expand-row",children:[e.jsxs("select",{value:N,onChange:x=>_(x.target.value),children:[e.jsx("option",{value:"ancestors",children:"ancestors — the parents its keys point at"}),e.jsx("option",{value:"descendants",children:"descendants — what points at it"}),e.jsx("option",{value:"both",children:"both"})]}),e.jsxs("label",{children:["levels",e.jsx("input",{type:"number",min:1,max:10,value:B,onChange:x=>E(Math.max(1,Math.min(10,Number(x.target.value))))})]}),e.jsx("button",{className:"sme-secondary",onClick:T,disabled:!w,title:w?"Preview related objects to add":"Available once the model has at least one saved subject area to walk the graph from",children:"Preview"})]}),S&&e.jsxs("div",{className:"sa-hops",children:[S.length===0&&e.jsx("p",{className:"sme-muted",children:"nothing new to add"}),S.map(x=>e.jsxs("label",{className:"sa-hop",children:[e.jsx("input",{type:"checkbox",checked:R.has(x.id),onChange:()=>G(R,x.id,A)}),e.jsx("span",{className:"sa-hop-name",children:x.name}),e.jsxs("span",{className:"sa-hop-why",children:["via ",x.via_name," · ",x.direction.replace(/s$/,""),", level ",x.level]})]},x.id)),S.length>0&&e.jsxs("div",{className:"sa-hop-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:()=>C(null),children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!R.size,onClick:()=>{H([...R],!0),C(null)},children:["Add ",R.size]})]})]})]}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:t,children:"Cancel"}),e.jsxs("button",{className:"sme-primary",disabled:!i.trim(),onClick:J,children:["Create",d.length>0&&` with ${d.length} object${d.length===1?"":"s"}`]})]})]})})}const bs=new Set(["set_definition","set_stewardship","set_subject_area","set_pattern","rename_entity","add_attribute","update_attribute","delete_attribute","set_alignment","clear_alignment","set_term_map","clear_term_map","update_synonyms","set_object_definition","set_subject_area_members","create_subject_area","update_subject_area","create_entity","delete_entity","create_relationship","rename_relationship","update_relationship","delete_relationship"]);function gs({doc:s,subjectArea:n,onSubjectArea:t,exec:i,canEdit:l,direct:m=!1,onSelectEntity:c,onImported:r,onImportPreview:d,openImport:v=!1,prefillImport:j="",query:b="",busy:o}){var I;const[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(!1),[C,R]=a.useState(null),A=a.useRef(null),w=a.useMemo(()=>({canEdit:l,mode:m?"direct":"staged",allow:m?void 0:bs,canArbitrate:m,canCommit:m}),[l,m]),$=a.useCallback(g=>{N(g),g&&(c==null||c(g))},[c]);return e.jsxs("div",{className:"sme-model-view",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsxs("div",{className:"sme-nav-head",children:[e.jsx("span",{children:"Subject areas"}),l&&e.jsx("button",{className:"sme-nav-add",title:"New subject area",onClick:()=>S(!0),children:"+"})]}),e.jsxs("button",{className:"sme-sa"+(n===""?" active":""),onClick:()=>t(""),children:["Whole model",e.jsx("span",{className:"sme-sa-count",children:((I=s.counts)==null?void 0:I.entities_total)??s.entities.length})]}),s.subject_areas.map(g=>e.jsxs("button",{className:"sme-sa"+(n===g.id?" active":""),onClick:()=>t(g.id),title:g.definition??void 0,children:[g.name,e.jsx("span",{className:"sme-sa-count",children:g.member_count??0})]},g.id))]}),E&&e.jsx(xs,{objects:s.entities.flatMap(g=>g.conceptual?[{id:g.conceptual.id,kind:"conceptual_entity",name:g.conceptual.name,definition:g.conceptual.definition??null,synonyms:[],subject_area:g.conceptual.subject_area??null,stewardship:null,ontology:null,where_used:[]}]:[]),onClose:()=>S(!1),onCreate:(g,O,u)=>{const M=Ne();i("create_subject_area",{name:g,...O?{definition:O}:{},id:M}),u.length&&i("set_subject_area_members",{id:M,members:u}),S(!1),t(M)}}),e.jsxs("div",{className:"erd-wrap",children:[e.jsxs("div",{className:"erd-bar",children:[e.jsxs("span",{className:"erd-count",children:[s.entities.length," entities · ",s.relationships.length," relationships",s.scope&&" · scoped"]}),l&&e.jsx("button",{className:"erd-action",onClick:()=>{var g;return(g=A.current)==null?void 0:g.newEntity()},title:"Add an entity (n)",children:"+ Entity"}),e.jsx("span",{className:"erd-hint",children:"drag between entities to relate them"}),e.jsxs("span",{className:"erd-group",children:[e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.relayout()},title:"Auto-arrange the diagram",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⟲"}),"Re-layout"]}),e.jsxs("button",{className:"erd-action ghost",onClick:()=>{var g;return(g=A.current)==null?void 0:g.fitView()},title:"Fit the whole model in view",children:[e.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"⛶"}),"Fit"]})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsxs("span",{className:"erd-group",children:[e.jsx("button",{className:"erd-action ghost"+(_==="ontology"?" on":""),onClick:()=>B(g=>g==="ontology"?null:"ontology"),children:"Ontology"}),e.jsx("button",{className:"erd-action ghost"+(_==="layers"?" on":""),onClick:()=>B(g=>g==="layers"?null:"layers"),children:"Layers"})]}),e.jsx("span",{className:"erd-sep","aria-hidden":"true"}),e.jsx(Ue,{exec:i,canEdit:l,onImported:r,onPreview:d,openImport:v,prefillImport:j}),o&&e.jsx("span",{className:"erd-busy",children:"updating…"}),!l&&e.jsx("span",{className:"sme-chip",children:"read-only"}),C&&e.jsx("span",{className:"erd-error",children:C})]}),e.jsxs("div",{className:"erd-canvas canvas-wrap",children:[e.jsx(Fe,{children:e.jsx(Te,{doc:s,caps:w,exec:i,selectedId:f,onSelect:$,query:b,onError:R,handleRef:A})}),_&&e.jsxs("aside",{className:"side-panel",children:[e.jsxs("div",{className:"detail-header",children:[e.jsx("h2",{children:_==="ontology"?"Ontology":"Ontology layers"}),e.jsx("button",{className:"icon-btn",onClick:()=>B(null),children:"✕"})]}),_==="ontology"?e.jsx(Ye,{}):e.jsx(Je,{refreshKey:0,onFocusEntity:g=>{var O;B(null),(O=A.current)==null||O.focusEntity(g)}})]})]})]})]})}function vs({user:s,onView:n}){const[t,i]=a.useState(null),[l,m]=a.useState(null);if(a.useEffect(()=>{Qe(s).then(i).catch(r=>m(String(r)))},[s]),l)return e.jsx("p",{className:"sme-splash error",children:l});if(!t)return e.jsx("div",{className:"sme-splash",children:"◮ looking for your proposals…"});if(!t.git)return e.jsx("p",{className:"sme-placeholder",children:"This model isn't in a git repository."});const c=t.proposals.filter(r=>!r.merged).length;return e.jsxs("div",{className:"pr-wrap",children:[e.jsxs("div",{className:"pr-head",children:[e.jsx("h2",{children:"My proposals"}),e.jsxs("span",{className:"meta",children:[c," open · base: ",t.base]})]}),!t.proposals.length&&e.jsx("p",{className:"sme-placeholder",children:"Nothing proposed yet. Edits you submit for review will appear here."}),t.proposals.map(r=>e.jsx(ys,{p:r,gh:t.gh,onView:()=>n(r.branch)},r.branch)),!t.gh&&t.proposals.length>0&&e.jsxs("div",{className:"pr-degrade",children:["Review status isn't available here (",e.jsx("code",{children:"gh"})," is not installed or not signed in). Branch, contents, merge state and conflicts all still come from git — each card links out to the compare view."]})]})}function Ns(s,n){var t,i;return s.merged?{kind:"accepted",text:"✅ Accepted"}:s.pushed?n&&((t=s.pr)==null?void 0:t.state)==="CLOSED"?{kind:"declined",text:"✖ Declined"}:n&&((i=s.pr)==null?void 0:i.reviews)==="CHANGES_REQUESTED"?{kind:"changes",text:"💬 Changes requested"}:{kind:"awaiting",text:"⏳ Awaiting review"}:{kind:"local",text:"📥 Saved locally"}}function ys({p:s,gh:n,onView:t}){const i=Ns(s,n);return e.jsxs("div",{className:"pr-card"+(i.kind==="attention"?" attention":""),children:[e.jsxs("div",{className:"pr-top",children:[e.jsx("span",{className:"pr-title",children:s.title}),e.jsx("span",{className:"pr-chip "+i.kind,children:i.text})]}),e.jsxs("div",{className:"pr-branch",children:[s.branch," · ",s.created,s.behind>0&&` · ${s.behind} behind`]}),e.jsxs("div",{className:"pr-foot",children:[e.jsx("span",{className:"pr-link",children:s.merged?e.jsxs(e.Fragment,{children:["merged",n&&s.pr?` · PR #${s.pr.number}`:""]}):s.pushed?n&&s.pr?e.jsxs("a",{href:s.pr.url,target:"_blank",rel:"noreferrer",children:["PR #",s.pr.number]}):s.compare_url?e.jsx("a",{href:s.compare_url,target:"_blank",rel:"noreferrer",children:"open the compare view →"}):"pushed":"not sent yet — no connection to the shared repo"}),e.jsx("span",{className:"pr-btns",children:e.jsx("button",{className:"sme-secondary",onClick:t,children:"View"})})]})]})}function ws({changes:s,routeAdvice:n,identity:t,user:i,onUser:l,onDrop:m,onClose:c,onProposed:r}){const d=!!(t&&t.source!=="anonymous"),[v,j]=a.useState(i||(localStorage.getItem("mdl.sme.user")??"")),[b,o]=a.useState(s.length===1?`Update ${s[0].label.toLowerCase()}`:"Glossary updates"),[f,N]=a.useState(""),[_,B]=a.useState(!1),E=we(_?f:b),[S,C]=a.useState(""),[R,A]=a.useState(!1),[w,$]=a.useState(null),[I,g]=a.useState(null),O=()=>{!d&&!v.trim()||(d||(localStorage.setItem("mdl.sme.user",v.trim()),l==null||l(v.trim())),A(!0),g(null),Xe({user:d?"":v.trim(),slug:E,title:b,body:S.trim(),changes:s.map(u=>({op:u.op,payload:u.payload}))}).then($).catch(u=>g(u instanceof Ze?u.message:String(u))).finally(()=>A(!1)))};return w!=null&&w.ok?e.jsx("div",{className:"sme-modal-backdrop",onClick:()=>r(w),children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsx("h2",{children:"✓ Sent for review"}),e.jsx("p",{children:w.message}),w.pr_url&&e.jsx("p",{children:e.jsx("a",{href:w.pr_url,target:"_blank",rel:"noreferrer",children:"View pull request →"})}),w.compare_url&&e.jsx("p",{children:e.jsx("a",{href:w.compare_url,target:"_blank",rel:"noreferrer",children:"Open the pull request →"})}),e.jsxs("p",{className:"sme-muted",children:["Your suggestion is on branch ",e.jsx("code",{children:w.branch}),". A steward will review it."]}),e.jsx("div",{className:"sme-modal-foot",children:e.jsx("button",{className:"sme-primary",onClick:()=>r(w),children:"Done"})})]})}):e.jsx("div",{className:"sme-modal-backdrop",onClick:c,children:e.jsxs("div",{className:"sme-modal",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsx("h2",{children:"Submit for review"}),e.jsx("button",{className:"sme-secondary",onClick:c,children:"✕"})]}),e.jsx("h3",{children:"Your changes"}),e.jsx("ul",{className:"sme-diff",children:s.map((u,M)=>e.jsxs("li",{children:[e.jsxs("div",{className:"sme-diff-head",children:[e.jsx("b",{children:u.label}),e.jsx("button",{className:"sme-link danger",onClick:()=>m(M),children:"discard"})]}),e.jsx("div",{className:"sme-diff-before",children:u.before}),e.jsx("div",{className:"sme-diff-after",children:u.after})]},M))}),d?e.jsxs("p",{className:"sme-signed-in",children:["Signed in as ",e.jsx("strong",{children:t.name}),t.email?` (${t.email})`:""," — this proposal is attributed to you."]}):e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Your name (for attribution)"}),e.jsx("input",{value:v,onChange:u=>j(u.target.value),placeholder:"e.g. a.hough"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{value:b,onChange:u=>o(u.target.value)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Branch name (edit to add a ticket id, e.g. PROJ-123)"}),e.jsx("input",{value:_?f:E,onChange:u=>{B(!0),N(u.target.value)},placeholder:"clarify-counterparty"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Note for the reviewer (optional)"}),e.jsx("textarea",{rows:2,value:S,onChange:u=>C(u.target.value)})]}),e.jsx(ks,{cl:n,user:d?t.name:v,changeSlug:E}),I&&e.jsx("p",{className:"sme-error-line",children:I}),e.jsxs("div",{className:"sme-modal-foot",children:[e.jsx("button",{className:"sme-secondary",onClick:c,children:"Keep editing"}),e.jsx("button",{className:"sme-primary",disabled:R||!d&&!v.trim()||s.length===0,onClick:O,children:R?"Submitting…":"Submit for review"})]})]})})}function ks({cl:s,user:n,changeSlug:t}){if(!(s!=null&&s.primary))return null;const i=s.reviewers_actual??s.reviewers,l=we(n||"you"),m=s.routes.length>1;return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"sub-advice",children:[e.jsx("span",{className:"i",children:"ⓘ"})," These changes span routes"," ",e.jsx("strong",{children:s.routes.join(" and ")}),". The whole proposal will be reviewed as route ",s.primary," (",s.primary_name,") — the strictest gate wins, so it needs"," ",i.join(", ")," plus ",e.jsx("code",{children:s.gates[s.gates.length-1]}),". Proposing the meaning-only changes separately would get them reviewed faster."]}),e.jsxs("div",{className:"sub-dest",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Goes to"}),e.jsxs("code",{children:["sme/",l,"/",t||"…"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:i.join(", ")})]})]})]})}function we(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"change"}const ke=[{id:"all",label:"All"},{id:"additions",label:"Additions"},{id:"modifications",label:"Modifications"},{id:"moves",label:"Renames"},{id:"deletions",label:"Deletions"},{id:"conflicts",label:"Conflicts"}];function _e(s,n){switch(n){case"all":return!0;case"additions":return s.change==="added";case"deletions":return s.change==="removed";case"moves":return s.renamed;case"modifications":return s.change==="modified"&&!s.renamed;case"conflicts":return s.severity==="breaking"}}function _s(s,n){return n==="all"?s.objects:s.objects.filter(t=>_e(t,n))}function Ss(s){const n={};for(const{id:t}of ke)n[t]=t==="all"?s.objects.length:s.objects.filter(i=>_e(i,t)).length;return n}function Q(s,n){return`${s}\0${n}`}function Se(s){const n=s.fields.map(t=>Q(s.ulid,t.field));for(const t of s.children)for(const i of t.fields)n.push(Q(s.ulid,`${t.ulid}.${i.field}`));return n.length?n:[Q(s.ulid,"*")]}function Ce(s,n){const t=Se(s),i=t.filter(l=>n.has(l)).length;return i===0?"none":i===t.length?"all":"some"}function Ae(s,n){return Ce(s,n)!=="none"}function Cs(s,n){return s.objects.filter(t=>Ae(t,n)).map(t=>t.ulid)}function As(s,n){const t=new Set;for(const i of s.objects){if(i.object_kind!=="logical_entity"||i.change!=="added"||!Ae(i,n))continue;const l=i.name_after??i.name_before;l&&t.add(l)}return t}function $s(s,n){if(n.size===0)return[];const t=new Set,i=[],l=m=>[m.entity_id,m.from_entity,m.to_entity,m.from,m.to].filter(c=>typeof c=="string");for(const m of s){const c=m.payload;switch(m.op){case"create_entity":{const r=typeof c.name=="string"?c.name:"",d=typeof c.id=="string"?c.id:"";n.has(r)&&(t.add(d),i.push(m));break}case"add_attribute":{const r=typeof c.entity_id=="string"?c.entity_id:"";t.has(r)&&i.push(m);break}case"create_relationship":case"create_key_group":{const r=l(c);r.length>0&&r.every(d=>t.has(d))&&i.push(m);break}default:i.push(m)}}return i}function $e(s){const n=new Set;for(const t of s.objects)for(const i of Se(t))n.add(i);return n}const Es="modulepreload",Rs=function(s){return"/"+s},me={},Ms=function(n,t,i){let l=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),r=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));l=Promise.allSettled(t.map(d=>{if(d=Rs(d),d in me)return;me[d]=!0;const v=d.endsWith(".css"),j=v?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${j}`))return;const b=document.createElement("link");if(b.rel=v?"stylesheet":Es,v||(b.as="script"),b.crossOrigin="",b.href=d,r&&b.setAttribute("nonce",r),document.head.appendChild(b),v)return new Promise((o,f)=>{b.addEventListener("load",o),b.addEventListener("error",()=>f(new Error(`Unable to preload CSS for ${d}`)))})}))}function m(c){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=c,window.dispatchEvent(r),!r.defaultPrevented)throw c}return l.then(c=>{for(const r of c||[])r.status==="rejected"&&m(r.reason);return n().catch(m)})};function Ds({diff:s,selectable:n,selected:t,onToggle:i,onToggleField:l}){var f;const[m,c]=a.useState("all"),r=a.useMemo(()=>_s(s,m),[s,m]),d=a.useMemo(()=>Ss(s),[s]),[v,j]=a.useState(((f=s.objects[0])==null?void 0:f.ulid)??null),b=a.useMemo(()=>r.find(N=>N.ulid===v)??r[0]??s.objects[0]??null,[r,s,v]),o=!!l;return s.objects.length?e.jsxs("div",{className:"rv-wrap",children:[n!==void 0&&e.jsx("div",{className:"rv-filters",role:"tablist","aria-label":"Filter changes",children:ke.filter(N=>N.id==="all"||d[N.id]>0).map(N=>e.jsxs("button",{role:"tab","aria-selected":m===N.id,className:"rv-filter"+(m===N.id?" active":""),onClick:()=>c(N.id),children:[N.label,e.jsx("span",{className:"rv-filter-count",children:d[N.id]})]},N.id))}),e.jsxs("div",{className:"rv-body",children:[e.jsx("div",{className:"rv-list",children:r.length===0?e.jsx("p",{className:"sme-placeholder",children:"No changes match this filter."}):r.map(N=>e.jsx(Is,{obj:N,active:N.ulid===((b==null?void 0:b.ulid)??""),selectable:n,perField:o,objState:o?Ce(N,t??new Set):void 0,checkedObject:(t==null?void 0:t.has(N.ulid))??!0,onSelect:()=>j(N.ulid),onToggleObject:()=>i==null?void 0:i(N.ulid),onToggleField:l},N.ulid))}),e.jsx("div",{className:"rv-detail",children:b&&e.jsx(Os,{obj:b,selectable:n,perField:o,selected:t,onToggleField:l})})]})]}):e.jsxs("p",{className:"sme-placeholder",children:["No model changes against ",s.base.label,"."]})}function Ps(s){return s.renamed?"renamed":s.severity==="breaking"?"breaking":s.change}function Is({obj:s,active:n,selectable:t,perField:i,objState:l,checkedObject:m,onSelect:c,onToggleObject:r,onToggleField:d}){const v=o=>{o&&i&&(o.indeterminate=l==="some")},j=i?l!=="none":m,b=()=>{if(!i)return r();for(const o of s.fields)d==null||d(s.ulid,o.field);for(const o of s.children)for(const f of o.fields)d==null||d(s.ulid,`${o.ulid}.${f.field}`);!s.fields.length&&!s.children.length&&(d==null||d(s.ulid,"*"))};return e.jsxs("div",{className:"rv-obj"+(n?" active":""),onClick:c,children:[e.jsxs("div",{className:"rv-obj-head",children:[t&&e.jsx("input",{type:"checkbox",ref:v,checked:j,onClick:o=>o.stopPropagation(),onChange:b,"aria-label":`include ${s.name_before??s.name_after}`}),e.jsx("span",{className:"rv-obj-name",children:s.name_before??s.name_after}),e.jsx("span",{className:"rv-obj-kind",children:s.object_kind_label}),e.jsxs("span",{className:"sev "+(s.renamed?"renamed":s.severity),children:[s.severity==="breaking"&&"⚠ ",Ps(s)]})]}),e.jsxs("ul",{className:"rv-obj-fields",children:[s.fields.map((o,f)=>e.jsx("li",{children:o.label},o.field+f)),s.children.flatMap(o=>o.fields.map((f,N)=>e.jsxs("li",{children:[f.label,": ",o.name_before??o.name_after]},o.ulid+N)))]})]})}function Os({obj:s,selectable:n,perField:t,selected:i,onToggleField:l}){const m=s.children.flatMap(r=>r.fields.map(d=>({field:d,on:r.name_before??r.name_after??"",key:`${r.ulid}.${d.field}`}))),c=(r,d)=>{if(!n||!t)return d;const v=Q(s.ulid,r);return e.jsxs("div",{className:"rv-field-pick",children:[e.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.has(v))??!0,onChange:()=>l==null?void 0:l(s.ulid,r),"aria-label":`include change: ${r}`}),e.jsx("div",{className:"rv-field-body",children:d})]})};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.renamed?`${s.name_before} → ${s.name_after}`:s.name_before??s.name_after}),e.jsxs("div",{className:"rv-detail-kind",children:[s.object_kind_label,s.renamed&&" · renamed",s.path&&e.jsxs("span",{className:"rv-src",children:[" · ",s.path]})]}),s.fields.map((r,d)=>e.jsx("div",{children:c(r.field,e.jsx(ue,{f:r}))},r.field+d)),m.map(({field:r,on:d,key:v},j)=>e.jsx("div",{children:c(v,e.jsx(ue,{f:r,on:d}))},"c"+j)),s.severity==="breaking"&&e.jsxs("div",{className:"rv-note",children:[e.jsx("span",{className:"i",children:"ⓘ"}),e.jsxs("span",{children:["This is a structural change (route B). It will need an architect's review, and CI will run ",e.jsx("code",{children:"mdl drift --check"}),"."]})]})]})}function ue({f:s,on:n}){var i,l,m;const t=n?`${s.label}: ${n}`:s.label;if((i=s.breaks)!=null&&i.length)return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-break",children:[e.jsxs("div",{className:"rv-break-head",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[n??String(s.before??"")," removed"]}),s.detail&&e.jsx("span",{className:"rv-break-meta",children:s.detail})]}),e.jsxs("div",{className:"rv-break-body",children:["This is realised by ",s.breaks.length," dbt model",s.breaks.length>1?"s":"",". Removing it will break ",s.breaks.length>1?"them":"it","."]}),e.jsx("ul",{className:"rv-usage",children:s.breaks.map(c=>e.jsxs("li",{children:[e.jsxs("span",{className:"m",children:["→ ",c.name]}),e.jsxs("span",{className:"p",children:[c.target," · ",c.materialization]})]},c.name))})]})]});if(s.kind==="definition_changed"){const c=String(s.before??""),r=String(s.after??"");return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-ba",children:[e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"before"}),e.jsx("div",{className:"rv-ba-text",children:je(c,r,"del")})]}),e.jsxs("div",{className:"rv-ba-col",children:[e.jsx("div",{className:"rv-ba-label",children:"after"}),e.jsx("div",{className:"rv-ba-text",children:je(r,c,"ins")})]})]})]})}if(Array.isArray(s.before)||Array.isArray(s.after)){const c=new Set(((l=s.before)==null?void 0:l.map(String))??[]),r=new Set(((m=s.after)==null?void 0:m.map(String))??[]),d=[...r].filter(j=>!c.has(j)),v=[...c].filter(j=>!r.has(j));return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-chips",children:[d.map(j=>e.jsxs("span",{className:"rv-chip-add",children:["+ ",j]},"a"+j)),v.map(j=>e.jsxs("span",{className:"rv-chip-del",children:["− ",j]},"r"+j))]})]})}return e.jsxs("div",{className:"rv-section",children:[e.jsx("h3",{children:t}),e.jsxs("div",{className:"rv-scalar",children:[e.jsx("span",{className:"from",children:pe(s.before)}),e.jsx("span",{className:"arrow",children:"→"}),e.jsx("span",{className:"to",children:pe(s.after)})]})]})}function pe(s){return s==null||s===""?"—":typeof s=="boolean"?s?"yes":"no":typeof s=="object"?JSON.stringify(s):String(s)}function je(s,n,t){const i=s.split(/(\s+)/),l=n.split(/(\s+)/),m=o=>o.toLowerCase().replace(/[.,;:]/g,""),c=i.length,r=l.length,d=Array.from({length:c+1},()=>new Array(r+1).fill(0));for(let o=c-1;o>=0;o--)for(let f=r-1;f>=0;f--)d[o][f]=m(i[o])===m(l[f])?d[o+1][f+1]+1:Math.max(d[o+1][f],d[o][f+1]);const v=new Set;let j=0,b=0;for(;j=d[j][b+1]?j++:b++;return i.map((o,f)=>!o.trim()||v.has(f)?e.jsx("span",{children:o},f):t==="del"?e.jsx("del",{children:o},f):e.jsx("ins",{children:o},f))}const Bs=a.lazy(()=>Ms(()=>import("./ModelDiagram-CxAF-B4F.js"),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.ModelDiagram})));function Ls({stagedDiff:s,stagedRoute:n,user:t,onBack:i,onSubmit:l,excluded:m,onToggleField:c,selectable:r,action:d}){const[v,j]=a.useState(null),[b,o]=a.useState(null),[f,N]=a.useState(null),[_,B]=a.useState(null),[E,S]=a.useState(null),[C,R]=a.useState("changes"),A=a.useCallback(()=>{be(t).then($=>{B($);const I=$.base_branch??"main";s?j(s):es("HEAD").then(g=>g.ok?j(g):S(g.error??"could not read the model")).catch(g=>S(String(g))),n?o(n):ss("HEAD").then(o).catch(()=>{}),ns(I).then(N).catch(()=>{})}).catch($=>S(String($)))},[t,s,n]);if(a.useEffect(A,[A]),E)return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:null}),e.jsx("p",{className:"sme-splash error",children:e.jsx("pre",{children:E})})]});if(!v)return e.jsx("div",{className:"sme-splash",children:"◮ reading your changes…"});const w=new Set([...$e(v)].filter($=>!m.has($)));return e.jsxs("div",{className:"rv-shell",children:[e.jsx(fe,{onBack:i,diff:v,tab:C,onTab:R}),C==="changes"?e.jsx(Ds,{diff:v,selectable:r,selected:w,onToggleField:c}):e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"sme-splash",children:"◮ drawing the model…"}),children:e.jsx(Bs,{severityByUlid:zs(v)})}),e.jsxs("div",{className:"rv-foot",children:[e.jsx(Hs,{cl:b}),e.jsx(Ws,{conf:f,ctx:_}),e.jsxs("div",{className:"rv-actions",children:[e.jsx("button",{className:"sme-secondary",onClick:i,children:d?"Cancel":"Keep editing"}),d?e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||!!d.disabledReason,title:d.disabledReason??"",onClick:()=>d.apply(Cs(v,w)),children:d.label}):e.jsx("button",{className:"sme-primary",disabled:!v.objects.length||(_?!_.can_propose:!1),title:_&&!_.can_propose?"the working tree has uncommitted changes":"",onClick:()=>l(b),children:"Submit for review →"})]})]})]})}function zs(s){const n=new Map;for(const t of s.objects)n.set(t.ulid,t.severity);return n}function fe({onBack:s,diff:n,tab:t,onTab:i}){const l=n==null?void 0:n.counts;return e.jsxs("div",{className:"rv-head",children:[e.jsxs("div",{children:[e.jsx("button",{className:"rv-back",onClick:s,children:"‹ Back to terms"}),e.jsx("h1",{className:"rv-title",children:"Review your changes"}),l&&e.jsxs("div",{className:"rv-sub",children:[l.objects," object",l.objects===1?"":"s"," ·"," ",(l.breaking??0)+(l.additive??0)+(l.cosmetic??0)," changes",(n==null?void 0:n.has_breaking)&&e.jsxs("span",{className:"warn",children:[" · ⚠ ",l.breaking," breaking"]})," · comparing to ",e.jsx("code",{children:n==null?void 0:n.base.label})]})]}),i&&e.jsxs("div",{className:"rv-tabs",children:[e.jsxs("button",{className:"rv-tab"+(t==="changes"?" active":""),onClick:()=>i("changes"),children:["Changes ",(n==null?void 0:n.objects.length)??0]}),e.jsx("button",{className:"rv-tab"+(t==="diagram"?" active":""),onClick:()=>i("diagram"),children:"Diagram"})]})]})}function Hs({cl:s}){if(!(s!=null&&s.primary))return null;const n=s.reviewers_actual??s.reviewers;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rv-route",children:[e.jsxs("span",{className:"rv-route-badge",children:["Route ",s.primary," · ",s.primary_name]}),e.jsx("span",{className:"k",children:"Reviewers"}),e.jsx("span",{children:n.join(", ")}),s.reviewers_actual&&e.jsx("span",{className:"rv-src",children:"from .github/CODEOWNERS"})]}),e.jsxs("div",{className:"rv-gates",children:["CI gates"," ",s.gates.map(t=>e.jsx("code",{children:t},t))]})]})}function Ws({conf:s,ctx:n}){return s!=null&&s.ok?s.clean?e.jsxs("div",{className:"rv-conflict ok",children:[e.jsx("span",{children:"✓"}),e.jsxs("span",{children:["Merges cleanly onto ",s.base]}),s.behind>0&&e.jsxs("span",{className:"detail",children:["· ",s.base," is ",s.behind," commit",s.behind===1?"":"s"," ahead"]}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"detail",children:"· uncommitted changes in the working tree"})]}):e.jsxs("div",{className:"rv-conflict bad",children:[e.jsx("span",{children:"⚠"}),e.jsxs("span",{children:[s.base," has changed and ",s.files.length," file",s.files.length===1?"":"s"," now conflict"]}),e.jsx("span",{className:"detail",children:s.files.map(t=>t.path).join(", ")})]}):null}function qs({term:s,canEdit:n,pendingCount:t,onEdit:i}){var l,m;return e.jsxs("div",{className:"sme-card",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("div",{children:[e.jsx("h1",{children:s.name}),((l=s.subject_area)==null?void 0:l.name)&&e.jsx("span",{className:"sme-chip",children:s.subject_area.name}),s.kind==="term"&&e.jsx("span",{className:"sme-chip",children:"glossary term"})]}),n&&e.jsx("button",{className:"sme-primary",onClick:i,children:t>0?"Continue editing":"Suggest an edit"})]}),e.jsx("p",{className:"sme-definition",children:s.definition??e.jsx("em",{children:"No definition yet."})}),s.synonyms.length>0&&e.jsxs("section",{children:[e.jsx("h3",{children:"Also called"}),e.jsx("div",{children:s.synonyms.map(c=>e.jsx("span",{className:"sme-chip",children:c},c))})]}),s.stewardship&&(s.stewardship.owner||s.stewardship.steward)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Who owns this"}),s.stewardship.owner&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"owner"}),e.jsx("span",{children:s.stewardship.owner})]}),s.stewardship.steward&&e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"steward"}),e.jsx("span",{children:s.stewardship.steward})]})]}),((m=s.ontology)==null?void 0:m.aligns_to)&&e.jsxs("section",{children:[e.jsx("h3",{children:"Standard it maps to"}),e.jsxs("div",{className:"sme-kv",children:[e.jsx("span",{className:"k",children:"aligned to"}),e.jsx("code",{children:s.ontology.aligns_to}),s.ontology.status==="proposed"&&e.jsx("span",{className:"sme-badge proposed",children:"awaiting architect"})]})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Where it's used"}),s.where_used.length===0?e.jsx("p",{className:"sme-muted",children:s.kind==="term"?"A glossary term — not yet realised by a data model.":"Not yet realised by any data model."}):e.jsx("ul",{className:"sme-usage",children:s.where_used.map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"sme-usage-model",children:c.logical_entity}),c.unmanaged&&e.jsx("span",{className:"sme-badge",children:"engineer-owned"}),c.physical.length>0&&e.jsx("span",{className:"sme-usage-phys",children:c.physical.map(r=>r.name).join(", ")})]},c.logical_id))})]})]})}function Gs({term:s,pending:n,onStage:t,onDone:i,catalogOwned:l=[],catalog:m=null}){var $,I,g,O;const c=u=>l.includes(u),r=u=>n.find(M=>M.label===u),d=(u,M)=>{const z=r(u);return z?z.after:M},[v,j]=a.useState(d("Definition",s.definition??"")),[b,o]=a.useState(s.synonyms),[f,N]=a.useState(""),[_,B]=a.useState((($=s.stewardship)==null?void 0:$.owner)??""),[E,S]=a.useState(((I=s.stewardship)==null?void 0:I.steward)??""),C=()=>{v.trim()!==(s.definition??"").trim()&&t({op:"set_definition",payload:{id:s.id,definition:v.trim()},label:"Definition",before:s.definition??"(none)",after:v.trim()||"(none)"})},R=(u,M)=>{var z,W;t({op:"set_stewardship",payload:{id:s.id,owner:u||null,steward:M||null},label:"Stewardship",before:`owner: ${((z=s.stewardship)==null?void 0:z.owner)??"—"} · steward: ${((W=s.stewardship)==null?void 0:W.steward)??"—"}`,after:`owner: ${u||"—"} · steward: ${M||"—"}`})},A=u=>{o(u),t({op:"update_synonyms",payload:{id:s.id,synonyms:u},label:"Also called",before:s.synonyms.join(", ")||"(none)",after:u.join(", ")||"(none)"})},w=s.kind==="term";return e.jsxs("div",{className:"sme-editor",children:[e.jsxs("div",{className:"sme-card-head",children:[e.jsxs("h1",{children:["Suggest an edit — ",s.name]}),e.jsx("button",{className:"sme-secondary",onClick:i,children:"Back"})]}),e.jsxs("p",{className:"sme-hint",children:["You can refine what this term ",e.jsx("em",{children:"means"}),". Structure (keys, relationships, how it's built) stays with the data team."]}),(c("definition")||c("synonyms")||c("stewardship"))&&m&&e.jsxs("div",{className:"sme-catalog-banner",children:["Definitions, synonyms, and ownership are mastered in ",e.jsx("b",{children:m.name}),". Edit them there — this glossary mirrors them read-only.",m.url&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("a",{href:m.url,target:"_blank",rel:"noreferrer",children:["Open in ",m.name," →"]})]}),e.jsx("div",{className:"sme-catalog-note",children:"You can still propose a standard mapping below."})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Definition"}),c("definition")?e.jsx("p",{className:"sme-readonly-value",children:s.definition??"—"}):e.jsx("textarea",{rows:4,value:v,onChange:u=>j(u.target.value),onBlur:C,placeholder:"A plain-language business definition…"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Also called (synonyms)"}),c("synonyms")?e.jsx("div",{className:"sme-syn-row",children:s.synonyms.length?s.synonyms.map(u=>e.jsx("span",{className:"sme-chip",children:u},u)):e.jsx("span",{className:"sme-muted",children:"none"})}):e.jsxs("div",{className:"sme-syn-row",children:[b.map(u=>e.jsxs("span",{className:"sme-chip removable",onClick:()=>A(b.filter(M=>M!==u)),children:[u," ✕"]},u)),e.jsx("input",{value:f,placeholder:"add + Enter",onChange:u=>N(u.target.value),onKeyDown:u=>{u.key==="Enter"&&f.trim()&&(A([...b,f.trim()]),N(""))}})]})]}),!w&&(c("stewardship")?e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("p",{className:"sme-readonly-value",children:((g=s.stewardship)==null?void 0:g.owner)??"—"})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("p",{className:"sme-readonly-value",children:((O=s.stewardship)==null?void 0:O.steward)??"—"})]})]}):e.jsxs("div",{className:"sme-field-row",children:[e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Owner"}),e.jsx("input",{value:_,onChange:u=>B(u.target.value),onBlur:()=>R(_,E)})]}),e.jsxs("label",{className:"sme-field",children:[e.jsx("span",{children:"Steward"}),e.jsx("input",{value:E,onChange:u=>S(u.target.value),onBlur:()=>R(_,E)})]})]})),e.jsx(Vs,{term:s,onStage:t}),e.jsx("p",{className:"sme-note",children:n.length>0?`${n.length} change(s) staged — use “Submit for review” at the top when you're done.`:"Changes you make are collected until you submit them for review."})]})}const Ks=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch"];function Vs({term:s,onStage:n}){var b;const[t,i]=a.useState(!1),[l,m]=a.useState(s.name),[c,r]=a.useState([]),[d,v]=a.useState("skos:closeMatch"),j=o=>{m(o),ts(o).then(f=>r(f.results)).catch(()=>r([]))};return t?e.jsxs("div",{className:"sme-field sme-align",children:[e.jsx("span",{children:"Propose a standard mapping (a suggestion; the architect confirms)"}),e.jsx("input",{value:l,onChange:o=>j(o.target.value),placeholder:"Search standards…",autoFocus:!0}),e.jsx("div",{className:"sme-align-results",children:c.map(o=>e.jsxs("button",{className:"sme-align-card",onClick:()=>{var f;n({op:"set_alignment",payload:{id:s.id,aligns_to:o.prefixed,alignment:d,status:"proposed"},label:"Standard mapping",before:((f=s.ontology)==null?void 0:f.aligns_to)??"(none)",after:`${o.prefixed} (${d}, proposed)`}),i(!1)},children:[e.jsx("strong",{children:o.label})," ",e.jsx("code",{children:o.prefixed}),o.definition&&e.jsx("span",{className:"sme-align-def",children:o.definition})]},o.iri))}),e.jsx("select",{value:d,onChange:o=>v(o.target.value),children:Ks.map(o=>e.jsx("option",{children:o},o))})]}):e.jsxs("div",{className:"sme-field",children:[e.jsx("span",{children:"Standard mapping"}),e.jsxs("div",{children:[(b=s.ontology)!=null&&b.aligns_to?e.jsx("code",{className:"sme-current-align",children:s.ontology.aligns_to}):e.jsx("span",{className:"sme-muted",children:"not mapped to a standard"}),e.jsx("button",{className:"sme-link",onClick:()=>i(!0),children:"Propose a mapping…"})]})]})}function Us(){const[s,n]=a.useState(null),[t,i]=a.useState(!0),[l,m]=a.useState(null),[c,r]=a.useState(""),[d,v]=a.useState(null),[j,b]=a.useState(""),[o,f]=a.useState(""),[N,_]=a.useState(null),[B,E]=a.useState(!1),[S,C]=a.useState([]),[R,A]=a.useState(!1),w=a.useMemo(()=>new URLSearchParams(window.location.search).get("import"),[]),$=!!w,I=w&&w!=="1"?w:null,[g,O]=a.useState("");a.useEffect(()=>{I&&as(I).then(p=>p.ok&&p.content&&O(p.content)).catch(()=>{})},[I]);const[u,M]=a.useState($?"model":window.location.hash==="#proposals"?"proposals":"browse"),[z,W]=a.useState(new Set),[H,G]=a.useState(null),[T,J]=a.useState(()=>localStorage.getItem("mdl.sme.user")??""),[x,h]=a.useState(null),[k,D]=a.useState(null),[q,Ee]=a.useState(!1),[Re,Me]=a.useState(null),De=a.useCallback((p,y)=>{var Y;const L=Z=>{var ce;const F=k==null?void 0:k.entities.find(oe=>{var de;return oe.id===Z||((de=oe.conceptual)==null?void 0:de.id)===Z});return((ce=F==null?void 0:F.conceptual)==null?void 0:ce.name)??(F==null?void 0:F.name)??"object"},P=L(y.id??y.entity_id);switch(p){case"create_entity":return{label:`New entity: ${y.name}`,before:"—",after:String(y.name??"")};case"create_relationship":return{label:`New relationship: ${L(y.from_entity)} → ${L(y.to_entity)}`,before:"—",after:String(y.cardinality??"many_to_one")};case"delete_entity":return{label:`Deleted ${P}`,before:P,after:"—"};case"delete_relationship":return{label:"Relationship removed",before:"",after:"—"};case"update_relationship":return{label:"Relationship changed",before:"",after:[y.cardinality,y.optionality,y.identifying?"identifying":""].filter(Boolean).join(", ")};case"set_definition":return{label:`Definition: ${P}`,before:"",after:String(y.definition??"")};case"add_attribute":return{label:`Attribute added to ${P}`,before:"—",after:String(y.name??"")};case"delete_attribute":return{label:`Attribute removed from ${P}`,before:"",after:"—"};case"update_attribute":return{label:`Attribute changed on ${P}`,before:"",after:JSON.stringify(y)};case"rename_entity":return{label:`Renamed ${P}`,before:P,after:String(y.name??"")};case"set_subject_area":return{label:`Subject area: ${P}`,before:"",after:String(y.subject_area??"none")};case"set_stewardship":return{label:`Stewardship: ${P}`,before:"",after:String(y.steward??"")};case"set_subject_area_members":{const Z=y.__label,F=((Y=y.members)==null?void 0:Y.length)??0;return{label:Z??"Subject area members",before:"",after:`${F} object${F===1?"":"s"}`}}case"set_alignment":return{label:`Alignment: ${P}`,before:"",after:String(y.aligns_to??"")};default:return{label:`${p.replace(/_/g," ")}: ${P}`,before:"",after:""}}},[k]),V=us({subjectArea:j,describe:De}),Pe=a.useCallback(async(p,y)=>{const L=(k==null?void 0:k.fingerprint)??"",P=await rs(p,y,L);return await ie(j||void 0).then(D),P},[k,j]),Ie=a.useMemo(()=>{const p={};for(const y of V.pending)y.op==="set_subject_area_members"&&(p[y.payload.id]=y.payload.members??[]);return p},[V.pending]),U=a.useMemo(()=>[...S,...V.pending],[S,V.pending]),[Oe,se]=a.useState(null),[Be,ne]=a.useState(null);a.useEffect(()=>{if(!U.length){se(null),ne(null);return}const p=new AbortController,y=U.map(L=>({op:L.op,payload:L.payload}));return xe(y,j||void 0,p.signal).then(L=>se(L.diff??null)).catch(L=>{L.name!=="AbortError"&&se(null)}),is(y).then(ne).catch(()=>ne(null)),()=>p.abort()},[U,j]);const Le=a.useMemo(()=>ps(U),[U]).size{M(p),window.location.hash=p==="browse"?"":`#${p}`},[]),te=a.useRef(!0);a.useEffect(()=>{const p=()=>{const y=window.location.hash;if(te.current&&!y&&$){te.current=!1;return}te.current=!1,M(y==="#proposals"?"proposals":y==="#review"?"review":y==="#model"?"model":y==="#areas"?"areas":"browse")};return p(),window.addEventListener("hashchange",p),()=>window.removeEventListener("hashchange",p)},[]);const ae=a.useCallback(()=>{ls({subject_area:j,q:o}).then(n).catch(p=>v(String(p)))},[j,o]);a.useEffect(ae,[ae]),a.useEffect(()=>{ie(j||void 0).then(p=>{i(p.read_only),r(p.project.name),D(p),Ee(!!p.direct),h(p.identity??null),p.identity&&p.identity.source!=="anonymous"&&p.identity.name&&J(p.identity.name)}).catch(()=>{}),cs().then(m).catch(()=>{})},[j]);const re=a.useMemo(()=>(s==null?void 0:s.terms.find(p=>p.id===N))??null,[s,N]),ze=a.useCallback(p=>{const y=p.key??ye(p.op,p.payload);C(L=>[...L.filter(P=>P.key!==y),{...p,key:y}])},[]),He=p=>C(y=>y.filter((L,P)=>P!==p)),We=()=>{C([]),A(!1),E(!1),ae()};if(d)return e.jsxs("div",{className:"sme-splash error",children:[e.jsx("h1",{children:"◮ Glossary"}),e.jsx("pre",{children:d}),e.jsxs("p",{children:["Is ",e.jsx("code",{children:"mdl glossary"})," pointed at a model?"]})]});if(!s)return e.jsx("div",{className:"sme-splash",children:"◮ loading glossary…"});const X=!t,le=(l==null?void 0:l.catalog_owned_fields)??[],qe=le.length>0;return e.jsxs("div",{className:"sme",children:[e.jsxs("header",{className:"sme-top",children:[e.jsxs("div",{className:"sme-brand",children:[e.jsx("span",{className:"sme-logo",children:"◮"}),e.jsx("span",{children:"Glossary"}),e.jsx("span",{className:"sme-project",children:c}),t&&e.jsx("span",{className:"sme-chip",children:"read-only"}),qe&&e.jsxs("span",{className:"sme-chip catalog",title:`Definitions are mastered in ${l==null?void 0:l.catalog_name}`,children:["mirrors ",l==null?void 0:l.catalog_name]})]}),e.jsx("input",{className:"sme-search",type:"search",placeholder:"Search terms & definitions…",value:o,onChange:p=>f(p.target.value)}),e.jsxs("nav",{className:"sme-tabs",children:[e.jsx("button",{className:"sme-tab"+(u==="browse"?" active":""),onClick:()=>K("browse"),children:"Terms"}),e.jsx("button",{className:"sme-tab"+(u==="model"?" active":""),onClick:()=>K("model"),children:"Model"}),e.jsx("button",{className:"sme-tab"+(u==="areas"?" active":""),onClick:()=>K("areas"),children:"Subject areas"}),e.jsx("button",{className:"sme-tab"+(u==="proposals"?" active":""),onClick:()=>K("proposals"),children:"My proposals"})]}),U.length>0&&e.jsxs("button",{className:"sme-tray",onClick:()=>K("review"),children:[U.length," change",U.length>1?"s":""," · Review →"]})]}),u==="browse"&&e.jsx(js,{user:T}),u==="review"?e.jsx(Ls,{stagedDiff:H??Oe,stagedRoute:H?null:Be,user:T,selectable:Le,excluded:z,onToggleField:(p,y)=>W(L=>{const P=new Set(L),Y=Q(p,y);return P.has(Y)?P.delete(Y):P.add(Y),P}),onBack:()=>{G(null),W(new Set),K("browse")},onSubmit:p=>{Me(p),A(!0)},action:H?{id:"apply-import",label:"Apply import →",primary:!0,apply:async()=>{const p=H,y=new Set([...$e(p)].filter(Y=>!z.has(Y))),L=As(p,y),P=$s(H.changes,L);await os(P,!0),G(null),W(new Set),K("browse"),await ie(j||void 0).then(D)}}:void 0}):u==="model"?V.previewDoc??k?e.jsx(gs,{doc:V.previewDoc??k,subjectArea:j,onSubjectArea:b,exec:q?Pe:V.exec,canEdit:X,direct:q,onImported:()=>K("review"),onImportPreview:p=>{W(new Set),G(p),K("review")},openImport:$,prefillImport:g,query:o,busy:V.busy}):e.jsx("div",{className:"sme-splash",children:"◮ loading the model…"}):u==="areas"?e.jsx(fs,{exec:V.exec,canEdit:X,stagedMembers:Ie}):u==="proposals"?e.jsx(vs,{user:T,onView:()=>K("review")}):e.jsxs("div",{className:"sme-body",children:[e.jsxs("nav",{className:"sme-nav",children:[e.jsx("button",{className:"sme-sa"+(j===""?" active":""),onClick:()=>b(""),children:"All subject areas"}),s.subject_areas.map(p=>e.jsx("button",{className:"sme-sa"+(j===p.id?" active":""),onClick:()=>b(p.id),title:p.definition??void 0,children:p.name},p.id))]}),e.jsxs("ul",{className:"sme-list",children:[s.terms.map(p=>{var y;return e.jsxs("li",{className:"sme-list-item"+(p.id===N?" active":""),onClick:()=>{_(p.id),E(!1)},children:[e.jsx("span",{className:"sme-term-name",children:p.name}),p.kind==="term"&&e.jsx("span",{className:"sme-kind",children:"term"}),((y=p.ontology)==null?void 0:y.status)==="proposed"&&e.jsx("span",{className:"sme-badge proposed",title:"alignment awaiting architect",children:"proposed"}),e.jsx("span",{className:"sme-term-def",children:p.definition??"no definition yet"})]},p.id)}),s.terms.length===0&&e.jsx("li",{className:"sme-empty",children:"no terms match"})]}),e.jsx("section",{className:"sme-detail",children:re?B&&X?e.jsx(Gs,{term:re,pending:S,onStage:ze,onDone:()=>E(!1),catalogOwned:le,catalog:l?{name:l.catalog_name,url:l.catalog_url}:null}):e.jsx(qs,{term:re,canEdit:X,pendingCount:S.length,onEdit:()=>E(!0)}):e.jsx("div",{className:"sme-placeholder",children:"Select a term to see its definition."})})]}),R&&e.jsx(ws,{changes:U,routeAdvice:Re,identity:x,user:T,onUser:p=>{J(p),localStorage.setItem("mdl.sme.user",p)},onDrop:He,onClose:()=>A(!1),onProposed:()=>{We(),V.clear(),W(new Set),K("proposals")}})]})}Ge.createRoot(document.getElementById("root")).render(e.jsx(Ke.StrictMode,{children:e.jsx(Us,{})})); diff --git a/packages/server/src/mdl_server/static/assets/styles-BzOwieT6.css b/packages/server/src/mdl_server/static/assets/styles-D9kpX-nz.css similarity index 59% rename from packages/server/src/mdl_server/static/assets/styles-BzOwieT6.css rename to packages/server/src/mdl_server/static/assets/styles-D9kpX-nz.css index 3786206..a7ca221 100644 --- a/packages/server/src/mdl_server/static/assets/styles-BzOwieT6.css +++ b/packages/server/src/mdl_server/static/assets/styles-D9kpX-nz.css @@ -1 +1 @@ -.react-flow{direction:ltr}.react-flow__container{position:absolute;width:100%;height:100%;top:0;left:0}.react-flow__pane{z-index:1;cursor:-webkit-grab;cursor:grab}.react-flow__pane.selection{cursor:pointer}.react-flow__pane.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__viewport{transform-origin:0 0;z-index:2;pointer-events:none}.react-flow__renderer{z-index:4}.react-flow__selection{z-index:6}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible{outline:none}.react-flow .react-flow__edges{pointer-events:none;overflow:visible}.react-flow__edge-path,.react-flow__connection-path{stroke:#b1b1b7;stroke-width:1;fill:none}.react-flow__edge{pointer-events:visibleStroke;cursor:pointer}.react-flow__edge.animated path{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__edge.animated path.react-flow__edge-interaction{stroke-dasharray:none;-webkit-animation:none;animation:none}.react-flow__edge.inactive{pointer-events:none}.react-flow__edge.selected,.react-flow__edge:focus,.react-flow__edge:focus-visible{outline:none}.react-flow__edge.selected .react-flow__edge-path,.react-flow__edge:focus .react-flow__edge-path,.react-flow__edge:focus-visible .react-flow__edge-path{stroke:#555}.react-flow__edge-textwrapper{pointer-events:all}.react-flow__edge-textbg{fill:#fff}.react-flow__edge .react-flow__edge-text{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__connection{pointer-events:none}.react-flow__connection .animated{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__connectionline{z-index:1001}.react-flow__nodes{pointer-events:none;transform-origin:0 0}.react-flow__node{position:absolute;-webkit-user-select:none;-moz-user-select:none;user-select:none;pointer-events:all;transform-origin:0 0;box-sizing:border-box;cursor:-webkit-grab;cursor:grab}.react-flow__node.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__nodesselection{z-index:3;transform-origin:left top;pointer-events:none}.react-flow__nodesselection-rect{position:absolute;pointer-events:all;cursor:-webkit-grab;cursor:grab}.react-flow__handle{position:absolute;pointer-events:none;min-width:5px;min-height:5px;width:6px;height:6px;background:#1a192b;border:1px solid white;border-radius:100%}.react-flow__handle.connectionindicator{pointer-events:all;cursor:crosshair}.react-flow__handle-bottom{top:auto;left:50%;bottom:-4px;transform:translate(-50%)}.react-flow__handle-top{left:50%;top:-4px;transform:translate(-50%)}.react-flow__handle-left{top:50%;left:-4px;transform:translateY(-50%)}.react-flow__handle-right{right:-4px;top:50%;transform:translateY(-50%)}.react-flow__edgeupdater{cursor:move;pointer-events:all}.react-flow__panel{position:absolute;z-index:5;margin:15px}.react-flow__panel.top{top:0}.react-flow__panel.bottom{bottom:0}.react-flow__panel.left{left:0}.react-flow__panel.right{right:0}.react-flow__panel.center{left:50%;transform:translate(-50%)}.react-flow__attribution{font-size:10px;background:#ffffff80;padding:2px 3px;margin:0}.react-flow__attribution a{text-decoration:none;color:#999}@-webkit-keyframes dashdraw{0%{stroke-dashoffset:10}}@keyframes dashdraw{0%{stroke-dashoffset:10}}.react-flow__edgelabel-renderer{position:absolute;width:100%;height:100%;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__edge.updating .react-flow__edge-path{stroke:#777}.react-flow__edge-text{font-size:10px}.react-flow__node.selectable:focus,.react-flow__node.selectable:focus-visible{outline:none}.react-flow__node-default,.react-flow__node-input,.react-flow__node-output,.react-flow__node-group{padding:10px;border-radius:3px;width:150px;font-size:12px;color:#222;text-align:center;border-width:1px;border-style:solid;border-color:#1a192b;background-color:#fff}.react-flow__node-default.selectable:hover,.react-flow__node-input.selectable:hover,.react-flow__node-output.selectable:hover,.react-flow__node-group.selectable:hover{box-shadow:0 1px 4px 1px #00000014}.react-flow__node-default.selectable.selected,.react-flow__node-default.selectable:focus,.react-flow__node-default.selectable:focus-visible,.react-flow__node-input.selectable.selected,.react-flow__node-input.selectable:focus,.react-flow__node-input.selectable:focus-visible,.react-flow__node-output.selectable.selected,.react-flow__node-output.selectable:focus,.react-flow__node-output.selectable:focus-visible,.react-flow__node-group.selectable.selected,.react-flow__node-group.selectable:focus,.react-flow__node-group.selectable:focus-visible{box-shadow:0 0 0 .5px #1a192b}.react-flow__node-group{background-color:#f0f0f040}.react-flow__nodesselection-rect,.react-flow__selection{background:#0059dc14;border:1px dotted rgba(0,89,220,.8)}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible,.react-flow__selection:focus,.react-flow__selection:focus-visible{outline:none}.react-flow__controls{box-shadow:0 0 2px 1px #00000014}.react-flow__controls-button{border:none;background:#fefefe;border-bottom:1px solid #eee;box-sizing:content-box;display:flex;justify-content:center;align-items:center;width:16px;height:16px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;padding:5px}.react-flow__controls-button:hover{background:#f4f4f4}.react-flow__controls-button svg{width:100%;max-width:12px;max-height:12px}.react-flow__controls-button:disabled{pointer-events:none}.react-flow__controls-button:disabled svg{fill-opacity:.4}.react-flow__minimap{background-color:#fff}.react-flow__minimap svg{display:block}.react-flow__resize-control{position:absolute}.react-flow__resize-control.left,.react-flow__resize-control.right{cursor:ew-resize}.react-flow__resize-control.top,.react-flow__resize-control.bottom{cursor:ns-resize}.react-flow__resize-control.top.left,.react-flow__resize-control.bottom.right{cursor:nwse-resize}.react-flow__resize-control.bottom.left,.react-flow__resize-control.top.right{cursor:nesw-resize}.react-flow__resize-control.handle{width:4px;height:4px;border:1px solid #fff;border-radius:1px;background-color:#3367d9;transform:translate(-50%,-50%)}.react-flow__resize-control.handle.left{left:0;top:50%}.react-flow__resize-control.handle.right{left:100%;top:50%}.react-flow__resize-control.handle.top{left:50%;top:0}.react-flow__resize-control.handle.bottom{left:50%;top:100%}.react-flow__resize-control.handle.top.left,.react-flow__resize-control.handle.bottom.left{left:0}.react-flow__resize-control.handle.top.right,.react-flow__resize-control.handle.bottom.right{left:100%}.react-flow__resize-control.line{border-color:#3367d9;border-width:0;border-style:solid}.react-flow__resize-control.line.left,.react-flow__resize-control.line.right{width:1px;transform:translate(-50%);top:0;height:100%}.react-flow__resize-control.line.left{left:0;border-left-width:1px}.react-flow__resize-control.line.right{left:100%;border-right-width:1px}.react-flow__resize-control.line.top,.react-flow__resize-control.line.bottom{height:1px;transform:translateY(-50%);left:0;width:100%}.react-flow__resize-control.line.top{top:0;border-top-width:1px}.react-flow__resize-control.line.bottom{border-bottom-width:1px;top:100%}.ie-wrap{position:relative;display:inline-flex;gap:6px}.erd-ico{font-size:13px;line-height:1;opacity:.85;margin-right:1px}.ie-wrap button:hover .erd-ico,.ie-wrap button.on .erd-ico,.ie-wrap button.active .erd-ico{opacity:1}.erd-caret{opacity:.55;margin-left:1px}.ie-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:30;min-width:220px;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:6px;box-shadow:0 12px 32px #00000073;display:flex;flex-direction:column;gap:2px}.ie-item{display:block;padding:8px 10px;border-radius:6px;color:var(--text);text-decoration:none;font-size:13px;cursor:pointer}.ie-item:hover{background:#5eead424;color:var(--accent)}.ie-dialect{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 10px 8px;margin-bottom:4px;border-bottom:1px solid var(--border);font-size:12px;color:var(--text-dim)}.ie-dialect select{background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;padding:3px 6px;font-size:12px}.ie-import{width:380px;padding:12px;gap:8px}.ie-tabs{display:flex;gap:4px}.ie-tab{flex:1;padding:6px 8px;border-radius:6px;font-size:12px;cursor:pointer;background:none;border:1px solid var(--border);color:var(--text-dim)}.ie-tab.active{border-color:var(--accent);color:var(--accent);background:#5eead41a}.ie-hint{font-size:11px;color:var(--text-dim);margin:0}.ie-textarea{width:100%;font-family:var(--mono);font-size:12px;resize:vertical;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:8px;padding:8px;box-sizing:border-box}.ie-textarea:focus{border-color:var(--accent);outline:none}.ie-file{font-size:11px;color:var(--text-dim)}.ie-warn{font-size:11px;color:var(--pk);margin:0}.ie-error{font-size:12px;color:var(--err);margin:0}.ie-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:4px}:root{--bg: #14110f;--bg-raised: #1c1815;--bg-card: #221d19;--border: #33291f;--border-strong: #4a3c2c;--text: #ece6dd;--text-dim: #a89a86;--accent: #e0a63a;--accent-soft: rgba(224, 166, 58, .15);--accent-ink: #241a08;--pk: #f2c14e;--err: #f0857a;--warn: #e6a94a;--ok: #6cbf73;--font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;--mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace}*{box-sizing:border-box}html,body,#root{height:100%;margin:0}body{font-family:var(--font);background:var(--bg);color:var(--text)}.app{display:flex;flex-direction:column;height:100%}.canvas-wrap{flex:1;position:relative;min-height:0}.react-flow{background:var(--bg)}.topbar{display:flex;flex-direction:column;padding:8px 16px 0;background:var(--bg-raised);border-bottom:1px solid var(--border);z-index:10}.topbar-row{display:flex;align-items:center;gap:14px}.topbar-row.context{padding-bottom:8px}.topbar-row.actions{gap:10px;padding-bottom:8px;flex-wrap:wrap}.brand{display:flex;align-items:baseline;gap:8px;white-space:nowrap}.logo{color:var(--accent);font-size:18px}.brand-name{font-weight:700;letter-spacing:.02em}.project-name{color:var(--text-dim);font-size:13px}.search{flex:0 1 300px;margin-left:auto;padding:7px 12px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-size:13px;outline:none}.search:focus{border-color:var(--accent)}.stats{display:flex;align-items:center;gap:12px;font-size:12px;color:var(--text-dim)}.stat-item{display:inline-flex;align-items:center;gap:5px}.stat-item svg{color:var(--text-dim)}.diag-chip{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:99px;font-weight:600}.diag-chip.ok{background:#34d39926;color:var(--ok)}.diag-chip.warn{background:#fbbf2426;color:var(--warn)}.diag-chip.err{background:#f8717126;color:var(--err)}.hamburger{position:relative;display:inline-flex;align-items:center;justify-content:center;padding:6px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer}.hamburger:hover{color:var(--text);border-color:var(--border-strong)}.hamburger.active{color:var(--accent);border-color:var(--accent)}.hamburger-badge{position:absolute;top:-6px;right:-6px;min-width:15px;height:15px;padding:0 3px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-size:10px;font-weight:700;line-height:15px;text-align:center}.btn-group{display:inline-flex;align-items:center;gap:2px;background:var(--bg-card);border:1px solid var(--border);border-radius:9px;padding:2px}.grp-tag{font-size:10px;color:var(--text-dim);opacity:.75;padding:0 6px 0 4px;letter-spacing:.03em;text-transform:none;white-space:nowrap}.grp-btn{display:inline-flex;align-items:center;gap:5px;padding:5px 9px;border-radius:6px;border:none;background:transparent;color:var(--text-dim);cursor:pointer;font-size:12px;white-space:nowrap}.grp-btn.icon-only{padding:5px 7px}.grp-btn:hover{color:var(--text);background:#ffffff0d}.grp-btn.active{color:var(--accent)}.grp-btn.active svg{color:var(--accent)}.grp-badge{width:6px;height:6px;border-radius:50%;background:var(--warn);display:inline-block;margin-left:1px}.dir-arrow{display:inline-flex;transition:transform .15s ease}.tool-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 11px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.tool-btn:hover{color:var(--text);border-color:var(--border-strong)}.tool-btn.active{color:var(--accent);border-color:var(--accent)}.tool-btn.primary{color:var(--accent);border-color:#e0a63a66;font-weight:600}.layout-picker{position:relative;display:inline-flex;gap:2px}.layout-picker .caret{font-size:10px}.layout-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:20;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:8px;padding:4px;min-width:150px;box-shadow:0 8px 24px #0006}.layout-menu button{display:block;width:100%;text-align:left;padding:7px 10px;border:0;border-radius:6px;background:transparent;color:var(--text-dim);cursor:pointer;font-size:13px}.layout-menu button:hover{background:var(--bg-card);color:var(--text)}.canvas-drawer{position:absolute;top:12px;left:12px;bottom:12px;width:300px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:16px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080;display:flex;flex-direction:column;gap:10px;transform:translate(calc(-100% - 16px));opacity:0;pointer-events:none;transition:transform .2s ease,opacity .2s ease}.canvas-drawer.open{transform:translate(0);opacity:1;pointer-events:auto}.drawer-header{display:flex;align-items:center;justify-content:space-between}.drawer-header h2{margin:0;font-size:15px;display:inline-flex;align-items:center;gap:7px}.drawer-header h2 svg{color:var(--accent)}.drawer-hint{font-size:11px;color:var(--text-dim);line-height:1.4}.sa-all{align-self:flex-start;padding:4px 10px;border-radius:7px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.sa-all:hover:not(:disabled){color:var(--text);border-color:var(--border-strong)}.sa-all.active{color:var(--accent);border-color:var(--accent)}.sa-all:disabled{opacity:.5;cursor:default}.sa-list{display:flex;flex-direction:column;gap:3px;margin-top:2px}.sa-row{display:flex;align-items:center;gap:9px;padding:7px 8px;border-radius:8px;cursor:pointer;border:1px solid transparent;-webkit-user-select:none;user-select:none}.sa-row:hover{background:var(--bg-card)}.sa-row.active{background:var(--accent-soft);border-color:#e0a63a66}.sa-row.muted{cursor:default;opacity:.7}.sa-row.muted:hover{background:transparent}.sa-row input[type=checkbox]{accent-color:var(--accent);cursor:pointer}.sa-chip{width:12px;height:12px;border-radius:3px;flex:0 0 auto}.sa-chip.none{background:repeating-linear-gradient(45deg,#4a3c2c,#4a3c2c 2px,transparent 2px,transparent 4px)}.sa-name{flex:1;font-size:13px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.sa-row.muted .sa-name{color:var(--text-dim)}.sa-count{font-size:11px;color:var(--text-dim);background:var(--bg-card);padding:1px 7px;border-radius:99px;flex:0 0 auto}.entity-node{width:264px;background:var(--bg-card);border:1px solid var(--border);border-top:3px solid var(--accent);border-radius:10px;overflow:hidden;box-shadow:0 4px 18px #00000059;font-size:12px;transition:opacity .15s,box-shadow .15s,border-color .15s}.entity-node.selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent),0 8px 24px #00000080}.entity-node.highlighted{box-shadow:0 0 0 2px var(--pk),0 8px 24px #00000080}.entity-node.dimmed{opacity:.18}.entity-header{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#ffffff08;border-bottom:1px solid var(--border)}.entity-name{font-weight:700;font-size:13px;letter-spacing:.01em}.entity-badges{display:flex;gap:4px}.badge{font-size:10px;padding:1px 6px;border-radius:99px;background:var(--accent-soft);color:var(--accent);text-transform:uppercase;letter-spacing:.05em}.badge.ontology{background:#93c5fd1f;color:#93c5fd}.attr-section{padding:4px 0}.attr-section.keys{border-bottom:1px solid var(--border);background:#fcd34d0a}.attr-row{display:flex;align-items:center;gap:6px;padding:3px 12px;height:26px;line-height:20px;position:relative}.attr-row.empty{color:var(--text-dim);font-style:italic}.attr-row.more{color:var(--text-dim);font-style:italic;cursor:pointer;justify-content:center;height:22px;font-size:11px}.attr-row.more:hover{color:var(--accent);background:var(--accent-soft)}.attr-row.rel-hit{background:var(--accent-soft);box-shadow:inset 2px 0 0 var(--accent)}.attr-row.rel-hit .attr-name{color:var(--accent);font-weight:600}.attr-row.rel-dim{opacity:.35}.attr-row.endpoint .attr-name{font-style:normal}.attr-port{width:8px!important;height:8px!important;opacity:0;top:50%!important}.attr-port.react-flow__handle-left{left:-5px!important}.attr-port.react-flow__handle-right{right:-5px!important}.entity-node:hover .attr-port{opacity:.5}.attr-row:hover .attr-port{opacity:1!important;background:var(--accent)!important}.attr-icon{width:14px;text-align:center;font-size:10px;flex:none}.attr-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attr-name.pk{color:var(--pk);font-weight:600}.attr-type{color:var(--text-dim);font-family:var(--mono);font-size:10px;flex:none}.attr-notnull{color:var(--text-dim);font-size:8px;flex:none}.port{width:11px!important;height:11px!important;background:var(--border-strong)!important;border:2px solid var(--bg)!important;opacity:.55;transition:transform .12s ease,background .12s ease,opacity .12s ease}.entity-node:hover .port{opacity:1;background:var(--accent)!important;transform:scale(1.25);box-shadow:0 0 0 4px var(--accent-soft);cursor:crosshair}.port:hover{transform:scale(1.6)!important;cursor:crosshair}.entity-node:hover{border-color:var(--accent);box-shadow:0 0 0 1px #e0a63a40}.react-flow__connectionline .react-flow__edge-path,.react-flow__connection-path{stroke:var(--accent)!important;stroke-width:2!important}.rel-path{stroke:var(--border-strong);stroke-width:1.6}.rel-edge{cursor:pointer}.rel-glyph{stroke:var(--border-strong);stroke-width:1.6;fill:none}.rel-glyph.ring{fill:var(--bg)}.rel-edge:hover .rel-path,.rel-edge.selected .rel-path,.rel-edge:hover .rel-glyph,.rel-edge.selected .rel-glyph{stroke:var(--accent)}.rel-edge.dimmed{opacity:.12}.rel-label{fill:var(--text);font-size:11px;text-anchor:middle;paint-order:stroke;stroke:var(--bg);stroke-width:4px}.rel-handle{cursor:ew-resize}.rel-handle,.rel-handle *{cursor:ew-resize!important}.rel-handle .rel-grip{fill:var(--accent);stroke:var(--bg);opacity:.95}.rel-handle .rel-grip-dot{fill:var(--bg)}.rel-handle:hover .rel-grip{fill:var(--accent);filter:brightness(1.15)}.rel-endpoint,.rel-endpoint *{cursor:move!important}.rel-endpoint .rel-endpoint-dot{fill:var(--accent);stroke:var(--bg);opacity:.95}.rel-endpoint:hover .rel-endpoint-dot{filter:brightness(1.2)}.layout-menu-sep{height:1px;margin:4px 0;background:var(--border)}.detail-panel{position:absolute;top:12px;right:12px;bottom:12px;width:340px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.detail-header{display:flex;justify-content:space-between;align-items:flex-start}.detail-header h2{margin:0 0 6px;font-size:18px}.icon-btn{background:none;border:none;color:var(--text-dim);cursor:pointer;font-size:14px}.icon-btn:hover{color:var(--text)}.definition{color:var(--text-dim);font-size:13px;line-height:1.5}.detail-panel section{margin-top:18px}.detail-panel h3{margin:0 0 8px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.kv{display:flex;gap:8px;margin:4px 0;font-size:12px;align-items:baseline}.kv .k{color:var(--text-dim);min-width:72px}.kv .v{word-break:break-all}.chip{display:inline-block;font-size:11px;padding:2px 8px;margin:2px 4px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim)}.chip.pattern{background:var(--accent-soft);color:var(--accent)}.chip.layer-industry{background:#93c5fd26;color:#93c5fd}.chip.layer-core{background:var(--accent-soft);color:var(--accent)}.chip.layer-domain{background:#f0abfc26;color:#f0abfc}.chip.layer-specialised{background:#fcd34d26;color:var(--pk)}.cat-badge{font-size:10px;font-weight:700;margin-left:6px;padding:2px 8px;border-radius:5px;cursor:help}.cat-badge.supertype{background:#a78bfa2e;color:#a78bfa}.cat-badge.subtype{background:var(--accent-soft);color:var(--accent)}.udp-row td{padding:3px 6px;border-bottom:1px solid var(--border);font-size:12px}.udp-key{color:var(--text-dim);font-family:var(--mono);font-size:11px}.udp-val{color:var(--text)}.enum-badge{font-size:8px;font-weight:700;margin-left:6px;padding:1px 5px;border-radius:4px;background:#a78bfa2e;color:#a78bfa;vertical-align:middle;cursor:help}.key-row{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:12px}.key-badge{font-size:9px;font-weight:700;padding:2px 6px;border-radius:5px;background:#94a3b826;color:var(--text-dim);flex:none}.key-badge.pk{background:#fcd34d2e;color:var(--pk)}.key-badge.unique,.key-badge.alternate{background:var(--accent-soft);color:var(--accent)}.key-name{font-weight:600}.key-cols{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}.attr-table td{padding:4px 6px;border-bottom:1px solid var(--border)}.attr-table td:first-child{width:100%}.attr-table td:first-child .edit-input{min-width:120px}.attr-table td.pk{color:var(--pk);font-weight:600}.attr-table td.type{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table td.null{color:var(--text-dim);font-size:10px;text-align:right}.rel-link{display:flex;gap:8px;align-items:center;width:100%;background:var(--bg-card);border:1px solid var(--border);border-radius:8px;color:var(--text);padding:7px 10px;margin:4px 0;cursor:pointer;font-size:12px;text-align:left}.rel-link:hover{border-color:var(--accent)}.rel-card{color:var(--text-dim);font-family:var(--mono);font-size:11px}.ulid{font-family:var(--mono);font-size:11px;color:var(--text-dim);cursor:copy;word-break:break-all}.ulid:hover{color:var(--accent)}.splash{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--text-dim)}.splash.error pre{background:var(--bg-card);padding:12px 16px;border-radius:8px;max-width:640px;overflow:auto;color:var(--err);font-size:12px}.react-flow__minimap{background:var(--bg-raised)!important;border-radius:10px}.react-flow__controls{border-radius:10px;overflow:hidden;box-shadow:none!important}.react-flow__controls-button{background:var(--bg-raised)!important;border-bottom:1px solid var(--border)!important;fill:var(--text-dim)!important}.react-flow__controls-button:hover{fill:var(--text)!important}.edit-input{width:100%;padding:6px 9px;border-radius:7px;font-size:12px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-family:var(--font);outline:none}.edit-input:focus{border-color:var(--accent)}.entity-title-input{font-size:17px;font-weight:700;background:transparent;border-color:transparent;padding-left:0}.entity-title-input:hover,.entity-title-input:focus{border-color:var(--border);background:var(--bg-card);padding-left:9px}.definition-input{color:var(--text-dim);line-height:1.5;resize:vertical}.chip-select,.cell-select{font-size:11px;padding:2px 6px;margin:2px 6px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim);border:1px solid transparent;outline:none}.chip-select:hover,.cell-select:hover{border-color:var(--border-strong);color:var(--text)}.cell-select{border-radius:6px;background:transparent;max-width:110px}.mini-btn{font-size:11px;padding:3px 9px;border-radius:7px;cursor:pointer;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim)}.mini-btn:hover{color:var(--accent);border-color:var(--accent)}.mini-btn.danger:hover{color:var(--err);border-color:var(--err)}.h3-actions{float:right;display:inline-flex;gap:6px}.empty-hint{color:var(--text-dim);font-size:12px;font-style:italic}.add-attr{display:flex;gap:6px;margin-top:8px}.rel-row{display:flex;gap:6px;align-items:flex-start}.rel-row .rel-main{flex:1}.verb-phrases{display:flex;align-items:center;gap:4px;margin-top:2px;padding-left:4px}.verb-phrases .verb-input{font-size:11px;font-style:italic;color:var(--text-dim);min-width:40px}.verb-phrases .verb-sep{color:var(--text-dim);font-size:11px}.physical-name-row{display:flex;align-items:center;gap:6px;margin-top:2px}.physical-name-row .physical-label{font-size:9px;text-transform:uppercase;color:var(--text-dim);letter-spacing:.04em}.physical-name-input{font-size:12px;color:var(--text-dim)}.physical-col{display:block;font-size:10px;color:var(--text-dim);font-family:var(--mono, monospace)}.physical-col-input{display:block;font-size:10px;color:var(--text-dim)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#05080db3;z-index:50;display:flex;align-items:center;justify-content:center}.modal{width:440px;max-height:80vh;overflow-y:auto;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:14px;padding:20px;box-shadow:0 24px 80px #0009}.modal.wide{width:600px}.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}.modal-header h2{margin:0;font-size:16px}.modal-search{margin-bottom:10px}.modal-footer{display:flex;gap:10px;justify-content:flex-end;align-items:center;margin-top:14px}.modal-footer label{font-size:11px;color:var(--text-dim);display:flex;flex-direction:column;gap:3px}.modal-footer select,.form-row select{background:var(--bg-card);color:var(--text);border:1px solid var(--border);border-radius:7px;padding:5px 8px;font-size:12px}.primary-btn{padding:8px 16px;border-radius:8px;border:none;cursor:pointer;background:var(--accent);color:var(--accent-ink);font-weight:700;font-size:13px}.primary-btn:disabled{opacity:.4;cursor:default}.danger-btn{padding:8px 16px;border-radius:8px;border:1px solid var(--err);cursor:pointer;background:#f8717124;color:var(--err);font-weight:700;font-size:13px}.form-row{display:flex;flex-direction:column;gap:4px;margin-bottom:14px;font-size:12px;color:var(--text-dim)}.form-row>label{font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:10px}.form-error{color:var(--err);font-size:11px}.form-preview{color:var(--text-dim);font-size:11px;word-break:break-all;opacity:.85}.form-preview:before{content:""}.form-hint{color:var(--text-dim);font-size:11px;font-style:italic;opacity:.75;word-break:break-word}.term-results{display:flex;flex-direction:column;gap:8px;max-height:44vh;overflow-y:auto}.term-card{text-align:left;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:10px 12px;cursor:pointer;color:var(--text)}.term-card:hover{border-color:var(--border-strong)}.term-card.picked{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}.term-head{display:flex;justify-content:space-between;align-items:baseline}.term-label{font-weight:600;font-size:13px}.term-source{font-size:10px;color:var(--text-dim);text-transform:uppercase;letter-spacing:.06em}.term-iri{font-size:10px;color:var(--accent);display:block;margin:2px 0;word-break:break-all}.term-def{font-size:11px;color:var(--text-dim);margin:4px 0 0;line-height:1.45}.kind-badge{font-size:8px;padding:1px 5px;margin-right:6px;border-radius:999px;background:#f0abfc26;color:#f0abfc;letter-spacing:.04em}.src-picker{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}.src-chip{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:3px 9px;border-radius:999px;background:var(--bg);border:1px solid var(--border);color:var(--text-dim);cursor:pointer}.src-chip:hover{border-color:var(--border-strong);color:var(--text)}.src-chip.active{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}.src-layer{font-size:8px;padding:0 5px;border-radius:999px;text-transform:uppercase;letter-spacing:.04em}.side-panel{position:absolute;top:12px;right:12px;bottom:12px;width:380px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.side-panel h2{margin:0;font-size:16px}.side-panel h4{margin:10px 0 6px;font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.panel-body{margin-top:12px}.panel-body.ok{color:var(--ok)}.meta-line{font-size:10px;color:var(--text-dim);margin:6px 0 10px}.coverage-banner{font-size:12px;padding:8px 12px;border-radius:9px;margin-bottom:12px;background:#34d3991a;color:var(--ok)}.coverage-banner.warn{background:#fbbf241a;color:var(--warn)}.layer-band{border:1px dashed var(--border);border-radius:10px;padding:8px 12px 10px;margin-bottom:10px}.layer-band.external{border-style:solid;background:#93c5fd0a}.stack-term{display:flex;justify-content:space-between;align-items:baseline;gap:8px;width:100%;background:var(--bg-card);border:1px solid var(--border);color:var(--text);border-radius:7px;padding:5px 10px;margin:4px 0;font-size:12px;cursor:pointer;text-align:left}div.stack-term{cursor:default}.stack-term:hover{border-color:var(--border-strong)}.stack-term.uncovered{border-color:var(--err)}.align-arrow{font-size:10px;color:var(--accent);white-space:nowrap}.align-arrow.unresolved{color:var(--warn)}.align-arrow.missing{color:var(--err);font-style:italic}.align-arrow.proposed{color:var(--warn);font-style:italic}.ref-list{display:flex;flex-direction:column;gap:6px;margin-top:4px}.ref-card{border:1px solid var(--border);border-radius:8px;padding:6px 8px;background:var(--bg)}.ref-card.proposed{border-color:var(--warn)}.ref-head{display:flex;align-items:baseline;gap:8px;justify-content:space-between}.ref-uri{font-family:var(--mono);font-size:12px;word-break:break-all}.ref-status{font-size:9px;text-transform:uppercase;letter-spacing:.04em}.ref-status.accepted{color:var(--accent)}.ref-status.proposed{color:var(--warn)}.ref-meta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:5px}.ref-pill{font-size:10px;padding:1px 6px;border-radius:999px;background:var(--accent-soft);color:var(--accent)}.ref-via{font-size:10px;color:var(--text-dim)}.ref-actions{display:flex;gap:6px;margin-top:6px}.dirty-list{list-style:none;padding:0;margin:0 0 10px;font-size:12px}.dirty-list li{padding:2px 0}.dirty-state{color:var(--warn);margin-right:6px;font-family:var(--mono)}.diff-view{background:var(--bg);border:1px solid var(--border);border-radius:9px;padding:10px;font-size:10.5px;line-height:1.5;overflow:auto;max-height:42vh;font-family:var(--mono);white-space:pre;margin-bottom:10px}.diff-add{color:var(--ok)}.diff-del{color:var(--err)}.diff-hunk{color:#93c5fd}.decision{border:1px solid var(--border);border-radius:9px;padding:8px 12px;margin-bottom:8px}.decision.accepted{opacity:.65}.decision.rejected{opacity:.45}.decision-head{display:flex;gap:6px;align-items:center}.decision-mark{font-weight:700}.decision-subject{font-size:12px;margin:6px 0}.decision-actions{display:flex;gap:6px}.toast{position:absolute;bottom:20px;left:50%;transform:translate(-50%);background:var(--bg-raised);border:1px solid var(--warn);color:var(--text);border-radius:10px;padding:10px 18px;font-size:12px;z-index:60;box-shadow:0 10px 30px #00000080} +.react-flow{direction:ltr}.react-flow__container{position:absolute;width:100%;height:100%;top:0;left:0}.react-flow__pane{z-index:1;cursor:-webkit-grab;cursor:grab}.react-flow__pane.selection{cursor:pointer}.react-flow__pane.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__viewport{transform-origin:0 0;z-index:2;pointer-events:none}.react-flow__renderer{z-index:4}.react-flow__selection{z-index:6}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible{outline:none}.react-flow .react-flow__edges{pointer-events:none;overflow:visible}.react-flow__edge-path,.react-flow__connection-path{stroke:#b1b1b7;stroke-width:1;fill:none}.react-flow__edge{pointer-events:visibleStroke;cursor:pointer}.react-flow__edge.animated path{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__edge.animated path.react-flow__edge-interaction{stroke-dasharray:none;-webkit-animation:none;animation:none}.react-flow__edge.inactive{pointer-events:none}.react-flow__edge.selected,.react-flow__edge:focus,.react-flow__edge:focus-visible{outline:none}.react-flow__edge.selected .react-flow__edge-path,.react-flow__edge:focus .react-flow__edge-path,.react-flow__edge:focus-visible .react-flow__edge-path{stroke:#555}.react-flow__edge-textwrapper{pointer-events:all}.react-flow__edge-textbg{fill:#fff}.react-flow__edge .react-flow__edge-text{pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__connection{pointer-events:none}.react-flow__connection .animated{stroke-dasharray:5;-webkit-animation:dashdraw .5s linear infinite;animation:dashdraw .5s linear infinite}.react-flow__connectionline{z-index:1001}.react-flow__nodes{pointer-events:none;transform-origin:0 0}.react-flow__node{position:absolute;-webkit-user-select:none;-moz-user-select:none;user-select:none;pointer-events:all;transform-origin:0 0;box-sizing:border-box;cursor:-webkit-grab;cursor:grab}.react-flow__node.dragging{cursor:-webkit-grabbing;cursor:grabbing}.react-flow__nodesselection{z-index:3;transform-origin:left top;pointer-events:none}.react-flow__nodesselection-rect{position:absolute;pointer-events:all;cursor:-webkit-grab;cursor:grab}.react-flow__handle{position:absolute;pointer-events:none;min-width:5px;min-height:5px;width:6px;height:6px;background:#1a192b;border:1px solid white;border-radius:100%}.react-flow__handle.connectionindicator{pointer-events:all;cursor:crosshair}.react-flow__handle-bottom{top:auto;left:50%;bottom:-4px;transform:translate(-50%)}.react-flow__handle-top{left:50%;top:-4px;transform:translate(-50%)}.react-flow__handle-left{top:50%;left:-4px;transform:translateY(-50%)}.react-flow__handle-right{right:-4px;top:50%;transform:translateY(-50%)}.react-flow__edgeupdater{cursor:move;pointer-events:all}.react-flow__panel{position:absolute;z-index:5;margin:15px}.react-flow__panel.top{top:0}.react-flow__panel.bottom{bottom:0}.react-flow__panel.left{left:0}.react-flow__panel.right{right:0}.react-flow__panel.center{left:50%;transform:translate(-50%)}.react-flow__attribution{font-size:10px;background:#ffffff80;padding:2px 3px;margin:0}.react-flow__attribution a{text-decoration:none;color:#999}@-webkit-keyframes dashdraw{0%{stroke-dashoffset:10}}@keyframes dashdraw{0%{stroke-dashoffset:10}}.react-flow__edgelabel-renderer{position:absolute;width:100%;height:100%;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.react-flow__edge.updating .react-flow__edge-path{stroke:#777}.react-flow__edge-text{font-size:10px}.react-flow__node.selectable:focus,.react-flow__node.selectable:focus-visible{outline:none}.react-flow__node-default,.react-flow__node-input,.react-flow__node-output,.react-flow__node-group{padding:10px;border-radius:3px;width:150px;font-size:12px;color:#222;text-align:center;border-width:1px;border-style:solid;border-color:#1a192b;background-color:#fff}.react-flow__node-default.selectable:hover,.react-flow__node-input.selectable:hover,.react-flow__node-output.selectable:hover,.react-flow__node-group.selectable:hover{box-shadow:0 1px 4px 1px #00000014}.react-flow__node-default.selectable.selected,.react-flow__node-default.selectable:focus,.react-flow__node-default.selectable:focus-visible,.react-flow__node-input.selectable.selected,.react-flow__node-input.selectable:focus,.react-flow__node-input.selectable:focus-visible,.react-flow__node-output.selectable.selected,.react-flow__node-output.selectable:focus,.react-flow__node-output.selectable:focus-visible,.react-flow__node-group.selectable.selected,.react-flow__node-group.selectable:focus,.react-flow__node-group.selectable:focus-visible{box-shadow:0 0 0 .5px #1a192b}.react-flow__node-group{background-color:#f0f0f040}.react-flow__nodesselection-rect,.react-flow__selection{background:#0059dc14;border:1px dotted rgba(0,89,220,.8)}.react-flow__nodesselection-rect:focus,.react-flow__nodesselection-rect:focus-visible,.react-flow__selection:focus,.react-flow__selection:focus-visible{outline:none}.react-flow__controls{box-shadow:0 0 2px 1px #00000014}.react-flow__controls-button{border:none;background:#fefefe;border-bottom:1px solid #eee;box-sizing:content-box;display:flex;justify-content:center;align-items:center;width:16px;height:16px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;padding:5px}.react-flow__controls-button:hover{background:#f4f4f4}.react-flow__controls-button svg{width:100%;max-width:12px;max-height:12px}.react-flow__controls-button:disabled{pointer-events:none}.react-flow__controls-button:disabled svg{fill-opacity:.4}.react-flow__minimap{background-color:#fff}.react-flow__minimap svg{display:block}.react-flow__resize-control{position:absolute}.react-flow__resize-control.left,.react-flow__resize-control.right{cursor:ew-resize}.react-flow__resize-control.top,.react-flow__resize-control.bottom{cursor:ns-resize}.react-flow__resize-control.top.left,.react-flow__resize-control.bottom.right{cursor:nwse-resize}.react-flow__resize-control.bottom.left,.react-flow__resize-control.top.right{cursor:nesw-resize}.react-flow__resize-control.handle{width:4px;height:4px;border:1px solid #fff;border-radius:1px;background-color:#3367d9;transform:translate(-50%,-50%)}.react-flow__resize-control.handle.left{left:0;top:50%}.react-flow__resize-control.handle.right{left:100%;top:50%}.react-flow__resize-control.handle.top{left:50%;top:0}.react-flow__resize-control.handle.bottom{left:50%;top:100%}.react-flow__resize-control.handle.top.left,.react-flow__resize-control.handle.bottom.left{left:0}.react-flow__resize-control.handle.top.right,.react-flow__resize-control.handle.bottom.right{left:100%}.react-flow__resize-control.line{border-color:#3367d9;border-width:0;border-style:solid}.react-flow__resize-control.line.left,.react-flow__resize-control.line.right{width:1px;transform:translate(-50%);top:0;height:100%}.react-flow__resize-control.line.left{left:0;border-left-width:1px}.react-flow__resize-control.line.right{left:100%;border-right-width:1px}.react-flow__resize-control.line.top,.react-flow__resize-control.line.bottom{height:1px;transform:translateY(-50%);left:0;width:100%}.react-flow__resize-control.line.top{top:0;border-top-width:1px}.react-flow__resize-control.line.bottom{border-bottom-width:1px;top:100%}.ie-wrap{position:relative;display:inline-flex;gap:6px}.erd-ico{font-size:13px;line-height:1;opacity:.85;margin-right:1px}.ie-wrap button:hover .erd-ico,.ie-wrap button.on .erd-ico,.ie-wrap button.active .erd-ico{opacity:1}.erd-caret{opacity:.55;margin-left:1px}.ie-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:30;min-width:220px;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:6px;box-shadow:0 12px 32px #00000073;display:flex;flex-direction:column;gap:2px}.ie-item{display:block;padding:8px 10px;border-radius:6px;color:var(--text);text-decoration:none;font-size:13px;cursor:pointer}.ie-item:hover{background:#5eead424;color:var(--accent)}.ie-dialect{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 10px 8px;margin-bottom:4px;border-bottom:1px solid var(--border);font-size:12px;color:var(--text-dim)}.ie-dialect select{background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:6px;padding:3px 6px;font-size:12px}.ie-import{width:380px;padding:12px;gap:8px}.ie-tabs{display:flex;gap:4px}.ie-tab{flex:1;padding:6px 8px;border-radius:6px;font-size:12px;cursor:pointer;background:none;border:1px solid var(--border);color:var(--text-dim)}.ie-tab.active{border-color:var(--accent);color:var(--accent);background:#5eead41a}.ie-hint{font-size:11px;color:var(--text-dim);margin:0}.ie-textarea{width:100%;font-family:var(--mono);font-size:12px;resize:vertical;background:var(--bg);color:var(--text);border:1px solid var(--border);border-radius:8px;padding:8px;box-sizing:border-box}.ie-textarea:focus{border-color:var(--accent);outline:none}.ie-file{font-size:11px;color:var(--text-dim)}.ie-warn{font-size:11px;color:var(--pk);margin:0}.ie-error{font-size:12px;color:var(--err);margin:0}.ie-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:4px}:root{--bg: #14110f;--bg-raised: #1c1815;--bg-card: #221d19;--border: #33291f;--border-strong: #4a3c2c;--text: #ece6dd;--text-dim: #a89a86;--accent: #e0a63a;--accent-soft: rgba(224, 166, 58, .15);--accent-ink: #241a08;--pk: #f2c14e;--err: #f0857a;--warn: #e6a94a;--ok: #6cbf73;--font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;--mono: "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace}*{box-sizing:border-box}html,body,#root{height:100%;margin:0}body{font-family:var(--font);background:var(--bg);color:var(--text)}.app{display:flex;flex-direction:column;height:100%}.canvas-wrap{flex:1;position:relative;min-height:0}.react-flow{background:var(--bg)}.topbar{display:flex;flex-direction:column;padding:8px 16px 0;background:var(--bg-raised);border-bottom:1px solid var(--border);z-index:10}.topbar-row{display:flex;align-items:center;gap:14px}.topbar-row.context{padding-bottom:8px}.topbar-row.actions{gap:10px;padding-bottom:8px;flex-wrap:wrap}.brand{display:flex;align-items:baseline;gap:8px;white-space:nowrap}.logo{color:var(--accent);font-size:18px}.brand-name{font-weight:700;letter-spacing:.02em}.project-name{color:var(--text-dim);font-size:13px}.search{flex:0 1 300px;margin-left:auto;padding:7px 12px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-size:13px;outline:none}.search:focus{border-color:var(--accent)}.stats{display:flex;align-items:center;gap:12px;font-size:12px;color:var(--text-dim)}.stat-item{display:inline-flex;align-items:center;gap:5px}.stat-item svg{color:var(--text-dim)}.diag-chip{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:99px;font-weight:600}.diag-chip.ok{background:#34d39926;color:var(--ok)}.diag-chip.warn{background:#fbbf2426;color:var(--warn)}.diag-chip.err{background:#f8717126;color:var(--err)}.hamburger{position:relative;display:inline-flex;align-items:center;justify-content:center;padding:6px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer}.hamburger:hover{color:var(--text);border-color:var(--border-strong)}.hamburger.active{color:var(--accent);border-color:var(--accent)}.hamburger-badge{position:absolute;top:-6px;right:-6px;min-width:15px;height:15px;padding:0 3px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-size:10px;font-weight:700;line-height:15px;text-align:center}.btn-group{display:inline-flex;align-items:center;gap:2px;background:var(--bg-card);border:1px solid var(--border);border-radius:9px;padding:2px}.grp-tag{font-size:10px;color:var(--text-dim);opacity:.75;padding:0 6px 0 4px;letter-spacing:.03em;text-transform:none;white-space:nowrap}.grp-btn{display:inline-flex;align-items:center;gap:5px;padding:5px 9px;border-radius:6px;border:none;background:transparent;color:var(--text-dim);cursor:pointer;font-size:12px;white-space:nowrap}.grp-btn.icon-only{padding:5px 7px}.grp-btn:hover{color:var(--text);background:#ffffff0d}.grp-btn.active{color:var(--accent)}.grp-btn.active svg{color:var(--accent)}.grp-badge{width:6px;height:6px;border-radius:50%;background:var(--warn);display:inline-block;margin-left:1px}.dir-arrow{display:inline-flex;transition:transform .15s ease}.tool-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 11px;border-radius:8px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.tool-btn:hover{color:var(--text);border-color:var(--border-strong)}.tool-btn.active{color:var(--accent);border-color:var(--accent)}.tool-btn.primary{color:var(--accent);border-color:#e0a63a66;font-weight:600}.layout-picker{position:relative;display:inline-flex;gap:2px}.layout-picker .caret{font-size:10px}.layout-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:20;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:8px;padding:4px;min-width:150px;box-shadow:0 8px 24px #0006}.layout-menu button{display:block;width:100%;text-align:left;padding:7px 10px;border:0;border-radius:6px;background:transparent;color:var(--text-dim);cursor:pointer;font-size:13px}.layout-menu button:hover{background:var(--bg-card);color:var(--text)}.canvas-drawer{position:absolute;top:12px;left:12px;bottom:12px;width:300px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:16px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080;display:flex;flex-direction:column;gap:10px;transform:translate(calc(-100% - 16px));opacity:0;pointer-events:none;transition:transform .2s ease,opacity .2s ease}.canvas-drawer.open{transform:translate(0);opacity:1;pointer-events:auto}.drawer-header{display:flex;align-items:center;justify-content:space-between}.drawer-header h2{margin:0;font-size:15px;display:inline-flex;align-items:center;gap:7px}.drawer-header h2 svg{color:var(--accent)}.drawer-hint{font-size:11px;color:var(--text-dim);line-height:1.4}.sa-all{align-self:flex-start;padding:4px 10px;border-radius:7px;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim);cursor:pointer;font-size:12px}.sa-all:hover:not(:disabled){color:var(--text);border-color:var(--border-strong)}.sa-all.active{color:var(--accent);border-color:var(--accent)}.sa-all:disabled{opacity:.5;cursor:default}.sa-list{display:flex;flex-direction:column;gap:3px;margin-top:2px}.sa-row{display:flex;align-items:center;gap:9px;padding:7px 8px;border-radius:8px;cursor:pointer;border:1px solid transparent;-webkit-user-select:none;user-select:none}.sa-row:hover{background:var(--bg-card)}.sa-row.active{background:var(--accent-soft);border-color:#e0a63a66}.sa-row.muted{cursor:default;opacity:.7}.sa-row.muted:hover{background:transparent}.sa-row input[type=checkbox]{accent-color:var(--accent);cursor:pointer}.sa-chip{width:12px;height:12px;border-radius:3px;flex:0 0 auto}.sa-chip.none{background:repeating-linear-gradient(45deg,#4a3c2c,#4a3c2c 2px,transparent 2px,transparent 4px)}.sa-name{flex:1;font-size:13px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.sa-row.muted .sa-name{color:var(--text-dim)}.sa-count{font-size:11px;color:var(--text-dim);background:var(--bg-card);padding:1px 7px;border-radius:99px;flex:0 0 auto}.entity-node{width:264px;background:var(--bg-card);border:1px solid var(--border);border-top:3px solid var(--accent);border-radius:10px;overflow:hidden;box-shadow:0 4px 18px #00000059;font-size:12px;transition:opacity .15s,box-shadow .15s,border-color .15s}.entity-node.selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent),0 8px 24px #00000080}.entity-node.highlighted{box-shadow:0 0 0 2px var(--pk),0 8px 24px #00000080}.entity-node.dimmed{opacity:.18}.entity-header{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#ffffff08;border-bottom:1px solid var(--border)}.entity-name{font-weight:700;font-size:13px;letter-spacing:.01em}.entity-badges{display:flex;gap:4px}.badge{font-size:10px;padding:1px 6px;border-radius:99px;background:var(--accent-soft);color:var(--accent);text-transform:uppercase;letter-spacing:.05em}.badge.ontology{background:#93c5fd1f;color:#93c5fd}.attr-section{padding:4px 0}.attr-section.keys{border-bottom:1px solid var(--border);background:#fcd34d0a}.attr-row{display:flex;align-items:center;gap:6px;padding:3px 12px;height:26px;line-height:20px;position:relative}.attr-row.empty{color:var(--text-dim);font-style:italic}.attr-row.more{color:var(--text-dim);font-style:italic;cursor:pointer;justify-content:center;height:22px;font-size:11px}.attr-row.more:hover{color:var(--accent);background:var(--accent-soft)}.attr-row.rel-hit{background:var(--accent-soft);box-shadow:inset 2px 0 0 var(--accent)}.attr-row.rel-hit .attr-name{color:var(--accent);font-weight:600}.attr-row.rel-dim{opacity:.35}.attr-row.endpoint .attr-name{font-style:normal}.attr-port{width:8px!important;height:8px!important;opacity:0;top:50%!important}.attr-port.react-flow__handle-left{left:-5px!important}.attr-port.react-flow__handle-right{right:-5px!important}.entity-node:hover .attr-port{opacity:.5}.attr-row:hover .attr-port{opacity:1!important;background:var(--accent)!important}.attr-icon{width:14px;text-align:center;font-size:10px;flex:none}.attr-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attr-name.pk{color:var(--pk);font-weight:600}.attr-type{color:var(--text-dim);font-family:var(--mono);font-size:10px;flex:none}.attr-notnull{color:var(--text-dim);font-size:8px;flex:none}.port{width:11px!important;height:11px!important;background:var(--border-strong)!important;border:2px solid var(--bg)!important;opacity:.55;transition:transform .12s ease,background .12s ease,opacity .12s ease}.entity-node:hover .port{opacity:1;background:var(--accent)!important;transform:scale(1.25);box-shadow:0 0 0 4px var(--accent-soft);cursor:crosshair}.port:hover{transform:scale(1.6)!important;cursor:crosshair}.entity-node:hover{border-color:var(--accent);box-shadow:0 0 0 1px #e0a63a40}.react-flow__connectionline .react-flow__edge-path,.react-flow__connection-path{stroke:var(--accent)!important;stroke-width:2!important}.rel-path{stroke:var(--border-strong);stroke-width:1.6}.rel-edge{cursor:pointer}.rel-glyph{stroke:var(--border-strong);stroke-width:1.6;fill:none}.rel-glyph.ring{fill:var(--bg)}.rel-edge:hover .rel-path,.rel-edge.selected .rel-path,.rel-edge:hover .rel-glyph,.rel-edge.selected .rel-glyph{stroke:var(--accent)}.rel-edge.dimmed{opacity:.12}.rel-label{fill:var(--text);font-size:11px;text-anchor:middle;paint-order:stroke;stroke:var(--bg);stroke-width:4px}.rel-handle{cursor:ew-resize}.rel-handle,.rel-handle *{cursor:ew-resize!important}.rel-handle .rel-grip{fill:var(--accent);stroke:var(--bg);opacity:1}.rel-handle .rel-grip-dot{fill:var(--bg)}.rel-handle:hover .rel-grip{fill:var(--accent);filter:brightness(1.25) drop-shadow(0 0 3px var(--accent))}.rel-endpoint,.rel-endpoint *{cursor:move!important}.rel-endpoint .rel-endpoint-dot{fill:var(--accent);stroke:var(--bg);opacity:1}.rel-endpoint:hover .rel-endpoint-dot{filter:brightness(1.3) drop-shadow(0 0 3px var(--accent))}.rel-edge.selected .rel-path{stroke-width:2.2;filter:drop-shadow(0 0 2px var(--accent))}.layout-menu-sep{height:1px;margin:4px 0;background:var(--border)}.detail-panel{position:absolute;top:12px;right:12px;bottom:12px;width:340px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.detail-header{display:flex;justify-content:space-between;align-items:flex-start}.detail-header h2{margin:0 0 6px;font-size:18px}.icon-btn{background:none;border:none;color:var(--text-dim);cursor:pointer;font-size:14px}.icon-btn:hover{color:var(--text)}.definition{color:var(--text-dim);font-size:13px;line-height:1.5}.detail-panel section{margin-top:18px}.detail-panel h3{margin:0 0 8px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.kv{display:flex;gap:8px;margin:4px 0;font-size:12px;align-items:baseline}.kv .k{color:var(--text-dim);min-width:72px}.kv .v{word-break:break-all}.chip{display:inline-block;font-size:11px;padding:2px 8px;margin:2px 4px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim)}.chip.pattern{background:var(--accent-soft);color:var(--accent)}.chip.layer-industry{background:#93c5fd26;color:#93c5fd}.chip.layer-core{background:var(--accent-soft);color:var(--accent)}.chip.layer-domain{background:#f0abfc26;color:#f0abfc}.chip.layer-specialised{background:#fcd34d26;color:var(--pk)}.cat-badge{font-size:10px;font-weight:700;margin-left:6px;padding:2px 8px;border-radius:5px;cursor:help}.cat-badge.supertype{background:#a78bfa2e;color:#a78bfa}.cat-badge.subtype{background:var(--accent-soft);color:var(--accent)}.udp-row td{padding:3px 6px;border-bottom:1px solid var(--border);font-size:12px}.udp-key{color:var(--text-dim);font-family:var(--mono);font-size:11px}.udp-val{color:var(--text)}.enum-badge{font-size:8px;font-weight:700;margin-left:6px;padding:1px 5px;border-radius:4px;background:#a78bfa2e;color:#a78bfa;vertical-align:middle;cursor:help}.key-row{display:flex;align-items:center;gap:8px;padding:4px 0;font-size:12px}.key-badge{font-size:9px;font-weight:700;padding:2px 6px;border-radius:5px;background:#94a3b826;color:var(--text-dim);flex:none}.key-badge.pk{background:#fcd34d2e;color:var(--pk)}.key-badge.unique,.key-badge.alternate{background:var(--accent-soft);color:var(--accent)}.key-name{font-weight:600}.key-cols{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}.attr-table td{padding:4px 6px;border-bottom:1px solid var(--border)}.attr-table td:first-child{width:100%}.attr-table td:first-child .edit-input{min-width:120px}.attr-table td.pk{color:var(--pk);font-weight:600}.attr-table td.type{color:var(--text-dim);font-family:var(--mono);font-size:11px}.attr-table td.null{color:var(--text-dim);font-size:10px;text-align:right}.rel-link{display:flex;gap:8px;align-items:center;width:100%;background:var(--bg-card);border:1px solid var(--border);border-radius:8px;color:var(--text);padding:7px 10px;margin:4px 0;cursor:pointer;font-size:12px;text-align:left}.rel-link:hover{border-color:var(--accent)}.rel-card{color:var(--text-dim);font-family:var(--mono);font-size:11px}.ulid{font-family:var(--mono);font-size:11px;color:var(--text-dim);cursor:copy;word-break:break-all}.ulid:hover{color:var(--accent)}.splash{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--text-dim)}.splash.error pre{background:var(--bg-card);padding:12px 16px;border-radius:8px;max-width:640px;overflow:auto;color:var(--err);font-size:12px}.react-flow__minimap{background:var(--bg-raised)!important;border-radius:10px}.react-flow__controls{border-radius:10px;overflow:hidden;box-shadow:none!important}.react-flow__controls-button{background:var(--bg-raised)!important;border-bottom:1px solid var(--border)!important;fill:var(--text-dim)!important}.react-flow__controls-button:hover{fill:var(--text)!important}.edit-input{width:100%;padding:6px 9px;border-radius:7px;font-size:12px;border:1px solid var(--border);background:var(--bg-card);color:var(--text);font-family:var(--font);outline:none}.edit-input:focus{border-color:var(--accent)}.entity-title-input{font-size:17px;font-weight:700;background:transparent;border-color:transparent;padding-left:0}.entity-title-input:hover,.entity-title-input:focus{border-color:var(--border);background:var(--bg-card);padding-left:9px}.definition-input{color:var(--text-dim);line-height:1.5;resize:vertical}.chip-select,.cell-select{font-size:11px;padding:2px 6px;margin:2px 6px 2px 0;border-radius:99px;background:#94a3b81f;color:var(--text-dim);border:1px solid transparent;outline:none}.chip-select:hover,.cell-select:hover{border-color:var(--border-strong);color:var(--text)}.cell-select{border-radius:6px;background:transparent;max-width:110px}.mini-btn{font-size:11px;padding:3px 9px;border-radius:7px;cursor:pointer;border:1px solid var(--border);background:var(--bg-card);color:var(--text-dim)}.mini-btn:hover{color:var(--accent);border-color:var(--accent)}.mini-btn.danger:hover{color:var(--err);border-color:var(--err)}.h3-actions{float:right;display:inline-flex;gap:6px}.empty-hint{color:var(--text-dim);font-size:12px;font-style:italic}.add-attr{display:flex;gap:6px;margin-top:8px}.rel-row{display:flex;gap:6px;align-items:flex-start}.rel-row .rel-main{flex:1}.verb-phrases{display:flex;align-items:center;gap:4px;margin-top:2px;padding-left:4px}.verb-phrases .verb-input{font-size:11px;font-style:italic;color:var(--text-dim);min-width:40px}.verb-phrases .verb-sep{color:var(--text-dim);font-size:11px}.physical-name-row{display:flex;align-items:center;gap:6px;margin-top:2px}.physical-name-row .physical-label{font-size:9px;text-transform:uppercase;color:var(--text-dim);letter-spacing:.04em}.physical-name-input{font-size:12px;color:var(--text-dim)}.physical-col{display:block;font-size:10px;color:var(--text-dim);font-family:var(--mono, monospace)}.physical-col-input{display:block;font-size:10px;color:var(--text-dim)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#05080db3;z-index:50;display:flex;align-items:center;justify-content:center}.modal{width:440px;max-height:80vh;overflow-y:auto;background:var(--bg-raised);border:1px solid var(--border-strong);border-radius:14px;padding:20px;box-shadow:0 24px 80px #0009}.modal.wide{width:600px}.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}.modal-header h2{margin:0;font-size:16px}.modal-search{margin-bottom:10px}.modal-footer{display:flex;gap:10px;justify-content:flex-end;align-items:center;margin-top:14px}.modal-footer label{font-size:11px;color:var(--text-dim);display:flex;flex-direction:column;gap:3px}.modal-footer select,.form-row select{background:var(--bg-card);color:var(--text);border:1px solid var(--border);border-radius:7px;padding:5px 8px;font-size:12px}.primary-btn{padding:8px 16px;border-radius:8px;border:none;cursor:pointer;background:var(--accent);color:var(--accent-ink);font-weight:700;font-size:13px}.primary-btn:disabled{opacity:.4;cursor:default}.danger-btn{padding:8px 16px;border-radius:8px;border:1px solid var(--err);cursor:pointer;background:#f8717124;color:var(--err);font-weight:700;font-size:13px}.form-row{display:flex;flex-direction:column;gap:4px;margin-bottom:14px;font-size:12px;color:var(--text-dim)}.form-row>label{font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:10px}.form-error{color:var(--err);font-size:11px}.form-preview{color:var(--text-dim);font-size:11px;word-break:break-all;opacity:.85}.form-preview:before{content:""}.form-hint{color:var(--text-dim);font-size:11px;font-style:italic;opacity:.75;word-break:break-word}.term-results{display:flex;flex-direction:column;gap:8px;max-height:44vh;overflow-y:auto}.term-card{text-align:left;background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:10px 12px;cursor:pointer;color:var(--text)}.term-card:hover{border-color:var(--border-strong)}.term-card.picked{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}.term-head{display:flex;justify-content:space-between;align-items:baseline}.term-label{font-weight:600;font-size:13px}.term-source{font-size:10px;color:var(--text-dim);text-transform:uppercase;letter-spacing:.06em}.term-iri{font-size:10px;color:var(--accent);display:block;margin:2px 0;word-break:break-all}.term-def{font-size:11px;color:var(--text-dim);margin:4px 0 0;line-height:1.45}.kind-badge{font-size:8px;padding:1px 5px;margin-right:6px;border-radius:999px;background:#f0abfc26;color:#f0abfc;letter-spacing:.04em}.src-picker{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}.src-chip{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:3px 9px;border-radius:999px;background:var(--bg);border:1px solid var(--border);color:var(--text-dim);cursor:pointer}.src-chip:hover{border-color:var(--border-strong);color:var(--text)}.src-chip.active{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}.src-layer{font-size:8px;padding:0 5px;border-radius:999px;text-transform:uppercase;letter-spacing:.04em}.side-panel{position:absolute;top:12px;right:12px;bottom:12px;width:380px;background:var(--bg-raised);border:1px solid var(--border);border-radius:14px;padding:18px;overflow-y:auto;z-index:9;box-shadow:0 12px 40px #00000080}.side-panel h2{margin:0;font-size:16px}.side-panel h4{margin:10px 0 6px;font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim)}.panel-body{margin-top:12px}.panel-body.ok{color:var(--ok)}.meta-line{font-size:10px;color:var(--text-dim);margin:6px 0 10px}.coverage-banner{font-size:12px;padding:8px 12px;border-radius:9px;margin-bottom:12px;background:#34d3991a;color:var(--ok)}.coverage-banner.warn{background:#fbbf241a;color:var(--warn)}.layer-band{border:1px dashed var(--border);border-radius:10px;padding:8px 12px 10px;margin-bottom:10px}.layer-band.external{border-style:solid;background:#93c5fd0a}.stack-term{display:flex;justify-content:space-between;align-items:baseline;gap:8px;width:100%;background:var(--bg-card);border:1px solid var(--border);color:var(--text);border-radius:7px;padding:5px 10px;margin:4px 0;font-size:12px;cursor:pointer;text-align:left}div.stack-term{cursor:default}.stack-term:hover{border-color:var(--border-strong)}.stack-term.uncovered{border-color:var(--err)}.align-arrow{font-size:10px;color:var(--accent);white-space:nowrap}.align-arrow.unresolved{color:var(--warn)}.align-arrow.missing{color:var(--err);font-style:italic}.align-arrow.proposed{color:var(--warn);font-style:italic}.ref-list{display:flex;flex-direction:column;gap:6px;margin-top:4px}.ref-card{border:1px solid var(--border);border-radius:8px;padding:6px 8px;background:var(--bg)}.ref-card.proposed{border-color:var(--warn)}.ref-head{display:flex;align-items:baseline;gap:8px;justify-content:space-between}.ref-uri{font-family:var(--mono);font-size:12px;word-break:break-all}.ref-status{font-size:9px;text-transform:uppercase;letter-spacing:.04em}.ref-status.accepted{color:var(--accent)}.ref-status.proposed{color:var(--warn)}.ref-meta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:5px}.ref-pill{font-size:10px;padding:1px 6px;border-radius:999px;background:var(--accent-soft);color:var(--accent)}.ref-via{font-size:10px;color:var(--text-dim)}.ref-actions{display:flex;gap:6px;margin-top:6px}.dirty-list{list-style:none;padding:0;margin:0 0 10px;font-size:12px}.dirty-list li{padding:2px 0}.dirty-state{color:var(--warn);margin-right:6px;font-family:var(--mono)}.diff-view{background:var(--bg);border:1px solid var(--border);border-radius:9px;padding:10px;font-size:10.5px;line-height:1.5;overflow:auto;max-height:42vh;font-family:var(--mono);white-space:pre;margin-bottom:10px}.diff-add{color:var(--ok)}.diff-del{color:var(--err)}.diff-hunk{color:#93c5fd}.decision{border:1px solid var(--border);border-radius:9px;padding:8px 12px;margin-bottom:8px}.decision.accepted{opacity:.65}.decision.rejected{opacity:.45}.decision-head{display:flex;gap:6px;align-items:center}.decision-mark{font-weight:700}.decision-subject{font-size:12px;margin:6px 0}.decision-actions{display:flex;gap:6px}.toast{position:absolute;bottom:20px;left:50%;transform:translate(-50%);background:var(--bg-raised);border:1px solid var(--warn);color:var(--text);border-radius:10px;padding:10px 18px;font-size:12px;z-index:60;box-shadow:0 10px 30px #00000080} diff --git a/packages/server/src/mdl_server/static/assets/styles-CY4hT8Nm.js b/packages/server/src/mdl_server/static/assets/styles-DqoimPMg.js similarity index 50% rename from packages/server/src/mdl_server/static/assets/styles-CY4hT8Nm.js rename to packages/server/src/mdl_server/static/assets/styles-DqoimPMg.js index 42cf482..81542fa 100644 --- a/packages/server/src/mdl_server/static/assets/styles-CY4hT8Nm.js +++ b/packages/server/src/mdl_server/static/assets/styles-DqoimPMg.js @@ -1,4 +1,4 @@ -var dc=Object.defineProperty;var fc=(e,t,n)=>t in e?dc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _e=(e,t,n)=>fc(e,typeof t!="symbol"?t+"":t,n);import{r as w,g as Co,R as A,j as h}from"./client-DOmNpTln.js";function Re(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;nt in e?dc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _e=(e,t,n)=>fc(e,typeof t!="symbol"?t+"":t,n);import{r as w,g as $o,R as A,j as h}from"./client-DOmNpTln.js";function Me(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;nt in e?dc(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Ot=w;function hc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var mc=typeof Object.is=="function"?Object.is:hc,pc=Ot.useState,gc=Ot.useEffect,yc=Ot.useLayoutEffect,xc=Ot.useDebugValue;function wc(e,t){var n=t(),r=pc({inst:{value:n,getSnapshot:t}}),s=r[0].inst,o=r[1];return yc(function(){s.value=n,s.getSnapshot=t,Wn(s)&&o({inst:s})},[e,n,t]),gc(function(){return Wn(s)&&o({inst:s}),e(function(){Wn(s)&&o({inst:s})})},[e]),xc(n),n}function Wn(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!mc(e,n)}catch{return!0}}function bc(e,t){return t()}var vc=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?bc:wc;Ro.useSyncExternalStore=Ot.useSyncExternalStore!==void 0?Ot.useSyncExternalStore:vc;Ao.exports=Ro;var _c=Ao.exports;/** + */var Lt=w;function hc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var mc=typeof Object.is=="function"?Object.is:hc,pc=Lt.useState,gc=Lt.useEffect,yc=Lt.useLayoutEffect,xc=Lt.useDebugValue;function wc(e,t){var n=t(),r=pc({inst:{value:n,getSnapshot:t}}),s=r[0].inst,o=r[1];return yc(function(){s.value=n,s.getSnapshot=t,qn(s)&&o({inst:s})},[e,n,t]),gc(function(){return qn(s)&&o({inst:s}),e(function(){qn(s)&&o({inst:s})})},[e]),xc(n),n}function qn(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!mc(e,n)}catch{return!0}}function bc(e,t){return t()}var vc=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?bc:wc;To.useSyncExternalStore=Lt.useSyncExternalStore!==void 0?Lt.useSyncExternalStore:vc;Io.exports=To;var _c=Io.exports;/** * @license React * use-sync-external-store-shim/with-selector.production.js * @@ -14,10 +14,10 @@ var dc=Object.defineProperty;var fc=(e,t,n)=>t in e?dc(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Dn=w,Ec=_c;function Nc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var Sc=typeof Object.is=="function"?Object.is:Nc,kc=Ec.useSyncExternalStore,jc=Dn.useRef,Cc=Dn.useEffect,Mc=Dn.useMemo,$c=Dn.useDebugValue;$o.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var o=jc(null);if(o.current===null){var i={hasValue:!1,value:null};o.current=i}else i=o.current;o=Mc(function(){function c(f){if(!u){if(u=!0,l=f,f=r(f),s!==void 0&&i.hasValue){var p=i.value;if(s(p,f))return d=p}return d=f}if(p=d,Sc(l,f))return p;var x=r(f);return s!==void 0&&s(p,x)?(l=f,p):(l=f,d=x)}var u=!1,l,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=kc(e,o[0],o[1]);return Cc(function(){i.hasValue=!0,i.value=a},[a]),$c(a),a};Mo.exports=$o;var Ac=Mo.exports;const Rc=Co(Ac),Ic={},ts=e=>{let t;const n=new Set,r=(l,d)=>{const m=typeof l=="function"?l(t):l;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(p=>p(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>u,subscribe:l=>(n.add(l),()=>n.delete(l)),destroy:()=>{(Ic?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},u=t=e(r,s,c);return c},Tc=e=>e?ts(e):ts,{useDebugValue:Oc}=A,{useSyncExternalStoreWithSelector:Lc}=Rc,Dc=e=>e;function Io(e,t=Dc,n){const r=Lc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Oc(r),r}const ns=(e,t)=>{const n=Tc(e),r=(s,o=t)=>Io(n,s,o);return Object.assign(r,n),r},Pc=(e,t)=>e?ns(e,t):ns;function Ce(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var zc={value:()=>{}};function Pn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}bn.prototype=Pn.prototype={constructor:bn,on:function(e,t){var n=this._,r=Hc(e+"",n),s,o=-1,i=r.length;if(arguments.length<2){for(;++o0)for(var n=new Array(s),r=0,s,o;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),ss.hasOwnProperty(t)?{space:ss[t],local:e}:e}function Vc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===fr&&t.documentElement.namespaceURI===fr?t.createElement(e):t.createElementNS(n,e)}}function Bc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function To(e){var t=zn(e);return(t.local?Bc:Vc)(t)}function Gc(){}function Mr(e){return e==null?Gc:function(){return this.querySelector(e)}}function Yc(e){typeof e!="function"&&(e=Mr(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=M&&(M=E+1);!($=v[M])&&++M=0;)(i=r[s])&&(o&&i.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(i,o),o=i);return this}function gl(e){e||(e=yl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),o=0;ot?1:e>=t?0:NaN}function xl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function wl(){return Array.from(this)}function bl(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Al:typeof t=="function"?Il:Rl)(e,t,n??"")):Lt(this.node(),e)}function Lt(e,t){return e.style.getPropertyValue(t)||zo(e).getComputedStyle(e,null).getPropertyValue(t)}function Ol(e){return function(){delete this[e]}}function Ll(e,t){return function(){this[e]=t}}function Dl(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Pl(e,t){return arguments.length>1?this.each((t==null?Ol:typeof t=="function"?Dl:Ll)(e,t)):this.node()[e]}function Ho(e){return e.trim().split(/^|\s+/)}function $r(e){return e.classList||new Fo(e)}function Fo(e){this._node=e,this._names=Ho(e.getAttribute("class")||"")}Fo.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Vo(e,t){for(var n=$r(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function fu(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,o;n()=>e;function hr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:o,x:i,y:a,dx:c,dy:u,dispatch:l}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:l}})}hr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function _u(e){return!e.ctrlKey&&!e.button}function Eu(){return this.parentNode}function Nu(e,t){return t??{x:e.x,y:e.y}}function Su(){return navigator.maxTouchPoints||"ontouchstart"in this}function ku(){var e=_u,t=Eu,n=Nu,r=Su,s={},o=Pn("start","drag","end"),i=0,a,c,u,l,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",g,vu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,$){if(!(l||!e.call(this,b,$))){var j=M(this,t.call(this,b,$),b,$,"mouse");j&&(Fe(b.view).on("mousemove.drag",p,qt).on("mouseup.drag",x,qt),Xo(b.view),Un(b),u=!1,a=b.clientX,c=b.clientY,j("start",b))}}function p(b){if(Rt(b),!u){var $=b.clientX-a,j=b.clientY-c;u=$*$+j*j>d}s.mouse("drag",b)}function x(b){Fe(b.view).on("mousemove.drag mouseup.drag",null),Wo(b.view,u),Rt(b),s.mouse("end",b)}function v(b,$){if(e.call(this,b,$)){var j=b.changedTouches,_=t.call(this,b,$),R=j.length,N,I;for(N=0;N>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?dn(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?dn(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Cu.exec(e))?new De(t[1],t[2],t[3],1):(t=Mu.exec(e))?new De(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=$u.exec(e))?dn(t[1],t[2],t[3],t[4]):(t=Au.exec(e))?dn(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Ru.exec(e))?ds(t[1],t[2]/100,t[3]/100,1):(t=Iu.exec(e))?ds(t[1],t[2]/100,t[3]/100,t[4]):os.hasOwnProperty(e)?cs(os[e]):e==="transparent"?new De(NaN,NaN,NaN,0):null}function cs(e){return new De(e>>16&255,e>>8&255,e&255,1)}function dn(e,t,n,r){return r<=0&&(e=t=n=NaN),new De(e,t,n,r)}function Lu(e){return e instanceof sn||(e=Qt(e)),e?(e=e.rgb(),new De(e.r,e.g,e.b,e.opacity)):new De}function mr(e,t,n,r){return arguments.length===1?Lu(e):new De(e,t,n,r??1)}function De(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Ar(De,mr,Uo(sn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new De(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Kt:Math.pow(Kt,e),new De(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new De(vt(this.r),vt(this.g),vt(this.b),kn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:ls,formatHex:ls,formatHex8:Du,formatRgb:us,toString:us}));function ls(){return`#${wt(this.r)}${wt(this.g)}${wt(this.b)}`}function Du(){return`#${wt(this.r)}${wt(this.g)}${wt(this.b)}${wt((isNaN(this.opacity)?1:this.opacity)*255)}`}function us(){const e=kn(this.opacity);return`${e===1?"rgb(":"rgba("}${vt(this.r)}, ${vt(this.g)}, ${vt(this.b)}${e===1?")":`, ${e})`}`}function kn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function vt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function wt(e){return e=vt(e),(e<16?"0":"")+e.toString(16)}function ds(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Xe(e,t,n,r)}function qo(e){if(e instanceof Xe)return new Xe(e.h,e.s,e.l,e.opacity);if(e instanceof sn||(e=Qt(e)),!e)return new Xe;if(e instanceof Xe)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),o=Math.max(t,n,r),i=NaN,a=o-s,c=(o+s)/2;return a?(t===o?i=(n-r)/a+(n0&&c<1?0:i,new Xe(i,a,c,e.opacity)}function Pu(e,t,n,r){return arguments.length===1?qo(e):new Xe(e,t,n,r??1)}function Xe(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Ar(Xe,Pu,Uo(sn,{brighter(e){return e=e==null?Sn:Math.pow(Sn,e),new Xe(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Kt:Math.pow(Kt,e),new Xe(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new De(qn(e>=240?e-240:e+120,s,r),qn(e,s,r),qn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Xe(fs(this.h),fn(this.s),fn(this.l),kn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=kn(this.opacity);return`${e===1?"hsl(":"hsla("}${fs(this.h)}, ${fn(this.s)*100}%, ${fn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function fs(e){return e=(e||0)%360,e<0?e+360:e}function fn(e){return Math.max(0,Math.min(1,e||0))}function qn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Ko=e=>()=>e;function zu(e,t){return function(n){return e+n*t}}function Hu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Fu(e){return(e=+e)==1?Zo:function(t,n){return n-t?Hu(t,n,e):Ko(isNaN(t)?n:t)}}function Zo(e,t){var n=t-e;return n?zu(e,n):Ko(isNaN(e)?t:e)}const hs=function e(t){var n=Fu(t);function r(s,o){var i=n((s=mr(s)).r,(o=mr(o)).r),a=n(s.g,o.g),c=n(s.b,o.b),u=Zo(s.opacity,o.opacity);return function(l){return s.r=i(l),s.g=a(l),s.b=c(l),s.opacity=u(l),s+""}}return r.gamma=e,r}(1);function dt(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var pr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Kn=new RegExp(pr.source,"g");function Vu(e){return function(){return e}}function Bu(e){return function(t){return e(t)+""}}function Gu(e,t){var n=pr.lastIndex=Kn.lastIndex=0,r,s,o,i=-1,a=[],c=[];for(e=e+"",t=t+"";(r=pr.exec(e))&&(s=Kn.exec(t));)(o=s.index)>n&&(o=t.slice(n,o),a[i]?a[i]+=o:a[++i]=o),(r=r[0])===(s=s[0])?a[i]?a[i]+=s:a[++i]=s:(a[++i]=null,c.push({i,x:dt(r,s)})),n=Kn.lastIndex;return n180?l+=360:l-u>180&&(u+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:dt(u,l)})):l&&d.push(s(d)+"rotate("+l+r)}function a(u,l,d,m){u!==l?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:dt(u,l)}):l&&d.push(s(d)+"skewX("+l+r)}function c(u,l,d,m,f,p){if(u!==d||l!==m){var x=f.push(s(f)+"scale(",null,",",null,")");p.push({i:x-4,x:dt(u,d)},{i:x-2,x:dt(l,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(u,l){var d=[],m=[];return u=e(u),l=e(l),o(u.translateX,u.translateY,l.translateX,l.translateY,d,m),i(u.rotate,l.rotate,d,m),a(u.skewX,l.skewX,d,m),c(u.scaleX,u.scaleY,l.scaleX,l.scaleY,d,m),u=l=null,function(f){for(var p=-1,x=m.length,v;++p=0&&e._call.call(void 0,t),e=e._next;--Dt}function gs(){Et=(Cn=Jt.now())+Hn,Dt=Yt=0;try{ed()}finally{Dt=0,nd(),Et=0}}function td(){var e=Jt.now(),t=e-Cn;t>ei&&(Hn-=t,Cn=e)}function nd(){for(var e,t=jn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:jn=n);Xt=e,yr(r)}function yr(e){if(!Dt){Yt&&(Yt=clearTimeout(Yt));var t=e-Et;t>24?(e<1/0&&(Yt=setTimeout(gs,e-Jt.now()-Hn)),Ht&&(Ht=clearInterval(Ht))):(Ht||(Cn=Jt.now(),Ht=setInterval(td,ei)),Dt=1,ti(gs))}}function ys(e,t,n){var r=new Mn;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var rd=Pn("start","end","cancel","interrupt"),sd=[],ri=0,xs=1,xr=2,vn=3,ws=4,wr=5,_n=6;function Fn(e,t,n,r,s,o){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;od(e,n,{name:t,index:r,group:s,on:rd,tween:sd,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:ri})}function Ir(e,t){var n=We(e,t);if(n.state>ri)throw new Error("too late; already scheduled");return n}function Je(e,t){var n=We(e,t);if(n.state>vn)throw new Error("too late; already running");return n}function We(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function od(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=ni(o,0,n.time);function o(u){n.state=xs,n.timer.restart(i,n.delay,n.time),n.delay<=u&&i(u-n.delay)}function i(u){var l,d,m,f;if(n.state!==xs)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===vn)return ys(i);f.state===ws?(f.state=_n,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[l]):+lxr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function Od(e,t,n){var r,s,o=Td(t)?Ir:Je;return function(){var i=o(this,e),a=i.on;a!==r&&(s=(r=a).copy()).on(t,n),i.on=s}}function Ld(e,t){var n=this._id;return arguments.length<2?We(this.node(),n).on.on(e):this.each(Od(n,e,t))}function Dd(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Pd(){return this.on("end.remove",Dd(this._id))}function zd(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Mr(e));for(var r=this._groups,s=r.length,o=new Array(s),i=0;i()=>e;function df(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function st(e,t,n){this.k=e,this.x=t,this.y=n}st.prototype={constructor:st,scale:function(e){return e===1?this:new st(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new st(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var ot=new st(1,0,0);st.prototype;function Zn(e){e.stopImmediatePropagation()}function Ft(e){e.preventDefault(),e.stopImmediatePropagation()}function ff(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function hf(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function bs(){return this.__zoom||ot}function mf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function pf(){return navigator.maxTouchPoints||"ontouchstart"in this}function gf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),i>o?(o+i)/2:Math.min(0,o)||Math.max(0,i))}function ai(){var e=ff,t=hf,n=gf,r=mf,s=pf,o=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Qu,u=Pn("start","zoom","end"),l,d,m,f=500,p=150,x=0,v=10;function g(y){y.property("__zoom",bs).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",I).filter(s).on("touchstart.zoom",L).on("touchmove.zoom",V).on("touchend.zoom touchcancel.zoom",F).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(y,C,S,O){var D=y.selection?y.selection():y;D.property("__zoom",bs),y!==D?$(y,C,S,O):D.interrupt().each(function(){j(this,arguments).event(O).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},g.scaleBy=function(y,C,S,O){g.scaleTo(y,function(){var D=this.__zoom.k,k=typeof C=="function"?C.apply(this,arguments):C;return D*k},S,O)},g.scaleTo=function(y,C,S,O){g.transform(y,function(){var D=t.apply(this,arguments),k=this.__zoom,T=S==null?b(D):typeof S=="function"?S.apply(this,arguments):S,P=k.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n(M(E(k,z),T,P),D,i)},S,O)},g.translateBy=function(y,C,S,O){g.transform(y,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),i)},null,O)},g.translateTo=function(y,C,S,O,D){g.transform(y,function(){var k=t.apply(this,arguments),T=this.__zoom,P=O==null?b(k):typeof O=="function"?O.apply(this,arguments):O;return n(ot.translate(P[0],P[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof S=="function"?-S.apply(this,arguments):-S),k,i)},O,D)};function E(y,C){return C=Math.max(o[0],Math.min(o[1],C)),C===y.k?y:new st(C,y.x,y.y)}function M(y,C,S){var O=C[0]-S[0]*y.k,D=C[1]-S[1]*y.k;return O===y.x&&D===y.y?y:new st(y.k,O,D)}function b(y){return[(+y[0][0]+ +y[1][0])/2,(+y[0][1]+ +y[1][1])/2]}function $(y,C,S,O){y.on("start.zoom",function(){j(this,arguments).event(O).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(O).end()}).tween("zoom",function(){var D=this,k=arguments,T=j(D,k).event(O),P=t.apply(D,k),z=S==null?b(P):typeof S=="function"?S.apply(D,k):S,U=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),X=D.__zoom,Z=typeof C=="function"?C.apply(D,k):C,J=c(X.invert(z).concat(U/X.k),Z.invert(z).concat(U/Z.k));return function(se){if(se===1)se=Z;else{var ee=J(se),oe=U/ee[2];se=new st(oe,z[0]-ee[0]*oe,z[1]-ee[1]*oe)}T.zoom(null,se)}})}function j(y,C,S){return!S&&y.__zooming||new _(y,C)}function _(y,C){this.that=y,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(y,C),this.taps=0}_.prototype={event:function(y){return y&&(this.sourceEvent=y),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(y,C){return this.mouse&&y!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&y!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&y!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(y){var C=Fe(this.that).datum();u.call(y,this.that,new df(y,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:u}),C)}};function R(y,...C){if(!e.apply(this,arguments))return;var S=j(this,C).event(y),O=this.__zoom,D=Math.max(o[0],Math.min(o[1],O.k*Math.pow(2,r.apply(this,arguments)))),k=Ye(y);if(S.wheel)(S.mouse[0][0]!==k[0]||S.mouse[0][1]!==k[1])&&(S.mouse[1]=O.invert(S.mouse[0]=k)),clearTimeout(S.wheel);else{if(O.k===D)return;S.mouse=[k,O.invert(k)],En(this),S.start()}Ft(y),S.wheel=setTimeout(T,p),S.zoom("mouse",n(M(E(O,D),S.mouse[0],S.mouse[1]),S.extent,i));function T(){S.wheel=null,S.end()}}function N(y,...C){if(m||!e.apply(this,arguments))return;var S=y.currentTarget,O=j(this,C,!0).event(y),D=Fe(y.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",U,!0),k=Ye(y,S),T=y.clientX,P=y.clientY;Xo(y.view),Zn(y),O.mouse=[k,this.__zoom.invert(k)],En(this),O.start();function z(X){if(Ft(X),!O.moved){var Z=X.clientX-T,J=X.clientY-P;O.moved=Z*Z+J*J>x}O.event(X).zoom("mouse",n(M(O.that.__zoom,O.mouse[0]=Ye(X,S),O.mouse[1]),O.extent,i))}function U(X){D.on("mousemove.zoom mouseup.zoom",null),Wo(X.view,O.moved),Ft(X),O.event(X).end()}}function I(y,...C){if(e.apply(this,arguments)){var S=this.__zoom,O=Ye(y.changedTouches?y.changedTouches[0]:y,this),D=S.invert(O),k=S.k*(y.shiftKey?.5:2),T=n(M(E(S,k),O,D),t.apply(this,C),i);Ft(y),a>0?Fe(this).transition().duration(a).call($,T,O,y):Fe(this).call(g.transform,T,O,y)}}function L(y,...C){if(e.apply(this,arguments)){var S=y.touches,O=S.length,D=j(this,C,y.changedTouches.length===O).event(y),k,T,P,z;for(Zn(y),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},ci=at.error001();function he(e,t){const n=w.useContext(Vn);if(n===null)throw new Error(ci);return Io(n,e,t)}const Se=()=>{const e=w.useContext(Vn);if(e===null)throw new Error(ci);return w.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},xf=e=>e.userSelectionActive?"none":"all";function Or({position:e,children:t,className:n,style:r,...s}){const o=he(xf),i=`${e}`.split("-");return A.createElement("div",{className:Re(["react-flow__panel",n,...i]),style:{...r,pointerEvents:o},...s},t)}function wf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Or,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const bf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:o={},labelBgPadding:i=[2,4],labelBgBorderRadius:a=2,children:c,className:u,...l})=>{const d=w.useRef(null),[m,f]=w.useState({x:0,y:0,width:0,height:0}),p=Re(["react-flow__edge-textwrapper",u]);return w.useEffect(()=>{if(d.current){const x=d.current.getBBox();f({x:x.x,y:x.y,width:x.width,height:x.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:p,visibility:m.width?"visible":"hidden",...l},s&&A.createElement("rect",{width:m.width+2*i[0],x:-i[0],y:-i[1],height:m.height+2*i[1],className:"react-flow__edge-textbg",style:o,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var vf=w.memo(bf);const Lr=e=>({width:e.offsetWidth,height:e.offsetHeight}),Pt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Dr=(e={x:0,y:0},t)=>({x:Pt(e.x,t[0][0],t[1][0]),y:Pt(e.y,t[0][1],t[1][1])}),vs=(e,t,n)=>en?-Pt(Math.abs(e-n),1,50)/50:0,li=(e,t)=>{const n=vs(e.x,35,t.width-35)*20,r=vs(e.y,35,t.height-35)*20;return[n,r]},ui=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},di=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),en=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),fi=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),_s=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),_f=(e,t)=>fi(di(en(e),en(t))),br=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},Ef=e=>Ve(e.width)&&Ve(e.height)&&Ve(e.x)&&Ve(e.y),Ve=e=>!isNaN(e)&&isFinite(e),be=Symbol.for("internals"),hi=["Enter"," ","Escape"],Nf=(e,t)=>{},Sf=e=>"nativeEvent"in e;function vr(e){var s,o;const t=Sf(e)?e.nativeEvent:e,n=((o=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:o[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const mi=e=>"clientX"in e,gt=(e,t)=>{var o,i;const n=mi(e),r=n?e.clientX:(o=e.touches)==null?void 0:o[0].clientX,s=n?e.clientY:(i=e.touches)==null?void 0:i[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},$n=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},on=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:l,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Ve(n)&&Ve(r)?A.createElement(vf,{x:n,y:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u}):null);on.displayName="BaseEdge";function Vt(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(o=>o.id===e);s&&n(r,{...s})}}function pi({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,o=n{const[v,g,E]=yi({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:o});return A.createElement(on,{path:v,labelX:g,labelY:E,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:x})});Pr.displayName="SimpleBezierEdge";const Ns={[K.Left]:{x:-1,y:0},[K.Right]:{x:1,y:0},[K.Top]:{x:0,y:-1},[K.Bottom]:{x:0,y:1}},kf=({source:e,sourcePosition:t=K.Bottom,target:n})=>t===K.Left||t===K.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function jf({source:e,sourcePosition:t=K.Bottom,target:n,targetPosition:r=K.Top,center:s,offset:o}){const i=Ns[t],a=Ns[r],c={x:e.x+i.x*o,y:e.y+i.y*o},u={x:n.x+a.x*o,y:n.y+a.y*o},l=kf({source:c,sourcePosition:t,target:u}),d=l.x!==0?"x":"y",m=l[d];let f=[],p,x;const v={x:0,y:0},g={x:0,y:0},[E,M,b,$]=pi({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(i[d]*a[d]===-1){p=s.x??E,x=s.y??M;const _=[{x:p,y:c.y},{x:p,y:u.y}],R=[{x:c.x,y:x},{x:u.x,y:x}];i[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:u.y}],R=[{x:u.x,y:c.y}];if(d==="x"?f=i.x===m?R:_:f=i.y===m?_:R,t===r){const F=Math.abs(e[d]-n[d]);if(F<=o){const y=Math.min(o-1,o-F);i[d]===m?v[d]=(c[d]>e[d]?-1:1)*y:g[d]=(u[d]>n[d]?-1:1)*y}}if(t!==r){const F=d==="x"?"y":"x",y=i[d]===a[F],C=c[F]>u[F],S=c[F]=V?(p=(N.x+I.x)/2,x=f[0].y):(p=f[0].x,x=(N.y+I.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:u.x+g.x,y:u.y+g.y},n],p,x,b,$]}function Cf(e,t,n,r){const s=Math.min(Ss(e,t)/2,Ss(t,n)/2,r),{x:o,y:i}=t;if(e.x===o&&o===n.x||e.y===i&&i===n.y)return`L${o} ${i}`;if(e.y===i){const u=e.x{let M="";return E>0&&E{const[g,E,M]=Rn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:x==null?void 0:x.borderRadius,offset:x==null?void 0:x.offset});return A.createElement(on,{path:g,labelX:E,labelY:M,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:f,markerStart:p,interactionWidth:v})});Bn.displayName="SmoothStepEdge";const zr=w.memo(e=>{var t;return A.createElement(Bn,{...e,pathOptions:w.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});zr.displayName="StepEdge";function Mf({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,o,i,a]=pi({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,o,i,a]}const Hr=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[p,x,v]=Mf({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(on,{path:p,labelX:x,labelY:v,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:d,markerStart:m,interactionWidth:f})});Hr.displayName="StraightEdge";function pn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function ks({pos:e,x1:t,y1:n,x2:r,y2:s,c:o}){switch(e){case K.Left:return[t-pn(t-r,o),n];case K.Right:return[t+pn(r-t,o),n];case K.Top:return[t,n-pn(n-s,o)];case K.Bottom:return[t,n+pn(s-n,o)]}}function xi({sourceX:e,sourceY:t,sourcePosition:n=K.Bottom,targetX:r,targetY:s,targetPosition:o=K.Top,curvature:i=.25}){const[a,c]=ks({pos:n,x1:e,y1:t,x2:r,y2:s,c:i}),[u,l]=ks({pos:o,x1:r,y1:s,x2:e,y2:t,c:i}),[d,m,f,p]=gi({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:u,targetControlY:l});return[`M${e},${t} C${a},${c} ${u},${l} ${r},${s}`,d,m,f,p]}const In=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=K.Bottom,targetPosition:o=K.Top,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,pathOptions:x,interactionWidth:v})=>{const[g,E,M]=xi({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:o,curvature:x==null?void 0:x.curvature});return A.createElement(on,{path:g,labelX:E,labelY:M,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:v})});In.displayName="BezierEdge";const Fr=w.createContext(null),$f=Fr.Provider;Fr.Consumer;const Af=()=>w.useContext(Fr),Rf=e=>"id"in e&&"source"in e&&"target"in e,If=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,_r=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Tf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),Of=(e,t)=>{if(!e.source||!e.target)return t;let n;return Rf(e)?n={...e}:n={...e,id:If(e)},Tf(n,t)?t:t.concat(n)},Er=({x:e,y:t},[n,r,s],o,[i,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return o?{x:i*Math.round(c.x/i),y:a*Math.round(c.y/a)}:c},wi=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),_t=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},an=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:o,y:i}=_t(s,t).positionAbsolute;return di(r,en({x:o,y:i,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return fi(n)},Lf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),an(e,t)),bi=(e,t,[n,r,s]=[0,0,1],o=!1,i=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},u=[];return e.forEach(l=>{const{width:d,height:m,selectable:f=!0,hidden:p=!1}=l;if(i&&!f||p)return!1;const{positionAbsolute:x}=_t(l,a),v={x:x.x,y:x.y,width:d||0,height:m||0},g=br(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,M=o&&g>0,b=(d||0)*(m||0);(E||M||g>=b||l.dragging)&&u.push(l)}),u},vi=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},_i=(e,t,n,r,s,o=.1)=>{const i=t/(e.width*(1+o)),a=n/(e.height*(1+o)),c=Math.min(i,a),u=Pt(c,r,s),l=e.x+e.width/2,d=e.y+e.height/2,m=t/2-l*u,f=n/2-d*u;return{x:m,y:f,zoom:u}},xt=(e,t=0)=>e.transition().duration(t);function js(e,t,n,r){return(t[n]||[]).reduce((s,o)=>{var i,a;return`${e.id}-${o.id}-${n}`!==r&&s.push({id:o.id||null,type:n,nodeId:e.id,x:(((i=e.positionAbsolute)==null?void 0:i.x)??0)+o.x+o.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+o.y+o.height/2}),s},[])}function Df(e,t,n,r,s,o){const{x:i,y:a}=gt(e),u=t.elementsFromPoint(i,a).find(p=>p.classList.contains("react-flow__handle"));if(u){const p=u.getAttribute("data-nodeid");if(p){const x=Vr(void 0,u),v=u.getAttribute("data-handleid"),g=o({nodeId:p,id:v,type:x});if(g){const E=s.find(M=>M.nodeId===p&&M.type===x&&M.id===v);return{handle:{id:v,type:x,nodeId:p,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:g}}}}let l=[],d=1/0;if(s.forEach(p=>{const x=Math.sqrt((p.x-n.x)**2+(p.y-n.y)**2);if(x<=r){const v=o(p);x<=d&&(xp.isValid),f=l.some(({handle:p})=>p.type==="target");return l.find(({handle:p,validHandleResult:x})=>f?p.type==="target":m?x.isValid:!0)||l[0]}const Pf={source:null,target:null,sourceHandle:null,targetHandle:null},Ei=()=>({handleDomNode:null,isValid:!1,connection:Pf,endHandle:null});function Ni(e,t,n,r,s,o,i){const a=s==="target",c=i.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),u={...Ei(),handleDomNode:c};if(c){const l=Vr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),p=c.classList.contains("connectableend"),x={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};u.connection=x,f&&p&&(t===Nt.Strict?a&&l==="source"||!a&&l==="target":d!==n||m!==r)&&(u.endHandle={nodeId:d,handleId:m,type:l},u.isValid=o(x))}return u}function zf({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,o)=>{if(o[be]){const{handleBounds:i}=o[be];let a=[],c=[];i&&(a=js(o,i,"source",`${t}-${n}-${r}`),c=js(o,i,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Vr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function Qn(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Hf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function Si({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:o,setState:i,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:u}){const l=ui(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:p,onConnectStart:x,panBy:v,getNodes:g,cancelConnection:E}=o();let M=0,b;const{x:$,y:j}=gt(e),_=l==null?void 0:l.elementFromPoint($,j),R=Vr(c,_),N=m==null?void 0:m.getBoundingClientRect();if(!N||!R)return;let I,L=gt(e,N),V=!1,F=null,y=!1,C=null;const S=zf({nodes:g(),nodeId:n,handleId:t,handleType:R}),O=()=>{if(!f)return;const[T,P]=li(L,N);v({x:T,y:P}),M=requestAnimationFrame(O)};i({connectionPosition:L,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),x==null||x(e,{nodeId:n,handleId:t,handleType:R});function D(T){const{transform:P}=o();L=gt(T,N);const{handle:z,validHandleResult:U}=Df(T,l,Er(L,P,!1,[1,1]),p,S,X=>Ni(X,d,n,t,s?"target":"source",a,l));if(b=z,V||(O(),V=!0),C=U.handleDomNode,F=U.connection,y=U.isValid,i({connectionPosition:b&&y?wi({x:b.x,y:b.y},P):L,connectionStatus:Hf(!!b,y),connectionEndHandle:U.endHandle}),!b&&!y&&!C)return Qn(I);F.source!==F.target&&C&&(Qn(I),I=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",y),C.classList.toggle("react-flow__handle-valid",y))}function k(T){var P,z;(b||C)&&F&&y&&(r==null||r(F)),(z=(P=o()).onConnectEnd)==null||z.call(P,T),c&&(u==null||u(T)),Qn(I),E(),cancelAnimationFrame(M),V=!1,y=!1,F=null,C=null,l.removeEventListener("mousemove",D),l.removeEventListener("mouseup",k),l.removeEventListener("touchmove",D),l.removeEventListener("touchend",k)}l.addEventListener("mousemove",D),l.addEventListener("mouseup",k),l.addEventListener("touchmove",D),l.addEventListener("touchend",k)}const Cs=()=>!0,Ff=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Vf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:o,connectionClickStartHandle:i}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n,clickConnecting:(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n}},ki=w.forwardRef(({type:e="source",position:t=K.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:o=!0,id:i,onConnect:a,children:c,className:u,onMouseDown:l,onTouchStart:d,...m},f)=>{var N,I;const p=i||null,x=e==="target",v=Se(),g=Af(),{connectOnClick:E,noPanClassName:M}=he(Ff,Ce),{connecting:b,clickConnecting:$}=he(Vf(g,p,e),Ce);g||(I=(N=v.getState()).onError)==null||I.call(N,"010",at.error010());const j=L=>{const{defaultEdgeOptions:V,onConnect:F,hasDefaultEdges:y}=v.getState(),C={...V,...L};if(y){const{edges:S,setEdges:O}=v.getState();O(Of(C,S))}F==null||F(C),a==null||a(C)},_=L=>{if(!g)return;const V=mi(L);s&&(V&&L.button===0||!V)&&Si({event:L,handleId:p,nodeId:g,onConnect:j,isTarget:x,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||Cs}),V?l==null||l(L):d==null||d(L)},R=L=>{const{onClickConnectStart:V,onClickConnectEnd:F,connectionClickStartHandle:y,connectionMode:C,isValidConnection:S}=v.getState();if(!g||!y&&!s)return;if(!y){V==null||V(L,{nodeId:g,handleId:p,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:g,type:e,handleId:p}});return}const O=ui(L.target),D=n||S||Cs,{connection:k,isValid:T}=Ni({nodeId:g,id:p,type:e},C,y.nodeId,y.handleId||null,y.type,D,O);T&&j(k),F==null||F(L),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":p,"data-nodeid":g,"data-handlepos":t,"data-id":`${g}-${p}-${e}`,className:Re(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",M,u,{source:!x,target:x,connectable:r,connectablestart:s,connectableend:o,connecting:$,connectionindicator:r&&(s&&!b||o&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});ki.displayName="Handle";var mt=w.memo(ki);const ji=({data:e,isConnectable:t,targetPosition:n=K.Top,sourcePosition:r=K.Bottom})=>A.createElement(A.Fragment,null,A.createElement(mt,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(mt,{type:"source",position:r,isConnectable:t}));ji.displayName="DefaultNode";var Nr=w.memo(ji);const Ci=({data:e,isConnectable:t,sourcePosition:n=K.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(mt,{type:"source",position:n,isConnectable:t}));Ci.displayName="InputNode";var Mi=w.memo(Ci);const $i=({data:e,isConnectable:t,targetPosition:n=K.Top})=>A.createElement(A.Fragment,null,A.createElement(mt,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);$i.displayName="OutputNode";var Ai=w.memo($i);const Br=()=>null;Br.displayName="GroupNode";const Bf=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),gn=e=>e.id;function Gf(e,t){return Ce(e.selectedNodes.map(gn),t.selectedNodes.map(gn))&&Ce(e.selectedEdges.map(gn),t.selectedEdges.map(gn))}const Ri=w.memo(({onSelectionChange:e})=>{const t=Se(),{selectedNodes:n,selectedEdges:r}=he(Bf,Gf);return w.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(o=>o(s))},[n,r,e]),null});Ri.displayName="SelectionListener";const Yf=e=>!!e.onSelectionChange;function Xf({onSelectionChange:e}){const t=he(Yf);return e||t?A.createElement(Ri,{onSelectionChange:e}):null}const Wf=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function kt(e,t){w.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ue(e,t,n){w.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Uf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:o,onConnectEnd:i,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:u,nodesConnectable:l,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:p,minZoom:x,maxZoom:v,nodeExtent:g,onNodesChange:E,onEdgesChange:M,elementsSelectable:b,connectionMode:$,snapGrid:j,snapToGrid:_,translateExtent:R,connectOnClick:N,defaultEdgeOptions:I,fitView:L,fitViewOptions:V,onNodesDelete:F,onEdgesDelete:y,onNodeDrag:C,onNodeDragStart:S,onNodeDragStop:O,onSelectionDrag:D,onSelectionDragStart:k,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:U,autoPanOnConnect:X,autoPanOnNodeDrag:Z,onError:J,connectionRadius:se,isValidConnection:ee,nodeDragThreshold:oe})=>{const{setNodes:ce,setEdges:we,setDefaultNodesAndEdges:ye,setMinZoom:me,setMaxZoom:pe,setTranslateExtent:ge,setNodeExtent:Ne,reset:ae}=he(Wf,Ce),q=Se();return w.useEffect(()=>{const xe=r==null?void 0:r.map(Te=>({...Te,...I}));return ye(n,xe),()=>{ae()}},[]),ue("defaultEdgeOptions",I,q.setState),ue("connectionMode",$,q.setState),ue("onConnect",s,q.setState),ue("onConnectStart",o,q.setState),ue("onConnectEnd",i,q.setState),ue("onClickConnectStart",a,q.setState),ue("onClickConnectEnd",c,q.setState),ue("nodesDraggable",u,q.setState),ue("nodesConnectable",l,q.setState),ue("nodesFocusable",d,q.setState),ue("edgesFocusable",m,q.setState),ue("edgesUpdatable",f,q.setState),ue("elementsSelectable",b,q.setState),ue("elevateNodesOnSelect",p,q.setState),ue("snapToGrid",_,q.setState),ue("snapGrid",j,q.setState),ue("onNodesChange",E,q.setState),ue("onEdgesChange",M,q.setState),ue("connectOnClick",N,q.setState),ue("fitViewOnInit",L,q.setState),ue("fitViewOnInitOptions",V,q.setState),ue("onNodesDelete",F,q.setState),ue("onEdgesDelete",y,q.setState),ue("onNodeDrag",C,q.setState),ue("onNodeDragStart",S,q.setState),ue("onNodeDragStop",O,q.setState),ue("onSelectionDrag",D,q.setState),ue("onSelectionDragStart",k,q.setState),ue("onSelectionDragStop",T,q.setState),ue("noPanClassName",P,q.setState),ue("nodeOrigin",z,q.setState),ue("rfId",U,q.setState),ue("autoPanOnConnect",X,q.setState),ue("autoPanOnNodeDrag",Z,q.setState),ue("onError",J,q.setState),ue("connectionRadius",se,q.setState),ue("isValidConnection",ee,q.setState),ue("nodeDragThreshold",oe,q.setState),kt(e,ce),kt(t,we),kt(x,me),kt(v,pe),kt(R,ge),kt(g,Ne),null},Ms={display:"none"},qf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Ii="react-flow__node-desc",Ti="react-flow__edge-desc",Kf="react-flow__aria-live",Zf=e=>e.ariaLiveMessage;function Qf({rfId:e}){const t=he(Zf);return A.createElement("div",{id:`${Kf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:qf},t)}function Jf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${Ii}-${e}`,style:Ms},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Ti}-${e}`,style:Ms},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Qf,{rfId:e}))}var nn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=w.useState(!1),s=w.useRef(!1),o=w.useRef(new Set([])),[i,a]=w.useMemo(()=>{if(e!==null){const u=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),l=u.reduce((d,m)=>d.concat(...m),[]);return[u,l]}return[[],[]]},[e]);return w.useEffect(()=>{const c=typeof document<"u"?document:null,u=(t==null?void 0:t.target)||c;if(e!==null){const l=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&vr(f))return!1;const x=As(f.code,a);o.current.add(f[x]),$s(i,o.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&vr(f))return!1;const x=As(f.code,a);$s(i,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(f[x]),f.key==="Meta"&&o.current.clear(),s.current=!1},m=()=>{o.current.clear(),r(!1)};return u==null||u.addEventListener("keydown",l),u==null||u.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{u==null||u.removeEventListener("keydown",l),u==null||u.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function $s(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function As(e,t){return t.includes(e)?"code":"key"}function Oi(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const o=t.get(s),i=_t(o,r);return Oi(o,t,{x:(n.x??0)+i.x,y:(n.y??0)+i.y,z:(((a=o[be])==null?void 0:a.z)??0)>(n.z??0)?((c=o[be])==null?void 0:c.z)??0:n.z??0},r)}function Li(e,t,n){e.forEach(r=>{var o;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:i,y:a,z:c}=Oi(r,e,{...r.position,z:((o=r[be])==null?void 0:o.z)??0},t);r.positionAbsolute={x:i,y:a},r[be].z=c,n!=null&&n[r.id]&&(r[be].isParent=!0)}})}function Jn(e,t,n,r){const s=new Map,o={},i=r?1e3:0;return e.forEach(a=>{var f;const c=(Ve(a.zIndex)?a.zIndex:0)+(a.selected?i:0),u=t.get(a.id),l={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(o[d]=!0);const m=(u==null?void 0:u.type)&&(u==null?void 0:u.type)!==a.type;Object.defineProperty(l,be,{enumerable:!1,value:{handleBounds:m||(f=u==null?void 0:u[be])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,l)}),Li(s,n,o),s}function Di(e,t={}){const{getNodes:n,width:r,height:s,minZoom:o,maxZoom:i,d3Zoom:a,d3Selection:c,fitViewOnInitDone:u,fitViewOnInit:l,nodeOrigin:d}=e(),m=t.initial&&!u&&l;if(a&&c&&(m||!t.initial)){const p=n().filter(v=>{var E;const g=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?g&&t.nodes.some(M=>M.id===v.id):g}),x=p.every(v=>v.width&&v.height);if(p.length>0&&x){const v=an(p,d),{x:g,y:E,zoom:M}=_i(v,r,s,t.minZoom??o,t.maxZoom??i,t.padding??.1),b=ot.translate(g,E).scale(M);return typeof t.duration=="number"&&t.duration>0?a.transform(xt(c,t.duration),b):a.transform(c,b),!0}}return!1}function eh(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[be]:r[be],selected:n.selected})}),new Map(t)}function th(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function yn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:o,onNodesChange:i,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:u}=n();e!=null&&e.length&&(c&&r({nodeInternals:eh(e,s)}),i==null||i(e)),t!=null&&t.length&&(u&&r({edges:th(t,o)}),a==null||a(t))}const jt=()=>{},nh={zoomIn:jt,zoomOut:jt,zoomTo:jt,getZoom:()=>1,setViewport:jt,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:jt,fitBounds:jt,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),sh=()=>{const e=Se(),{d3Zoom:t,d3Selection:n}=he(rh,Ce);return w.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(xt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(xt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,o)=>t.scaleTo(xt(n,o==null?void 0:o.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,o)=>{const[i,a,c]=e.getState().transform,u=ot.translate(s.x??i,s.y??a).scale(s.zoom??c);t.transform(xt(n,o==null?void 0:o.duration),u)},getViewport:()=>{const[s,o,i]=e.getState().transform;return{x:s,y:o,zoom:i}},fitView:s=>Di(e.getState,s),setCenter:(s,o,i)=>{const{width:a,height:c,maxZoom:u}=e.getState(),l=typeof(i==null?void 0:i.zoom)<"u"?i.zoom:u,d=a/2-s*l,m=c/2-o*l,f=ot.translate(d,m).scale(l);t.transform(xt(n,i==null?void 0:i.duration),f)},fitBounds:(s,o)=>{const{width:i,height:a,minZoom:c,maxZoom:u}=e.getState(),{x:l,y:d,zoom:m}=_i(s,i,a,c,u,(o==null?void 0:o.padding)??.1),f=ot.translate(l,d).scale(m);t.transform(xt(n,o==null?void 0:o.duration),f)},project:s=>{const{transform:o,snapToGrid:i,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),Er(s,o,i,a)},screenToFlowPosition:s=>{const{transform:o,snapToGrid:i,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:u,y:l}=c.getBoundingClientRect(),d={x:s.x-u,y:s.y-l};return Er(d,o,i,a)},flowToScreenPosition:s=>{const{transform:o,domNode:i}=e.getState();if(!i)return s;const{x:a,y:c}=i.getBoundingClientRect(),u=wi(s,o);return{x:u.x+a,y:u.y+c}},viewportInitialized:!0}:nh,[t,n])};function cn(){const e=sh(),t=Se(),n=w.useCallback(()=>t.getState().getNodes().map(x=>({...x})),[]),r=w.useCallback(x=>t.getState().nodeInternals.get(x),[]),s=w.useCallback(()=>{const{edges:x=[]}=t.getState();return x.map(v=>({...v}))},[]),o=w.useCallback(x=>{const{edges:v=[]}=t.getState();return v.find(g=>g.id===x)},[]),i=w.useCallback(x=>{const{getNodes:v,setNodes:g,hasDefaultNodes:E,onNodesChange:M}=t.getState(),b=v(),$=typeof x=="function"?x(b):x;if(E)g($);else if(M){const j=$.length===0?b.map(_=>({type:"remove",id:_.id})):$.map(_=>({item:_,type:"reset"}));M(j)}},[]),a=w.useCallback(x=>{const{edges:v=[],setEdges:g,hasDefaultEdges:E,onEdgesChange:M}=t.getState(),b=typeof x=="function"?x(v):x;if(E)g(b);else if(M){const $=b.length===0?v.map(j=>({type:"remove",id:j.id})):b.map(j=>({item:j,type:"reset"}));M($)}},[]),c=w.useCallback(x=>{const v=Array.isArray(x)?x:[x],{getNodes:g,setNodes:E,hasDefaultNodes:M,onNodesChange:b}=t.getState();if(M){const j=[...g(),...v];E(j)}else if(b){const $=v.map(j=>({item:j,type:"add"}));b($)}},[]),u=w.useCallback(x=>{const v=Array.isArray(x)?x:[x],{edges:g=[],setEdges:E,hasDefaultEdges:M,onEdgesChange:b}=t.getState();if(M)E([...g,...v]);else if(b){const $=v.map(j=>({item:j,type:"add"}));b($)}},[]),l=w.useCallback(()=>{const{getNodes:x,edges:v=[],transform:g}=t.getState(),[E,M,b]=g;return{nodes:x().map($=>({...$})),edges:v.map($=>({...$})),viewport:{x:E,y:M,zoom:b}}},[]),d=w.useCallback(({nodes:x,edges:v})=>{const{nodeInternals:g,getNodes:E,edges:M,hasDefaultNodes:b,hasDefaultEdges:$,onNodesDelete:j,onEdgesDelete:_,onNodesChange:R,onEdgesChange:N}=t.getState(),I=(x||[]).map(C=>C.id),L=(v||[]).map(C=>C.id),V=E().reduce((C,S)=>{const O=S.parentNode||S.parentId,D=!I.includes(S.id)&&O&&C.find(T=>T.id===O);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(I.includes(S.id)||D)&&C.push(S),C},[]),F=M.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),y=F.filter(C=>L.includes(C.id));if(V||y){const C=vi(V,F),S=[...y,...C],O=S.reduce((D,k)=>(D.includes(k.id)||D.push(k.id),D),[]);if(($||b)&&($&&t.setState({edges:M.filter(D=>!O.includes(D.id))}),b&&(V.forEach(D=>{g.delete(D.id)}),t.setState({nodeInternals:new Map(g)}))),O.length>0&&(_==null||_(S),N&&N(O.map(D=>({id:D,type:"remove"})))),V.length>0&&(j==null||j(V),R)){const D=V.map(k=>({id:k.id,type:"remove"}));R(D)}}},[]),m=w.useCallback(x=>{const v=Ef(x),g=v?null:t.getState().nodeInternals.get(x.id);return!v&&!g?[null,null,v]:[v?x:_s(g),g,v]},[]),f=w.useCallback((x,v=!0,g)=>{const[E,M,b]=m(x);return E?(g||t.getState().getNodes()).filter($=>{if(!b&&($.id===M.id||!$.positionAbsolute))return!1;const j=_s($),_=br(j,E);return v&&_>0||_>=E.width*E.height}):[]},[]),p=w.useCallback((x,v,g=!0)=>{const[E]=m(x);if(!E)return!1;const M=br(E,v);return g&&M>0||M>=E.width*E.height},[]);return w.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:o,setNodes:i,setEdges:a,addNodes:c,addEdges:u,toObject:l,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:p}),[e,n,r,s,o,i,a,c,u,l,d,f,p])}const oh={actInsideInputWithModifier:!1};var ih=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=Se(),{deleteElements:r}=cn(),s=nn(e,oh),o=nn(t);w.useEffect(()=>{if(s){const{edges:i,getNodes:a}=n.getState(),c=a().filter(l=>l.selected),u=i.filter(l=>l.selected);r({nodes:c,edges:u}),n.setState({nodesSelectionActive:!1})}},[s]),w.useEffect(()=>{n.setState({multiSelectionActive:o})},[o])};function ah(e){const t=Se();w.useEffect(()=>{let n;const r=()=>{var o,i;if(!e.current)return;const s=Lr(e.current);(s.height===0||s.width===0)&&((i=(o=t.getState()).onError)==null||i.call(o,"004",at.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Gr={position:"absolute",width:"100%",height:"100%",top:0,left:0},ch=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,xn=e=>({x:e.x,y:e.y,zoom:e.k}),Ct=(e,t)=>e.target.closest(`.${t}`),Rs=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Is=e=>{const t=e.ctrlKey&&$n()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},lh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),uh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:o=!0,panOnScroll:i=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=bt.Free,zoomOnDoubleClick:u=!0,elementsSelectable:l,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:p,maxZoom:x,zoomActivationKeyCode:v,preventScrolling:g=!0,children:E,noWheelClassName:M,noPanClassName:b})=>{const $=w.useRef(),j=Se(),_=w.useRef(!1),R=w.useRef(!1),N=w.useRef(null),I=w.useRef({x:0,y:0,zoom:0}),{d3Zoom:L,d3Selection:V,d3ZoomHandler:F,userSelectionActive:y}=he(lh,Ce),C=nn(v),S=w.useRef(0),O=w.useRef(!1),D=w.useRef();return ah(N),w.useEffect(()=>{if(N.current){const k=N.current.getBoundingClientRect(),T=ai().scaleExtent([p,x]).translateExtent(f),P=Fe(N.current).call(T),z=ot.translate(m.x,m.y).scale(Pt(m.zoom,p,x)),U=[[0,0],[k.width,k.height]],X=T.constrain()(z,U,f);T.transform(P,X),T.wheelDelta(Is),j.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[X.x,X.y,X.k],domNode:N.current.closest(".react-flow")})}},[]),w.useEffect(()=>{V&&L&&(i&&!C&&!y?V.on("wheel.zoom",k=>{if(Ct(k,M))return!1;k.preventDefault(),k.stopImmediatePropagation();const T=V.property("__zoom").k||1;if(k.ctrlKey&&o){const ee=Ye(k),oe=Is(k),ce=T*Math.pow(2,oe);L.scaleTo(V,ce,ee,k);return}const P=k.deltaMode===1?20:1;let z=c===bt.Vertical?0:k.deltaX*P,U=c===bt.Horizontal?0:k.deltaY*P;!$n()&&k.shiftKey&&c!==bt.Vertical&&(z=k.deltaY*P,U=0),L.translateBy(V,-(z/T)*a,-(U/T)*a,{internal:!0});const X=xn(V.property("__zoom")),{onViewportChangeStart:Z,onViewportChange:J,onViewportChangeEnd:se}=j.getState();clearTimeout(D.current),O.current||(O.current=!0,t==null||t(k,X),Z==null||Z(X)),O.current&&(e==null||e(k,X),J==null||J(X),D.current=setTimeout(()=>{n==null||n(k,X),se==null||se(X),O.current=!1},150))},{passive:!1}):typeof F<"u"&&V.on("wheel.zoom",function(k,T){if(!g&&k.type==="wheel"&&!k.ctrlKey||Ct(k,M))return null;k.preventDefault(),F.call(this,k,T)},{passive:!1}))},[y,i,c,V,L,F,C,o,g,M,t,e,n]),w.useEffect(()=>{L&&L.on("start",k=>{var z,U;if(!k.sourceEvent||k.sourceEvent.internal)return null;S.current=(z=k.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=j.getState(),P=xn(k.transform);_.current=!0,I.current=P,((U=k.sourceEvent)==null?void 0:U.type)==="mousedown"&&j.setState({paneDragging:!0}),T==null||T(P),t==null||t(k.sourceEvent,P)})},[L,t]),w.useEffect(()=>{L&&(y&&!_.current?L.on("zoom",null):y||L.on("zoom",k=>{var P;const{onViewportChange:T}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),R.current=!!(r&&Rs(d,S.current??0)),(e||T)&&!((P=k.sourceEvent)!=null&&P.internal)){const z=xn(k.transform);T==null||T(z),e==null||e(k.sourceEvent,z)}}))},[y,L,e,d,r]),w.useEffect(()=>{L&&L.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=j.getState();if(_.current=!1,j.setState({paneDragging:!1}),r&&Rs(d,S.current??0)&&!R.current&&r(k.sourceEvent),R.current=!1,(n||T)&&ch(I.current,k.transform)){const P=xn(k.transform);I.current=P,clearTimeout($.current),$.current=setTimeout(()=>{T==null||T(P),n==null||n(k.sourceEvent,P)},i?150:0)}})},[L,i,d,n,r]),w.useEffect(()=>{L&&L.filter(k=>{const T=C||s,P=o&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(Ct(k,"react-flow__node")||Ct(k,"react-flow__edge")))return!0;if(!d&&!T&&!i&&!u&&!o||y||!u&&k.type==="dblclick"||Ct(k,M)&&k.type==="wheel"||Ct(k,b)&&(k.type!=="wheel"||i&&k.type==="wheel"&&!C)||!o&&k.ctrlKey&&k.type==="wheel"||!T&&!i&&!P&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&z})},[y,L,s,o,i,u,d,l,C]),A.createElement("div",{className:"react-flow__renderer",ref:N,style:Gr},E)},dh=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function fh(){const{userSelectionActive:e,userSelectionRect:t}=he(dh,Ce);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Ts(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,o=t.position.y+t.height-r.height;if(s>0||o>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),o>0&&(r.style.height+=o),t.position.x<0){const i=Math.abs(t.position.x);r.position.x=r.position.x-i,r.style.width+=i,t.position.x=0}if(t.position.y<0){const i=Math.abs(t.position.y);r.position.y=r.position.y-i,r.style.height+=i,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function hh(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const o=e.filter(a=>a.id===s.id);if(o.length===0)return r.push(s),r;const i={...s};for(const a of o)if(a)switch(a.type){case"select":{i.selected=a.selected;break}case"position":{typeof a.position<"u"&&(i.position=a.position),typeof a.positionAbsolute<"u"&&(i.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(i.dragging=a.dragging),i.expandParent&&Ts(r,i);break}case"dimensions":{typeof a.dimensions<"u"&&(i.width=a.dimensions.width,i.height=a.dimensions.height),typeof a.updateStyle<"u"&&(i.style={...i.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(i.resizing=a.resizing),i.expandParent&&Ts(r,i);break}case"remove":return r}return r.push(i),r},n)}function mh(e,t){return hh(e,t)}const ft=(e,t)=>({id:e,type:"select",selected:t});function $t(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ft(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ft(r.id,!1))),n},[])}const er=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},ph=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Pi=w.memo(({isSelecting:e,selectionMode:t=tn.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:o,onPaneContextMenu:i,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:u,onPaneMouseLeave:l,children:d})=>{const m=w.useRef(null),f=Se(),p=w.useRef(0),x=w.useRef(0),v=w.useRef(),{userSelectionActive:g,elementsSelectable:E,dragging:M}=he(ph,Ce),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),p.current=0,x.current=0},$=F=>{o==null||o(F),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=F=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){F.preventDefault();return}i==null||i(F)},_=a?F=>a(F):void 0,R=F=>{const{resetSelectedElements:y,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||F.button!==0||F.target!==m.current||!v.current)return;const{x:S,y:O}=gt(F,v.current);y(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:O,x:S,y:O}}),r==null||r(F)},N=F=>{const{userSelectionRect:y,nodeInternals:C,edges:S,transform:O,onNodesChange:D,onEdgesChange:k,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!y)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=gt(F,v.current),U=y.startX??0,X=y.startY??0,Z={...y,x:z.xce.id),oe=se.map(ce=>ce.id);if(p.current!==oe.length){p.current=oe.length;const ce=$t(J,oe);ce.length&&(D==null||D(ce))}if(x.current!==ee.length){x.current=ee.length;const ce=$t(S,ee);ce.length&&(k==null||k(ce))}f.setState({userSelectionRect:Z})},I=F=>{if(F.button!==0)return;const{userSelectionRect:y}=f.getState();!g&&y&&F.target===m.current&&($==null||$(F)),f.setState({nodesSelectionActive:p.current>0}),b(),s==null||s(F)},L=F=>{g&&(f.setState({nodesSelectionActive:p.current>0}),s==null||s(F)),b()},V=E&&(e||g);return A.createElement("div",{className:Re(["react-flow__pane",{dragging:M,selection:e}]),onClick:V?void 0:er($,m),onContextMenu:er(j,m),onWheel:er(_,m),onMouseEnter:V?void 0:c,onMouseDown:V?R:void 0,onMouseMove:V?N:u,onMouseUp:V?I:void 0,onMouseLeave:V?L:l,ref:m,style:Gr},d,A.createElement(fh,null))});Pi.displayName="Pane";function zi(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:zi(r,t):!1}function Os(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function gh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!zi(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var o,i;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((o=s.positionAbsolute)==null?void 0:o.x)??0),y:n.y-(((i=s.positionAbsolute)==null?void 0:i.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function yh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function Hi(e,t,n,r,s=[0,0],o){const i=yh(e,e.extent||r);let a=i;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=_t(d,s).positionAbsolute;a=d&&Ve(m)&&Ve(f)&&Ve(d.width)&&Ve(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else o==null||o("005",at.error005()),a=i;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=_t(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let u={x:0,y:0};if(c){const d=n.get(c);u=_t(d,s).positionAbsolute}const l=a&&a!=="parent"?Dr(t,a):t;return{position:{x:l.x-u.x,y:l.y-u.y},positionAbsolute:l}}function tr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Ls=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const o=Array.from(s),i=t.getBoundingClientRect(),a={x:i.width*r[0],y:i.height*r[1]};return o.map(c=>{const u=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(u.left-i.left-a.x)/n,y:(u.top-i.top-a.y)/n,...Lr(c)}})};function Bt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function Sr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:o,multiSelectionActive:i,nodeInternals:a,onError:c}=t.getState(),u=a.get(e);if(!u){c==null||c("012",at.error012(e));return}t.setState({nodesSelectionActive:!1}),u.selected?(n||u.selected&&i)&&(o({nodes:[u],edges:[]}),requestAnimationFrame(()=>{var l;return(l=r==null?void 0:r.current)==null?void 0:l.blur()})):s([e])}function xh(){const e=Se();return w.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:o}=e.getState(),i=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(i-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:o?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:o?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function nr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Fi({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:o,selectNodesOnDrag:i}){const a=Se(),[c,u]=w.useState(!1),l=w.useRef([]),d=w.useRef({x:null,y:null}),m=w.useRef(0),f=w.useRef(null),p=w.useRef({x:0,y:0}),x=w.useRef(null),v=w.useRef(!1),g=w.useRef(!1),E=w.useRef(!1),M=xh();return w.useEffect(()=>{if(e!=null&&e.current){const b=Fe(e.current),$=({x:R,y:N})=>{const{nodeInternals:I,onNodeDrag:L,onSelectionDrag:V,updateNodePositions:F,nodeExtent:y,snapGrid:C,snapToGrid:S,nodeOrigin:O,onError:D}=a.getState();d.current={x:R,y:N};let k=!1,T={x:0,y:0,x2:0,y2:0};if(l.current.length>1&&y){const z=an(l.current,O);T=en(z)}if(l.current=l.current.map(z=>{const U={x:R-z.distance.x,y:N-z.distance.y};S&&(U.x=C[0]*Math.round(U.x/C[0]),U.y=C[1]*Math.round(U.y/C[1]));const X=[[y[0][0],y[0][1]],[y[1][0],y[1][1]]];l.current.length>1&&y&&!z.extent&&(X[0][0]=z.positionAbsolute.x-T.x+y[0][0],X[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+y[1][0],X[0][1]=z.positionAbsolute.y-T.y+y[0][1],X[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+y[1][1]);const Z=Hi(z,U,I,X,O,D);return k=k||z.position.x!==Z.position.x||z.position.y!==Z.position.y,z.position=Z.position,z.positionAbsolute=Z.positionAbsolute,z}),!k)return;F(l.current,!0,!0),u(!0);const P=s?L:nr(V);if(P&&x.current){const[z,U]=tr({nodeId:s,dragItems:l.current,nodeInternals:I});P(x.current,z,U)}},j=()=>{if(!f.current)return;const[R,N]=li(p.current,f.current);if(R!==0||N!==0){const{transform:I,panBy:L}=a.getState();d.current.x=(d.current.x??0)-R/I[2],d.current.y=(d.current.y??0)-N/I[2],L({x:R,y:N})&&$(d.current)}m.current=requestAnimationFrame(j)},_=R=>{var O;const{nodeInternals:N,multiSelectionActive:I,nodesDraggable:L,unselectNodesAndEdges:V,onNodeDragStart:F,onSelectionDragStart:y}=a.getState();g.current=!0;const C=s?F:nr(y);(!i||!o)&&!I&&s&&((O=N.get(s))!=null&&O.selected||V()),s&&o&&i&&Sr({id:s,store:a,nodeRef:e});const S=M(R);if(d.current=S,l.current=gh(N,L,S,s),C&&l.current){const[D,k]=tr({nodeId:s,dragItems:l.current,nodeInternals:N});C(R.sourceEvent,D,k)}};if(t)b.on(".drag",null);else{const R=ku().on("start",N=>{const{domNode:I,nodeDragThreshold:L}=a.getState();L===0&&_(N),E.current=!1;const V=M(N);d.current=V,f.current=(I==null?void 0:I.getBoundingClientRect())||null,p.current=gt(N.sourceEvent,f.current)}).on("drag",N=>{var F,y;const I=M(N),{autoPanOnNodeDrag:L,nodeDragThreshold:V}=a.getState();if(N.sourceEvent.type==="touchmove"&&N.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&g.current&&L&&(v.current=!0,j()),!g.current){const C=I.xSnapped-(((F=d==null?void 0:d.current)==null?void 0:F.x)??0),S=I.ySnapped-(((y=d==null?void 0:d.current)==null?void 0:y.y)??0);Math.sqrt(C*C+S*S)>V&&_(N)}(d.current.x!==I.xSnapped||d.current.y!==I.ySnapped)&&l.current&&g.current&&(x.current=N.sourceEvent,p.current=gt(N.sourceEvent,f.current),$(I))}}).on("end",N=>{if(!(!g.current||E.current)&&(u(!1),v.current=!1,g.current=!1,cancelAnimationFrame(m.current),l.current)){const{updateNodePositions:I,nodeInternals:L,onNodeDragStop:V,onSelectionDragStop:F}=a.getState(),y=s?V:nr(F);if(I(l.current,!1,!1),y){const[C,S]=tr({nodeId:s,dragItems:l.current,nodeInternals:L});y(N.sourceEvent,C,S)}}}).filter(N=>{const I=N.target;return!N.button&&(!n||!Os(I,`.${n}`,e))&&(!r||Os(I,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,o,a,s,i,M]),c}function Vi(){const e=Se();return w.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:o,getNodes:i,snapToGrid:a,snapGrid:c,onError:u,nodesDraggable:l}=e.getState(),d=i().filter(E=>E.selected&&(E.draggable||l&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,p=n.isShiftPressed?4:1,x=n.x*m*p,v=n.y*f*p,g=d.map(E=>{if(E.positionAbsolute){const M={x:E.positionAbsolute.x+x,y:E.positionAbsolute.y+v};a&&(M.x=c[0]*Math.round(M.x/c[0]),M.y=c[1]*Math.round(M.y/c[1]));const{positionAbsolute:b,position:$}=Hi(E,M,r,s,void 0,u);E.position=$,E.positionAbsolute=b}return E});o(g,!0,!1)},[])}const Tt={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Gt=e=>{const t=({id:n,type:r,data:s,xPos:o,yPos:i,xPosOrigin:a,yPosOrigin:c,selected:u,onClick:l,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:p,onDoubleClick:x,style:v,className:g,isDraggable:E,isSelectable:M,isConnectable:b,isFocusable:$,selectNodesOnDrag:j,sourcePosition:_,targetPosition:R,hidden:N,resizeObserver:I,dragHandle:L,zIndex:V,isParent:F,noDragClassName:y,noPanClassName:C,initialized:S,disableKeyboardA11y:O,ariaLabel:D,rfId:k,hasHandleBounds:T})=>{const P=Se(),z=w.useRef(null),U=w.useRef(null),X=w.useRef(_),Z=w.useRef(R),J=w.useRef(r),se=M||E||l||d||m||f,ee=Vi(),oe=Bt(n,P.getState,d),ce=Bt(n,P.getState,m),we=Bt(n,P.getState,f),ye=Bt(n,P.getState,p),me=Bt(n,P.getState,x),pe=ae=>{const{nodeDragThreshold:q}=P.getState();if(M&&(!j||!E||q>0)&&Sr({id:n,store:P,nodeRef:z}),l){const xe=P.getState().nodeInternals.get(n);xe&&l(ae,{...xe})}},ge=ae=>{if(!vr(ae)&&!O)if(hi.includes(ae.key)&&M){const q=ae.key==="Escape";Sr({id:n,store:P,unselect:q,nodeRef:z})}else E&&u&&Object.prototype.hasOwnProperty.call(Tt,ae.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${ae.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~o}, y: ${~~i}`}),ee({x:Tt[ae.key].x,y:Tt[ae.key].y,isShiftPressed:ae.shiftKey}))};w.useEffect(()=>()=>{U.current&&(I==null||I.unobserve(U.current),U.current=null)},[]),w.useEffect(()=>{if(z.current&&!N){const ae=z.current;(!S||!T||U.current!==ae)&&(U.current&&(I==null||I.unobserve(U.current)),I==null||I.observe(ae),U.current=ae)}},[N,S,T]),w.useEffect(()=>{const ae=J.current!==r,q=X.current!==_,xe=Z.current!==R;z.current&&(ae||q||xe)&&(ae&&(J.current=r),q&&(X.current=_),xe&&(Z.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const Ne=Fi({nodeRef:z,disabled:N||!E,noDragClassName:y,handleSelector:L,nodeId:n,isSelectable:M,selectNodesOnDrag:j});return N?null:A.createElement("div",{className:Re(["react-flow__node",`react-flow__node-${r}`,{[C]:E},g,{selected:u,selectable:M,parent:F,dragging:Ne}]),ref:z,style:{zIndex:V,transform:`translate(${a}px,${c}px)`,pointerEvents:se?"all":"none",visibility:S?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:oe,onMouseMove:ce,onMouseLeave:we,onContextMenu:ye,onClick:pe,onDoubleClick:me,onKeyDown:$?ge:void 0,tabIndex:$?0:void 0,role:$?"button":void 0,"aria-describedby":O?void 0:`${Ii}-${k}`,"aria-label":D},A.createElement($f,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:o,yPos:i,selected:u,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:Ne,dragHandle:L,zIndex:V})))};return t.displayName="NodeWrapper",w.memo(t)};const wh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...an(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function bh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Se(),{width:s,height:o,x:i,y:a,transformString:c,userSelectionActive:u}=he(wh,Ce),l=Vi(),d=w.useRef(null);if(w.useEffect(()=>{var p;n||(p=d.current)==null||p.focus({preventScroll:!0})},[n]),Fi({nodeRef:d}),u||!s||!o)return null;const m=e?p=>{const x=r.getState().getNodes().filter(v=>v.selected);e(p,x)}:void 0,f=p=>{Object.prototype.hasOwnProperty.call(Tt,p.key)&&l({x:Tt[p.key].x,y:Tt[p.key].y,isShiftPressed:p.shiftKey})};return A.createElement("div",{className:Re(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:o,top:a,left:i}}))}var vh=w.memo(bh);const _h=e=>e.nodesSelectionActive,Bi=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:i,deleteKeyCode:a,onMove:c,onMoveStart:u,onMoveEnd:l,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:p,onSelectionEnd:x,multiSelectionKeyCode:v,panActivationKeyCode:g,zoomActivationKeyCode:E,elementsSelectable:M,zoomOnScroll:b,zoomOnPinch:$,panOnScroll:j,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:N,panOnDrag:I,defaultViewport:L,translateExtent:V,minZoom:F,maxZoom:y,preventScrolling:C,onSelectionContextMenu:S,noWheelClassName:O,noPanClassName:D,disableKeyboardA11y:k})=>{const T=he(_h),P=nn(d),z=nn(g),U=z||I,X=z||j,Z=P||m&&U!==!0;return ih({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(uh,{onMove:c,onMoveStart:u,onMoveEnd:l,onPaneContextMenu:o,elementsSelectable:M,zoomOnScroll:b,zoomOnPinch:$,panOnScroll:X,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:N,panOnDrag:!P&&U,defaultViewport:L,translateExtent:V,minZoom:F,maxZoom:y,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:O,noPanClassName:D},A.createElement(Pi,{onSelectionStart:p,onSelectionEnd:x,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:i,panOnDrag:U,isSelecting:!!Z,selectionMode:f},e,T&&A.createElement(vh,{onSelectionContextMenu:S,noPanClassName:D,disableKeyboardA11y:k})))};Bi.displayName="FlowRenderer";var Eh=w.memo(Bi);function Nh(e){return he(w.useCallback(n=>e?bi(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function Sh(e){const t={input:Gt(e.input||Mi),default:Gt(e.default||Nr),output:Gt(e.output||Ai),group:Gt(e.group||Br)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,o)=>(s[o]=Gt(e[o]||Nr),s),n);return{...t,...r}}const kh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},jh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Gi=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:o,onError:i}=he(jh,Ce),a=Nh(e.onlyRenderVisibleElements),c=w.useRef(),u=w.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const l=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));o(m)});return c.current=l,l},[]);return w.useEffect(()=>()=>{var l;(l=c==null?void 0:c.current)==null||l.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Gr},a.map(l=>{var $,j,_;let d=l.type||"default";e.nodeTypes[d]||(i==null||i("003",at.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(l.draggable||t&&typeof l.draggable>"u"),p=!!(l.selectable||s&&typeof l.selectable>"u"),x=!!(l.connectable||n&&typeof l.connectable>"u"),v=!!(l.focusable||r&&typeof l.focusable>"u"),g=e.nodeExtent?Dr(l.positionAbsolute,e.nodeExtent):l.positionAbsolute,E=(g==null?void 0:g.x)??0,M=(g==null?void 0:g.y)??0,b=kh({x:E,y:M,width:l.width??0,height:l.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:l.id,id:l.id,className:l.className,style:l.style,type:d,data:l.data,sourcePosition:l.sourcePosition||K.Bottom,targetPosition:l.targetPosition||K.Top,hidden:l.hidden,xPos:E,yPos:M,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!l.selected,isDraggable:f,isSelectable:p,isConnectable:x,isFocusable:v,resizeObserver:u,dragHandle:l.dragHandle,zIndex:(($=l[be])==null?void 0:$.z)??0,isParent:!!((j=l[be])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!l.width&&!!l.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:l.ariaLabel,hasHandleBounds:!!((_=l[be])!=null&&_.handleBounds)})}))};Gi.displayName="NodeRenderer";var Ch=w.memo(Gi);const Mh=(e,t,n)=>n===K.Left?e-t:n===K.Right?e+t:e,$h=(e,t,n)=>n===K.Top?e-t:n===K.Bottom?e+t:e,Ds="react-flow__edgeupdater",Ps=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:o,onMouseOut:i,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:o,onMouseOut:i,className:Re([Ds,`${Ds}-${a}`]),cx:Mh(t,r,e),cy:$h(n,r,e),r,stroke:"transparent",fill:"transparent"}),Ah=()=>!0;var Mt=e=>{const t=({id:n,className:r,type:s,data:o,onClick:i,onEdgeDoubleClick:a,selected:c,animated:u,label:l,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:x,style:v,source:g,target:E,sourceX:M,sourceY:b,targetX:$,targetY:j,sourcePosition:_,targetPosition:R,elementsSelectable:N,hidden:I,sourceHandleId:L,targetHandleId:V,onContextMenu:F,onMouseEnter:y,onMouseMove:C,onMouseLeave:S,reconnectRadius:O,onReconnect:D,onReconnectStart:k,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:U,ariaLabel:X,isFocusable:Z,isReconnectable:J,pathOptions:se,interactionWidth:ee,disableKeyboardA11y:oe})=>{const ce=w.useRef(null),[we,ye]=w.useState(!1),[me,pe]=w.useState(!1),ge=Se(),Ne=w.useMemo(()=>`url('#${_r(z,U)}')`,[z,U]),ae=w.useMemo(()=>`url('#${_r(P,U)}')`,[P,U]);if(I)return null;const q=W=>{var de;const{edges:ie,addSelectedEdges:re,unselectNodesAndEdges:Q,multiSelectionActive:le}=ge.getState(),ne=ie.find(je=>je.id===n);ne&&(N&&(ge.setState({nodesSelectionActive:!1}),ne.selected&&le?(Q({nodes:[],edges:[ne]}),(de=ce.current)==null||de.blur()):re([n])),i&&i(W,ne))},xe=Vt(n,ge.getState,a),Te=Vt(n,ge.getState,F),ze=Vt(n,ge.getState,y),qe=Vt(n,ge.getState,C),ke=Vt(n,ge.getState,S),Me=(W,ie)=>{if(W.button!==0)return;const{edges:re,isValidConnection:Q}=ge.getState(),le=ie?E:g,ne=(ie?V:L)||null,de=ie?"target":"source",je=Q||Ah,Le=ie,$e=re.find(Ae=>Ae.id===n);pe(!0),k==null||k(W,$e,de);const Ie=Ae=>{pe(!1),T==null||T(Ae,$e,de)};Si({event:W,handleId:ne,nodeId:le,onConnect:Ae=>D==null?void 0:D($e,Ae),isTarget:Le,getState:ge.getState,setState:ge.setState,isValidConnection:je,edgeUpdaterType:de,onReconnectEnd:Ie})},Oe=W=>Me(W,!0),H=W=>Me(W,!1),Y=()=>ye(!0),B=()=>ye(!1),te=!N&&!i,G=W=>{var ie;if(!oe&&hi.includes(W.key)&&N){const{unselectNodesAndEdges:re,addSelectedEdges:Q,edges:le}=ge.getState();W.key==="Escape"?((ie=ce.current)==null||ie.blur(),re({edges:[le.find(de=>de.id===n)]})):Q([n])}};return A.createElement("g",{className:Re(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:u,inactive:te,updating:we}]),onClick:q,onDoubleClick:xe,onContextMenu:Te,onMouseEnter:ze,onMouseMove:qe,onMouseLeave:ke,onKeyDown:Z?G:void 0,tabIndex:Z?0:void 0,role:Z?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":X===null?void 0:X||`Edge from ${g} to ${E}`,"aria-describedby":Z?`${Ti}-${U}`:void 0,ref:ce},!me&&A.createElement(e,{id:n,source:g,target:E,selected:c,animated:u,label:l,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:x,data:o,style:v,sourceX:M,sourceY:b,targetX:$,targetY:j,sourcePosition:_,targetPosition:R,sourceHandleId:L,targetHandleId:V,markerStart:Ne,markerEnd:ae,pathOptions:se,interactionWidth:ee}),J&&A.createElement(A.Fragment,null,(J==="source"||J===!0)&&A.createElement(Ps,{position:_,centerX:M,centerY:b,radius:O,onMouseDown:Oe,onMouseEnter:Y,onMouseOut:B,type:"source"}),(J==="target"||J===!0)&&A.createElement(Ps,{position:R,centerX:$,centerY:j,radius:O,onMouseDown:H,onMouseEnter:Y,onMouseOut:B,type:"target"})))};return t.displayName="EdgeWrapper",w.memo(t)};function Rh(e){const t={default:Mt(e.default||In),straight:Mt(e.bezier||Hr),step:Mt(e.step||zr),smoothstep:Mt(e.step||Bn),simplebezier:Mt(e.simplebezier||Pr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,o)=>(s[o]=Mt(e[o]||In),s),n);return{...t,...r}}function zs(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,o=(n==null?void 0:n.width)||t.width,i=(n==null?void 0:n.height)||t.height;switch(e){case K.Top:return{x:r+o/2,y:s};case K.Right:return{x:r+o,y:s+i/2};case K.Bottom:return{x:r+o/2,y:s+i};case K.Left:return{x:r,y:s+i/2}}}function Hs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const Ih=(e,t,n,r,s,o)=>{const i=zs(n,e,t),a=zs(o,r,s);return{sourceX:i.x,sourceY:i.y,targetX:a.x,targetY:a.y}};function Th({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:o,width:i,height:a,transform:c}){const u={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+o)};u.x===u.x2&&(u.x2+=1),u.y===u.y2&&(u.y2+=1);const l=en({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:i/c[2],height:a/c[2]}),d=Math.max(0,Math.min(l.x2,u.x2)-Math.max(l.x,u.x)),m=Math.max(0,Math.min(l.y2,u.y2)-Math.max(l.y,u.y));return Math.ceil(d*m)>0}function Fs(e){var r,s,o,i,a;const t=((r=e==null?void 0:e[be])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.y)<"u";return[{x:((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const Oh=[{level:0,isMaxLevel:!0,edges:[]}];function Lh(e,t,n=!1){let r=-1;const s=e.reduce((i,a)=>{var l,d;const c=Ve(a.zIndex);let u=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),p=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),x=Math.max(((l=f==null?void 0:f[be])==null?void 0:l.z)||0,((d=m==null?void 0:m[be])==null?void 0:d.z)||0,1e3);u=(c?a.zIndex:0)+(p?x:0)}return i[u]?i[u].push(a):i[u]=[a],r=u>r?u:r,i},{}),o=Object.entries(s).map(([i,a])=>{const c=+i;return{edges:a,level:c,isMaxLevel:c===r}});return o.length===0?Oh:o}function Dh(e,t,n){const r=he(w.useCallback(s=>e?s.edges.filter(o=>{const i=t.get(o.source),a=t.get(o.target);return(i==null?void 0:i.width)&&(i==null?void 0:i.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Th({sourcePos:i.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:i.width,sourceHeight:i.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Lh(r,t,n)}const Ph=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),zh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Vs={[An.Arrow]:Ph,[An.ArrowClosed]:zh};function Hh(e){const t=Se();return w.useMemo(()=>{var s,o;return Object.prototype.hasOwnProperty.call(Vs,e)?Vs[e]:((o=(s=t.getState()).onError)==null||o.call(s,"009",at.error009(e)),null)},[e])}const Fh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:o="strokeWidth",strokeWidth:i,orient:a="auto-start-reverse"})=>{const c=Hh(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:i})):null},Vh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,o)=>([o.markerStart,o.markerEnd].forEach(i=>{if(i&&typeof i=="object"){const a=_r(i,t);r.includes(a)||(s.push({id:a,color:i.color||e,...i}),r.push(a))}}),s),[]).sort((s,o)=>s.id.localeCompare(o.id))},Yi=({defaultColor:e,rfId:t})=>{const n=he(w.useCallback(Vh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((o,i)=>o.id!==s[i].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Fh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};Yi.displayName="MarkerDefinitions";var Bh=w.memo(Yi);const Gh=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Xi=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:o,onEdgeContextMenu:i,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:u,onEdgeClick:l,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:x,children:v,disableKeyboardA11y:g})=>{const{edgesFocusable:E,edgesUpdatable:M,elementsSelectable:b,width:$,height:j,connectionMode:_,nodeInternals:R,onError:N}=he(Gh,Ce),I=Dh(t,R,n);return $?A.createElement(A.Fragment,null,I.map(({level:L,edges:V,isMaxLevel:F})=>A.createElement("svg",{key:L,style:{zIndex:L},width:$,height:j,className:"react-flow__edges react-flow__container"},F&&A.createElement(Bh,{defaultColor:e,rfId:r}),A.createElement("g",null,V.map(y=>{const[C,S,O]=Fs(R.get(y.source)),[D,k,T]=Fs(R.get(y.target));if(!O||!T)return null;let P=y.type||"default";s[P]||(N==null||N("011",at.error011(P)),P="default");const z=s[P]||s.default,U=_===Nt.Strict?k.target:(k.target??[]).concat(k.source??[]),X=Hs(S.source,y.sourceHandle),Z=Hs(U,y.targetHandle),J=(X==null?void 0:X.position)||K.Bottom,se=(Z==null?void 0:Z.position)||K.Top,ee=!!(y.focusable||E&&typeof y.focusable>"u"),oe=y.reconnectable||y.updatable,ce=typeof m<"u"&&(oe||M&&typeof oe>"u");if(!X||!Z)return N==null||N("008",at.error008(X,y)),null;const{sourceX:we,sourceY:ye,targetX:me,targetY:pe}=Ih(C,X,J,D,Z,se);return A.createElement(z,{key:y.id,id:y.id,className:Re([y.className,o]),type:P,data:y.data,selected:!!y.selected,animated:!!y.animated,hidden:!!y.hidden,label:y.label,labelStyle:y.labelStyle,labelShowBg:y.labelShowBg,labelBgStyle:y.labelBgStyle,labelBgPadding:y.labelBgPadding,labelBgBorderRadius:y.labelBgBorderRadius,style:y.style,source:y.source,target:y.target,sourceHandleId:y.sourceHandle,targetHandleId:y.targetHandle,markerEnd:y.markerEnd,markerStart:y.markerStart,sourceX:we,sourceY:ye,targetX:me,targetY:pe,sourcePosition:J,targetPosition:se,elementsSelectable:b,onContextMenu:i,onMouseEnter:a,onMouseMove:c,onMouseLeave:u,onClick:l,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:x,rfId:r,ariaLabel:y.ariaLabel,isFocusable:ee,isReconnectable:ce,pathOptions:"pathOptions"in y?y.pathOptions:void 0,interactionWidth:y.interactionWidth,disableKeyboardA11y:g})})))),v):null};Xi.displayName="EdgeRenderer";var Yh=w.memo(Xi);const Xh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Wh({children:e}){const t=he(Xh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Uh(e){const t=cn(),n=w.useRef(!1);w.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const qh={[K.Left]:K.Right,[K.Right]:K.Left,[K.Top]:K.Bottom,[K.Bottom]:K.Top},Wi=({nodeId:e,handleType:t,style:n,type:r=ht.Bezier,CustomComponent:s,connectionStatus:o})=>{var j,_,R;const{fromNode:i,handleId:a,toX:c,toY:u,connectionMode:l}=he(w.useCallback(N=>({fromNode:N.nodeInternals.get(e),handleId:N.connectionHandleId,toX:(N.connectionPosition.x-N.transform[0])/N.transform[2],toY:(N.connectionPosition.y-N.transform[1])/N.transform[2],connectionMode:N.connectionMode}),[e]),Ce),d=(j=i==null?void 0:i[be])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(l===Nt.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!i||!m)return null;const f=a?m.find(N=>N.id===a):m[0],p=f?f.x+f.width/2:(i.width??0)/2,x=f?f.y+f.height/2:i.height??0,v=(((_=i.positionAbsolute)==null?void 0:_.x)??0)+p,g=(((R=i.positionAbsolute)==null?void 0:R.y)??0)+x,E=f==null?void 0:f.position,M=E?qh[E]:null;if(!E||!M)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:i,fromHandle:f,fromX:v,fromY:g,toX:c,toY:u,fromPosition:E,toPosition:M,connectionStatus:o});let b="";const $={sourceX:v,sourceY:g,sourcePosition:E,targetX:c,targetY:u,targetPosition:M};return r===ht.Bezier?[b]=xi($):r===ht.Step?[b]=Rn({...$,borderRadius:0}):r===ht.SmoothStep?[b]=Rn($):r===ht.SimpleBezier?[b]=yi($):b=`M${v},${g} ${c},${u}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};Wi.displayName="ConnectionLine";const Kh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Zh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:o,nodesConnectable:i,width:a,height:c,connectionStatus:u}=he(Kh,Ce);return!(s&&o&&a&&i)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:Re(["react-flow__connection",u])},A.createElement(Wi,{nodeId:s,handleType:o,style:t,type:n,CustomComponent:r,connectionStatus:u})))}function Bs(e,t){return w.useRef(null),Se(),w.useMemo(()=>t(e),[e])}const Ui=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:o,onNodeClick:i,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:u,onNodeMouseEnter:l,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:p,onSelectionStart:x,onSelectionEnd:v,connectionLineType:g,connectionLineStyle:E,connectionLineComponent:M,connectionLineContainerStyle:b,selectionKeyCode:$,selectionOnDrag:j,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:N,zoomActivationKeyCode:I,deleteKeyCode:L,onlyRenderVisibleElements:V,elementsSelectable:F,selectNodesOnDrag:y,defaultViewport:C,translateExtent:S,minZoom:O,maxZoom:D,preventScrolling:k,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:U,panOnScrollSpeed:X,panOnScrollMode:Z,zoomOnDoubleClick:J,panOnDrag:se,onPaneClick:ee,onPaneMouseEnter:oe,onPaneMouseMove:ce,onPaneMouseLeave:we,onPaneScroll:ye,onPaneContextMenu:me,onEdgeContextMenu:pe,onEdgeMouseEnter:ge,onEdgeMouseMove:Ne,onEdgeMouseLeave:ae,onReconnect:q,onReconnectStart:xe,onReconnectEnd:Te,reconnectRadius:ze,noDragClassName:qe,noWheelClassName:ke,noPanClassName:Me,elevateEdgesOnSelect:Oe,disableKeyboardA11y:H,nodeOrigin:Y,nodeExtent:B,rfId:te})=>{const G=Bs(e,Sh),W=Bs(t,Rh);return Uh(o),A.createElement(Eh,{onPaneClick:ee,onPaneMouseEnter:oe,onPaneMouseMove:ce,onPaneMouseLeave:we,onPaneContextMenu:me,onPaneScroll:ye,deleteKeyCode:L,selectionKeyCode:$,selectionOnDrag:j,selectionMode:_,onSelectionStart:x,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:N,zoomActivationKeyCode:I,elementsSelectable:F,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:J,panOnScroll:U,panOnScrollSpeed:X,panOnScrollMode:Z,panOnDrag:se,defaultViewport:C,translateExtent:S,minZoom:O,maxZoom:D,onSelectionContextMenu:p,preventScrolling:k,noDragClassName:qe,noWheelClassName:ke,noPanClassName:Me,disableKeyboardA11y:H},A.createElement(Wh,null,A.createElement(Yh,{edgeTypes:W,onEdgeClick:a,onEdgeDoubleClick:u,onlyRenderVisibleElements:V,onEdgeContextMenu:pe,onEdgeMouseEnter:ge,onEdgeMouseMove:Ne,onEdgeMouseLeave:ae,onReconnect:q,onReconnectStart:xe,onReconnectEnd:Te,reconnectRadius:ze,defaultMarkerColor:T,noPanClassName:Me,elevateEdgesOnSelect:!!Oe,disableKeyboardA11y:H,rfId:te},A.createElement(Zh,{style:E,type:g,component:M,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(Ch,{nodeTypes:G,onNodeClick:i,onNodeDoubleClick:c,onNodeMouseEnter:l,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:y,onlyRenderVisibleElements:V,noPanClassName:Me,noDragClassName:qe,disableKeyboardA11y:H,nodeOrigin:Y,nodeExtent:B,rfId:te})))};Ui.displayName="GraphView";var Qh=w.memo(Ui);const kr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],lt={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:kr,nodeExtent:kr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:Nt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:Nf,isValidConnection:void 0},Jh=()=>Pc((e,t)=>({...lt,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:o}=t();e({nodeInternals:Jn(n,r,s,o)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",o=typeof r<"u",i=s?Jn(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:i,edges:o?r:[],hasDefaultNodes:s,hasDefaultEdges:o})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:o,fitViewOnInitDone:i,fitViewOnInitOptions:a,domNode:c,nodeOrigin:u}=t(),l=c==null?void 0:c.querySelector(".react-flow__viewport");if(!l)return;const d=window.getComputedStyle(l),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((x,v)=>{const g=s.get(v.id);if(g!=null&&g.hidden)s.set(g.id,{...g,[be]:{...g[be],handleBounds:void 0}});else if(g){const E=Lr(v.nodeElement);!!(E.width&&E.height&&(g.width!==E.width||g.height!==E.height||v.forceUpdate))&&(s.set(g.id,{...g,[be]:{...g[be],handleBounds:{source:Ls(".source",v.nodeElement,m,u),target:Ls(".target",v.nodeElement,m,u)}},...E}),x.push({id:g.id,type:"dimensions",dimensions:E}))}return x},[]);Li(s,u);const p=i||o&&!i&&Di(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:p}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:o}=t(),i=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});o(i)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:o,nodeOrigin:i,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(o){const u=mh(n,a()),l=Jn(u,s,i,c);e({nodeInternals:l})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:o}=t();let i,a=null;r?i=n.map(c=>ft(c,!0)):(i=$t(o(),n),a=$t(s,[])),yn({changedNodes:i,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:o}=t();let i,a=null;r?i=n.map(c=>ft(c,!0)):(i=$t(s,n),a=$t(o(),[])),yn({changedNodes:a,changedEdges:i,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:o}=t(),i=n||o(),a=r||s,c=i.map(l=>(l.selected=!1,ft(l.id,!1))),u=a.map(l=>ft(l.id,!1));yn({changedNodes:c,changedEdges:u,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),o=r().filter(a=>a.selected).map(a=>ft(a.id,!1)),i=n.filter(a=>a.selected).map(a=>ft(a.id,!1));yn({changedNodes:o,changedEdges:i,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=Dr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:o,d3Zoom:i,d3Selection:a,translateExtent:c}=t();if(!i||!a||!n.x&&!n.y)return!1;const u=ot.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),l=[[0,0],[s,o]],d=i==null?void 0:i.constrain()(u,l,c);return i.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:lt.connectionNodeId,connectionHandleId:lt.connectionHandleId,connectionHandleType:lt.connectionHandleType,connectionStatus:lt.connectionStatus,connectionStartHandle:lt.connectionStartHandle,connectionEndHandle:lt.connectionEndHandle}),reset:()=>e({...lt})}),Object.is),qi=({children:e})=>{const t=w.useRef(null);return t.current||(t.current=Jh()),A.createElement(yf,{value:t.current},e)};qi.displayName="ReactFlowProvider";const Ki=({children:e})=>w.useContext(Vn)?A.createElement(A.Fragment,null,e):A.createElement(qi,null,e);Ki.displayName="ReactFlowWrapper";const em={input:Mi,default:Nr,output:Ai,group:Br},tm={default:In,straight:Hr,step:zr,smoothstep:Bn,simplebezier:Pr},nm=[0,0],rm=[15,15],sm={x:0,y:0,zoom:1},om={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Zi=w.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:o=em,edgeTypes:i=tm,onNodeClick:a,onEdgeClick:c,onInit:u,onMove:l,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:p,onConnectEnd:x,onClickConnectStart:v,onClickConnectEnd:g,onNodeMouseEnter:E,onNodeMouseMove:M,onNodeMouseLeave:b,onNodeContextMenu:$,onNodeDoubleClick:j,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:N,onNodesDelete:I,onEdgesDelete:L,onSelectionChange:V,onSelectionDragStart:F,onSelectionDrag:y,onSelectionDragStop:C,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,connectionMode:k=Nt.Strict,connectionLineType:T=ht.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:U,deleteKeyCode:X="Backspace",selectionKeyCode:Z="Shift",selectionOnDrag:J=!1,selectionMode:se=tn.Full,panActivationKeyCode:ee="Space",multiSelectionKeyCode:oe=$n()?"Meta":"Control",zoomActivationKeyCode:ce=$n()?"Meta":"Control",snapToGrid:we=!1,snapGrid:ye=rm,onlyRenderVisibleElements:me=!1,selectNodesOnDrag:pe=!0,nodesDraggable:ge,nodesConnectable:Ne,nodesFocusable:ae,nodeOrigin:q=nm,edgesFocusable:xe,edgesUpdatable:Te,elementsSelectable:ze,defaultViewport:qe=sm,minZoom:ke=.5,maxZoom:Me=2,translateExtent:Oe=kr,preventScrolling:H=!0,nodeExtent:Y,defaultMarkerColor:B="#b1b1b7",zoomOnScroll:te=!0,zoomOnPinch:G=!0,panOnScroll:W=!1,panOnScrollSpeed:ie=.5,panOnScrollMode:re=bt.Free,zoomOnDoubleClick:Q=!0,panOnDrag:le=!0,onPaneClick:ne,onPaneMouseEnter:de,onPaneMouseMove:je,onPaneMouseLeave:Le,onPaneScroll:$e,onPaneContextMenu:Ie,children:He,onEdgeContextMenu:Ae,onEdgeDoubleClick:Ke,onEdgeMouseEnter:fe,onEdgeMouseMove:et,onEdgeMouseLeave:zt,onEdgeUpdate:La,onEdgeUpdateStart:Da,onEdgeUpdateEnd:Pa,onReconnect:za,onReconnectStart:Ha,onReconnectEnd:Fa,reconnectRadius:Va=10,edgeUpdaterRadius:Ba=10,onNodesChange:Ga,onEdgesChange:Ya,noDragClassName:Xa="nodrag",noWheelClassName:Wa="nowheel",noPanClassName:Qr="nopan",fitView:Ua=!1,fitViewOptions:qa,connectOnClick:Ka=!0,attributionPosition:Za,proOptions:Qa,defaultEdgeOptions:Ja,elevateNodesOnSelect:ec=!0,elevateEdgesOnSelect:tc=!1,disableKeyboardA11y:Jr=!1,autoPanOnConnect:nc=!0,autoPanOnNodeDrag:rc=!0,connectionRadius:sc=20,isValidConnection:oc,onError:ic,style:ac,id:es,nodeDragThreshold:cc,...lc},uc)=>{const Xn=es||"1";return A.createElement("div",{...lc,style:{...ac,...om},ref:uc,className:Re(["react-flow",s]),"data-testid":"rf__wrapper",id:es},A.createElement(Ki,null,A.createElement(Qh,{onInit:u,onMove:l,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:M,onNodeMouseLeave:b,onNodeContextMenu:$,onNodeDoubleClick:j,nodeTypes:o,edgeTypes:i,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:U,selectionKeyCode:Z,selectionOnDrag:J,selectionMode:se,deleteKeyCode:X,multiSelectionKeyCode:oe,panActivationKeyCode:ee,zoomActivationKeyCode:ce,onlyRenderVisibleElements:me,selectNodesOnDrag:pe,defaultViewport:qe,translateExtent:Oe,minZoom:ke,maxZoom:Me,preventScrolling:H,zoomOnScroll:te,zoomOnPinch:G,zoomOnDoubleClick:Q,panOnScroll:W,panOnScrollSpeed:ie,panOnScrollMode:re,panOnDrag:le,onPaneClick:ne,onPaneMouseEnter:de,onPaneMouseMove:je,onPaneMouseLeave:Le,onPaneScroll:$e,onPaneContextMenu:Ie,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,onEdgeContextMenu:Ae,onEdgeDoubleClick:Ke,onEdgeMouseEnter:fe,onEdgeMouseMove:et,onEdgeMouseLeave:zt,onReconnect:za??La,onReconnectStart:Ha??Da,onReconnectEnd:Fa??Pa,reconnectRadius:Va??Ba,defaultMarkerColor:B,noDragClassName:Xa,noWheelClassName:Wa,noPanClassName:Qr,elevateEdgesOnSelect:tc,rfId:Xn,disableKeyboardA11y:Jr,nodeOrigin:q,nodeExtent:Y}),A.createElement(Uf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:p,onConnectEnd:x,onClickConnectStart:v,onClickConnectEnd:g,nodesDraggable:ge,nodesConnectable:Ne,nodesFocusable:ae,edgesFocusable:xe,edgesUpdatable:Te,elementsSelectable:ze,elevateNodesOnSelect:ec,minZoom:ke,maxZoom:Me,nodeExtent:Y,onNodesChange:Ga,onEdgesChange:Ya,snapToGrid:we,snapGrid:ye,connectionMode:k,translateExtent:Oe,connectOnClick:Ka,defaultEdgeOptions:Ja,fitView:Ua,fitViewOptions:qa,onNodesDelete:I,onEdgesDelete:L,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:N,onSelectionDrag:y,onSelectionDragStart:F,onSelectionDragStop:C,noPanClassName:Qr,nodeOrigin:q,rfId:Xn,autoPanOnConnect:nc,autoPanOnNodeDrag:rc,onError:ic,connectionRadius:sc,isValidConnection:oc,nodeDragThreshold:cc}),A.createElement(Xf,{onSelectionChange:V}),He,A.createElement(wf,{proOptions:Qa,position:Za}),A.createElement(Jf,{rfId:Xn,disableKeyboardA11y:Jr})))});Zi.displayName="ReactFlow";const Qi=({id:e,x:t,y:n,width:r,height:s,style:o,color:i,strokeColor:a,strokeWidth:c,className:u,borderRadius:l,shapeRendering:d,onClick:m,selected:f})=>{const{background:p,backgroundColor:x}=o||{},v=i||p||x;return A.createElement("rect",{className:Re(["react-flow__minimap-node",{selected:f},u]),x:t,y:n,rx:l,ry:l,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?g=>m(g,e):void 0})};Qi.displayName="MiniMapNode";var im=w.memo(Qi);const am=e=>e.nodeOrigin,cm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),rr=e=>e instanceof Function?e:()=>e;function lm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:o=im,onClick:i}){const a=he(cm,Ce),c=he(am),u=rr(t),l=rr(e),d=rr(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:p,y:x}=_t(f,c).positionAbsolute;return A.createElement(o,{key:f.id,x:p,y:x,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:u(f),borderRadius:r,strokeColor:l(f),strokeWidth:s,shapeRendering:m,onClick:i,id:f.id})}))}var um=w.memo(lm);const dm=200,fm=150,hm=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?_f(an(t,e.nodeOrigin),n):n,rfId:e.rfId}},mm="react-flow__minimap-desc";function Ji({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:o=5,nodeStrokeWidth:i=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:u="none",maskStrokeWidth:l=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:p=!1,zoomable:x=!1,ariaLabel:v="React Flow mini map",inversePan:g=!1,zoomStep:E=10,offsetScale:M=5}){const b=Se(),$=w.useRef(null),{boundingRect:j,viewBB:_,rfId:R}=he(hm,Ce),N=(e==null?void 0:e.width)??dm,I=(e==null?void 0:e.height)??fm,L=j.width/N,V=j.height/I,F=Math.max(L,V),y=F*N,C=F*I,S=M*F,O=j.x-(y-j.width)/2-S,D=j.y-(C-j.height)/2-S,k=y+S*2,T=C+S*2,P=`${mm}-${R}`,z=w.useRef(0);z.current=F,w.useEffect(()=>{if($.current){const Z=Fe($.current),J=oe=>{const{transform:ce,d3Selection:we,d3Zoom:ye}=b.getState();if(oe.sourceEvent.type!=="wheel"||!we||!ye)return;const me=-oe.sourceEvent.deltaY*(oe.sourceEvent.deltaMode===1?.05:oe.sourceEvent.deltaMode?1:.002)*E,pe=ce[2]*Math.pow(2,me);ye.scaleTo(we,pe)},se=oe=>{const{transform:ce,d3Selection:we,d3Zoom:ye,translateExtent:me,width:pe,height:ge}=b.getState();if(oe.sourceEvent.type!=="mousemove"||!we||!ye)return;const Ne=z.current*Math.max(1,ce[2])*(g?-1:1),ae={x:ce[0]-oe.sourceEvent.movementX*Ne,y:ce[1]-oe.sourceEvent.movementY*Ne},q=[[0,0],[pe,ge]],xe=ot.translate(ae.x,ae.y).scale(ce[2]),Te=ye.constrain()(xe,q,me);ye.transform(we,Te)},ee=ai().on("zoom",p?se:null).on("zoom.wheel",x?J:null);return Z.call(ee),()=>{Z.on("zoom",null)}}},[p,x,g,E]);const U=m?Z=>{const J=Ye(Z);m(Z,{x:J[0],y:J[1]})}:void 0,X=f?(Z,J)=>{const se=b.getState().nodeInternals.get(J);f(Z,se)}:void 0;return A.createElement(Or,{position:d,style:e,className:Re(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:N,height:I,viewBox:`${O} ${D} ${k} ${T}`,role:"img","aria-labelledby":P,ref:$,onClick:U},v&&A.createElement("title",{id:P},v),A.createElement(um,{onClick:X,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:o,nodeClassName:s,nodeStrokeWidth:i,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${O-S},${D-S}h${k+S*2}v${T+S*2}h${-k-S*2}z - M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:u,strokeWidth:l,pointerEvents:"none"})))}Ji.displayName="MiniMap";var pm=w.memo(Ji);function gm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function ym(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function xm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function wm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function bm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const Wt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:Re(["react-flow__controls-button",t]),...n},e);Wt.displayName="ControlButton";const vm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),ea=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:o,onZoomOut:i,onFitView:a,onInteractiveChange:c,className:u,children:l,position:d="bottom-left"})=>{const m=Se(),[f,p]=w.useState(!1),{isInteractive:x,minZoomReached:v,maxZoomReached:g}=he(vm,Ce),{zoomIn:E,zoomOut:M,fitView:b}=cn();if(w.useEffect(()=>{p(!0)},[]),!f)return null;const $=()=>{E(),o==null||o()},j=()=>{M(),i==null||i()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!x,nodesConnectable:!x,elementsSelectable:!x}),c==null||c(!x)};return A.createElement(Or,{className:Re(["react-flow__controls",u]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(Wt,{onClick:$,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:g},A.createElement(gm,null)),A.createElement(Wt,{onClick:j,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(ym,null))),n&&A.createElement(Wt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(xm,null)),r&&A.createElement(Wt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},x?A.createElement(bm,null):A.createElement(wm,null)),l)};ea.displayName="Controls";var _m=w.memo(ea),Be;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Be||(Be={}));function Em({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function Nm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const Sm={[Be.Dots]:"#91919a",[Be.Lines]:"#eee",[Be.Cross]:"#e2e2e2"},km={[Be.Dots]:1,[Be.Lines]:1,[Be.Cross]:6},jm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function ta({id:e,variant:t=Be.Dots,gap:n=20,size:r,lineWidth:s=1,offset:o=2,color:i,style:a,className:c}){const u=w.useRef(null),{transform:l,patternId:d}=he(jm,Ce),m=i||Sm[t],f=r||km[t],p=t===Be.Dots,x=t===Be.Cross,v=Array.isArray(n)?n:[n,n],g=[v[0]*l[2]||1,v[1]*l[2]||1],E=f*l[2],M=x?[E,E]:g,b=p?[E/o,E/o]:[M[0]/o,M[1]/o];return A.createElement("svg",{className:Re(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:u,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:l[0]%g[0],y:l[1]%g[1],width:g[0],height:g[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},p?A.createElement(Nm,{color:m,radius:E/o}):A.createElement(Em,{dimensions:M,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}ta.displayName="Background";var Cm=w.memo(ta);const Yr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Tn(e){return Yr+e}async function ve(e){const t=await fetch(Tn(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function ct(e,t){const n=await fetch(Tn(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new na(r.error??`${e}: ${n.status}`,n.status);return r}class na extends Error{constructor(n,r){super(n);_e(this,"status");this.status=r}}const zx=e=>ve(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),Hx=()=>ve("/api/diagnostics"),ra=(e,t)=>ve(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),sa=()=>ve("/api/ontology/ontologies"),Mm=e=>ve(`/api/ontology/term?ref=${encodeURIComponent(e)}`),$m=()=>ve("/api/ontology/stack"),Am=()=>ve("/api/ontology/coverage"),Rm=(e,t,n)=>ct("/api/command",{op:e,payload:t,fingerprint:n??""}),Im=()=>ve("/api/git/status"),Tm=()=>ve("/api/git/diff"),Om=e=>ct("/api/git/commit",{message:e}),Lm=()=>ct("/api/git/discard",{}),Dm=()=>ve("/api/decisions"),Gs=(e,t)=>ct(`/api/decisions/${e}/verdict`,{verdict:t}),Fx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),ve(`/api/glossary/terms?${t.toString()}`)},Vx=()=>ve("/api/glossary/config"),Bx=e=>ct("/api/git/propose",e),Gx=(e="HEAD")=>ve(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Yx=(e="HEAD")=>ve(`/api/git/classify?base=${encodeURIComponent(e)}`),Xx=e=>ct("/api/git/classify",{changes:e}),Wx=e=>ve(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Ux=(e="")=>ve(`/api/git/context?user=${encodeURIComponent(e)}`),qx=(e="")=>ve(`/api/git/proposals?user=${encodeURIComponent(e)}`),Pm=()=>ve("/api/export"),zm=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Yr}/api/export/${encodeURIComponent(e)}${n}`},Hm=(e,t,n)=>ct("/api/import",{format:e,content:t,dialect:n}),Fm=(e,t)=>ct("/api/import/preview",{format:e,content:t}),Kx=e=>ve(`/api/import/stash/${encodeURIComponent(e)}`),Zx=async(e,t=!1)=>{for(const n of e)try{await Rm(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Qx=(e,t,n)=>fetch(`${Yr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new na(await r.text(),r.status);return await r.json()}),Jx=()=>ve("/api/glossary/subject-areas"),ew=e=>ve(`/api/glossary/subject-area/${e}`),tw=(e,t)=>ct(`/api/glossary/subject-area/${e}/expand`,t);function nw(){return{async load(e){try{const t=await ve(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Tn("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Tn(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Vm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Bm(e){return e??""}const Xr="__entity_source",Wr="__entity_target",Gm=w.memo(function({data:t,selected:n}){var j;const{entity:r,color:s,dimmed:o,highlighted:i,showTypes:a,collapseDetail:c,expanded:u,onToggleExpand:l,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:p}=t,x=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>x(_.a)-x(R.a)||_.i-R.i).map(_=>_.a),g=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const M=!!c&&!u;let b=0;if(M){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const $=(_,R)=>{const N="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:N,onMouseEnter:p?()=>p(_.id):void 0,onMouseLeave:p?()=>p(null):void 0,children:[h.jsx(mt,{id:_.id,type:"target",position:K.Left,className:"port attr-port"}),h.jsx(mt,{id:_.id,type:"source",position:K.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Vm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Bm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(o?" dimmed":"")+(i?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(mt,{id:Wr,type:"target",position:K.Left,className:"port"}),h.jsx(mt,{id:Xr,type:"source",position:K.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((j=r.conceptual)==null?void 0:j.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var N;const _=(((N=r.conceptual)==null?void 0:N.ontology_refs)??[]).filter(I=>I.uri);if(_.length===0)return null;const R=_.map(I=>I.uri).join(` -`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),g.length>0&&h.jsx("div",{className:"attr-section keys",children:g.map(_=>$(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>$(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:l?()=>l(r.id):void 0,children:`+${b} more`}),u&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:l?()=>l(r.id):void 0,children:"− collapse"})]})]})}),Ym=["string","integer","bigint","decimal","boolean","date","timestamp"];function Xm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:o,onAlign:i,onEditMapping:a}){var m,f,p,x,v,g,E,M,b,$,j,_,R;const c=!n.canEdit,u=e.conceptual,l=t.relationships.filter(N=>N.from.entity===e.id||N.to.entity===e.id),d=N=>{var I;return((I=t.entities.find(L=>L.id===N))==null?void 0:I.name)??N};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(nt,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,name:N})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(nt,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,physical_name:N})})]}),h.jsxs("div",{children:[h.jsx(Um,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Km,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(nt,{value:((m=u==null?void 0:u.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:N=>r("set_definition",{id:e.id,definition:N})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>i(e),children:(((f=u==null?void 0:u.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((p=u==null?void 0:u.ontology_refs)==null?void 0:p.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(u==null?void 0:u.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${u.ontology_layer}`,children:u.ontology_layer}),u.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Wm,{entityId:e.id,refs:(u==null?void 0:u.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(x=e.term_map)!=null&&x.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((g=e.term_map)==null?void 0:g.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),(M=e.term_map)!=null&&M.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[(($=e.term_map)==null?void 0:$.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(nt,{value:((_=u==null?void 0:u.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:N=>{var I;return r("set_stewardship",{id:e.id,owner:N,steward:((I=u==null?void 0:u.stewardship)==null?void 0:I.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(nt,{value:((R=u==null?void 0:u.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:N=>{var I;return r("set_stewardship",{id:e.id,owner:((I=u==null?void 0:u.stewardship)==null?void 0:I.owner)??null,steward:N})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(N=>h.jsx(Qm,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(Jm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(N=>{const I=N.members.map(L=>{var V;return((V=e.attributes.find(F=>F.id===L))==null?void 0:V.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+N.type,children:N.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:N.name}),h.jsx("span",{className:"key-cols",children:I})]},N.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([N,I])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:N}),h.jsx("td",{className:"udp-val",children:String(I)})]},N))})})]}),l.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",l.length,")"]}),l.map(N=>{const I=N.from.entity===e.id?N.to.entity:N.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>o(I),children:[h.jsx("span",{className:"rel-card",children:ep(N,e.id)}),d(I)]}),(N.verb_phrase||N.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(nt,{value:N.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:L=>r("update_relationship",{id:N.id,verb_phrase:L})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(nt,{value:N.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:L=>r("update_relationship",{id:N.id,inverse_verb_phrase:L})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${N.name}`,onClick:()=>r("delete_relationship",{id:N.id}),children:"✕"})]},N.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var N;return(N=navigator.clipboard)==null?void 0:N.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Wm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,o=t.filter(i=>i.uri);return o.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:o.map((i,a)=>{const c=i.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:i.uri??void 0,children:i.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[i.predicate&&h.jsx("span",{className:"ref-pill",children:i.predicate}),i.layer&&h.jsx("span",{className:`chip layer-${i.layer}`,children:i.layer}),i.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",i.resolved_via]}),typeof i.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(i.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:i.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:i.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${i.uri}-${a}`)})})}function nt({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:o=""}){const[i,a]=w.useState(e);w.useEffect(()=>a(e),[e]);const c=()=>{i.trim()!==e.trim()&&t(i.trim())};return n?h.jsx("span",{className:o,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${o}`,value:i,placeholder:s,rows:3,onChange:u=>a(u.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${o}`,value:i,placeholder:s,onChange:u=>a(u.target.value),onBlur:c,onKeyDown:u=>u.key==="Enter"&&u.target.blur()})}function Um({entity:e,doc:t,readOnly:n,exec:r}){var o,i,a;const s=((i=(o=e.conceptual)==null?void 0:o.subject_area)==null?void 0:i.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const qm=["","scd2","hub","link","satellite","bridge"];function Km({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:qm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Zm=["attribute","business_key","measure","surrogate_key"];function Qm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const o=i=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...i});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(nt,{value:e.name,readOnly:!1,onCommit:i=>o({name:i})}),(e.physical_name||!1)&&h.jsx(nt,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:i=>o({physical_name:i})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:i=>o({domain:i.target.value}),children:[...new Set([...Ym,...n.domains??[],e.domain??"string"])].sort().map(i=>h.jsx("option",{value:i,children:i},i))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:i=>o({role:i.target.value}),title:"role",children:Zm.map(i=>h.jsx("option",{value:i,children:i==="business_key"?"🔑 key":i==="measure"?"Σ measure":i},i))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:i=>o({nullable:!i.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Jm({entity:e,exec:t}){const[n,r]=w.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:o=>r(o.target.value),onKeyDown:o=>o.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function ep(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var tp="\0",yt="\0",Ys="";let np=class{constructor(t){_e(this,"_isDirected",!0);_e(this,"_isMultigraph",!1);_e(this,"_isCompound",!1);_e(this,"_label");_e(this,"_defaultNodeLabelFn",()=>{});_e(this,"_defaultEdgeLabelFn",()=>{});_e(this,"_nodes",{});_e(this,"_in",{});_e(this,"_preds",{});_e(this,"_out",{});_e(this,"_sucs",{});_e(this,"_edgeObjs",{});_e(this,"_edgeLabels",{});_e(this,"_nodeCount",0);_e(this,"_edgeCount",0);_e(this,"_parent");_e(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[yt]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(o){r.length>1?s.setNode(o,n):s.setNode(o)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=yt,this._children[t]={},this._children[yt][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=yt;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==yt)return n}}children(t=yt){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===yt)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([i,a]){t(i)&&n.setNode(i,a)}),Object.values(this._edgeObjs).forEach(function(i){n.hasNode(i.v)&&n.hasNode(i.w)&&n.setEdge(i,r.edge(i))});var s={};function o(i){var a=r.parent(i);return a===void 0||n.hasNode(a)?(s[i]=a,a):a in s?s[a]:o(a)}return this._isCompound&&n.nodes().forEach(i=>n.setParent(i,o(i))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(o,i){return s.length>1?r.setEdge(o,i,n):r.setEdge(o,i),i}),this}setEdge(){var t,n,r,s,o=!1,i=arguments[0];typeof i=="object"&&i!==null&&"v"in i?(t=i.v,n=i.w,r=i.name,arguments.length===2&&(s=arguments[1],o=!0)):(t=i,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],o=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Ut(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return o&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=o?s:this._defaultEdgeLabelFn(t,n,r);var c=rp(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Xs(this._preds[n],t),Xs(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?sr(this._isDirected,arguments[0]):Ut(this._isDirected,t,n,r),o=this._edgeObjs[s];return o&&(t=o.v,n=o.w,delete this._edgeLabels[s],delete this._edgeObjs[s],Ws(this._preds[n],t),Ws(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(o=>o.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(o=>o.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Xs(e,t){e[t]?e[t]++:e[t]=1}function Ws(e,t){--e[t]||delete e[t]}function Ut(e,t,n,r){var s=""+t,o=""+n;if(!e&&s>o){var i=s;s=o,o=i}return s+Ys+o+Ys+(r===void 0?tp:r)}function rp(e,t,n,r){var s=""+t,o=""+n;if(!e&&s>o){var i=s;s=o,o=i}var a={v:s,w:o};return r&&(a.name=r),a}function sr(e,t){return Ut(e,t.v,t.w,t.name)}var Ur=np,sp="2.2.4",op={Graph:Ur,version:sp},ip=Ur,ap={write:cp,read:dp};function cp(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:lp(e),edges:up(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function lp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function up(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function dp(e){var t=new ip(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var fp=hp;function hp(e){var t={},n=[],r;function s(o){Object.hasOwn(t,o)||(t[o]=!0,r.push(o),e.successors(o).forEach(s),e.predecessors(o).forEach(s))}return e.nodes().forEach(function(o){r=[],s(o),r.length&&n.push(r)}),n}let mp=class{constructor(){_e(this,"_arr",[]);_e(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,o=s.length;return r[t]=o,s.push({key:t,priority:n}),this._decrease(o),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,o=t;r>1,!(n[s].priority1;function yp(e,t,n,r){return xp(e,String(t),n||gp,r||function(s){return e.outEdges(s)})}function xp(e,t,n,r){var s={},o=new pp,i,a,c=function(u){var l=u.v!==i?u.v:u.w,d=s[l],m=n(u),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+u+" Weight: "+m);f0&&(i=o.removeMin(),a=s[i],a.distance!==Number.POSITIVE_INFINITY);)r(i).forEach(c);return s}var wp=ia,bp=vp;function vp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=wp(e,s,t,n),r},{})}var aa=_p;function _p(e){var t=0,n=[],r={},s=[];function o(i){var a=r[i]={onStack:!0,lowlink:t,index:t++};if(n.push(i),e.successors(i).forEach(function(l){Object.hasOwn(r,l)?r[l].onStack&&(a.lowlink=Math.min(a.lowlink,r[l].index)):(o(l),a.lowlink=Math.min(a.lowlink,r[l].lowlink))}),a.lowlink===a.index){var c=[],u;do u=n.pop(),r[u].onStack=!1,c.push(u);while(i!==u);s.push(c)}}return e.nodes().forEach(function(i){Object.hasOwn(r,i)||o(i)}),s}var Ep=aa,Np=Sp;function Sp(e){return Ep(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var kp=Cp,jp=()=>1;function Cp(e,t,n){return Mp(e,t||jp,n||function(r){return e.outEdges(r)})}function Mp(e,t,n){var r={},s=e.nodes();return s.forEach(function(o){r[o]={},r[o][o]={distance:0},s.forEach(function(i){o!==i&&(r[o][i]={distance:Number.POSITIVE_INFINITY})}),n(o).forEach(function(i){var a=i.v===o?i.w:i.v,c=t(i);r[o][a]={distance:c,predecessor:o}})}),s.forEach(function(o){var i=r[o];s.forEach(function(a){var c=r[a];s.forEach(function(u){var l=c[o],d=i[u],m=c[u],f=l.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?Ip:Tp,o=[],i={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,i,o)}),o}function Ip(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var o=s.pop();o[1]?r.push(o[0]):Object.hasOwn(n,o[0])||(n[o[0]]=!0,s.push([o[0],!0]),da(t(o[0]),i=>s.push([i,!1])))}}function Tp(e,t,n,r){for(var s=[e];s.length>0;){var o=s.pop();Object.hasOwn(n,o)||(n[o]=!0,r.push(o),da(t(o),i=>s.push(i)))}}function da(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var Op=ua,Lp=Dp;function Dp(e,t){return Op(e,t,"post")}var Pp=ua,zp=Hp;function Hp(e,t){return Pp(e,t,"pre")}var Fp=Ur,Vp=oa,Bp=Gp;function Gp(e,t){var n=new Fp,r={},s=new Vp,o;function i(c){var u=c.v===o?c.w:c.v,l=s.priority(u);if(l!==void 0){var d=t(c);d0;){if(o=s.removeMin(),Object.hasOwn(r,o))n.setEdge(o,r[o]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(o).forEach(i)}return n}var Yp={components:fp,dijkstra:ia,dijkstraAll:bp,findCycles:Np,floydWarshall:kp,isAcyclic:$p,postorder:Lp,preorder:zp,prim:Bp,tarjan:aa,topsort:la},qs=op,Ue={Graph:qs.Graph,json:ap,alg:Yp,version:qs.version};let Xp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Ks(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Ks(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Wp)),r=r._prev;return"["+t.join(", ")+"]"}};function Ks(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Wp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Up=Xp;let qp=Ue.Graph,Kp=Up;var Zp=Jp;let Qp=()=>1;function Jp(e,t){if(e.nodeCount()<=1)return[];let n=tg(e,t||Qp);return eg(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function eg(e,t,n){let r=[],s=t[t.length-1],o=t[0],i;for(;e.nodeCount();){for(;i=o.dequeue();)or(e,t,n,i);for(;i=s.dequeue();)or(e,t,n,i);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(i=t[a].dequeue(),i){r=r.concat(or(e,t,n,i,!0));break}}}return r}function or(e,t,n,r,s){let o=s?[]:void 0;return e.inEdges(r.v).forEach(i=>{let a=e.edge(i),c=e.node(i.v);s&&o.push({v:i.v,w:i.w}),c.out-=a,Cr(t,n,c)}),e.outEdges(r.v).forEach(i=>{let a=e.edge(i),c=i.w,u=e.node(c);u.in-=a,Cr(t,n,u)}),e.removeNode(r.v),o}function tg(e,t){let n=new qp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,u=t(a),l=c+u;n.setEdge(a.v,a.w,l),s=Math.max(s,n.node(a.v).out+=u),r=Math.max(r,n.node(a.w).in+=u)});let o=ng(s+r+3).map(()=>new Kp),i=r+1;return n.nodes().forEach(a=>{Cr(o,i,n.node(a))}),{graph:n,buckets:o,zeroIdx:i}}function Cr(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function ng(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function sg(e){let t=new fa({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function og(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return qr(e.nodes(),t)}function ig(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return qr(e.nodes(),t)}function ag(e,t){let n=e.x,r=e.y,s=t.x-n,o=t.y-r,i=e.width/2,a=e.height/2;if(!s&&!o)throw new Error("Not possible to find intersection inside of the rectangle");let c,u;return Math.abs(o)*i>Math.abs(s)*a?(o<0&&(a=-a),c=a*s/o,u=a):(s<0&&(i=-i),c=i,u=i*o/s),{x:n+c,y:r+u}}function cg(e){let t=ya(pa(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function lg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Gn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function ug(e){let t=e.nodes().map(i=>e.node(i).rank),n=Gn(Math.min,t),r=[];e.nodes().forEach(i=>{let a=e.node(i).rank-n;r[a]||(r[a]=[]),r[a].push(i)});let s=0,o=e.graph().nodeRankFactor;Array.from(r).forEach((i,a)=>{i===void 0&&a%o!==0?--s:i!==void 0&&s&&i.forEach(c=>e.node(c).rank+=s)})}function dg(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),ha(e,"border",s,t)}function fg(e,t=ma){const n=[];for(let r=0;rma){const n=fg(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function pa(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Gn(Math.max,n)}function hg(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function mg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function pg(e,t){return t()}let gg=0;function ga(e){var t=++gg;return e+(""+t)}function ya(e,t,n=1){t==null&&(t=e,e=0);let r=o=>otr[t]),Object.entries(e).reduce((r,[s,o])=>(r[s]=n(o,s),r),{})}function qr(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let wg=Zp,bg=Ee.uniqueId;var vg={run:_g,undo:Ng};function _g(e){(e.graph().acyclicer==="greedy"?wg(e,n(e)):Eg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,bg("rev"))});function n(r){return s=>r.edge(s).weight}}function Eg(e){let t=[],n={},r={};function s(o){Object.hasOwn(r,o)||(r[o]=!0,n[o]=!0,e.outEdges(o).forEach(i=>{Object.hasOwn(n,i.w)?t.push(i):s(i.w)}),delete n[o])}return e.nodes().forEach(s),t}function Ng(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let Sg=Ee;var kg={run:jg,undo:Mg};function jg(e){e.graph().dummyChains=[],e.edges().forEach(t=>Cg(e,t))}function Cg(e,t){let n=t.v,r=e.node(n).rank,s=t.w,o=e.node(s).rank,i=t.name,a=e.edge(t),c=a.labelRank;if(o===r+1)return;e.removeEdge(t);let u,l,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:$g}=Ee;var Yn={longestPath:Ag,slack:Rg};function Ag(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let o=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var i=$g(Math.min,o);return i===Number.POSITIVE_INFINITY&&(i=0),s.rank=i}e.sources().forEach(n)}function Rg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var Ig=Ue.Graph,On=Yn.slack,xa=Tg;function Tg(e){var t=new Ig({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,o;Og(t,e){var o=s.v,i=r===o?s.w:o;!e.hasNode(i)&&!On(t,s)&&(e.setNode(i,{}),e.setEdge(r,i,{}),n(i))})}return e.nodes().forEach(n),e.nodeCount()}function Lg(e,t){return t.edges().reduce((r,s)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(o=On(t,s)),ot.node(r).rank+=n)}var Pg=xa,Zs=Yn.slack,zg=Yn.longestPath,Hg=Ue.alg.preorder,Fg=Ue.alg.postorder,Vg=Ee.simplify,Bg=St;St.initLowLimValues=Zr;St.initCutValues=Kr;St.calcCutValue=wa;St.leaveEdge=va;St.enterEdge=_a;St.exchangeEdges=Ea;function St(e){e=Vg(e),zg(e);var t=Pg(e);Zr(t),Kr(t,e);for(var n,r;n=va(t);)r=_a(t,e,n),Ea(t,e,n,r)}function Kr(e,t){var n=Fg(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Gg(e,t,r))}function Gg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=wa(e,t,n)}function wa(e,t,n){var r=e.node(n),s=r.parent,o=!0,i=t.edge(n,s),a=0;return i||(o=!1,i=t.edge(s,n)),a=i.weight,t.nodeEdges(n).forEach(c=>{var u=c.v===n,l=u?c.w:c.v;if(l!==s){var d=u===o,m=t.edge(c).weight;if(a+=d?m:-m,Xg(e,n,l)){var f=e.edge(n,l).cutvalue;a+=d?-f:f}}}),a}function Zr(e,t){arguments.length<2&&(t=e.nodes()[0]),ba(e,{},1,t)}function ba(e,t,n,r,s){var o=n,i=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=ba(e,t,n,a,r))}),i.low=o,i.lim=n++,s?i.parent=s:delete i.parent,n}function va(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function _a(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var o=e.node(r),i=e.node(s),a=o,c=!1;o.lim>i.lim&&(a=i,c=!0);var u=t.edges().filter(l=>c===Qs(e,e.node(l.v),a)&&c!==Qs(e,e.node(l.w),a));return u.reduce((l,d)=>Zs(t,d)!t.node(s).parent),r=Hg(e,n);r=r.slice(1),r.forEach(s=>{var o=e.node(s).parent,i=t.edge(s,o),a=!1;i||(i=t.edge(o,s),a=!0),t.node(s).rank=t.node(o).rank+(a?i.minlen:-i.minlen)})}function Xg(e,t,n){return e.hasEdge(t,n)}function Qs(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Wg=Yn,Na=Wg.longestPath,Ug=xa,qg=Bg,Kg=Zg;function Zg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":Js(e);break;case"tight-tree":Jg(e);break;case"longest-path":Qg(e);break;case"none":break;default:Js(e)}}var Qg=Na;function Jg(e){Na(e),Ug(e)}function Js(e){qg(e)}var ey=ty;function ty(e){let t=ry(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,o=ny(e,t,s.v,s.w),i=o.path,a=o.lca,c=0,u=i[c],l=!0;for(;n!==s.w;){if(r=e.node(n),l){for(;(u=i[c])!==a&&e.node(u).maxRanki||a>t[c].lim));for(u=c,c=r;(c=e.parent(c))!==u;)o.push(c);return{path:s.concat(o.reverse()),lca:u}}function ry(e){let t={},n=0;function r(s){let o=n;e.children(s).forEach(r),t[s]={low:o,lim:n++}}return e.children().forEach(r),t}let Ln=Ee;var sy={run:oy,cleanup:cy};function oy(e){let t=Ln.addDummyNode(e,"root",{},"_root"),n=iy(e),r=Object.values(n),s=Ln.applyWithChunking(Math.max,r)-1,o=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=o);let i=ay(e)+1;e.children().forEach(a=>Sa(e,t,o,i,s,n,a)),e.graph().nodeRankFactor=o}function Sa(e,t,n,r,s,o,i){let a=e.children(i);if(!a.length){i!==t&&e.setEdge(t,i,{weight:0,minlen:n});return}let c=Ln.addBorderNode(e,"_bt"),u=Ln.addBorderNode(e,"_bb"),l=e.node(i);e.setParent(c,i),l.borderTop=c,e.setParent(u,i),l.borderBottom=u,a.forEach(d=>{Sa(e,t,n,r,s,o,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,p=m.borderBottom?m.borderBottom:d,x=m.borderTop?r:2*r,v=f!==p?1:s-o[i]+1;e.setEdge(c,f,{weight:x,minlen:v,nestingEdge:!0}),e.setEdge(p,u,{weight:x,minlen:v,nestingEdge:!0})}),e.parent(i)||e.setEdge(t,c,{weight:0,minlen:s+o[i]})}function iy(e){var t={};function n(r,s){var o=e.children(r);o&&o.length&&o.forEach(i=>n(i,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function ay(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function cy(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let ly=Ee;var uy=dy;function dy(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let o=s.minRank,i=s.maxRank+1;oto(e.node(t))),e.edges().forEach(t=>to(e.edge(t)))}function to(e){let t=e.width;e.width=e.height,e.height=t}function py(e){e.nodes().forEach(t=>ir(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ir),Object.hasOwn(n,"y")&&ir(n)})}function ir(e){e.y=-e.y}function gy(e){e.nodes().forEach(t=>ar(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(ar),Object.hasOwn(n,"x")&&ar(n)})}function ar(e){let t=e.x;e.x=e.y,e.y=t}let no=Ee;var yy=xy;function xy(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=no.applyWithChunking(Math.max,r),o=no.range(s+1).map(()=>[]);function i(c){if(t[c])return;t[c]=!0;let u=e.node(c);o[u.rank].push(c),e.successors(c).forEach(i)}return n.sort((c,u)=>e.node(c).rank-e.node(u).rank).forEach(i),o}let wy=Ee.zipObject;var by=vy;function vy(e,t){let n=0;for(let r=1;rl)),s=t.flatMap(u=>e.outEdges(u).map(l=>({pos:r[l.w],weight:e.edge(l).weight})).sort((l,d)=>l.pos-d.pos)),o=1;for(;o{let l=u.pos+o;a[l]+=u.weight;let d=0;for(;l>0;)l%2&&(d+=a[l+1]),l=l-1>>1,a[l]+=u.weight;c+=u.weight*d}),c}var Ey=Ny;function Ny(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((o,i)=>{let a=e.edge(i),c=e.node(i.v);return{sum:o.sum+a.weight*c.order,weight:o.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let Sy=Ee;var ky=jy;function jy(e,t){let n={};e.forEach((s,o)=>{let i=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i:o};s.barycenter!==void 0&&(i.barycenter=s.barycenter,i.weight=s.weight)}),t.edges().forEach(s=>{let o=n[s.v],i=n[s.w];o!==void 0&&i!==void 0&&(i.indegree++,o.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return Cy(r)}function Cy(e){let t=[];function n(s){return o=>{o.merged||(o.barycenter===void 0||s.barycenter===void 0||o.barycenter>=s.barycenter)&&My(s,o)}}function r(s){return o=>{o.in.push(s),--o.indegree===0&&e.push(o)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>Sy.pick(s,["vs","i","barycenter","weight"]))}function My(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let $y=Ee;var Ay=Ry;function Ry(e,t){let n=$y.partition(e,l=>Object.hasOwn(l,"barycenter")),r=n.lhs,s=n.rhs.sort((l,d)=>d.i-l.i),o=[],i=0,a=0,c=0;r.sort(Iy(!!t)),c=ro(o,s,c),r.forEach(l=>{c+=l.vs.length,o.push(l.vs),i+=l.barycenter*l.weight,a+=l.weight,c=ro(o,s,c)});let u={vs:o.flat(!0)};return a&&(u.barycenter=i/a,u.weight=a),u}function ro(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function Iy(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Ty=Ey,Oy=ky,Ly=Ay;var Dy=ja;function ja(e,t,n,r){let s=e.children(t),o=e.node(t),i=o?o.borderLeft:void 0,a=o?o.borderRight:void 0,c={};i&&(s=s.filter(m=>m!==i&&m!==a));let u=Ty(e,s);u.forEach(m=>{if(e.children(m.v).length){let f=ja(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&zy(m,f)}});let l=Oy(u,n);Py(l,c);let d=Ly(l,r);if(i&&(d.vs=[i,d.vs,a].flat(!0),e.predecessors(i).length)){let m=e.node(e.predecessors(i)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function Py(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function zy(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let Hy=Ue.Graph,Fy=Ee;var Vy=By;function By(e,t,n,r){r||(r=e.nodes());let s=Gy(e),o=new Hy({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(i=>e.node(i));return r.forEach(i=>{let a=e.node(i),c=e.parent(i);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(o.setNode(i),o.setParent(i,c||s),e[n](i).forEach(u=>{let l=u.v===i?u.w:u.v,d=o.edge(l,i),m=d!==void 0?d.weight:0;o.setEdge(l,i,{weight:e.edge(u).weight+m})}),Object.hasOwn(a,"minRank")&&o.setNode(i,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),o}function Gy(e){for(var t;e.hasNode(t=Fy.uniqueId("_root")););return t}var Yy=Xy;function Xy(e,t,n){let r={},s;n.forEach(o=>{let i=e.parent(o),a,c;for(;i;){if(a=e.parent(i),a?(c=r[a],r[a]=i):(c=s,s=i),c&&c!==i){t.setEdge(c,i);return}i=a}})}let Wy=yy,Uy=by,qy=Dy,Ky=Vy,Zy=Yy,Qy=Ue.Graph,wn=Ee;var Jy=Ca;function Ca(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,Ca);return}let n=wn.maxRank(e),r=so(e,wn.range(1,n+1),"inEdges"),s=so(e,wn.range(n-1,-1,-1),"outEdges"),o=Wy(e);if(oo(e,o),t&&t.disableOptimalOrderHeuristic)return;let i=Number.POSITIVE_INFINITY,a;for(let c=0,u=0;u<4;++c,++u){e0(c%2?r:s,c%4>=2),o=wn.buildLayerMatrix(e);let l=Uy(e,o);l{r.has(o)||r.set(o,[]),r.get(o).push(i)};for(const o of e.nodes()){const i=e.node(o);if(typeof i.rank=="number"&&s(i.rank,o),typeof i.minRank=="number"&&typeof i.maxRank=="number")for(let a=i.minRank;a<=i.maxRank;a++)a!==i.rank&&s(a,o)}return t.map(function(o){return Ky(e,o,n,r.get(o)||[])})}function e0(e,t){let n=new Qy;e.forEach(function(r){let s=r.graph().root,o=qy(r,s,n,t);o.vs.forEach((i,a)=>r.node(i).order=a),Zy(r,n,o.vs)})}function oo(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let t0=Ue.Graph,rt=Ee;var n0={positionX:h0};function r0(e,t){let n={};function r(s,o){let i=0,a=0,c=s.length,u=o[o.length-1];return o.forEach((l,d)=>{let m=o0(e,l),f=m?e.node(m).order:c;(m||l===u)&&(o.slice(a,d+1).forEach(p=>{e.predecessors(p).forEach(x=>{let v=e.node(x),g=v.order;(g{l=o[d],e.node(l).dummy&&e.predecessors(l).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderu)&&Ma(n,m,l)})})}function s(o,i){let a=-1,c,u=0;return i.forEach((l,d)=>{if(e.node(l).dummy==="border"){let m=e.predecessors(l);m.length&&(c=e.node(m[0]).order,r(i,u,d,a,c),u=d,a=c)}r(i,u,i.length,c,o.length)}),i}return t.length&&t.reduce(s),n}function o0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Ma(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function i0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function a0(e,t,n,r){let s={},o={},i={};return t.forEach(a=>{a.forEach((c,u)=>{s[c]=c,o[c]=c,i[c]=u})}),t.forEach(a=>{let c=-1;a.forEach(u=>{let l=r(u);if(l.length){l=l.sort((m,f)=>i[m]-i[f]);let d=(l.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let p=l[m];o[u]===u&&cMath.max(m,o[f.v]+i.edge(f)),0)}function l(d){let m=i.outEdges(d).reduce((p,x)=>Math.min(p,o[x.w]-i.edge(x)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(o[d]=Math.max(o[d],m))}return c(u,i.predecessors.bind(i)),c(l,i.successors.bind(i)),Object.keys(r).forEach(d=>o[d]=o[n[d]]),o}function l0(e,t,n,r){let s=new t0,o=e.graph(),i=m0(o.nodesep,o.edgesep,r);return t.forEach(a=>{let c;a.forEach(u=>{let l=n[u];if(s.setNode(l),c){var d=n[c],m=s.edge(d,l);s.setEdge(d,l,Math.max(i(e,u,c),m||0))}c=u})}),s}function u0(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let u=p0(e,a)/2;s=Math.max(c+u,s),o=Math.min(c-u,o)});const i=s-o;return i{["l","r"].forEach(i=>{let a=o+i,c=e[a];if(c===t)return;let u=Object.values(c),l=r-rt.applyWithChunking(Math.min,u);i!=="l"&&(l=s-rt.applyWithChunking(Math.max,u)),l&&(e[a]=rt.mapValues(c,d=>d+l))})})}function f0(e,t){return rt.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(o=>o[r]).sort((o,i)=>o-i);return(s[1]+s[2])/2}})}function h0(e){let t=rt.buildLayerMatrix(e),n=Object.assign(r0(e,t),s0(e,t)),r={},s;["u","d"].forEach(i=>{s=i==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(i==="u"?e.predecessors:e.successors).bind(e),u=a0(e,s,n,c),l=c0(e,s,u.root,u.align,a==="r");a==="r"&&(l=rt.mapValues(l,d=>-d)),r[i+a]=l})});let o=u0(e,r);return d0(r,o),f0(r,e.graph().align)}function m0(e,t,n){return(r,s,o)=>{let i=r.node(s),a=r.node(o),c=0,u;if(c+=i.width/2,Object.hasOwn(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":u=-i.width/2;break;case"r":u=i.width/2;break}if(u&&(c+=n?u:-u),u=0,c+=(i.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":u=a.width/2;break;case"r":u=-a.width/2;break}return u&&(c+=n?u:-u),u=0,c}}function p0(e,t){return e.node(t).width}let $a=Ee,g0=n0.positionX;var y0=x0;function x0(e){e=$a.asNonCompoundGraph(e),w0(e),Object.entries(g0(e)).forEach(([t,n])=>e.node(t).x=n)}function w0(e){let t=$a.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const o=s.reduce((i,a)=>{const c=e.node(a).height;return i>c?i:c},0);s.forEach(i=>e.node(i).y=r+o/2),r+=o+n})}let io=vg,ao=kg,b0=Kg,v0=Ee.normalizeRanks,_0=ey,E0=Ee.removeEmptyRanks,co=sy,N0=uy,lo=fy,S0=Jy,k0=y0,Ge=Ee,j0=Ue.Graph;var C0=M0;function M0(e,t){let n=t&&t.debugTiming?Ge.time:Ge.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>z0(e));n(" runLayout",()=>$0(r,n,t)),n(" updateInputGraph",()=>A0(e,r))})}function $0(e,t,n){t(" makeSpaceForEdgeLabels",()=>H0(e)),t(" removeSelfEdges",()=>q0(e)),t(" acyclic",()=>io.run(e)),t(" nestingGraph.run",()=>co.run(e)),t(" rank",()=>b0(Ge.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>F0(e)),t(" removeEmptyRanks",()=>E0(e)),t(" nestingGraph.cleanup",()=>co.cleanup(e)),t(" normalizeRanks",()=>v0(e)),t(" assignRankMinMax",()=>V0(e)),t(" removeEdgeLabelProxies",()=>B0(e)),t(" normalize.run",()=>ao.run(e)),t(" parentDummyChains",()=>_0(e)),t(" addBorderSegments",()=>N0(e)),t(" order",()=>S0(e,n)),t(" insertSelfEdges",()=>K0(e)),t(" adjustCoordinateSystem",()=>lo.adjust(e)),t(" position",()=>k0(e)),t(" positionSelfEdges",()=>Z0(e)),t(" removeBorderNodes",()=>U0(e)),t(" normalize.undo",()=>ao.undo(e)),t(" fixupEdgeLabelCoords",()=>X0(e)),t(" undoCoordinateSystem",()=>lo.undo(e)),t(" translateGraph",()=>G0(e)),t(" assignNodeIntersects",()=>Y0(e)),t(" reversePoints",()=>W0(e)),t(" acyclic.undo",()=>io.undo(e))}function A0(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let R0=["nodesep","edgesep","ranksep","marginx","marginy"],I0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},T0=["acyclicer","ranker","rankdir","align"],O0=["width","height","rank"],uo={width:0,height:0},L0=["minlen","weight","width","height","labeloffset"],D0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},P0=["labelpos"];function z0(e){let t=new j0({multigraph:!0,compound:!0}),n=lr(e.graph());return t.setGraph(Object.assign({},I0,cr(n,R0),Ge.pick(n,T0))),e.nodes().forEach(r=>{let s=lr(e.node(r));const o=cr(s,O0);Object.keys(uo).forEach(i=>{o[i]===void 0&&(o[i]=uo[i])}),t.setNode(r,o),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=lr(e.edge(r));t.setEdge(r,Object.assign({},D0,cr(s,L0),Ge.pick(s,P0)))}),t}function H0(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function F0(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),o={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};Ge.addDummyNode(e,"edge-proxy",o,"_ep")}})}function V0(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function B0(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function G0(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,o=e.graph(),i=o.marginx||0,a=o.marginy||0;function c(u){let l=u.x,d=u.y,m=u.width,f=u.height;t=Math.min(t,l-m/2),n=Math.max(n,l+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(u=>c(e.node(u))),e.edges().forEach(u=>{let l=e.edge(u);Object.hasOwn(l,"x")&&c(l)}),t-=i,r-=a,e.nodes().forEach(u=>{let l=e.node(u);l.x-=t,l.y-=r}),e.edges().forEach(u=>{let l=e.edge(u);l.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(l,"x")&&(l.x-=t),Object.hasOwn(l,"y")&&(l.y-=r)}),o.width=n-t+i,o.height=s-r+a}function Y0(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),o,i;n.points?(o=n.points[0],i=n.points[n.points.length-1]):(n.points=[],o=s,i=r),n.points.unshift(Ge.intersectRect(r,o)),n.points.push(Ge.intersectRect(s,i))})}function X0(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function W0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function U0(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),o=e.node(n.borderLeft[n.borderLeft.length-1]),i=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(i.x-o.x),n.height=Math.abs(s.y-r.y),n.x=o.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function q0(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function K0(e){var t=Ge.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,o)=>{var i=e.node(s);i.order=o+r,(i.selfEdges||[]).forEach(a=>{Ge.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:i.rank,order:o+ ++r,e:a.e,label:a.label},"_se")}),delete i.selfEdges})})}function Z0(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,o=r.y,i=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*i/3,y:o-a},{x:s+5*i/6,y:o-a},{x:s+i,y:o},{x:s+5*i/6,y:o+a},{x:s+2*i/3,y:o+a}],n.label.x=n.x,n.label.y=n.y}})}function cr(e,t){return Ge.mapValues(Ge.pick(e,t),Number)}function lr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Q0=Ee,J0=Ue.Graph;var ex={debugOrdering:tx};function tx(e){let t=Q0.buildLayerMatrix(e),n=new J0({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let o="layer"+s;n.setNode(o,{rank:"same"}),r.reduce((i,a)=>(n.setEdge(i,a,{style:"invis"}),a))}),n}var nx="1.1.8",rx={graphlib:Ue,layout:C0,debug:ex,util:{time:Ee.time,notime:Ee.notime},version:nx};const fo=Co(rx),Qe=264,sx=44,ox=26,ix=14;function pt(e){const t=Math.max(e.attributes.length,1);return sx+t*ox+ix}const ax=40;function ur(e,t,n,r="auto",s,o="LR"){const i=cx(n,s);return r==="grid"?go(e,n,i):r==="clustered"?po(e,t,n,i,o):r==="hierarchical"||e.length<=ax?ho(e,t,n,o):new Set(e.map(c=>i(c.id)).filter(Boolean)).size>1?po(e,t,n,i,o):go(e,n,i)}function cx(e,t){return n=>{var r,s,o;if(t){const i=t.get(n);if(i)return i.name}return((o=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:o.name)??""}}function Aa(e,t,n,r=!1,s="LR"){const o=new fo.graphlib.Graph;o.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),o.setDefaultEdgeLabel(()=>({}));const i=new Set(e.map(l=>l.id));for(const l of e){const d=n.get(l.id);o.setNode(l.id,{width:Qe,height:d?pt(d):120})}for(const l of t)i.has(l.source)&&i.has(l.target)&&o.setEdge(l.source,l.target,{minlen:1,weight:2});fo.layout(o);let a=0,c=0;return{nodes:e.map(l=>{const d=o.node(l.id),m=n.get(l.id),f=m?pt(m):120,p=d.x-Qe/2,x=d.y-f/2;return a=Math.max(a,p+Qe),c=Math.max(c,x+f),{...l,position:{x:p,y:x}}}),width:a,height:c}}function ho(e,t,n,r="LR"){return Aa(e,t,n,!1,r).nodes}function lx(e,t){const n=a=>{const c=t.get(a);return c?pt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let o=0,i=0;for(let a=0;a{const d=l*(Qe+Ra);s.push({...u,position:{x:d,y:o}}),i=Math.max(i,d+Qe)}),o+=Math.max(...c.map(u=>n(u.id)))+Ia}return{nodes:s,width:i,height:o}}const mo=120;function po(e,t,n,r,s="LR"){const o=new Map;for(const m of e){const f=r(m.id);(o.get(f)??o.set(f,[]).get(f)).push(m)}const a=[...o.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=o.get(m),p=new Set(f.map(E=>E.id));let x=0;for(const E of t)p.has(E.source)&&p.has(E.target)&&x++;const g=f.length<=8&&x>=f.length-1?Aa(f,t,n,!0,s):lx(f,n);return{name:m,...g}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),u=[];let l=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const Ra=40,Ia=40;function go(e,t,n){const r=u=>{const l=t.get(u);return l?pt(l):120},s=[...e].sort((u,l)=>{var x,v;const d=n(u.id),m=n(l.id);if(d!==m)return d.localeCompare(m);const f=((x=t.get(u.id))==null?void 0:x.name)??u.id,p=((v=t.get(l.id))==null?void 0:v.name)??l.id;return f.localeCompare(p)}),o=Math.max(1,Math.round(Math.sqrt(s.length))),i=Array.from({length:o},(u,l)=>l*(Qe+Ra)),a=new Map;let c=0;for(let u=0;ua.set(m.id,{x:i[f],y:c}));const d=Math.max(...l.map(m=>r(m.id)));c+=d+Ia}return e.map(u=>({...u,position:a.get(u.id)??u.position}))}function ln({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const ux=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],Ta=["industry","core","domain","specialised"];function dx({entity:e,exec:t,onClose:n}){var b,$;const[r,s]=w.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[o,i]=w.useState([]),[a,c]=w.useState(null),[u,l]=w.useState(null),[d,m]=w.useState("skos:exactMatch"),[f,p]=w.useState((($=e.conceptual)==null?void 0:$.ontology_layer)??"core"),[x,v]=w.useState([]),[g,E]=w.useState("");w.useEffect(()=>{sa().then(j=>v(j.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return i([]);ra(r,g||void 0).then(_=>{i(_.results),c(_.loaded_terms)}).catch(()=>i([]))},200);return()=>clearTimeout(j)},[r,g]);const M=()=>{u&&t("set_alignment",{id:e.id,aligns_to:u.prefixed,alignment:d,layer:f,resolved_via:u.source}).then(n)};return h.jsxs(ln,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[x.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(g===""?" active":""),onClick:()=>E(""),children:"all sources"}),x.map(j=>h.jsx("button",{className:"src-chip"+(g===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:g?`Search within ${g}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&x.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[o.map(j=>h.jsxs("button",{className:"term-card"+((u==null?void 0:u.iri)===j.iri?" picked":""),onClick:()=>l(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&o.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:ux.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>p(j.target.value),children:Ta.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!u,onClick:M,children:["Align",u?` to ${u.label}`:""]})]})]})}function fx({entity:e,doc:t,exec:n,onClose:r}){var b,$,j;const[s,o]=w.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[i,a]=w.useState((($=e.term_map)==null?void 0:$.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),l=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=l.length===0&&d(i),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:i.trim()||null}).then(r)},p=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",x=t.project.kg_base_iri||`urn:${p}:`,v=(j=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:j.members.map(_=>{var R;return(R=e.attributes.find(N=>N.id===_))==null?void 0:R.name}).filter(Boolean),g=v&&v.length?`${x}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=i.trim()||`${x}${e.id}`,M=s.trim()||g;return h.jsxs(ln,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:i,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(i)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>o(_.target.value)}),l.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",l.length>1?"s":"",": ",l.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",M]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function hx({doc:e,exec:t,onClose:n,onCreated:r}){const[s,o]=w.useState(""),[i,a]=w.useState(""),[c,u]=w.useState(""),[l,d]=w.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:i||null,subject_area:c||null,layer:l||null}).then(f=>{const p=f==null?void 0:f.created_id;n(),p&&r(p)})};return h.jsxs(ln,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>o(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:i,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>u(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:l,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),Ta.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const Oa=["many_to_one","one_to_many","one_to_one","many_to_many"];function mx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:o,onClose:i}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),u=w.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[l,d]=w.useState(r??""),[m,f]=w.useState(s??(u==null?void 0:u.id)??""),[p,x]=w.useState("many_to_one"),[v,g]=w.useState("mandatory");if(!a||!c)return null;const E=l==="__new__",M=()=>o("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:l||null,to_attribute:m||null,create_from_fk:E,cardinality:p,optionality:v}).then(i);return h.jsxs(ln,{title:`${a.name} → ${c.name}`,onClose:i,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:p,onChange:b=>x(b.target.value),children:Oa.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:l,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",u?` "${u.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>g(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:M,children:"Create relationship"})})]})}function px({rel:e,doc:t,exec:n,onClose:r}){const s=g=>{var E;return((E=t.entities.find(M=>M.id===g))==null?void 0:E.name)??"?"},[o,i]=w.useState(e.name),[a,c]=w.useState(e.cardinality),[u,l]=w.useState(e.optionality),[d,m]=w.useState(e.identifying),[f,p]=w.useState(!1),x=async()=>{o.trim()&&o.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:o.trim()}),(a!==e.cardinality||u!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:u,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(ln,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:o,onChange:g=>i(g.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:g=>c(g.target.value),children:Oa.map(g=>h.jsx("option",{children:g},g))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:u,onChange:g=>l(g.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:g=>m(g.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>p(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:x,children:"Save"})]})]})}const yo=10,gx=6,At=24;function yx(e,t){return t?e:Math.round(e/yo)*yo}function xx(e,t,n){const r=[...t];for(const i of n)r.push(i.left-At,i.right+At);let s=e,o=gx;for(const i of r){const a=Math.abs(i-e);at.left&&ei.left&&no.left&&n=i.right?(l.push({x:n,y:t.y},{x:i.right,y:t.y}),m={ox:1,oy:0}):(l.push({x:n,y:t.y},{x:i.left,y:t.y}),m={ox:-1,oy:0});return{path:Ex(l),sourceOut:d,targetOut:m}}const ut=8;function Sx(e,t,n){const r=Math.abs(e-n.left),s=Math.abs(e-n.right),o=Math.abs(t-n.top),i=Math.abs(t-n.bottom),a=Math.min(r,s,o,i),c=(u,l,d)=>Math.min(Math.max(u,l),d);return a===r?{side:"left",x:n.left,y:c(t,n.top+ut,n.bottom-ut)}:a===s?{side:"right",x:n.right,y:c(t,n.top+ut,n.bottom-ut)}:a===o?{side:"top",x:c(e,n.left+ut,n.right-ut),y:n.top}:{side:"bottom",x:c(e,n.left+ut,n.right-ut),y:n.bottom}}function wo(e,t){const n=(r,s,o)=>Math.min(Math.max(r,s),o);switch(e.side){case"left":return{x:t.left,y:n(e.y,t.top,t.bottom),out:{ox:-1,oy:0}};case"right":return{x:t.right,y:n(e.y,t.top,t.bottom),out:{ox:1,oy:0}};case"top":return{x:n(e.x??(t.left+t.right)/2,t.left,t.right),y:t.top,out:{ox:0,oy:-1}};default:return{x:n(e.x??(t.left+t.right)/2,t.left,t.right),y:t.bottom,out:{ox:0,oy:1}}}}const dr=3,kx=w.memo(function({id:t,source:n,target:r,sourceX:s,sourceY:o,targetX:i,targetY:a,sourcePosition:c,targetPosition:u,data:l,selected:d}){const{screenToFlowPosition:m}=cn(),f=he(re=>re.transform[2]),p=he(re=>vo(re.nodeInternals.get(n)),bo),x=he(re=>vo(re.nodeInternals.get(r)),bo),[v,g]=w.useState(null),[E,M]=w.useState(null),b=w.useRef(!1),$=w.useRef(0),j=l==null?void 0:l.onRouteChange,_=!!j,R=v??(l==null?void 0:l.routeX),N=p??(l==null?void 0:l.sourceCard),I=x??(l==null?void 0:l.targetCard),L=(E==null?void 0:E.end)==="source"?E.a:l==null?void 0:l.sourceAnchor,V=(E==null?void 0:E.end)==="target"?E.a:l==null?void 0:l.targetAnchor,F=L&&N?wo(L,N):{x:s,y:o,out:null},y=V&&I?wo(V,I):{x:i,y:a,out:null},C=F.x,S=F.y,O=y.x,D=y.y,k=(L==null?void 0:L.side)==="right"?K.Right:(L==null?void 0:L.side)==="left"?K.Left:c,T=(V==null?void 0:V.side)==="right"?K.Right:(V==null?void 0:V.side)==="left"?K.Left:u,[P,z,U]=Rn({sourceX:C,sourceY:S,sourcePosition:k,targetX:O,targetY:D,targetPosition:T,borderRadius:10,...R!=null?{centerX:R}:{}}),X=N,Z=I,J=R!=null&&X&&Z?Nx({x:C,y:S},{y:D},R,k===K.Left?-1:1,T===K.Left?-1:1,X,Z):null,se=J?J.path:P,ee=l==null?void 0:l.relationship,oe=(l==null?void 0:l.dimmed)??!1,ce=(ee==null?void 0:ee.cardinality)??"many_to_one",we=(ee==null?void 0:ee.optionality)==="optional",ye=(ee==null?void 0:ee.identifying)??!1,me=ce==="many_to_one"||ce==="many_to_many",pe=ce==="one_to_many"||ce==="many_to_many",ge="rel-edge"+(d?" selected":"")+(oe?" dimmed":""),Ne=((l==null?void 0:l.memberCount)??0)>1,ae=l==null?void 0:l.onHoverEdge,q=R??z,xe=U,Te=q,ze=xe,qe=J?J.sourceOut:F.out??{ox:k===K.Left?-1:1,oy:0},ke=J?J.targetOut:y.out??{ox:T===K.Left?-1:1,oy:0},Me={x:C,y:S},Oe=J&&Z?ke.oy!==0?{x:R,y:ke.oy<0?Z.top:Z.bottom}:{x:ke.ox>0?Z.right:Z.left,y:D}:{x:O,y:D},H=w.useCallback(re=>j&&ee&&j(ee.id,re),[j,ee]),Y=w.useCallback(re=>{var $e,Ie;if(!_||re.button!==0)return;re.stopPropagation(),(Ie=($e=re.target).setPointerCapture)==null||Ie.call($e,re.pointerId),b.current=!0,$.current=0;const le=m({x:re.clientX,y:re.clientY}).x;let ne=0,de=R??q;const je=He=>{const Ae=m({x:He.clientX,y:He.clientY});$.current=Math.max($.current,Math.abs(Ae.x-le)),de=bx(Ae.x,{shift:He.shiftKey,source:(l==null?void 0:l.sourceCard)??{left:s,right:s},target:(l==null?void 0:l.targetCard)??{left:i,right:i}}),ne||(ne=requestAnimationFrame(()=>{ne=0,g(de)}))},Le=()=>{window.removeEventListener("pointermove",je),window.removeEventListener("pointerup",Le),ne&&cancelAnimationFrame(ne),b.current=!1,g(null),$.current>=dr&&H(de)};window.addEventListener("pointermove",je),window.addEventListener("pointerup",Le)},[_,m,R,q,l,s,i,H]),B=w.useCallback(re=>{$.current>=dr&&(re.stopPropagation(),$.current=0)},[]),te=w.useCallback(re=>{_&&(re.stopPropagation(),H(null))},[_,H]),G=l==null?void 0:l.onAnchorChange,W=w.useCallback(re=>Q=>{var Ie,He;const le=re==="source"?N:I;if(!G||!ee||!le||Q.button!==0)return;Q.stopPropagation(),(He=(Ie=Q.target).setPointerCapture)==null||He.call(Ie,Q.pointerId),$.current=0;const ne=m({x:Q.clientX,y:Q.clientY});let de=0,je=null;const Le=Ae=>{const Ke=m({x:Ae.clientX,y:Ae.clientY});$.current=Math.max($.current,Math.hypot(Ke.x-ne.x,Ke.y-ne.y)),je=Sx(Ke.x,Ke.y,le),de||(de=requestAnimationFrame(()=>{de=0,M({end:re,a:je})}))},$e=()=>{window.removeEventListener("pointermove",Le),window.removeEventListener("pointerup",$e),de&&cancelAnimationFrame(de),M(null),$.current>=dr&&je&&G(ee.id,re,je)};window.addEventListener("pointermove",Le),window.addEventListener("pointerup",$e)},[G,ee,N,I,m]),ie=w.useCallback(re=>Q=>{!G||!ee||(Q.stopPropagation(),G(ee.id,re,null))},[G,ee]);return h.jsxs("g",{className:ge,onMouseEnter:ae?()=>ae(ee.id):void 0,onMouseLeave:ae?()=>ae(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:se,fill:"none",strokeDasharray:ye?void 0:"6 4"}),h.jsx("path",{d:se,fill:"none",strokeWidth:16/f,stroke:"transparent"}),h.jsx(Eo,{x:Me.x,y:Me.y,out:qe,many:me,optional:we}),h.jsx(Eo,{x:Oe.x,y:Oe.y,out:ke,many:pe,optional:!1}),!!G&&((l==null?void 0:l.hovered)||d||E!=null)&&h.jsxs(h.Fragment,{children:[h.jsx(_o,{x:Me.x,y:Me.y,zoom:f,onPointerDown:W("source"),onDoubleClick:ie("source")}),h.jsx(_o,{x:Oe.x,y:Oe.y,zoom:f,onPointerDown:W("target"),onDoubleClick:ie("target")})]}),_&&((l==null?void 0:l.hovered)||d||v!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:Y,onClickCapture:B,onDoubleClick:te,children:[h.jsx("rect",{x:q-20/f,y:Math.min(S,D),width:40/f,height:Math.max(Math.abs(D-S),24/f),fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:q-5.5/f,y:xe-11/f,width:11/f,height:22/f,rx:5/f,strokeWidth:1.5/f}),h.jsx("circle",{className:"rel-grip-dot",cx:q,cy:xe-4.5/f,r:1.1/f}),h.jsx("circle",{className:"rel-grip-dot",cx:q,cy:xe,r:1.1/f}),h.jsx("circle",{className:"rel-grip-dot",cx:q,cy:xe+4.5/f,r:1.1/f})]}),(d||Ne)&&ee&&h.jsxs("text",{className:"rel-label",x:Te,y:ze-8,children:[d?ee.verb_phrase||ee.name:"",Ne?`${d?" ":""}(${l.memberCount})`:""]})]})});function bo(e,t){return e===t?!0:!e||!t?!1:e.left===t.left&&e.right===t.right&&e.top===t.top&&e.bottom===t.bottom}function vo(e){if(!(e!=null&&e.positionAbsolute)||e.width==null||e.height==null)return null;const{x:t,y:n}=e.positionAbsolute;return{left:t,right:t+e.width,top:n,bottom:n+e.height}}function _o({x:e,y:t,zoom:n,onPointerDown:r,onDoubleClick:s}){return h.jsxs("g",{className:"rel-endpoint",style:{cursor:"move"},onPointerDown:r,onDoubleClick:s,children:[h.jsx("circle",{cx:e,cy:t,r:10/n,fill:"transparent"}),h.jsx("circle",{className:"rel-endpoint-dot",cx:e,cy:t,r:3.5/n,strokeWidth:1.5/n})]})}function Eo({x:e,y:t,out:n,many:r,optional:s}){const{ox:a,oy:c}=n,u=-c,l=a,d=p=>({x:e+a*p,y:t+c*p}),m=(p,x)=>({x:e+a*p+u*x,y:t+c*p+l*x}),f=[];if(r){const p=d(12),x=m(0,-7),v=d(0),g=m(0,7);f.push(h.jsx("path",{className:"rel-glyph",d:`M ${p.x} ${p.y} L ${x.x} ${x.y} M ${p.x} ${p.y} L ${v.x} ${v.y} M ${p.x} ${p.y} L ${g.x} ${g.y}`,fill:"none"},"foot"))}else{const p=m(9,-7),x=m(9,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:x.x,y2:x.y},"one"))}if(s){const p=d(18);f.push(h.jsx("circle",{className:"rel-glyph ring",cx:p.x,cy:p.y,r:4},"opt"))}else{const p=m(17,-7),x=m(17,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:x.x,y2:x.y},"mand"))}return h.jsx(h.Fragment,{children:f})}const jx={entity:Gm},Cx={relationship:kx},No=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],So="#8a7d6a";function ko(e){return{side:e.side,y:Math.round(e.y),...e.x!=null?{x:Math.round(e.x)}:{}}}function Mx(e,t,n){const s=Qe;let{x:o,y:i}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const u of n)ou.x&&iu.y&&(i=u.y+u.h+16,a=!0)}return{x:o,y:i}}function $x(e,t){const n=(o,i)=>{var a;return!!i&&!!((a=t.get(o))!=null&&a.attributes.some(c=>c.id===i))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Xr,targetHandle:n(e.to.entity,s)?s:Wr}}function iw({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:o="",showTypes:i=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:u,activeAreas:l,onError:d,handleRef:m,layoutStore:f}){const{fitView:p,fitBounds:x,getNodes:v}=cn(),[g,E]=w.useState([]),[M,b]=w.useState([]),$=w.useRef(!1),j=w.useMemo(()=>{const H=l&&l.size>0?[...l].sort():null;return H?"sa:"+H.join("+"):"__all__"},[l]),_=w.useRef(null),[R,N]=w.useState(0),I=w.useRef(new Map),L=w.useRef(null);w.useEffect(()=>{if(!f){_.current=null;return}const H=I.current.get(j);if(H){_.current=H,$.current=!1,N(B=>B+1);return}let Y=!1;return f.load(j).then(B=>{Y||(I.current.set(j,B),_.current=B,$.current=!1,N(te=>te+1))}),()=>{Y=!0}},[f,j]);const[V,F]=w.useState(null),[y,C]=w.useState(null),[S,O]=w.useState(!1),[D,k]=w.useState(null),[T,P]=w.useState(null),[z,U]=w.useState(null),[X,Z]=w.useState(null),J=w.useRef({}),se=!t.canEdit,ee=w.useRef(null),oe=w.useCallback(()=>{f&&(ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{const H={};for(const te of v())te.hidden||(H[te.id]={x:Math.round(te.position.x),y:Math.round(te.position.y)});const Y={};for(const[te,G]of Object.entries(J.current)){const W={};G.routeX!=null&&(W.routeX=Math.round(G.routeX)),G.sourceAnchor&&(W.sourceAnchor=ko(G.sourceAnchor)),G.targetAnchor&&(W.targetAnchor=ko(G.targetAnchor)),(W.routeX!=null||W.sourceAnchor||W.targetAnchor)&&(Y[te]=W)}const B={nodes:H,edges:Y};I.current.set(j,B),_.current=B,f.save(j,B)},800))},[f,v,j]),ce=w.useCallback((H,Y)=>{const B=J.current[H]??{};Y==null?delete B.routeX:B.routeX=Y,J.current[H]=B,b(te=>te.map(G=>G.id===H?{...G,data:{...G.data,routeX:Y??void 0}}:G)),oe()},[oe]),we=w.useCallback((H,Y,B)=>{const te=J.current[H]??{},G=Y==="source"?"sourceAnchor":"targetAnchor";B==null?delete te[G]:te[G]=B,J.current[H]=te,b(W=>W.map(ie=>ie.id===H?{...ie,data:{...ie.data,[G]:B??void 0}}:ie)),oe()},[oe]),ye=w.useMemo(()=>{const H=new Map;return e.subject_areas.forEach((Y,B)=>H.set(Y.id,No[B%No.length])),H},[e]),me=w.useMemo(()=>{const H=new Map;return e.entities.forEach(Y=>H.set(Y.id,Y)),H},[e]),pe=w.useMemo(()=>{const H=new Map,Y=new Map;return e.subject_areas.forEach(B=>{(B.members??[]).forEach(te=>Y.set(te,{id:B.id,name:B.name}))}),e.entities.forEach(B=>{var ie,re;const te=(ie=B.conceptual)!=null&&ie.id?Y.get(B.conceptual.id):void 0,G=(re=B.conceptual)==null?void 0:re.subject_area,W=te??(G?{id:G.id,name:G.name??G.id}:void 0);W&&H.set(B.id,W)}),H},[e]),ge=w.useCallback(H=>{var B;if(!l||l.size===0)return!1;const Y=(B=pe.get(H))==null?void 0:B.id;return!(Y&&l.has(Y))},[l,pe]),Ne=w.useMemo(()=>{const H=new Map,Y=(B,te)=>{if(!te.length)return;const G=H.get(B)??new Set;te.forEach(W=>G.add(W)),H.set(B,G)};for(const B of e.relationships)Y(B.from.entity,B.from.attributes),Y(B.to.entity,B.to.attributes);return H},[e]);w.useEffect(()=>{var re;const H=o.trim().toLowerCase(),Y=new Set;if(H)for(const Q of e.entities)(Q.name.toLowerCase()+" "+(((re=Q.conceptual)==null?void 0:re.name.toLowerCase())??"")+" "+Q.attributes.map(ne=>ne.name.toLowerCase()).join(" ")).includes(H)&&Y.add(Q.id);const B=new Set;if(r){B.add(r);for(const Q of e.relationships)Q.from.entity===r&&B.add(Q.to.entity),Q.to.entity===r&&B.add(Q.from.entity)}const te=e.entities.map(Q=>{const le=H!==""&&!Y.has(Q.id),ne=r!==null&&!B.has(Q.id);return{id:Q.id,type:"entity",position:{x:0,y:0},hidden:ge(Q.id),data:{entity:Q,color:(()=>{const de=pe.get(Q.id);return de?ye.get(de.id)??So:So})(),dimmed:le||ne,highlighted:H!==""&&Y.has(Q.id),showTypes:i,collapseDetail:a,expanded:(c==null?void 0:c.has(Q.id))??!1,onToggleExpand:u,endpointAttrs:Ne.get(Q.id),highlightAttrs:void 0,onHoverAttr:U}}}),G=e.relationships.filter(Q=>me.has(Q.from.entity)&&me.has(Q.to.entity)).map(Q=>{const{sourceHandle:le,targetHandle:ne}=$x(Q,me),de=r!==null&&Q.from.entity!==r&&Q.to.entity!==r;return{id:Q.id,source:Q.from.entity,target:Q.to.entity,sourceHandle:le,targetHandle:ne,type:"relationship",data:{relationship:Q,dimmed:de,memberCount:Math.max(Q.from.attributes.length,Q.to.attributes.length),onHoverEdge:Z}}}),W=_.current;if(J.current={},W)for(const[Q,le]of Object.entries(W.edges))J.current[Q]={...le.routeX!=null?{routeX:le.routeX}:{},...le.sourceAnchor?{sourceAnchor:le.sourceAnchor}:{},...le.targetAnchor?{targetAnchor:le.targetAnchor}:{}};const ie=Q=>{const le=new Map;for(const ne of Q)le.set(ne.id,{left:ne.position.x,right:ne.position.x+Qe,top:ne.position.y,bottom:ne.position.y+pt(ne.data.entity)});b(G.map(ne=>{const de=J.current[ne.id]??{};return{...ne,data:{...ne.data,routeX:de.routeX,sourceAnchor:de.sourceAnchor,targetAnchor:de.targetAnchor,onRouteChange:f?ce:void 0,onAnchorChange:f?we:void 0,sourceCard:le.get(ne.source),targetCard:le.get(ne.target)}}}))};E(Q=>{const le=new Map(Q.map(fe=>[fe.id,fe.position])),ne=te.every(fe=>le.has(fe.id)),de=((l==null?void 0:l.size)??0)>0;if($.current&&ne&&Q.length>=te.length&&!de){const fe=te.map(et=>({...et,position:le.get(et.id)??et.position}));return ie(fe),fe}const je=de?te.filter(fe=>!fe.hidden):te,Le=ur(je,G,me,"auto",pe),$e=new Map(Le.map(fe=>[fe.id,fe.position])),Ie=(W==null?void 0:W.nodes)??{},He=Object.keys(Ie).length>0,Ae=[],Ke=te.map(fe=>{const et=Ie[fe.id];if(et){const zt={x:et.x,y:et.y};return Ae.push({x:zt.x,y:zt.y,w:Qe,h:pt(fe.data.entity)}),{...fe,position:zt}}return $e.has(fe.id)?{...fe,position:$e.get(fe.id)}:le.has(fe.id)&&$.current?{...fe,position:le.get(fe.id)}:fe});if(He)for(const fe of Ke)Ie[fe.id]||fe.hidden||(fe.position=Mx(fe.position,pt(fe.data.entity),Ae),Ae.push({x:fe.position.x,y:fe.position.y,w:Qe,h:pt(fe.data.entity)}));return $.current=!0,He||requestAnimationFrame(()=>p({padding:.15,duration:300})),ie(Ke),Ke})},[e,o,r,i,a,c,u,ye,me,pe,ge,l,Ne,p,f,ce,we,R]);const ae=w.useMemo(()=>{const H=new Set,Y=new Set,B=new Map,te=(G,W)=>{if(!W.length)return;const ie=B.get(G)??new Set;W.forEach(re=>ie.add(re)),B.set(G,ie)};if(z)for(const G of e.relationships)(G.from.attributes.includes(z)||G.to.attributes.includes(z))&&(H.add(G.id),Y.add(G.from.entity),Y.add(G.to.entity),te(G.from.entity,G.from.attributes),te(G.to.entity,G.to.attributes));if(X){const G=e.relationships.find(W=>W.id===X);G&&(te(G.from.entity,G.from.attributes),te(G.to.entity,G.to.attributes))}return{active:z!==null,relsForAttr:H,entsForAttr:Y,hitAttrsByEntity:B}},[e,z,X]);w.useEffect(()=>{var te;const H=o.trim().toLowerCase(),Y=new Set;if(H)for(const G of e.entities)(G.name.toLowerCase()+" "+(((te=G.conceptual)==null?void 0:te.name.toLowerCase())??"")+" "+G.attributes.map(ie=>ie.name.toLowerCase()).join(" ")).includes(H)&&Y.add(G.id);const B=new Set;if(r){B.add(r);for(const G of e.relationships)G.from.entity===r&&B.add(G.to.entity),G.to.entity===r&&B.add(G.from.entity)}E(G=>G.map(W=>{const ie=H!==""&&!Y.has(W.id),re=r!==null&&!B.has(W.id),Q=ae.active&&!ae.entsForAttr.has(W.id),le=ie||re||Q,ne=H!==""&&Y.has(W.id)||ae.active&&ae.entsForAttr.has(W.id),de=ae.hitAttrsByEntity.get(W.id);return W.data.dimmed===le&&W.data.highlighted===ne&&W.data.highlightAttrs===de?W:{...W,data:{...W.data,dimmed:le,highlighted:ne,highlightAttrs:de}}})),b(G=>G.map(W=>{var Le,$e,Ie;const ie=(Le=W.data)==null?void 0:Le.relationship,re=r!==null&&ie!==void 0&&ie.from.entity!==r&&ie.to.entity!==r,Q=ae.active&&!ae.relsForAttr.has(W.id),le=re||Q,ne=X===W.id,de=r!==null&&ie!==void 0&&(ie.from.entity===r||ie.to.entity===r),je=ne||de?1e3:0;return(($e=W.data)==null?void 0:$e.dimmed)===le&&((Ie=W.data)==null?void 0:Ie.hovered)===ne&&W.zIndex===je?W:{...W,zIndex:je,data:{...W.data,dimmed:le,hovered:ne}}}))},[ae,X,o,r,e]),w.useEffect(()=>{var te;const H=o.trim().toLowerCase();if(!H)return;const Y=new Set;for(const G of e.entities)(G.name.toLowerCase()+" "+(((te=G.conceptual)==null?void 0:te.name.toLowerCase())??"")+" "+G.attributes.map(ie=>ie.name.toLowerCase()).join(" ")).includes(H)&&Y.add(G.id);if(!Y.size)return;const B=requestAnimationFrame(()=>{const G=v().filter(ie=>Y.has(ie.id));if(!G.length)return;const W=Lf(G);x(W,{padding:.35,duration:400})});return()=>cancelAnimationFrame(B)},[o,e,v,x]);const q=w.useCallback((H="auto",Y="LR")=>{L.current=Object.fromEntries(v().map(B=>[B.id,{x:B.position.x,y:B.position.y}])),E(B=>ur(B,M,me,H,pe,Y)),requestAnimationFrame(()=>p({padding:.15,duration:300})),oe()},[M,me,pe,p,v,oe]),xe=w.useCallback(()=>{const H=L.current;H&&(E(Y=>Y.map(B=>H[B.id]?{...B,position:H[B.id]}:B)),L.current=null,oe())},[oe]),Te=w.useCallback(()=>{f==null||f.reset(j),I.current.delete(j),_.current=null,J.current={},$.current=!1,b(H=>H.map(Y=>({...Y,data:{...Y.data,routeX:void 0}}))),E(H=>{const Y=ur(H,M,me,"auto",pe);return requestAnimationFrame(()=>p({padding:.15,duration:300})),Y})},[f,j,M,me,pe,p]),ze=w.useCallback(H=>{s(H),E(Y=>(Y.find(te=>te.id===H)&&requestAnimationFrame(()=>p({nodes:[{id:H}],padding:.4,duration:400})),Y))},[p,s]);w.useImperativeHandle(m,()=>({relayout:q,fitView:()=>p({padding:.15,duration:300}),focusEntity:ze,newEntity:()=>O(!0),resetLayout:Te,undoRelayout:xe}),[q,p,ze,Te,xe]);const qe=w.useCallback(H=>{if(se||!H.source||!H.target||H.source===H.target)return;const Y=H.sourceHandle&&H.sourceHandle!==Xr?H.sourceHandle:void 0,B=H.targetHandle&&H.targetHandle!==Wr?H.targetHandle:void 0;k({from:H.source,to:H.target,fromAttr:Y,toAttr:B})},[se]),ke=w.useCallback(async(H,Y)=>{try{return await n(H,Y)}catch(B){throw d==null||d(B instanceof Error?B.message:String(B)),B}},[n,d]),Me=r?me.get(r)??null:null,Oe=e.relationships.find(H=>H.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Zi,{nodes:g,edges:M,nodeTypes:jx,edgeTypes:Cx,onNodeClick:(H,Y)=>s(Y.id),onEdgeDoubleClick:(H,Y)=>!se&&P(Y.id),onPaneClick:()=>{s(null),P(null)},onNodeDragStop:(H,Y)=>{E(B=>B.map(te=>te.id===Y.id?{...te,position:Y.position}:te)),oe()},onConnect:qe,nodesConnectable:!se,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(Cm,{variant:Be.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(pm,{pannable:!0,zoomable:!0,nodeColor:H=>{var Y;return((Y=H.data)==null?void 0:Y.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(_m,{showInteractive:!1})]}),Me&&h.jsx(Xm,{entity:Me,doc:e,caps:t,exec:ke,onClose:()=>s(null),onFocusEntity:ze,onAlign:F,onEditMapping:C}),V&&h.jsx(dx,{entity:V,exec:ke,onClose:()=>F(null)}),y&&h.jsx(fx,{entity:y,doc:e,exec:ke,onClose:()=>C(null)}),S&&h.jsx(hx,{doc:e,exec:ke,onClose:()=>O(!1),onCreated:ze}),D&&h.jsx(mx,{doc:e,fromId:D.from,toId:D.to,initialFromAttr:D.fromAttr,initialToAttr:D.toAttr,exec:ke,onClose:()=>k(null)}),Oe&&h.jsx(px,{rel:Oe,doc:e,exec:ke,onClose:()=>P(null)})]})}function aw({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:o}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(Ax,{}),e==="layers"&&h.jsx(Ix,{refreshKey:r,onFocusEntity:o}),e==="changes"&&h.jsx(Tx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Ox,{readOnly:n})]})}function Ax(){const[e,t]=w.useState(""),[n,r]=w.useState([]),[s,o]=w.useState({loaded:0,vocabs:[]}),[i,a]=w.useState(null),[c,u]=w.useState([]),[l,d]=w.useState("");w.useEffect(()=>{sa().then(f=>u(f.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const f=setTimeout(()=>{ra(e||"a",l||void 0).then(p=>{r(e?p.results:[]),o({loaded:p.loaded_terms,vocabs:p.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,l]);const m=w.useCallback(f=>{Mm(f).then(a).catch(()=>{})},[]);return i?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:i.label}),h.jsx("code",{className:"term-iri",children:i.prefixed}),i.definition&&h.jsx("p",{className:"term-def",children:i.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:i.source})]}),i.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),i.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),i.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),i.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(l===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(l===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:l?`Search within ${l}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const Rx=["industry","core","domain","specialised"];function Ix({refreshKey:e,onFocusEntity:t}){const[n,r]=w.useState(null),[s,o]=w.useState(null);if(w.useEffect(()=>{$m().then(r).catch(()=>{}),Am().then(o).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const i=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),Rx.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var u;return h.jsxs("button",{className:"stack-term"+(i.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((l,d)=>h.jsxs("span",{className:"align-arrow"+(l.resolved?"":" unresolved")+(l.status==="proposed"?" proposed":""),title:l.ref+(l.resolved_via?` (via ${l.resolved_via})`:""),children:["↑ ",l.label,l.status==="proposed"?" ·prop":""]},`${l.ref}-${d}`)),!c.aligned_to&&(((u=c.aligned_refs)==null?void 0:u.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Tx({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=w.useState(null),[o,i]=w.useState(""),[a,c]=w.useState(""),[u,l]=w.useState(!1),d=w.useCallback(()=>{Im().then(s).catch(()=>s(null)),Tm().then(m=>i([m.diff,...m.untracked].filter(Boolean).join(` + */var zn=w,Ec=_c;function Nc(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var Sc=typeof Object.is=="function"?Object.is:Nc,kc=Ec.useSyncExternalStore,jc=zn.useRef,Cc=zn.useEffect,Mc=zn.useMemo,$c=zn.useDebugValue;Ro.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var o=jc(null);if(o.current===null){var i={hasValue:!1,value:null};o.current=i}else i=o.current;o=Mc(function(){function c(f){if(!u){if(u=!0,l=f,f=r(f),s!==void 0&&i.hasValue){var p=i.value;if(s(p,f))return d=p}return d=f}if(p=d,Sc(l,f))return p;var x=r(f);return s!==void 0&&s(p,x)?(l=f,p):(l=f,d=x)}var u=!1,l,d,m=n===void 0?null:n;return[function(){return c(t())},m===null?void 0:function(){return c(m())}]},[t,n,r,s]);var a=kc(e,o[0],o[1]);return Cc(function(){i.hasValue=!0,i.value=a},[a]),$c(a),a};Ao.exports=Ro;var Ac=Ao.exports;const Rc=$o(Ac),Ic={},rs=e=>{let t;const n=new Set,r=(l,d)=>{const m=typeof l=="function"?l(t):l;if(!Object.is(m,t)){const f=t;t=d??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(p=>p(t,f))}},s=()=>t,c={setState:r,getState:s,getInitialState:()=>u,subscribe:l=>(n.add(l),()=>n.delete(l)),destroy:()=>{(Ic?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},u=t=e(r,s,c);return c},Tc=e=>e?rs(e):rs,{useDebugValue:Oc}=A,{useSyncExternalStoreWithSelector:Lc}=Rc,Dc=e=>e;function Oo(e,t=Dc,n){const r=Lc(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Oc(r),r}const ss=(e,t)=>{const n=Tc(e),r=(s,o=t)=>Oo(n,s,o);return Object.assign(r,n),r},Pc=(e,t)=>e?ss(e,t):ss;function Ce(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var zc={value:()=>{}};function Hn(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}_n.prototype=Hn.prototype={constructor:_n,on:function(e,t){var n=this._,r=Hc(e+"",n),s,o=-1,i=r.length;if(arguments.length<2){for(;++o0)for(var n=new Array(s),r=0,s,o;r=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),is.hasOwnProperty(t)?{space:is[t],local:e}:e}function Vc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===mr&&t.documentElement.namespaceURI===mr?t.createElement(e):t.createElementNS(n,e)}}function Bc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Lo(e){var t=Fn(e);return(t.local?Bc:Vc)(t)}function Gc(){}function Ar(e){return e==null?Gc:function(){return this.querySelector(e)}}function Yc(e){typeof e!="function"&&(e=Ar(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s=M&&(M=E+1);!($=v[M])&&++M=0;)(i=r[s])&&(o&&i.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(i,o),o=i);return this}function gl(e){e||(e=yl);function t(d,m){return d&&m?e(d.__data__,m.__data__):!d-!m}for(var n=this._groups,r=n.length,s=new Array(r),o=0;ot?1:e>=t?0:NaN}function xl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function wl(){return Array.from(this)}function bl(){for(var e=this._groups,t=0,n=e.length;t1?this.each((t==null?Al:typeof t=="function"?Il:Rl)(e,t,n??"")):Dt(this.node(),e)}function Dt(e,t){return e.style.getPropertyValue(t)||Fo(e).getComputedStyle(e,null).getPropertyValue(t)}function Ol(e){return function(){delete this[e]}}function Ll(e,t){return function(){this[e]=t}}function Dl(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Pl(e,t){return arguments.length>1?this.each((t==null?Ol:typeof t=="function"?Dl:Ll)(e,t)):this.node()[e]}function Vo(e){return e.trim().split(/^|\s+/)}function Rr(e){return e.classList||new Bo(e)}function Bo(e){this._node=e,this._names=Vo(e.getAttribute("class")||"")}Bo.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Go(e,t){for(var n=Rr(e),r=-1,s=t.length;++r=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function fu(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,o;n()=>e;function pr(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:o,x:i,y:a,dx:c,dy:u,dispatch:l}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:l}})}pr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function _u(e){return!e.ctrlKey&&!e.button}function Eu(){return this.parentNode}function Nu(e,t){return t??{x:e.x,y:e.y}}function Su(){return navigator.maxTouchPoints||"ontouchstart"in this}function ku(){var e=_u,t=Eu,n=Nu,r=Su,s={},o=Hn("start","drag","end"),i=0,a,c,u,l,d=0;function m(b){b.on("mousedown.drag",f).filter(r).on("touchstart.drag",v).on("touchmove.drag",g,vu).on("touchend.drag touchcancel.drag",E).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(b,$){if(!(l||!e.call(this,b,$))){var j=M(this,t.call(this,b,$),b,$,"mouse");j&&(Fe(b.view).on("mousemove.drag",p,Zt).on("mouseup.drag",x,Zt),Uo(b.view),Kn(b),u=!1,a=b.clientX,c=b.clientY,j("start",b))}}function p(b){if(It(b),!u){var $=b.clientX-a,j=b.clientY-c;u=$*$+j*j>d}s.mouse("drag",b)}function x(b){Fe(b.view).on("mousemove.drag mouseup.drag",null),qo(b.view,u),It(b),s.mouse("end",b)}function v(b,$){if(e.call(this,b,$)){var j=b.changedTouches,_=t.call(this,b,$),R=j.length,N,I;for(N=0;N>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?hn(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?hn(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Cu.exec(e))?new De(t[1],t[2],t[3],1):(t=Mu.exec(e))?new De(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=$u.exec(e))?hn(t[1],t[2],t[3],t[4]):(t=Au.exec(e))?hn(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Ru.exec(e))?hs(t[1],t[2]/100,t[3]/100,1):(t=Iu.exec(e))?hs(t[1],t[2]/100,t[3]/100,t[4]):as.hasOwnProperty(e)?us(as[e]):e==="transparent"?new De(NaN,NaN,NaN,0):null}function us(e){return new De(e>>16&255,e>>8&255,e&255,1)}function hn(e,t,n,r){return r<=0&&(e=t=n=NaN),new De(e,t,n,r)}function Lu(e){return e instanceof an||(e=en(e)),e?(e=e.rgb(),new De(e.r,e.g,e.b,e.opacity)):new De}function gr(e,t,n,r){return arguments.length===1?Lu(e):new De(e,t,n,r??1)}function De(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Ir(De,gr,Ko(an,{brighter(e){return e=e==null?jn:Math.pow(jn,e),new De(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Qt:Math.pow(Qt,e),new De(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new De(_t(this.r),_t(this.g),_t(this.b),Cn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:ds,formatHex:ds,formatHex8:Du,formatRgb:fs,toString:fs}));function ds(){return`#${bt(this.r)}${bt(this.g)}${bt(this.b)}`}function Du(){return`#${bt(this.r)}${bt(this.g)}${bt(this.b)}${bt((isNaN(this.opacity)?1:this.opacity)*255)}`}function fs(){const e=Cn(this.opacity);return`${e===1?"rgb(":"rgba("}${_t(this.r)}, ${_t(this.g)}, ${_t(this.b)}${e===1?")":`, ${e})`}`}function Cn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function _t(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function bt(e){return e=_t(e),(e<16?"0":"")+e.toString(16)}function hs(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new We(e,t,n,r)}function Zo(e){if(e instanceof We)return new We(e.h,e.s,e.l,e.opacity);if(e instanceof an||(e=en(e)),!e)return new We;if(e instanceof We)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),o=Math.max(t,n,r),i=NaN,a=o-s,c=(o+s)/2;return a?(t===o?i=(n-r)/a+(n0&&c<1?0:i,new We(i,a,c,e.opacity)}function Pu(e,t,n,r){return arguments.length===1?Zo(e):new We(e,t,n,r??1)}function We(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Ir(We,Pu,Ko(an,{brighter(e){return e=e==null?jn:Math.pow(jn,e),new We(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Qt:Math.pow(Qt,e),new We(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new De(Zn(e>=240?e-240:e+120,s,r),Zn(e,s,r),Zn(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new We(ms(this.h),mn(this.s),mn(this.l),Cn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Cn(this.opacity);return`${e===1?"hsl(":"hsla("}${ms(this.h)}, ${mn(this.s)*100}%, ${mn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ms(e){return e=(e||0)%360,e<0?e+360:e}function mn(e){return Math.max(0,Math.min(1,e||0))}function Zn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Qo=e=>()=>e;function zu(e,t){return function(n){return e+n*t}}function Hu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Fu(e){return(e=+e)==1?Jo:function(t,n){return n-t?Hu(t,n,e):Qo(isNaN(t)?n:t)}}function Jo(e,t){var n=t-e;return n?zu(e,n):Qo(isNaN(e)?t:e)}const ps=function e(t){var n=Fu(t);function r(s,o){var i=n((s=gr(s)).r,(o=gr(o)).r),a=n(s.g,o.g),c=n(s.b,o.b),u=Jo(s.opacity,o.opacity);return function(l){return s.r=i(l),s.g=a(l),s.b=c(l),s.opacity=u(l),s+""}}return r.gamma=e,r}(1);function ft(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var yr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Qn=new RegExp(yr.source,"g");function Vu(e){return function(){return e}}function Bu(e){return function(t){return e(t)+""}}function Gu(e,t){var n=yr.lastIndex=Qn.lastIndex=0,r,s,o,i=-1,a=[],c=[];for(e=e+"",t=t+"";(r=yr.exec(e))&&(s=Qn.exec(t));)(o=s.index)>n&&(o=t.slice(n,o),a[i]?a[i]+=o:a[++i]=o),(r=r[0])===(s=s[0])?a[i]?a[i]+=s:a[++i]=s:(a[++i]=null,c.push({i,x:ft(r,s)})),n=Qn.lastIndex;return n180?l+=360:l-u>180&&(u+=360),m.push({i:d.push(s(d)+"rotate(",null,r)-2,x:ft(u,l)})):l&&d.push(s(d)+"rotate("+l+r)}function a(u,l,d,m){u!==l?m.push({i:d.push(s(d)+"skewX(",null,r)-2,x:ft(u,l)}):l&&d.push(s(d)+"skewX("+l+r)}function c(u,l,d,m,f,p){if(u!==d||l!==m){var x=f.push(s(f)+"scale(",null,",",null,")");p.push({i:x-4,x:ft(u,d)},{i:x-2,x:ft(l,m)})}else(d!==1||m!==1)&&f.push(s(f)+"scale("+d+","+m+")")}return function(u,l){var d=[],m=[];return u=e(u),l=e(l),o(u.translateX,u.translateY,l.translateX,l.translateY,d,m),i(u.rotate,l.rotate,d,m),a(u.skewX,l.skewX,d,m),c(u.scaleX,u.scaleY,l.scaleX,l.scaleY,d,m),u=l=null,function(f){for(var p=-1,x=m.length,v;++p=0&&e._call.call(void 0,t),e=e._next;--Pt}function xs(){Nt=($n=tn.now())+Vn,Pt=Wt=0;try{ed()}finally{Pt=0,nd(),Nt=0}}function td(){var e=tn.now(),t=e-$n;t>ni&&(Vn-=t,$n=e)}function nd(){for(var e,t=Mn,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Mn=n);Ut=e,wr(r)}function wr(e){if(!Pt){Wt&&(Wt=clearTimeout(Wt));var t=e-Nt;t>24?(e<1/0&&(Wt=setTimeout(xs,e-tn.now()-Vn)),Vt&&(Vt=clearInterval(Vt))):(Vt||($n=tn.now(),Vt=setInterval(td,ni)),Pt=1,ri(xs))}}function ws(e,t,n){var r=new An;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var rd=Hn("start","end","cancel","interrupt"),sd=[],oi=0,bs=1,br=2,En=3,vs=4,vr=5,Nn=6;function Bn(e,t,n,r,s,o){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;od(e,n,{name:t,index:r,group:s,on:rd,tween:sd,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:oi})}function Or(e,t){var n=Ue(e,t);if(n.state>oi)throw new Error("too late; already scheduled");return n}function Je(e,t){var n=Ue(e,t);if(n.state>En)throw new Error("too late; already running");return n}function Ue(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function od(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=si(o,0,n.time);function o(u){n.state=bs,n.timer.restart(i,n.delay,n.time),n.delay<=u&&i(u-n.delay)}function i(u){var l,d,m,f;if(n.state!==bs)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===En)return ws(i);f.state===vs?(f.state=Nn,f.timer.stop(),f.on.call("interrupt",e,e.__data__,f.index,f.group),delete r[l]):+lbr&&r.state=0&&(t=t.slice(0,n)),!t||t==="start"})}function Od(e,t,n){var r,s,o=Td(t)?Or:Je;return function(){var i=o(this,e),a=i.on;a!==r&&(s=(r=a).copy()).on(t,n),i.on=s}}function Ld(e,t){var n=this._id;return arguments.length<2?Ue(this.node(),n).on.on(e):this.each(Od(n,e,t))}function Dd(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Pd(){return this.on("end.remove",Dd(this._id))}function zd(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Ar(e));for(var r=this._groups,s=r.length,o=new Array(s),i=0;i()=>e;function df(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function st(e,t,n){this.k=e,this.x=t,this.y=n}st.prototype={constructor:st,scale:function(e){return e===1?this:new st(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new st(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var ot=new st(1,0,0);st.prototype;function Jn(e){e.stopImmediatePropagation()}function Bt(e){e.preventDefault(),e.stopImmediatePropagation()}function ff(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function hf(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function _s(){return this.__zoom||ot}function mf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function pf(){return navigator.maxTouchPoints||"ontouchstart"in this}function gf(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),i>o?(o+i)/2:Math.min(0,o)||Math.max(0,i))}function li(){var e=ff,t=hf,n=gf,r=mf,s=pf,o=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Qu,u=Hn("start","zoom","end"),l,d,m,f=500,p=150,x=0,v=10;function g(y){y.property("__zoom",_s).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",N).on("dblclick.zoom",I).filter(s).on("touchstart.zoom",L).on("touchmove.zoom",B).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(y,C,S,O){var D=y.selection?y.selection():y;D.property("__zoom",_s),y!==D?$(y,C,S,O):D.interrupt().each(function(){j(this,arguments).event(O).start().zoom(null,typeof C=="function"?C.apply(this,arguments):C).end()})},g.scaleBy=function(y,C,S,O){g.scaleTo(y,function(){var D=this.__zoom.k,k=typeof C=="function"?C.apply(this,arguments):C;return D*k},S,O)},g.scaleTo=function(y,C,S,O){g.transform(y,function(){var D=t.apply(this,arguments),k=this.__zoom,T=S==null?b(D):typeof S=="function"?S.apply(this,arguments):S,P=k.invert(T),z=typeof C=="function"?C.apply(this,arguments):C;return n(M(E(k,z),T,P),D,i)},S,O)},g.translateBy=function(y,C,S,O){g.transform(y,function(){return n(this.__zoom.translate(typeof C=="function"?C.apply(this,arguments):C,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),i)},null,O)},g.translateTo=function(y,C,S,O,D){g.transform(y,function(){var k=t.apply(this,arguments),T=this.__zoom,P=O==null?b(k):typeof O=="function"?O.apply(this,arguments):O;return n(ot.translate(P[0],P[1]).scale(T.k).translate(typeof C=="function"?-C.apply(this,arguments):-C,typeof S=="function"?-S.apply(this,arguments):-S),k,i)},O,D)};function E(y,C){return C=Math.max(o[0],Math.min(o[1],C)),C===y.k?y:new st(C,y.x,y.y)}function M(y,C,S){var O=C[0]-S[0]*y.k,D=C[1]-S[1]*y.k;return O===y.x&&D===y.y?y:new st(y.k,O,D)}function b(y){return[(+y[0][0]+ +y[1][0])/2,(+y[0][1]+ +y[1][1])/2]}function $(y,C,S,O){y.on("start.zoom",function(){j(this,arguments).event(O).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(O).end()}).tween("zoom",function(){var D=this,k=arguments,T=j(D,k).event(O),P=t.apply(D,k),z=S==null?b(P):typeof S=="function"?S.apply(D,k):S,U=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),W=D.__zoom,Q=typeof C=="function"?C.apply(D,k):C,te=c(W.invert(z).concat(U/W.k),Q.invert(z).concat(U/Q.k));return function(se){if(se===1)se=Q;else{var J=te(se),ae=U/J[2];se=new st(ae,z[0]-J[0]*ae,z[1]-J[1]*ae)}T.zoom(null,se)}})}function j(y,C,S){return!S&&y.__zooming||new _(y,C)}function _(y,C){this.that=y,this.args=C,this.active=0,this.sourceEvent=null,this.extent=t.apply(y,C),this.taps=0}_.prototype={event:function(y){return y&&(this.sourceEvent=y),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(y,C){return this.mouse&&y!=="mouse"&&(this.mouse[1]=C.invert(this.mouse[0])),this.touch0&&y!=="touch"&&(this.touch0[1]=C.invert(this.touch0[0])),this.touch1&&y!=="touch"&&(this.touch1[1]=C.invert(this.touch1[0])),this.that.__zoom=C,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(y){var C=Fe(this.that).datum();u.call(y,this.that,new df(y,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:u}),C)}};function R(y,...C){if(!e.apply(this,arguments))return;var S=j(this,C).event(y),O=this.__zoom,D=Math.max(o[0],Math.min(o[1],O.k*Math.pow(2,r.apply(this,arguments)))),k=Xe(y);if(S.wheel)(S.mouse[0][0]!==k[0]||S.mouse[0][1]!==k[1])&&(S.mouse[1]=O.invert(S.mouse[0]=k)),clearTimeout(S.wheel);else{if(O.k===D)return;S.mouse=[k,O.invert(k)],Sn(this),S.start()}Bt(y),S.wheel=setTimeout(T,p),S.zoom("mouse",n(M(E(O,D),S.mouse[0],S.mouse[1]),S.extent,i));function T(){S.wheel=null,S.end()}}function N(y,...C){if(m||!e.apply(this,arguments))return;var S=y.currentTarget,O=j(this,C,!0).event(y),D=Fe(y.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",U,!0),k=Xe(y,S),T=y.clientX,P=y.clientY;Uo(y.view),Jn(y),O.mouse=[k,this.__zoom.invert(k)],Sn(this),O.start();function z(W){if(Bt(W),!O.moved){var Q=W.clientX-T,te=W.clientY-P;O.moved=Q*Q+te*te>x}O.event(W).zoom("mouse",n(M(O.that.__zoom,O.mouse[0]=Xe(W,S),O.mouse[1]),O.extent,i))}function U(W){D.on("mousemove.zoom mouseup.zoom",null),qo(W.view,O.moved),Bt(W),O.event(W).end()}}function I(y,...C){if(e.apply(this,arguments)){var S=this.__zoom,O=Xe(y.changedTouches?y.changedTouches[0]:y,this),D=S.invert(O),k=S.k*(y.shiftKey?.5:2),T=n(M(E(S,k),O,D),t.apply(this,C),i);Bt(y),a>0?Fe(this).transition().duration(a).call($,T,O,y):Fe(this).call(g.transform,T,O,y)}}function L(y,...C){if(e.apply(this,arguments)){var S=y.touches,O=S.length,D=j(this,C,y.changedTouches.length===O).event(y),k,T,P,z;for(Jn(y),T=0;T"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},ui=at.error001();function me(e,t){const n=w.useContext(Gn);if(n===null)throw new Error(ui);return Oo(n,e,t)}const ke=()=>{const e=w.useContext(Gn);if(e===null)throw new Error(ui);return w.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},xf=e=>e.userSelectionActive?"none":"all";function Dr({position:e,children:t,className:n,style:r,...s}){const o=me(xf),i=`${e}`.split("-");return A.createElement("div",{className:Me(["react-flow__panel",n,...i]),style:{...r,pointerEvents:o},...s},t)}function wf({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:A.createElement(Dr,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},A.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const bf=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:o={},labelBgPadding:i=[2,4],labelBgBorderRadius:a=2,children:c,className:u,...l})=>{const d=w.useRef(null),[m,f]=w.useState({x:0,y:0,width:0,height:0}),p=Me(["react-flow__edge-textwrapper",u]);return w.useEffect(()=>{if(d.current){const x=d.current.getBBox();f({x:x.x,y:x.y,width:x.width,height:x.height})}},[n]),typeof n>"u"||!n?null:A.createElement("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:p,visibility:m.width?"visible":"hidden",...l},s&&A.createElement("rect",{width:m.width+2*i[0],x:-i[0],y:-i[1],height:m.height+2*i[1],className:"react-flow__edge-textbg",style:o,rx:a,ry:a}),A.createElement("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:d,style:r},n),c)};var vf=w.memo(bf);const Pr=e=>({width:e.offsetWidth,height:e.offsetHeight}),zt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),zr=(e={x:0,y:0},t)=>({x:zt(e.x,t[0][0],t[1][0]),y:zt(e.y,t[0][1],t[1][1])}),Es=(e,t,n)=>en?-zt(Math.abs(e-n),1,50)/50:0,di=(e,t)=>{const n=Es(e.x,35,t.width-35)*20,r=Es(e.y,35,t.height-35)*20;return[n,r]},fi=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},hi=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),nn=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),mi=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),Ns=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),_f=(e,t)=>mi(hi(nn(e),nn(t))),_r=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},Ef=e=>Ve(e.width)&&Ve(e.height)&&Ve(e.x)&&Ve(e.y),Ve=e=>!isNaN(e)&&isFinite(e),we=Symbol.for("internals"),pi=["Enter"," ","Escape"],Nf=(e,t)=>{},Sf=e=>"nativeEvent"in e;function Er(e){var s,o;const t=Sf(e)?e.nativeEvent:e,n=((o=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:o[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const gi=e=>"clientX"in e,yt=(e,t)=>{var o,i;const n=gi(e),r=n?e.clientX:(o=e.touches)==null?void 0:o[0].clientX,s=n?e.clientY:(i=e.touches)==null?void 0:i[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Rn=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},cn=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:d,markerStart:m,interactionWidth:f=20})=>A.createElement(A.Fragment,null,A.createElement("path",{id:e,style:l,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:d,markerStart:m}),f&&A.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}),s&&Ve(n)&&Ve(r)?A.createElement(vf,{x:n,y:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u}):null);cn.displayName="BaseEdge";function Gt(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(o=>o.id===e);s&&n(r,{...s})}}function yi({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,o=n{const[v,g,E]=wi({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:o});return A.createElement(cn,{path:v,labelX:g,labelY:E,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:x})});Hr.displayName="SimpleBezierEdge";const ks={[K.Left]:{x:-1,y:0},[K.Right]:{x:1,y:0},[K.Top]:{x:0,y:-1},[K.Bottom]:{x:0,y:1}},kf=({source:e,sourcePosition:t=K.Bottom,target:n})=>t===K.Left||t===K.Right?e.xMath.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function jf({source:e,sourcePosition:t=K.Bottom,target:n,targetPosition:r=K.Top,center:s,offset:o}){const i=ks[t],a=ks[r],c={x:e.x+i.x*o,y:e.y+i.y*o},u={x:n.x+a.x*o,y:n.y+a.y*o},l=kf({source:c,sourcePosition:t,target:u}),d=l.x!==0?"x":"y",m=l[d];let f=[],p,x;const v={x:0,y:0},g={x:0,y:0},[E,M,b,$]=yi({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(i[d]*a[d]===-1){p=s.x??E,x=s.y??M;const _=[{x:p,y:c.y},{x:p,y:u.y}],R=[{x:c.x,y:x},{x:u.x,y:x}];i[d]===m?f=d==="x"?_:R:f=d==="x"?R:_}else{const _=[{x:c.x,y:u.y}],R=[{x:u.x,y:c.y}];if(d==="x"?f=i.x===m?R:_:f=i.y===m?_:R,t===r){const H=Math.abs(e[d]-n[d]);if(H<=o){const y=Math.min(o-1,o-H);i[d]===m?v[d]=(c[d]>e[d]?-1:1)*y:g[d]=(u[d]>n[d]?-1:1)*y}}if(t!==r){const H=d==="x"?"y":"x",y=i[d]===a[H],C=c[H]>u[H],S=c[H]=B?(p=(N.x+I.x)/2,x=f[0].y):(p=f[0].x,x=(N.y+I.y)/2)}return[[e,{x:c.x+v.x,y:c.y+v.y},...f,{x:u.x+g.x,y:u.y+g.y},n],p,x,b,$]}function Cf(e,t,n,r){const s=Math.min(js(e,t)/2,js(t,n)/2,r),{x:o,y:i}=t;if(e.x===o&&o===n.x||e.y===i&&i===n.y)return`L${o} ${i}`;if(e.y===i){const u=e.x{let M="";return E>0&&E{const[g,E,M]=Tn({sourceX:e,sourceY:t,sourcePosition:d,targetX:n,targetY:r,targetPosition:m,borderRadius:x==null?void 0:x.borderRadius,offset:x==null?void 0:x.offset});return A.createElement(cn,{path:g,labelX:E,labelY:M,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:f,markerStart:p,interactionWidth:v})});Yn.displayName="SmoothStepEdge";const Fr=w.memo(e=>{var t;return A.createElement(Yn,{...e,pathOptions:w.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Fr.displayName="StepEdge";function Mf({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,o,i,a]=yi({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,o,i,a]}const Vr=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:d,markerStart:m,interactionWidth:f})=>{const[p,x,v]=Mf({sourceX:e,sourceY:t,targetX:n,targetY:r});return A.createElement(cn,{path:p,labelX:x,labelY:v,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:u,style:l,markerEnd:d,markerStart:m,interactionWidth:f})});Vr.displayName="StraightEdge";function yn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Cs({pos:e,x1:t,y1:n,x2:r,y2:s,c:o}){switch(e){case K.Left:return[t-yn(t-r,o),n];case K.Right:return[t+yn(r-t,o),n];case K.Top:return[t,n-yn(n-s,o)];case K.Bottom:return[t,n+yn(s-n,o)]}}function bi({sourceX:e,sourceY:t,sourcePosition:n=K.Bottom,targetX:r,targetY:s,targetPosition:o=K.Top,curvature:i=.25}){const[a,c]=Cs({pos:n,x1:e,y1:t,x2:r,y2:s,c:i}),[u,l]=Cs({pos:o,x1:r,y1:s,x2:e,y2:t,c:i}),[d,m,f,p]=xi({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:c,targetControlX:u,targetControlY:l});return[`M${e},${t} C${a},${c} ${u},${l} ${r},${s}`,d,m,f,p]}const On=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=K.Bottom,targetPosition:o=K.Top,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,pathOptions:x,interactionWidth:v})=>{const[g,E,M]=bi({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:o,curvature:x==null?void 0:x.curvature});return A.createElement(cn,{path:g,labelX:E,labelY:M,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:d,style:m,markerEnd:f,markerStart:p,interactionWidth:v})});On.displayName="BezierEdge";const Br=w.createContext(null),$f=Br.Provider;Br.Consumer;const Af=()=>w.useContext(Br),Rf=e=>"id"in e&&"source"in e&&"target"in e,If=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,Nr=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,Tf=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),Of=(e,t)=>{if(!e.source||!e.target)return t;let n;return Rf(e)?n={...e}:n={...e,id:If(e)},Tf(n,t)?t:t.concat(n)},Sr=({x:e,y:t},[n,r,s],o,[i,a])=>{const c={x:(e-n)/s,y:(t-r)/s};return o?{x:i*Math.round(c.x/i),y:a*Math.round(c.y/a)}:c},vi=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),Et=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},ln=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:o,y:i}=Et(s,t).positionAbsolute;return hi(r,nn({x:o,y:i,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return mi(n)},Lf=(e,t=[0,0])=>(console.warn("[DEPRECATED] `getRectOfNodes` is deprecated. Instead use `getNodesBounds` https://reactflow.dev/api-reference/utils/get-nodes-bounds."),ln(e,t)),_i=(e,t,[n,r,s]=[0,0,1],o=!1,i=!1,a=[0,0])=>{const c={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},u=[];return e.forEach(l=>{const{width:d,height:m,selectable:f=!0,hidden:p=!1}=l;if(i&&!f||p)return!1;const{positionAbsolute:x}=Et(l,a),v={x:x.x,y:x.y,width:d||0,height:m||0},g=_r(c,v),E=typeof d>"u"||typeof m>"u"||d===null||m===null,M=o&&g>0,b=(d||0)*(m||0);(E||M||g>=b||l.dragging)&&u.push(l)}),u},Ei=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},Ni=(e,t,n,r,s,o=.1)=>{const i=t/(e.width*(1+o)),a=n/(e.height*(1+o)),c=Math.min(i,a),u=zt(c,r,s),l=e.x+e.width/2,d=e.y+e.height/2,m=t/2-l*u,f=n/2-d*u;return{x:m,y:f,zoom:u}},wt=(e,t=0)=>e.transition().duration(t);function Ms(e,t,n,r){return(t[n]||[]).reduce((s,o)=>{var i,a;return`${e.id}-${o.id}-${n}`!==r&&s.push({id:o.id||null,type:n,nodeId:e.id,x:(((i=e.positionAbsolute)==null?void 0:i.x)??0)+o.x+o.width/2,y:(((a=e.positionAbsolute)==null?void 0:a.y)??0)+o.y+o.height/2}),s},[])}function Df(e,t,n,r,s,o){const{x:i,y:a}=yt(e),u=t.elementsFromPoint(i,a).find(p=>p.classList.contains("react-flow__handle"));if(u){const p=u.getAttribute("data-nodeid");if(p){const x=Gr(void 0,u),v=u.getAttribute("data-handleid"),g=o({nodeId:p,id:v,type:x});if(g){const E=s.find(M=>M.nodeId===p&&M.type===x&&M.id===v);return{handle:{id:v,type:x,nodeId:p,x:(E==null?void 0:E.x)||n.x,y:(E==null?void 0:E.y)||n.y},validHandleResult:g}}}}let l=[],d=1/0;if(s.forEach(p=>{const x=Math.sqrt((p.x-n.x)**2+(p.y-n.y)**2);if(x<=r){const v=o(p);x<=d&&(xp.isValid),f=l.some(({handle:p})=>p.type==="target");return l.find(({handle:p,validHandleResult:x})=>f?p.type==="target":m?x.isValid:!0)||l[0]}const Pf={source:null,target:null,sourceHandle:null,targetHandle:null},Si=()=>({handleDomNode:null,isValid:!1,connection:Pf,endHandle:null});function ki(e,t,n,r,s,o,i){const a=s==="target",c=i.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),u={...Si(),handleDomNode:c};if(c){const l=Gr(void 0,c),d=c.getAttribute("data-nodeid"),m=c.getAttribute("data-handleid"),f=c.classList.contains("connectable"),p=c.classList.contains("connectableend"),x={source:a?d:n,sourceHandle:a?m:r,target:a?n:d,targetHandle:a?r:m};u.connection=x,f&&p&&(t===St.Strict?a&&l==="source"||!a&&l==="target":d!==n||m!==r)&&(u.endHandle={nodeId:d,handleId:m,type:l},u.isValid=o(x))}return u}function zf({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,o)=>{if(o[we]){const{handleBounds:i}=o[we];let a=[],c=[];i&&(a=Ms(o,i,"source",`${t}-${n}-${r}`),c=Ms(o,i,"target",`${t}-${n}-${r}`)),s.push(...a,...c)}return s},[])}function Gr(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function er(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function Hf(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function ji({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:o,setState:i,isValidConnection:a,edgeUpdaterType:c,onReconnectEnd:u}){const l=fi(e.target),{connectionMode:d,domNode:m,autoPanOnConnect:f,connectionRadius:p,onConnectStart:x,panBy:v,getNodes:g,cancelConnection:E}=o();let M=0,b;const{x:$,y:j}=yt(e),_=l==null?void 0:l.elementFromPoint($,j),R=Gr(c,_),N=m==null?void 0:m.getBoundingClientRect();if(!N||!R)return;let I,L=yt(e,N),B=!1,H=null,y=!1,C=null;const S=zf({nodes:g(),nodeId:n,handleId:t,handleType:R}),O=()=>{if(!f)return;const[T,P]=di(L,N);v({x:T,y:P}),M=requestAnimationFrame(O)};i({connectionPosition:L,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:R,connectionStartHandle:{nodeId:n,handleId:t,type:R},connectionEndHandle:null}),x==null||x(e,{nodeId:n,handleId:t,handleType:R});function D(T){const{transform:P}=o();L=yt(T,N);const{handle:z,validHandleResult:U}=Df(T,l,Sr(L,P,!1,[1,1]),p,S,W=>ki(W,d,n,t,s?"target":"source",a,l));if(b=z,B||(O(),B=!0),C=U.handleDomNode,H=U.connection,y=U.isValid,i({connectionPosition:b&&y?vi({x:b.x,y:b.y},P):L,connectionStatus:Hf(!!b,y),connectionEndHandle:U.endHandle}),!b&&!y&&!C)return er(I);H.source!==H.target&&C&&(er(I),I=C,C.classList.add("connecting","react-flow__handle-connecting"),C.classList.toggle("valid",y),C.classList.toggle("react-flow__handle-valid",y))}function k(T){var P,z;(b||C)&&H&&y&&(r==null||r(H)),(z=(P=o()).onConnectEnd)==null||z.call(P,T),c&&(u==null||u(T)),er(I),E(),cancelAnimationFrame(M),B=!1,y=!1,H=null,C=null,l.removeEventListener("mousemove",D),l.removeEventListener("mouseup",k),l.removeEventListener("touchmove",D),l.removeEventListener("touchend",k)}l.addEventListener("mousemove",D),l.addEventListener("mouseup",k),l.addEventListener("touchmove",D),l.addEventListener("touchend",k)}const $s=()=>!0,Ff=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),Vf=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:o,connectionClickStartHandle:i}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(o==null?void 0:o.nodeId)===e&&(o==null?void 0:o.handleId)===t&&(o==null?void 0:o.type)===n,clickConnecting:(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.handleId)===t&&(i==null?void 0:i.type)===n}},Ci=w.forwardRef(({type:e="source",position:t=K.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:o=!0,id:i,onConnect:a,children:c,className:u,onMouseDown:l,onTouchStart:d,...m},f)=>{var N,I;const p=i||null,x=e==="target",v=ke(),g=Af(),{connectOnClick:E,noPanClassName:M}=me(Ff,Ce),{connecting:b,clickConnecting:$}=me(Vf(g,p,e),Ce);g||(I=(N=v.getState()).onError)==null||I.call(N,"010",at.error010());const j=L=>{const{defaultEdgeOptions:B,onConnect:H,hasDefaultEdges:y}=v.getState(),C={...B,...L};if(y){const{edges:S,setEdges:O}=v.getState();O(Of(C,S))}H==null||H(C),a==null||a(C)},_=L=>{if(!g)return;const B=gi(L);s&&(B&&L.button===0||!B)&&ji({event:L,handleId:p,nodeId:g,onConnect:j,isTarget:x,getState:v.getState,setState:v.setState,isValidConnection:n||v.getState().isValidConnection||$s}),B?l==null||l(L):d==null||d(L)},R=L=>{const{onClickConnectStart:B,onClickConnectEnd:H,connectionClickStartHandle:y,connectionMode:C,isValidConnection:S}=v.getState();if(!g||!y&&!s)return;if(!y){B==null||B(L,{nodeId:g,handleId:p,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:g,type:e,handleId:p}});return}const O=fi(L.target),D=n||S||$s,{connection:k,isValid:T}=ki({nodeId:g,id:p,type:e},C,y.nodeId,y.handleId||null,y.type,D,O);T&&j(k),H==null||H(L),v.setState({connectionClickStartHandle:null})};return A.createElement("div",{"data-handleid":p,"data-nodeid":g,"data-handlepos":t,"data-id":`${g}-${p}-${e}`,className:Me(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",M,u,{source:!x,target:x,connectable:r,connectablestart:s,connectableend:o,connecting:$,connectionindicator:r&&(s&&!b||o&&b)}]),onMouseDown:_,onTouchStart:_,onClick:E?R:void 0,ref:f,...m},c)});Ci.displayName="Handle";var pt=w.memo(Ci);const Mi=({data:e,isConnectable:t,targetPosition:n=K.Top,sourcePosition:r=K.Bottom})=>A.createElement(A.Fragment,null,A.createElement(pt,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,A.createElement(pt,{type:"source",position:r,isConnectable:t}));Mi.displayName="DefaultNode";var kr=w.memo(Mi);const $i=({data:e,isConnectable:t,sourcePosition:n=K.Bottom})=>A.createElement(A.Fragment,null,e==null?void 0:e.label,A.createElement(pt,{type:"source",position:n,isConnectable:t}));$i.displayName="InputNode";var Ai=w.memo($i);const Ri=({data:e,isConnectable:t,targetPosition:n=K.Top})=>A.createElement(A.Fragment,null,A.createElement(pt,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);Ri.displayName="OutputNode";var Ii=w.memo(Ri);const Yr=()=>null;Yr.displayName="GroupNode";const Bf=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),xn=e=>e.id;function Gf(e,t){return Ce(e.selectedNodes.map(xn),t.selectedNodes.map(xn))&&Ce(e.selectedEdges.map(xn),t.selectedEdges.map(xn))}const Ti=w.memo(({onSelectionChange:e})=>{const t=ke(),{selectedNodes:n,selectedEdges:r}=me(Bf,Gf);return w.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(o=>o(s))},[n,r,e]),null});Ti.displayName="SelectionListener";const Yf=e=>!!e.onSelectionChange;function Xf({onSelectionChange:e}){const t=me(Yf);return e||t?A.createElement(Ti,{onSelectionChange:e}):null}const Wf=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function jt(e,t){w.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function ce(e,t,n){w.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const Uf=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:o,onConnectEnd:i,onClickConnectStart:a,onClickConnectEnd:c,nodesDraggable:u,nodesConnectable:l,nodesFocusable:d,edgesFocusable:m,edgesUpdatable:f,elevateNodesOnSelect:p,minZoom:x,maxZoom:v,nodeExtent:g,onNodesChange:E,onEdgesChange:M,elementsSelectable:b,connectionMode:$,snapGrid:j,snapToGrid:_,translateExtent:R,connectOnClick:N,defaultEdgeOptions:I,fitView:L,fitViewOptions:B,onNodesDelete:H,onEdgesDelete:y,onNodeDrag:C,onNodeDragStart:S,onNodeDragStop:O,onSelectionDrag:D,onSelectionDragStart:k,onSelectionDragStop:T,noPanClassName:P,nodeOrigin:z,rfId:U,autoPanOnConnect:W,autoPanOnNodeDrag:Q,onError:te,connectionRadius:se,isValidConnection:J,nodeDragThreshold:ae})=>{const{setNodes:oe,setEdges:he,setDefaultNodesAndEdges:ye,setMinZoom:Ee,setMaxZoom:ve,setTranslateExtent:ue,setNodeExtent:ge,reset:le}=me(Wf,Ce),q=ke();return w.useEffect(()=>{const fe=r==null?void 0:r.map(Oe=>({...Oe,...I}));return ye(n,fe),()=>{le()}},[]),ce("defaultEdgeOptions",I,q.setState),ce("connectionMode",$,q.setState),ce("onConnect",s,q.setState),ce("onConnectStart",o,q.setState),ce("onConnectEnd",i,q.setState),ce("onClickConnectStart",a,q.setState),ce("onClickConnectEnd",c,q.setState),ce("nodesDraggable",u,q.setState),ce("nodesConnectable",l,q.setState),ce("nodesFocusable",d,q.setState),ce("edgesFocusable",m,q.setState),ce("edgesUpdatable",f,q.setState),ce("elementsSelectable",b,q.setState),ce("elevateNodesOnSelect",p,q.setState),ce("snapToGrid",_,q.setState),ce("snapGrid",j,q.setState),ce("onNodesChange",E,q.setState),ce("onEdgesChange",M,q.setState),ce("connectOnClick",N,q.setState),ce("fitViewOnInit",L,q.setState),ce("fitViewOnInitOptions",B,q.setState),ce("onNodesDelete",H,q.setState),ce("onEdgesDelete",y,q.setState),ce("onNodeDrag",C,q.setState),ce("onNodeDragStart",S,q.setState),ce("onNodeDragStop",O,q.setState),ce("onSelectionDrag",D,q.setState),ce("onSelectionDragStart",k,q.setState),ce("onSelectionDragStop",T,q.setState),ce("noPanClassName",P,q.setState),ce("nodeOrigin",z,q.setState),ce("rfId",U,q.setState),ce("autoPanOnConnect",W,q.setState),ce("autoPanOnNodeDrag",Q,q.setState),ce("onError",te,q.setState),ce("connectionRadius",se,q.setState),ce("isValidConnection",J,q.setState),ce("nodeDragThreshold",ae,q.setState),jt(e,oe),jt(t,he),jt(x,Ee),jt(v,ve),jt(R,ue),jt(g,ge),null},As={display:"none"},qf={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Oi="react-flow__node-desc",Li="react-flow__edge-desc",Kf="react-flow__aria-live",Zf=e=>e.ariaLiveMessage;function Qf({rfId:e}){const t=me(Zf);return A.createElement("div",{id:`${Kf}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:qf},t)}function Jf({rfId:e,disableKeyboardA11y:t}){return A.createElement(A.Fragment,null,A.createElement("div",{id:`${Oi}-${e}`,style:As},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),A.createElement("div",{id:`${Li}-${e}`,style:As},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&A.createElement(Qf,{rfId:e}))}var sn=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=w.useState(!1),s=w.useRef(!1),o=w.useRef(new Set([])),[i,a]=w.useMemo(()=>{if(e!==null){const u=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.split("+")),l=u.reduce((d,m)=>d.concat(...m),[]);return[u,l]}return[[],[]]},[e]);return w.useEffect(()=>{const c=typeof document<"u"?document:null,u=(t==null?void 0:t.target)||c;if(e!==null){const l=f=>{if(s.current=f.ctrlKey||f.metaKey||f.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&Er(f))return!1;const x=Is(f.code,a);o.current.add(f[x]),Rs(i,o.current,!1)&&(f.preventDefault(),r(!0))},d=f=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&Er(f))return!1;const x=Is(f.code,a);Rs(i,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(f[x]),f.key==="Meta"&&o.current.clear(),s.current=!1},m=()=>{o.current.clear(),r(!1)};return u==null||u.addEventListener("keydown",l),u==null||u.addEventListener("keyup",d),window.addEventListener("blur",m),()=>{u==null||u.removeEventListener("keydown",l),u==null||u.removeEventListener("keyup",d),window.removeEventListener("blur",m)}}},[e,r]),n};function Rs(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Is(e,t){return t.includes(e)?"code":"key"}function Di(e,t,n,r){var a,c;const s=e.parentNode||e.parentId;if(!s)return n;const o=t.get(s),i=Et(o,r);return Di(o,t,{x:(n.x??0)+i.x,y:(n.y??0)+i.y,z:(((a=o[we])==null?void 0:a.z)??0)>(n.z??0)?((c=o[we])==null?void 0:c.z)??0:n.z??0},r)}function Pi(e,t,n){e.forEach(r=>{var o;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:i,y:a,z:c}=Di(r,e,{...r.position,z:((o=r[we])==null?void 0:o.z)??0},t);r.positionAbsolute={x:i,y:a},r[we].z=c,n!=null&&n[r.id]&&(r[we].isParent=!0)}})}function tr(e,t,n,r){const s=new Map,o={},i=r?1e3:0;return e.forEach(a=>{var f;const c=(Ve(a.zIndex)?a.zIndex:0)+(a.selected?i:0),u=t.get(a.id),l={...a,positionAbsolute:{x:a.position.x,y:a.position.y}},d=a.parentNode||a.parentId;d&&(o[d]=!0);const m=(u==null?void 0:u.type)&&(u==null?void 0:u.type)!==a.type;Object.defineProperty(l,we,{enumerable:!1,value:{handleBounds:m||(f=u==null?void 0:u[we])==null?void 0:f.handleBounds,z:c}}),s.set(a.id,l)}),Pi(s,n,o),s}function zi(e,t={}){const{getNodes:n,width:r,height:s,minZoom:o,maxZoom:i,d3Zoom:a,d3Selection:c,fitViewOnInitDone:u,fitViewOnInit:l,nodeOrigin:d}=e(),m=t.initial&&!u&&l;if(a&&c&&(m||!t.initial)){const p=n().filter(v=>{var E;const g=t.includeHiddenNodes?v.width&&v.height:!v.hidden;return(E=t.nodes)!=null&&E.length?g&&t.nodes.some(M=>M.id===v.id):g}),x=p.every(v=>v.width&&v.height);if(p.length>0&&x){const v=ln(p,d),{x:g,y:E,zoom:M}=Ni(v,r,s,t.minZoom??o,t.maxZoom??i,t.padding??.1),b=ot.translate(g,E).scale(M);return typeof t.duration=="number"&&t.duration>0?a.transform(wt(c,t.duration),b):a.transform(c,b),!0}}return!1}function eh(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[we]:r[we],selected:n.selected})}),new Map(t)}function th(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function wn({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:o,onNodesChange:i,onEdgesChange:a,hasDefaultNodes:c,hasDefaultEdges:u}=n();e!=null&&e.length&&(c&&r({nodeInternals:eh(e,s)}),i==null||i(e)),t!=null&&t.length&&(u&&r({edges:th(t,o)}),a==null||a(t))}const Ct=()=>{},nh={zoomIn:Ct,zoomOut:Ct,zoomTo:Ct,getZoom:()=>1,setViewport:Ct,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:Ct,fitBounds:Ct,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},rh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),sh=()=>{const e=ke(),{d3Zoom:t,d3Selection:n}=me(rh,Ce);return w.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(wt(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(wt(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,o)=>t.scaleTo(wt(n,o==null?void 0:o.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,o)=>{const[i,a,c]=e.getState().transform,u=ot.translate(s.x??i,s.y??a).scale(s.zoom??c);t.transform(wt(n,o==null?void 0:o.duration),u)},getViewport:()=>{const[s,o,i]=e.getState().transform;return{x:s,y:o,zoom:i}},fitView:s=>zi(e.getState,s),setCenter:(s,o,i)=>{const{width:a,height:c,maxZoom:u}=e.getState(),l=typeof(i==null?void 0:i.zoom)<"u"?i.zoom:u,d=a/2-s*l,m=c/2-o*l,f=ot.translate(d,m).scale(l);t.transform(wt(n,i==null?void 0:i.duration),f)},fitBounds:(s,o)=>{const{width:i,height:a,minZoom:c,maxZoom:u}=e.getState(),{x:l,y:d,zoom:m}=Ni(s,i,a,c,u,(o==null?void 0:o.padding)??.1),f=ot.translate(l,d).scale(m);t.transform(wt(n,o==null?void 0:o.duration),f)},project:s=>{const{transform:o,snapToGrid:i,snapGrid:a}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),Sr(s,o,i,a)},screenToFlowPosition:s=>{const{transform:o,snapToGrid:i,snapGrid:a,domNode:c}=e.getState();if(!c)return s;const{x:u,y:l}=c.getBoundingClientRect(),d={x:s.x-u,y:s.y-l};return Sr(d,o,i,a)},flowToScreenPosition:s=>{const{transform:o,domNode:i}=e.getState();if(!i)return s;const{x:a,y:c}=i.getBoundingClientRect(),u=vi(s,o);return{x:u.x+a,y:u.y+c}},viewportInitialized:!0}:nh,[t,n])};function un(){const e=sh(),t=ke(),n=w.useCallback(()=>t.getState().getNodes().map(x=>({...x})),[]),r=w.useCallback(x=>t.getState().nodeInternals.get(x),[]),s=w.useCallback(()=>{const{edges:x=[]}=t.getState();return x.map(v=>({...v}))},[]),o=w.useCallback(x=>{const{edges:v=[]}=t.getState();return v.find(g=>g.id===x)},[]),i=w.useCallback(x=>{const{getNodes:v,setNodes:g,hasDefaultNodes:E,onNodesChange:M}=t.getState(),b=v(),$=typeof x=="function"?x(b):x;if(E)g($);else if(M){const j=$.length===0?b.map(_=>({type:"remove",id:_.id})):$.map(_=>({item:_,type:"reset"}));M(j)}},[]),a=w.useCallback(x=>{const{edges:v=[],setEdges:g,hasDefaultEdges:E,onEdgesChange:M}=t.getState(),b=typeof x=="function"?x(v):x;if(E)g(b);else if(M){const $=b.length===0?v.map(j=>({type:"remove",id:j.id})):b.map(j=>({item:j,type:"reset"}));M($)}},[]),c=w.useCallback(x=>{const v=Array.isArray(x)?x:[x],{getNodes:g,setNodes:E,hasDefaultNodes:M,onNodesChange:b}=t.getState();if(M){const j=[...g(),...v];E(j)}else if(b){const $=v.map(j=>({item:j,type:"add"}));b($)}},[]),u=w.useCallback(x=>{const v=Array.isArray(x)?x:[x],{edges:g=[],setEdges:E,hasDefaultEdges:M,onEdgesChange:b}=t.getState();if(M)E([...g,...v]);else if(b){const $=v.map(j=>({item:j,type:"add"}));b($)}},[]),l=w.useCallback(()=>{const{getNodes:x,edges:v=[],transform:g}=t.getState(),[E,M,b]=g;return{nodes:x().map($=>({...$})),edges:v.map($=>({...$})),viewport:{x:E,y:M,zoom:b}}},[]),d=w.useCallback(({nodes:x,edges:v})=>{const{nodeInternals:g,getNodes:E,edges:M,hasDefaultNodes:b,hasDefaultEdges:$,onNodesDelete:j,onEdgesDelete:_,onNodesChange:R,onEdgesChange:N}=t.getState(),I=(x||[]).map(C=>C.id),L=(v||[]).map(C=>C.id),B=E().reduce((C,S)=>{const O=S.parentNode||S.parentId,D=!I.includes(S.id)&&O&&C.find(T=>T.id===O);return(typeof S.deletable=="boolean"?S.deletable:!0)&&(I.includes(S.id)||D)&&C.push(S),C},[]),H=M.filter(C=>typeof C.deletable=="boolean"?C.deletable:!0),y=H.filter(C=>L.includes(C.id));if(B||y){const C=Ei(B,H),S=[...y,...C],O=S.reduce((D,k)=>(D.includes(k.id)||D.push(k.id),D),[]);if(($||b)&&($&&t.setState({edges:M.filter(D=>!O.includes(D.id))}),b&&(B.forEach(D=>{g.delete(D.id)}),t.setState({nodeInternals:new Map(g)}))),O.length>0&&(_==null||_(S),N&&N(O.map(D=>({id:D,type:"remove"})))),B.length>0&&(j==null||j(B),R)){const D=B.map(k=>({id:k.id,type:"remove"}));R(D)}}},[]),m=w.useCallback(x=>{const v=Ef(x),g=v?null:t.getState().nodeInternals.get(x.id);return!v&&!g?[null,null,v]:[v?x:Ns(g),g,v]},[]),f=w.useCallback((x,v=!0,g)=>{const[E,M,b]=m(x);return E?(g||t.getState().getNodes()).filter($=>{if(!b&&($.id===M.id||!$.positionAbsolute))return!1;const j=Ns($),_=_r(j,E);return v&&_>0||_>=E.width*E.height}):[]},[]),p=w.useCallback((x,v,g=!0)=>{const[E]=m(x);if(!E)return!1;const M=_r(E,v);return g&&M>0||M>=E.width*E.height},[]);return w.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:o,setNodes:i,setEdges:a,addNodes:c,addEdges:u,toObject:l,deleteElements:d,getIntersectingNodes:f,isNodeIntersecting:p}),[e,n,r,s,o,i,a,c,u,l,d,f,p])}const oh={actInsideInputWithModifier:!1};var ih=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=ke(),{deleteElements:r}=un(),s=sn(e,oh),o=sn(t);w.useEffect(()=>{if(s){const{edges:i,getNodes:a}=n.getState(),c=a().filter(l=>l.selected),u=i.filter(l=>l.selected);r({nodes:c,edges:u}),n.setState({nodesSelectionActive:!1})}},[s]),w.useEffect(()=>{n.setState({multiSelectionActive:o})},[o])};function ah(e){const t=ke();w.useEffect(()=>{let n;const r=()=>{var o,i;if(!e.current)return;const s=Pr(e.current);(s.height===0||s.width===0)&&((i=(o=t.getState()).onError)==null||i.call(o,"004",at.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const Xr={position:"absolute",width:"100%",height:"100%",top:0,left:0},ch=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,bn=e=>({x:e.x,y:e.y,zoom:e.k}),Mt=(e,t)=>e.target.closest(`.${t}`),Ts=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Os=e=>{const t=e.ctrlKey&&Rn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},lh=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),uh=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:o=!0,panOnScroll:i=!1,panOnScrollSpeed:a=.5,panOnScrollMode:c=vt.Free,zoomOnDoubleClick:u=!0,elementsSelectable:l,panOnDrag:d=!0,defaultViewport:m,translateExtent:f,minZoom:p,maxZoom:x,zoomActivationKeyCode:v,preventScrolling:g=!0,children:E,noWheelClassName:M,noPanClassName:b})=>{const $=w.useRef(),j=ke(),_=w.useRef(!1),R=w.useRef(!1),N=w.useRef(null),I=w.useRef({x:0,y:0,zoom:0}),{d3Zoom:L,d3Selection:B,d3ZoomHandler:H,userSelectionActive:y}=me(lh,Ce),C=sn(v),S=w.useRef(0),O=w.useRef(!1),D=w.useRef();return ah(N),w.useEffect(()=>{if(N.current){const k=N.current.getBoundingClientRect(),T=li().scaleExtent([p,x]).translateExtent(f),P=Fe(N.current).call(T),z=ot.translate(m.x,m.y).scale(zt(m.zoom,p,x)),U=[[0,0],[k.width,k.height]],W=T.constrain()(z,U,f);T.transform(P,W),T.wheelDelta(Os),j.setState({d3Zoom:T,d3Selection:P,d3ZoomHandler:P.on("wheel.zoom"),transform:[W.x,W.y,W.k],domNode:N.current.closest(".react-flow")})}},[]),w.useEffect(()=>{B&&L&&(i&&!C&&!y?B.on("wheel.zoom",k=>{if(Mt(k,M))return!1;k.preventDefault(),k.stopImmediatePropagation();const T=B.property("__zoom").k||1;if(k.ctrlKey&&o){const J=Xe(k),ae=Os(k),oe=T*Math.pow(2,ae);L.scaleTo(B,oe,J,k);return}const P=k.deltaMode===1?20:1;let z=c===vt.Vertical?0:k.deltaX*P,U=c===vt.Horizontal?0:k.deltaY*P;!Rn()&&k.shiftKey&&c!==vt.Vertical&&(z=k.deltaY*P,U=0),L.translateBy(B,-(z/T)*a,-(U/T)*a,{internal:!0});const W=bn(B.property("__zoom")),{onViewportChangeStart:Q,onViewportChange:te,onViewportChangeEnd:se}=j.getState();clearTimeout(D.current),O.current||(O.current=!0,t==null||t(k,W),Q==null||Q(W)),O.current&&(e==null||e(k,W),te==null||te(W),D.current=setTimeout(()=>{n==null||n(k,W),se==null||se(W),O.current=!1},150))},{passive:!1}):typeof H<"u"&&B.on("wheel.zoom",function(k,T){if(!g&&k.type==="wheel"&&!k.ctrlKey||Mt(k,M))return null;k.preventDefault(),H.call(this,k,T)},{passive:!1}))},[y,i,c,B,L,H,C,o,g,M,t,e,n]),w.useEffect(()=>{L&&L.on("start",k=>{var z,U;if(!k.sourceEvent||k.sourceEvent.internal)return null;S.current=(z=k.sourceEvent)==null?void 0:z.button;const{onViewportChangeStart:T}=j.getState(),P=bn(k.transform);_.current=!0,I.current=P,((U=k.sourceEvent)==null?void 0:U.type)==="mousedown"&&j.setState({paneDragging:!0}),T==null||T(P),t==null||t(k.sourceEvent,P)})},[L,t]),w.useEffect(()=>{L&&(y&&!_.current?L.on("zoom",null):y||L.on("zoom",k=>{var P;const{onViewportChange:T}=j.getState();if(j.setState({transform:[k.transform.x,k.transform.y,k.transform.k]}),R.current=!!(r&&Ts(d,S.current??0)),(e||T)&&!((P=k.sourceEvent)!=null&&P.internal)){const z=bn(k.transform);T==null||T(z),e==null||e(k.sourceEvent,z)}}))},[y,L,e,d,r]),w.useEffect(()=>{L&&L.on("end",k=>{if(!k.sourceEvent||k.sourceEvent.internal)return null;const{onViewportChangeEnd:T}=j.getState();if(_.current=!1,j.setState({paneDragging:!1}),r&&Ts(d,S.current??0)&&!R.current&&r(k.sourceEvent),R.current=!1,(n||T)&&ch(I.current,k.transform)){const P=bn(k.transform);I.current=P,clearTimeout($.current),$.current=setTimeout(()=>{T==null||T(P),n==null||n(k.sourceEvent,P)},i?150:0)}})},[L,i,d,n,r]),w.useEffect(()=>{L&&L.filter(k=>{const T=C||s,P=o&&k.ctrlKey;if((d===!0||Array.isArray(d)&&d.includes(1))&&k.button===1&&k.type==="mousedown"&&(Mt(k,"react-flow__node")||Mt(k,"react-flow__edge")))return!0;if(!d&&!T&&!i&&!u&&!o||y||!u&&k.type==="dblclick"||Mt(k,M)&&k.type==="wheel"||Mt(k,b)&&(k.type!=="wheel"||i&&k.type==="wheel"&&!C)||!o&&k.ctrlKey&&k.type==="wheel"||!T&&!i&&!P&&k.type==="wheel"||!d&&(k.type==="mousedown"||k.type==="touchstart")||Array.isArray(d)&&!d.includes(k.button)&&k.type==="mousedown")return!1;const z=Array.isArray(d)&&d.includes(k.button)||!k.button||k.button<=1;return(!k.ctrlKey||k.type==="wheel")&&z})},[y,L,s,o,i,u,d,l,C]),A.createElement("div",{className:"react-flow__renderer",ref:N,style:Xr},E)},dh=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function fh(){const{userSelectionActive:e,userSelectionRect:t}=me(dh,Ce);return e&&t?A.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Ls(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,o=t.position.y+t.height-r.height;if(s>0||o>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),o>0&&(r.style.height+=o),t.position.x<0){const i=Math.abs(t.position.x);r.position.x=r.position.x-i,r.style.width+=i,t.position.x=0}if(t.position.y<0){const i=Math.abs(t.position.y);r.position.y=r.position.y-i,r.style.height+=i,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function hh(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const o=e.filter(a=>a.id===s.id);if(o.length===0)return r.push(s),r;const i={...s};for(const a of o)if(a)switch(a.type){case"select":{i.selected=a.selected;break}case"position":{typeof a.position<"u"&&(i.position=a.position),typeof a.positionAbsolute<"u"&&(i.positionAbsolute=a.positionAbsolute),typeof a.dragging<"u"&&(i.dragging=a.dragging),i.expandParent&&Ls(r,i);break}case"dimensions":{typeof a.dimensions<"u"&&(i.width=a.dimensions.width,i.height=a.dimensions.height),typeof a.updateStyle<"u"&&(i.style={...i.style||{},...a.dimensions}),typeof a.resizing=="boolean"&&(i.resizing=a.resizing),i.expandParent&&Ls(r,i);break}case"remove":return r}return r.push(i),r},n)}function mh(e,t){return hh(e,t)}const ht=(e,t)=>({id:e,type:"select",selected:t});function At(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(ht(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(ht(r.id,!1))),n},[])}const nr=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},ph=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),Hi=w.memo(({isSelecting:e,selectionMode:t=rn.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:o,onPaneContextMenu:i,onPaneScroll:a,onPaneMouseEnter:c,onPaneMouseMove:u,onPaneMouseLeave:l,children:d})=>{const m=w.useRef(null),f=ke(),p=w.useRef(0),x=w.useRef(0),v=w.useRef(),{userSelectionActive:g,elementsSelectable:E,dragging:M}=me(ph,Ce),b=()=>{f.setState({userSelectionActive:!1,userSelectionRect:null}),p.current=0,x.current=0},$=H=>{o==null||o(H),f.getState().resetSelectedElements(),f.setState({nodesSelectionActive:!1})},j=H=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){H.preventDefault();return}i==null||i(H)},_=a?H=>a(H):void 0,R=H=>{const{resetSelectedElements:y,domNode:C}=f.getState();if(v.current=C==null?void 0:C.getBoundingClientRect(),!E||!e||H.button!==0||H.target!==m.current||!v.current)return;const{x:S,y:O}=yt(H,v.current);y(),f.setState({userSelectionRect:{width:0,height:0,startX:S,startY:O,x:S,y:O}}),r==null||r(H)},N=H=>{const{userSelectionRect:y,nodeInternals:C,edges:S,transform:O,onNodesChange:D,onEdgesChange:k,nodeOrigin:T,getNodes:P}=f.getState();if(!e||!v.current||!y)return;f.setState({userSelectionActive:!0,nodesSelectionActive:!1});const z=yt(H,v.current),U=y.startX??0,W=y.startY??0,Q={...y,x:z.xoe.id),ae=se.map(oe=>oe.id);if(p.current!==ae.length){p.current=ae.length;const oe=At(te,ae);oe.length&&(D==null||D(oe))}if(x.current!==J.length){x.current=J.length;const oe=At(S,J);oe.length&&(k==null||k(oe))}f.setState({userSelectionRect:Q})},I=H=>{if(H.button!==0)return;const{userSelectionRect:y}=f.getState();!g&&y&&H.target===m.current&&($==null||$(H)),f.setState({nodesSelectionActive:p.current>0}),b(),s==null||s(H)},L=H=>{g&&(f.setState({nodesSelectionActive:p.current>0}),s==null||s(H)),b()},B=E&&(e||g);return A.createElement("div",{className:Me(["react-flow__pane",{dragging:M,selection:e}]),onClick:B?void 0:nr($,m),onContextMenu:nr(j,m),onWheel:nr(_,m),onMouseEnter:B?void 0:c,onMouseDown:B?R:void 0,onMouseMove:B?N:u,onMouseUp:B?I:void 0,onMouseLeave:B?L:l,ref:m,style:Xr},d,A.createElement(fh,null))});Hi.displayName="Pane";function Fi(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:Fi(r,t):!1}function Ds(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function gh(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!Fi(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var o,i;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((o=s.positionAbsolute)==null?void 0:o.x)??0),y:n.y-(((i=s.positionAbsolute)==null?void 0:i.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function yh(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function Vi(e,t,n,r,s=[0,0],o){const i=yh(e,e.extent||r);let a=i;const c=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(c&&e.width&&e.height){const d=n.get(c),{x:m,y:f}=Et(d,s).positionAbsolute;a=d&&Ve(m)&&Ve(f)&&Ve(d.width)&&Ve(d.height)?[[m+e.width*s[0],f+e.height*s[1]],[m+d.width-e.width+e.width*s[0],f+d.height-e.height+e.height*s[1]]]:a}else o==null||o("005",at.error005()),a=i;else if(e.extent&&c&&e.extent!=="parent"){const d=n.get(c),{x:m,y:f}=Et(d,s).positionAbsolute;a=[[e.extent[0][0]+m,e.extent[0][1]+f],[e.extent[1][0]+m,e.extent[1][1]+f]]}let u={x:0,y:0};if(c){const d=n.get(c);u=Et(d,s).positionAbsolute}const l=a&&a!=="parent"?zr(t,a):t;return{position:{x:l.x-u.x,y:l.y-u.y},positionAbsolute:l}}function rr({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const Ps=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const o=Array.from(s),i=t.getBoundingClientRect(),a={x:i.width*r[0],y:i.height*r[1]};return o.map(c=>{const u=c.getBoundingClientRect();return{id:c.getAttribute("data-handleid"),position:c.getAttribute("data-handlepos"),x:(u.left-i.left-a.x)/n,y:(u.top-i.top-a.y)/n,...Pr(c)}})};function Yt(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function jr({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:o,multiSelectionActive:i,nodeInternals:a,onError:c}=t.getState(),u=a.get(e);if(!u){c==null||c("012",at.error012(e));return}t.setState({nodesSelectionActive:!1}),u.selected?(n||u.selected&&i)&&(o({nodes:[u],edges:[]}),requestAnimationFrame(()=>{var l;return(l=r==null?void 0:r.current)==null?void 0:l.blur()})):s([e])}function xh(){const e=ke();return w.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:o}=e.getState(),i=n.touches?n.touches[0].clientX:n.clientX,a=n.touches?n.touches[0].clientY:n.clientY,c={x:(i-r[0])/r[2],y:(a-r[1])/r[2]};return{xSnapped:o?s[0]*Math.round(c.x/s[0]):c.x,ySnapped:o?s[1]*Math.round(c.y/s[1]):c.y,...c}},[])}function sr(e){return(t,n,r)=>e==null?void 0:e(t,r)}function Bi({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:o,selectNodesOnDrag:i}){const a=ke(),[c,u]=w.useState(!1),l=w.useRef([]),d=w.useRef({x:null,y:null}),m=w.useRef(0),f=w.useRef(null),p=w.useRef({x:0,y:0}),x=w.useRef(null),v=w.useRef(!1),g=w.useRef(!1),E=w.useRef(!1),M=xh();return w.useEffect(()=>{if(e!=null&&e.current){const b=Fe(e.current),$=({x:R,y:N})=>{const{nodeInternals:I,onNodeDrag:L,onSelectionDrag:B,updateNodePositions:H,nodeExtent:y,snapGrid:C,snapToGrid:S,nodeOrigin:O,onError:D}=a.getState();d.current={x:R,y:N};let k=!1,T={x:0,y:0,x2:0,y2:0};if(l.current.length>1&&y){const z=ln(l.current,O);T=nn(z)}if(l.current=l.current.map(z=>{const U={x:R-z.distance.x,y:N-z.distance.y};S&&(U.x=C[0]*Math.round(U.x/C[0]),U.y=C[1]*Math.round(U.y/C[1]));const W=[[y[0][0],y[0][1]],[y[1][0],y[1][1]]];l.current.length>1&&y&&!z.extent&&(W[0][0]=z.positionAbsolute.x-T.x+y[0][0],W[1][0]=z.positionAbsolute.x+(z.width??0)-T.x2+y[1][0],W[0][1]=z.positionAbsolute.y-T.y+y[0][1],W[1][1]=z.positionAbsolute.y+(z.height??0)-T.y2+y[1][1]);const Q=Vi(z,U,I,W,O,D);return k=k||z.position.x!==Q.position.x||z.position.y!==Q.position.y,z.position=Q.position,z.positionAbsolute=Q.positionAbsolute,z}),!k)return;H(l.current,!0,!0),u(!0);const P=s?L:sr(B);if(P&&x.current){const[z,U]=rr({nodeId:s,dragItems:l.current,nodeInternals:I});P(x.current,z,U)}},j=()=>{if(!f.current)return;const[R,N]=di(p.current,f.current);if(R!==0||N!==0){const{transform:I,panBy:L}=a.getState();d.current.x=(d.current.x??0)-R/I[2],d.current.y=(d.current.y??0)-N/I[2],L({x:R,y:N})&&$(d.current)}m.current=requestAnimationFrame(j)},_=R=>{var O;const{nodeInternals:N,multiSelectionActive:I,nodesDraggable:L,unselectNodesAndEdges:B,onNodeDragStart:H,onSelectionDragStart:y}=a.getState();g.current=!0;const C=s?H:sr(y);(!i||!o)&&!I&&s&&((O=N.get(s))!=null&&O.selected||B()),s&&o&&i&&jr({id:s,store:a,nodeRef:e});const S=M(R);if(d.current=S,l.current=gh(N,L,S,s),C&&l.current){const[D,k]=rr({nodeId:s,dragItems:l.current,nodeInternals:N});C(R.sourceEvent,D,k)}};if(t)b.on(".drag",null);else{const R=ku().on("start",N=>{const{domNode:I,nodeDragThreshold:L}=a.getState();L===0&&_(N),E.current=!1;const B=M(N);d.current=B,f.current=(I==null?void 0:I.getBoundingClientRect())||null,p.current=yt(N.sourceEvent,f.current)}).on("drag",N=>{var H,y;const I=M(N),{autoPanOnNodeDrag:L,nodeDragThreshold:B}=a.getState();if(N.sourceEvent.type==="touchmove"&&N.sourceEvent.touches.length>1&&(E.current=!0),!E.current){if(!v.current&&g.current&&L&&(v.current=!0,j()),!g.current){const C=I.xSnapped-(((H=d==null?void 0:d.current)==null?void 0:H.x)??0),S=I.ySnapped-(((y=d==null?void 0:d.current)==null?void 0:y.y)??0);Math.sqrt(C*C+S*S)>B&&_(N)}(d.current.x!==I.xSnapped||d.current.y!==I.ySnapped)&&l.current&&g.current&&(x.current=N.sourceEvent,p.current=yt(N.sourceEvent,f.current),$(I))}}).on("end",N=>{if(!(!g.current||E.current)&&(u(!1),v.current=!1,g.current=!1,cancelAnimationFrame(m.current),l.current)){const{updateNodePositions:I,nodeInternals:L,onNodeDragStop:B,onSelectionDragStop:H}=a.getState(),y=s?B:sr(H);if(I(l.current,!1,!1),y){const[C,S]=rr({nodeId:s,dragItems:l.current,nodeInternals:L});y(N.sourceEvent,C,S)}}}).filter(N=>{const I=N.target;return!N.button&&(!n||!Ds(I,`.${n}`,e))&&(!r||Ds(I,r,e))});return b.call(R),()=>{b.on(".drag",null)}}}},[e,t,n,r,o,a,s,i,M]),c}function Gi(){const e=ke();return w.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:o,getNodes:i,snapToGrid:a,snapGrid:c,onError:u,nodesDraggable:l}=e.getState(),d=i().filter(E=>E.selected&&(E.draggable||l&&typeof E.draggable>"u")),m=a?c[0]:5,f=a?c[1]:5,p=n.isShiftPressed?4:1,x=n.x*m*p,v=n.y*f*p,g=d.map(E=>{if(E.positionAbsolute){const M={x:E.positionAbsolute.x+x,y:E.positionAbsolute.y+v};a&&(M.x=c[0]*Math.round(M.x/c[0]),M.y=c[1]*Math.round(M.y/c[1]));const{positionAbsolute:b,position:$}=Vi(E,M,r,s,void 0,u);E.position=$,E.positionAbsolute=b}return E});o(g,!0,!1)},[])}const Ot={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Xt=e=>{const t=({id:n,type:r,data:s,xPos:o,yPos:i,xPosOrigin:a,yPosOrigin:c,selected:u,onClick:l,onMouseEnter:d,onMouseMove:m,onMouseLeave:f,onContextMenu:p,onDoubleClick:x,style:v,className:g,isDraggable:E,isSelectable:M,isConnectable:b,isFocusable:$,selectNodesOnDrag:j,sourcePosition:_,targetPosition:R,hidden:N,resizeObserver:I,dragHandle:L,zIndex:B,isParent:H,noDragClassName:y,noPanClassName:C,initialized:S,disableKeyboardA11y:O,ariaLabel:D,rfId:k,hasHandleBounds:T})=>{const P=ke(),z=w.useRef(null),U=w.useRef(null),W=w.useRef(_),Q=w.useRef(R),te=w.useRef(r),se=M||E||l||d||m||f,J=Gi(),ae=Yt(n,P.getState,d),oe=Yt(n,P.getState,m),he=Yt(n,P.getState,f),ye=Yt(n,P.getState,p),Ee=Yt(n,P.getState,x),ve=le=>{const{nodeDragThreshold:q}=P.getState();if(M&&(!j||!E||q>0)&&jr({id:n,store:P,nodeRef:z}),l){const fe=P.getState().nodeInternals.get(n);fe&&l(le,{...fe})}},ue=le=>{if(!Er(le)&&!O)if(pi.includes(le.key)&&M){const q=le.key==="Escape";jr({id:n,store:P,unselect:q,nodeRef:z})}else E&&u&&Object.prototype.hasOwnProperty.call(Ot,le.key)&&(P.setState({ariaLiveMessage:`Moved selected node ${le.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~o}, y: ${~~i}`}),J({x:Ot[le.key].x,y:Ot[le.key].y,isShiftPressed:le.shiftKey}))};w.useEffect(()=>()=>{U.current&&(I==null||I.unobserve(U.current),U.current=null)},[]),w.useEffect(()=>{if(z.current&&!N){const le=z.current;(!S||!T||U.current!==le)&&(U.current&&(I==null||I.unobserve(U.current)),I==null||I.observe(le),U.current=le)}},[N,S,T]),w.useEffect(()=>{const le=te.current!==r,q=W.current!==_,fe=Q.current!==R;z.current&&(le||q||fe)&&(le&&(te.current=r),q&&(W.current=_),fe&&(Q.current=R),P.getState().updateNodeDimensions([{id:n,nodeElement:z.current,forceUpdate:!0}]))},[n,r,_,R]);const ge=Bi({nodeRef:z,disabled:N||!E,noDragClassName:y,handleSelector:L,nodeId:n,isSelectable:M,selectNodesOnDrag:j});return N?null:A.createElement("div",{className:Me(["react-flow__node",`react-flow__node-${r}`,{[C]:E},g,{selected:u,selectable:M,parent:H,dragging:ge}]),ref:z,style:{zIndex:B,transform:`translate(${a}px,${c}px)`,pointerEvents:se?"all":"none",visibility:S?"visible":"hidden",...v},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ae,onMouseMove:oe,onMouseLeave:he,onContextMenu:ye,onClick:ve,onDoubleClick:Ee,onKeyDown:$?ue:void 0,tabIndex:$?0:void 0,role:$?"button":void 0,"aria-describedby":O?void 0:`${Oi}-${k}`,"aria-label":D},A.createElement($f,{value:n},A.createElement(e,{id:n,data:s,type:r,xPos:o,yPos:i,selected:u,isConnectable:b,sourcePosition:_,targetPosition:R,dragging:ge,dragHandle:L,zIndex:B})))};return t.displayName="NodeWrapper",w.memo(t)};const wh=e=>{const t=e.getNodes().filter(n=>n.selected);return{...ln(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function bh({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=ke(),{width:s,height:o,x:i,y:a,transformString:c,userSelectionActive:u}=me(wh,Ce),l=Gi(),d=w.useRef(null);if(w.useEffect(()=>{var p;n||(p=d.current)==null||p.focus({preventScroll:!0})},[n]),Bi({nodeRef:d}),u||!s||!o)return null;const m=e?p=>{const x=r.getState().getNodes().filter(v=>v.selected);e(p,x)}:void 0,f=p=>{Object.prototype.hasOwnProperty.call(Ot,p.key)&&l({x:Ot[p.key].x,y:Ot[p.key].y,isShiftPressed:p.shiftKey})};return A.createElement("div",{className:Me(["react-flow__nodesselection","react-flow__container",t]),style:{transform:c}},A.createElement("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:s,height:o,top:a,left:i}}))}var vh=w.memo(bh);const _h=e=>e.nodesSelectionActive,Yi=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:i,deleteKeyCode:a,onMove:c,onMoveStart:u,onMoveEnd:l,selectionKeyCode:d,selectionOnDrag:m,selectionMode:f,onSelectionStart:p,onSelectionEnd:x,multiSelectionKeyCode:v,panActivationKeyCode:g,zoomActivationKeyCode:E,elementsSelectable:M,zoomOnScroll:b,zoomOnPinch:$,panOnScroll:j,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:N,panOnDrag:I,defaultViewport:L,translateExtent:B,minZoom:H,maxZoom:y,preventScrolling:C,onSelectionContextMenu:S,noWheelClassName:O,noPanClassName:D,disableKeyboardA11y:k})=>{const T=me(_h),P=sn(d),z=sn(g),U=z||I,W=z||j,Q=P||m&&U!==!0;return ih({deleteKeyCode:a,multiSelectionKeyCode:v}),A.createElement(uh,{onMove:c,onMoveStart:u,onMoveEnd:l,onPaneContextMenu:o,elementsSelectable:M,zoomOnScroll:b,zoomOnPinch:$,panOnScroll:W,panOnScrollSpeed:_,panOnScrollMode:R,zoomOnDoubleClick:N,panOnDrag:!P&&U,defaultViewport:L,translateExtent:B,minZoom:H,maxZoom:y,zoomActivationKeyCode:E,preventScrolling:C,noWheelClassName:O,noPanClassName:D},A.createElement(Hi,{onSelectionStart:p,onSelectionEnd:x,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:i,panOnDrag:U,isSelecting:!!Q,selectionMode:f},e,T&&A.createElement(vh,{onSelectionContextMenu:S,noPanClassName:D,disableKeyboardA11y:k})))};Yi.displayName="FlowRenderer";var Eh=w.memo(Yi);function Nh(e){return me(w.useCallback(n=>e?_i(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function Sh(e){const t={input:Xt(e.input||Ai),default:Xt(e.default||kr),output:Xt(e.output||Ii),group:Xt(e.group||Yr)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,o)=>(s[o]=Xt(e[o]||kr),s),n);return{...t,...r}}const kh=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},jh=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),Xi=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:o,onError:i}=me(jh,Ce),a=Nh(e.onlyRenderVisibleElements),c=w.useRef(),u=w.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const l=new ResizeObserver(d=>{const m=d.map(f=>({id:f.target.getAttribute("data-id"),nodeElement:f.target,forceUpdate:!0}));o(m)});return c.current=l,l},[]);return w.useEffect(()=>()=>{var l;(l=c==null?void 0:c.current)==null||l.disconnect()},[]),A.createElement("div",{className:"react-flow__nodes",style:Xr},a.map(l=>{var $,j,_;let d=l.type||"default";e.nodeTypes[d]||(i==null||i("003",at.error003(d)),d="default");const m=e.nodeTypes[d]||e.nodeTypes.default,f=!!(l.draggable||t&&typeof l.draggable>"u"),p=!!(l.selectable||s&&typeof l.selectable>"u"),x=!!(l.connectable||n&&typeof l.connectable>"u"),v=!!(l.focusable||r&&typeof l.focusable>"u"),g=e.nodeExtent?zr(l.positionAbsolute,e.nodeExtent):l.positionAbsolute,E=(g==null?void 0:g.x)??0,M=(g==null?void 0:g.y)??0,b=kh({x:E,y:M,width:l.width??0,height:l.height??0,origin:e.nodeOrigin});return A.createElement(m,{key:l.id,id:l.id,className:l.className,style:l.style,type:d,data:l.data,sourcePosition:l.sourcePosition||K.Bottom,targetPosition:l.targetPosition||K.Top,hidden:l.hidden,xPos:E,yPos:M,xPosOrigin:b.x,yPosOrigin:b.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!l.selected,isDraggable:f,isSelectable:p,isConnectable:x,isFocusable:v,resizeObserver:u,dragHandle:l.dragHandle,zIndex:(($=l[we])==null?void 0:$.z)??0,isParent:!!((j=l[we])!=null&&j.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!l.width&&!!l.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:l.ariaLabel,hasHandleBounds:!!((_=l[we])!=null&&_.handleBounds)})}))};Xi.displayName="NodeRenderer";var Ch=w.memo(Xi);const Mh=(e,t,n)=>n===K.Left?e-t:n===K.Right?e+t:e,$h=(e,t,n)=>n===K.Top?e-t:n===K.Bottom?e+t:e,zs="react-flow__edgeupdater",Hs=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:o,onMouseOut:i,type:a})=>A.createElement("circle",{onMouseDown:s,onMouseEnter:o,onMouseOut:i,className:Me([zs,`${zs}-${a}`]),cx:Mh(t,r,e),cy:$h(n,r,e),r,stroke:"transparent",fill:"transparent"}),Ah=()=>!0;var $t=e=>{const t=({id:n,className:r,type:s,data:o,onClick:i,onEdgeDoubleClick:a,selected:c,animated:u,label:l,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:x,style:v,source:g,target:E,sourceX:M,sourceY:b,targetX:$,targetY:j,sourcePosition:_,targetPosition:R,elementsSelectable:N,hidden:I,sourceHandleId:L,targetHandleId:B,onContextMenu:H,onMouseEnter:y,onMouseMove:C,onMouseLeave:S,reconnectRadius:O,onReconnect:D,onReconnectStart:k,onReconnectEnd:T,markerEnd:P,markerStart:z,rfId:U,ariaLabel:W,isFocusable:Q,isReconnectable:te,pathOptions:se,interactionWidth:J,disableKeyboardA11y:ae})=>{const oe=w.useRef(null),[he,ye]=w.useState(!1),[Ee,ve]=w.useState(!1),ue=ke(),ge=w.useMemo(()=>`url('#${Nr(z,U)}')`,[z,U]),le=w.useMemo(()=>`url('#${Nr(P,U)}')`,[P,U]);if(I)return null;const q=Z=>{var ne;const{edges:Y,addSelectedEdges:G,unselectNodesAndEdges:re,multiSelectionActive:xe}=ue.getState(),ee=Y.find(ie=>ie.id===n);ee&&(N&&(ue.setState({nodesSelectionActive:!1}),ee.selected&&xe?(re({nodes:[],edges:[ee]}),(ne=oe.current)==null||ne.blur()):G([n])),i&&i(Z,ee))},fe=Gt(n,ue.getState,a),Oe=Gt(n,ue.getState,H),Ke=Gt(n,ue.getState,y),Ye=Gt(n,ue.getState,C),$e=Gt(n,ue.getState,S),Ae=(Z,Y)=>{if(Z.button!==0)return;const{edges:G,isValidConnection:re}=ue.getState(),xe=Y?E:g,ee=(Y?B:L)||null,ne=Y?"target":"source",ie=re||Ah,pe=Y,Ie=G.find(Ne=>Ne.id===n);ve(!0),k==null||k(Z,Ie,ne);const Le=Ne=>{ve(!1),T==null||T(Ne,Ie,ne)};ji({event:Z,handleId:ee,nodeId:xe,onConnect:Ne=>D==null?void 0:D(Ie,Ne),isTarget:pe,getState:ue.getState,setState:ue.setState,isValidConnection:ie,edgeUpdaterType:ne,onReconnectEnd:Le})},je=Z=>Ae(Z,!0),Re=Z=>Ae(Z,!1),ze=()=>ye(!0),F=()=>ye(!1),X=!N&&!i,V=Z=>{var Y;if(!ae&&pi.includes(Z.key)&&N){const{unselectNodesAndEdges:G,addSelectedEdges:re,edges:xe}=ue.getState();Z.key==="Escape"?((Y=oe.current)==null||Y.blur(),G({edges:[xe.find(ne=>ne.id===n)]})):re([n])}};return A.createElement("g",{className:Me(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:c,animated:u,inactive:X,updating:he}]),onClick:q,onDoubleClick:fe,onContextMenu:Oe,onMouseEnter:Ke,onMouseMove:Ye,onMouseLeave:$e,onKeyDown:Q?V:void 0,tabIndex:Q?0:void 0,role:Q?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":W===null?void 0:W||`Edge from ${g} to ${E}`,"aria-describedby":Q?`${Li}-${U}`:void 0,ref:oe},!Ee&&A.createElement(e,{id:n,source:g,target:E,selected:c,animated:u,label:l,labelStyle:d,labelShowBg:m,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:x,data:o,style:v,sourceX:M,sourceY:b,targetX:$,targetY:j,sourcePosition:_,targetPosition:R,sourceHandleId:L,targetHandleId:B,markerStart:ge,markerEnd:le,pathOptions:se,interactionWidth:J}),te&&A.createElement(A.Fragment,null,(te==="source"||te===!0)&&A.createElement(Hs,{position:_,centerX:M,centerY:b,radius:O,onMouseDown:je,onMouseEnter:ze,onMouseOut:F,type:"source"}),(te==="target"||te===!0)&&A.createElement(Hs,{position:R,centerX:$,centerY:j,radius:O,onMouseDown:Re,onMouseEnter:ze,onMouseOut:F,type:"target"})))};return t.displayName="EdgeWrapper",w.memo(t)};function Rh(e){const t={default:$t(e.default||On),straight:$t(e.bezier||Vr),step:$t(e.step||Fr),smoothstep:$t(e.step||Yn),simplebezier:$t(e.simplebezier||Hr)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,o)=>(s[o]=$t(e[o]||On),s),n);return{...t,...r}}function Fs(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,o=(n==null?void 0:n.width)||t.width,i=(n==null?void 0:n.height)||t.height;switch(e){case K.Top:return{x:r+o/2,y:s};case K.Right:return{x:r+o,y:s+i/2};case K.Bottom:return{x:r+o/2,y:s+i};case K.Left:return{x:r,y:s+i/2}}}function Vs(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const Ih=(e,t,n,r,s,o)=>{const i=Fs(n,e,t),a=Fs(o,r,s);return{sourceX:i.x,sourceY:i.y,targetX:a.x,targetY:a.y}};function Th({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:o,width:i,height:a,transform:c}){const u={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+o)};u.x===u.x2&&(u.x2+=1),u.y===u.y2&&(u.y2+=1);const l=nn({x:(0-c[0])/c[2],y:(0-c[1])/c[2],width:i/c[2],height:a/c[2]}),d=Math.max(0,Math.min(l.x2,u.x2)-Math.max(l.x,u.x)),m=Math.max(0,Math.min(l.y2,u.y2)-Math.max(l.y,u.y));return Math.ceil(d*m)>0}function Bs(e){var r,s,o,i,a;const t=((r=e==null?void 0:e[we])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((o=e==null?void 0:e.positionAbsolute)==null?void 0:o.y)<"u";return[{x:((i=e==null?void 0:e.positionAbsolute)==null?void 0:i.x)||0,y:((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const Oh=[{level:0,isMaxLevel:!0,edges:[]}];function Lh(e,t,n=!1){let r=-1;const s=e.reduce((i,a)=>{var l,d;const c=Ve(a.zIndex);let u=c?a.zIndex:0;if(n){const m=t.get(a.target),f=t.get(a.source),p=a.selected||(m==null?void 0:m.selected)||(f==null?void 0:f.selected),x=Math.max(((l=f==null?void 0:f[we])==null?void 0:l.z)||0,((d=m==null?void 0:m[we])==null?void 0:d.z)||0,1e3);u=(c?a.zIndex:0)+(p?x:0)}return i[u]?i[u].push(a):i[u]=[a],r=u>r?u:r,i},{}),o=Object.entries(s).map(([i,a])=>{const c=+i;return{edges:a,level:c,isMaxLevel:c===r}});return o.length===0?Oh:o}function Dh(e,t,n){const r=me(w.useCallback(s=>e?s.edges.filter(o=>{const i=t.get(o.source),a=t.get(o.target);return(i==null?void 0:i.width)&&(i==null?void 0:i.height)&&(a==null?void 0:a.width)&&(a==null?void 0:a.height)&&Th({sourcePos:i.positionAbsolute||{x:0,y:0},targetPos:a.positionAbsolute||{x:0,y:0},sourceWidth:i.width,sourceHeight:i.height,targetWidth:a.width,targetHeight:a.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return Lh(r,t,n)}const Ph=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),zh=({color:e="none",strokeWidth:t=1})=>A.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Gs={[In.Arrow]:Ph,[In.ArrowClosed]:zh};function Hh(e){const t=ke();return w.useMemo(()=>{var s,o;return Object.prototype.hasOwnProperty.call(Gs,e)?Gs[e]:((o=(s=t.getState()).onError)==null||o.call(s,"009",at.error009(e)),null)},[e])}const Fh=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:o="strokeWidth",strokeWidth:i,orient:a="auto-start-reverse"})=>{const c=Hh(t);return c?A.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:a,refX:"0",refY:"0"},A.createElement(c,{color:n,strokeWidth:i})):null},Vh=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,o)=>([o.markerStart,o.markerEnd].forEach(i=>{if(i&&typeof i=="object"){const a=Nr(i,t);r.includes(a)||(s.push({id:a,color:i.color||e,...i}),r.push(a))}}),s),[]).sort((s,o)=>s.id.localeCompare(o.id))},Wi=({defaultColor:e,rfId:t})=>{const n=me(w.useCallback(Vh({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((o,i)=>o.id!==s[i].id)));return A.createElement("defs",null,n.map(r=>A.createElement(Fh,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};Wi.displayName="MarkerDefinitions";var Bh=w.memo(Wi);const Gh=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Ui=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:o,onEdgeContextMenu:i,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:u,onEdgeClick:l,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:x,children:v,disableKeyboardA11y:g})=>{const{edgesFocusable:E,edgesUpdatable:M,elementsSelectable:b,width:$,height:j,connectionMode:_,nodeInternals:R,onError:N}=me(Gh,Ce),I=Dh(t,R,n);return $?A.createElement(A.Fragment,null,I.map(({level:L,edges:B,isMaxLevel:H})=>A.createElement("svg",{key:L,style:{zIndex:L},width:$,height:j,className:"react-flow__edges react-flow__container"},H&&A.createElement(Bh,{defaultColor:e,rfId:r}),A.createElement("g",null,B.map(y=>{const[C,S,O]=Bs(R.get(y.source)),[D,k,T]=Bs(R.get(y.target));if(!O||!T)return null;let P=y.type||"default";s[P]||(N==null||N("011",at.error011(P)),P="default");const z=s[P]||s.default,U=_===St.Strict?k.target:(k.target??[]).concat(k.source??[]),W=Vs(S.source,y.sourceHandle),Q=Vs(U,y.targetHandle),te=(W==null?void 0:W.position)||K.Bottom,se=(Q==null?void 0:Q.position)||K.Top,J=!!(y.focusable||E&&typeof y.focusable>"u"),ae=y.reconnectable||y.updatable,oe=typeof m<"u"&&(ae||M&&typeof ae>"u");if(!W||!Q)return N==null||N("008",at.error008(W,y)),null;const{sourceX:he,sourceY:ye,targetX:Ee,targetY:ve}=Ih(C,W,te,D,Q,se);return A.createElement(z,{key:y.id,id:y.id,className:Me([y.className,o]),type:P,data:y.data,selected:!!y.selected,animated:!!y.animated,hidden:!!y.hidden,label:y.label,labelStyle:y.labelStyle,labelShowBg:y.labelShowBg,labelBgStyle:y.labelBgStyle,labelBgPadding:y.labelBgPadding,labelBgBorderRadius:y.labelBgBorderRadius,style:y.style,source:y.source,target:y.target,sourceHandleId:y.sourceHandle,targetHandleId:y.targetHandle,markerEnd:y.markerEnd,markerStart:y.markerStart,sourceX:he,sourceY:ye,targetX:Ee,targetY:ve,sourcePosition:te,targetPosition:se,elementsSelectable:b,onContextMenu:i,onMouseEnter:a,onMouseMove:c,onMouseLeave:u,onClick:l,onEdgeDoubleClick:d,onReconnect:m,onReconnectStart:f,onReconnectEnd:p,reconnectRadius:x,rfId:r,ariaLabel:y.ariaLabel,isFocusable:J,isReconnectable:oe,pathOptions:"pathOptions"in y?y.pathOptions:void 0,interactionWidth:y.interactionWidth,disableKeyboardA11y:g})})))),v):null};Ui.displayName="EdgeRenderer";var Yh=w.memo(Ui);const Xh=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Wh({children:e}){const t=me(Xh);return A.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function Uh(e){const t=un(),n=w.useRef(!1);w.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const qh={[K.Left]:K.Right,[K.Right]:K.Left,[K.Top]:K.Bottom,[K.Bottom]:K.Top},qi=({nodeId:e,handleType:t,style:n,type:r=mt.Bezier,CustomComponent:s,connectionStatus:o})=>{var j,_,R;const{fromNode:i,handleId:a,toX:c,toY:u,connectionMode:l}=me(w.useCallback(N=>({fromNode:N.nodeInternals.get(e),handleId:N.connectionHandleId,toX:(N.connectionPosition.x-N.transform[0])/N.transform[2],toY:(N.connectionPosition.y-N.transform[1])/N.transform[2],connectionMode:N.connectionMode}),[e]),Ce),d=(j=i==null?void 0:i[we])==null?void 0:j.handleBounds;let m=d==null?void 0:d[t];if(l===St.Loose&&(m=m||(d==null?void 0:d[t==="source"?"target":"source"])),!i||!m)return null;const f=a?m.find(N=>N.id===a):m[0],p=f?f.x+f.width/2:(i.width??0)/2,x=f?f.y+f.height/2:i.height??0,v=(((_=i.positionAbsolute)==null?void 0:_.x)??0)+p,g=(((R=i.positionAbsolute)==null?void 0:R.y)??0)+x,E=f==null?void 0:f.position,M=E?qh[E]:null;if(!E||!M)return null;if(s)return A.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:i,fromHandle:f,fromX:v,fromY:g,toX:c,toY:u,fromPosition:E,toPosition:M,connectionStatus:o});let b="";const $={sourceX:v,sourceY:g,sourcePosition:E,targetX:c,targetY:u,targetPosition:M};return r===mt.Bezier?[b]=bi($):r===mt.Step?[b]=Tn({...$,borderRadius:0}):r===mt.SmoothStep?[b]=Tn($):r===mt.SimpleBezier?[b]=wi($):b=`M${v},${g} ${c},${u}`,A.createElement("path",{d:b,fill:"none",className:"react-flow__connection-path",style:n})};qi.displayName="ConnectionLine";const Kh=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function Zh({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:o,nodesConnectable:i,width:a,height:c,connectionStatus:u}=me(Kh,Ce);return!(s&&o&&a&&i)?null:A.createElement("svg",{style:e,width:a,height:c,className:"react-flow__edges react-flow__connectionline react-flow__container"},A.createElement("g",{className:Me(["react-flow__connection",u])},A.createElement(qi,{nodeId:s,handleType:o,style:t,type:n,CustomComponent:r,connectionStatus:u})))}function Ys(e,t){return w.useRef(null),ke(),w.useMemo(()=>t(e),[e])}const Ki=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:o,onNodeClick:i,onEdgeClick:a,onNodeDoubleClick:c,onEdgeDoubleClick:u,onNodeMouseEnter:l,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,onSelectionContextMenu:p,onSelectionStart:x,onSelectionEnd:v,connectionLineType:g,connectionLineStyle:E,connectionLineComponent:M,connectionLineContainerStyle:b,selectionKeyCode:$,selectionOnDrag:j,selectionMode:_,multiSelectionKeyCode:R,panActivationKeyCode:N,zoomActivationKeyCode:I,deleteKeyCode:L,onlyRenderVisibleElements:B,elementsSelectable:H,selectNodesOnDrag:y,defaultViewport:C,translateExtent:S,minZoom:O,maxZoom:D,preventScrolling:k,defaultMarkerColor:T,zoomOnScroll:P,zoomOnPinch:z,panOnScroll:U,panOnScrollSpeed:W,panOnScrollMode:Q,zoomOnDoubleClick:te,panOnDrag:se,onPaneClick:J,onPaneMouseEnter:ae,onPaneMouseMove:oe,onPaneMouseLeave:he,onPaneScroll:ye,onPaneContextMenu:Ee,onEdgeContextMenu:ve,onEdgeMouseEnter:ue,onEdgeMouseMove:ge,onEdgeMouseLeave:le,onReconnect:q,onReconnectStart:fe,onReconnectEnd:Oe,reconnectRadius:Ke,noDragClassName:Ye,noWheelClassName:$e,noPanClassName:Ae,elevateEdgesOnSelect:je,disableKeyboardA11y:Re,nodeOrigin:ze,nodeExtent:F,rfId:X})=>{const V=Ys(e,Sh),Z=Ys(t,Rh);return Uh(o),A.createElement(Eh,{onPaneClick:J,onPaneMouseEnter:ae,onPaneMouseMove:oe,onPaneMouseLeave:he,onPaneContextMenu:Ee,onPaneScroll:ye,deleteKeyCode:L,selectionKeyCode:$,selectionOnDrag:j,selectionMode:_,onSelectionStart:x,onSelectionEnd:v,multiSelectionKeyCode:R,panActivationKeyCode:N,zoomActivationKeyCode:I,elementsSelectable:H,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:P,zoomOnPinch:z,zoomOnDoubleClick:te,panOnScroll:U,panOnScrollSpeed:W,panOnScrollMode:Q,panOnDrag:se,defaultViewport:C,translateExtent:S,minZoom:O,maxZoom:D,onSelectionContextMenu:p,preventScrolling:k,noDragClassName:Ye,noWheelClassName:$e,noPanClassName:Ae,disableKeyboardA11y:Re},A.createElement(Wh,null,A.createElement(Yh,{edgeTypes:Z,onEdgeClick:a,onEdgeDoubleClick:u,onlyRenderVisibleElements:B,onEdgeContextMenu:ve,onEdgeMouseEnter:ue,onEdgeMouseMove:ge,onEdgeMouseLeave:le,onReconnect:q,onReconnectStart:fe,onReconnectEnd:Oe,reconnectRadius:Ke,defaultMarkerColor:T,noPanClassName:Ae,elevateEdgesOnSelect:!!je,disableKeyboardA11y:Re,rfId:X},A.createElement(Zh,{style:E,type:g,component:M,containerStyle:b})),A.createElement("div",{className:"react-flow__edgelabel-renderer"}),A.createElement(Ch,{nodeTypes:V,onNodeClick:i,onNodeDoubleClick:c,onNodeMouseEnter:l,onNodeMouseMove:d,onNodeMouseLeave:m,onNodeContextMenu:f,selectNodesOnDrag:y,onlyRenderVisibleElements:B,noPanClassName:Ae,noDragClassName:Ye,disableKeyboardA11y:Re,nodeOrigin:ze,nodeExtent:F,rfId:X})))};Ki.displayName="GraphView";var Qh=w.memo(Ki);const Cr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ut={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:Cr,nodeExtent:Cr,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:St.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:Nf,isValidConnection:void 0},Jh=()=>Pc((e,t)=>({...ut,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:o}=t();e({nodeInternals:tr(n,r,s,o)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",o=typeof r<"u",i=s?tr(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:i,edges:o?r:[],hasDefaultNodes:s,hasDefaultEdges:o})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:o,fitViewOnInitDone:i,fitViewOnInitOptions:a,domNode:c,nodeOrigin:u}=t(),l=c==null?void 0:c.querySelector(".react-flow__viewport");if(!l)return;const d=window.getComputedStyle(l),{m22:m}=new window.DOMMatrixReadOnly(d.transform),f=n.reduce((x,v)=>{const g=s.get(v.id);if(g!=null&&g.hidden)s.set(g.id,{...g,[we]:{...g[we],handleBounds:void 0}});else if(g){const E=Pr(v.nodeElement);!!(E.width&&E.height&&(g.width!==E.width||g.height!==E.height||v.forceUpdate))&&(s.set(g.id,{...g,[we]:{...g[we],handleBounds:{source:Ps(".source",v.nodeElement,m,u),target:Ps(".target",v.nodeElement,m,u)}},...E}),x.push({id:g.id,type:"dimensions",dimensions:E}))}return x},[]);Pi(s,u);const p=i||o&&!i&&zi(t,{initial:!0,...a});e({nodeInternals:new Map(s),fitViewOnInitDone:p}),(f==null?void 0:f.length)>0&&(r==null||r(f))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:o}=t(),i=n.map(a=>{const c={id:a.id,type:"position",dragging:s};return r&&(c.positionAbsolute=a.positionAbsolute,c.position=a.position),c});o(i)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:o,nodeOrigin:i,getNodes:a,elevateNodesOnSelect:c}=t();if(n!=null&&n.length){if(o){const u=mh(n,a()),l=tr(u,s,i,c);e({nodeInternals:l})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:o}=t();let i,a=null;r?i=n.map(c=>ht(c,!0)):(i=At(o(),n),a=At(s,[])),wn({changedNodes:i,changedEdges:a,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:o}=t();let i,a=null;r?i=n.map(c=>ht(c,!0)):(i=At(s,n),a=At(o(),[])),wn({changedNodes:a,changedEdges:i,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:o}=t(),i=n||o(),a=r||s,c=i.map(l=>(l.selected=!1,ht(l.id,!1))),u=a.map(l=>ht(l.id,!1));wn({changedNodes:c,changedEdges:u,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),o=r().filter(a=>a.selected).map(a=>ht(a.id,!1)),i=n.filter(a=>a.selected).map(a=>ht(a.id,!1));wn({changedNodes:o,changedEdges:i,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=zr(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:o,d3Zoom:i,d3Selection:a,translateExtent:c}=t();if(!i||!a||!n.x&&!n.y)return!1;const u=ot.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),l=[[0,0],[s,o]],d=i==null?void 0:i.constrain()(u,l,c);return i.transform(a,d),r[0]!==d.x||r[1]!==d.y||r[2]!==d.k},cancelConnection:()=>e({connectionNodeId:ut.connectionNodeId,connectionHandleId:ut.connectionHandleId,connectionHandleType:ut.connectionHandleType,connectionStatus:ut.connectionStatus,connectionStartHandle:ut.connectionStartHandle,connectionEndHandle:ut.connectionEndHandle}),reset:()=>e({...ut})}),Object.is),Zi=({children:e})=>{const t=w.useRef(null);return t.current||(t.current=Jh()),A.createElement(yf,{value:t.current},e)};Zi.displayName="ReactFlowProvider";const Qi=({children:e})=>w.useContext(Gn)?A.createElement(A.Fragment,null,e):A.createElement(Zi,null,e);Qi.displayName="ReactFlowWrapper";const em={input:Ai,default:kr,output:Ii,group:Yr},tm={default:On,straight:Vr,step:Fr,smoothstep:Yn,simplebezier:Hr},nm=[0,0],rm=[15,15],sm={x:0,y:0,zoom:1},om={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Ji=w.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:o=em,edgeTypes:i=tm,onNodeClick:a,onEdgeClick:c,onInit:u,onMove:l,onMoveStart:d,onMoveEnd:m,onConnect:f,onConnectStart:p,onConnectEnd:x,onClickConnectStart:v,onClickConnectEnd:g,onNodeMouseEnter:E,onNodeMouseMove:M,onNodeMouseLeave:b,onNodeContextMenu:$,onNodeDoubleClick:j,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:N,onNodesDelete:I,onEdgesDelete:L,onSelectionChange:B,onSelectionDragStart:H,onSelectionDrag:y,onSelectionDragStop:C,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,connectionMode:k=St.Strict,connectionLineType:T=mt.Bezier,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:U,deleteKeyCode:W="Backspace",selectionKeyCode:Q="Shift",selectionOnDrag:te=!1,selectionMode:se=rn.Full,panActivationKeyCode:J="Space",multiSelectionKeyCode:ae=Rn()?"Meta":"Control",zoomActivationKeyCode:oe=Rn()?"Meta":"Control",snapToGrid:he=!1,snapGrid:ye=rm,onlyRenderVisibleElements:Ee=!1,selectNodesOnDrag:ve=!0,nodesDraggable:ue,nodesConnectable:ge,nodesFocusable:le,nodeOrigin:q=nm,edgesFocusable:fe,edgesUpdatable:Oe,elementsSelectable:Ke,defaultViewport:Ye=sm,minZoom:$e=.5,maxZoom:Ae=2,translateExtent:je=Cr,preventScrolling:Re=!0,nodeExtent:ze,defaultMarkerColor:F="#b1b1b7",zoomOnScroll:X=!0,zoomOnPinch:V=!0,panOnScroll:Z=!1,panOnScrollSpeed:Y=.5,panOnScrollMode:G=vt.Free,zoomOnDoubleClick:re=!0,panOnDrag:xe=!0,onPaneClick:ee,onPaneMouseEnter:ne,onPaneMouseMove:ie,onPaneMouseLeave:pe,onPaneScroll:Ie,onPaneContextMenu:Le,children:Te,onEdgeContextMenu:Ne,onEdgeDoubleClick:He,onEdgeMouseEnter:lt,onEdgeMouseMove:Ht,onEdgeMouseLeave:de,onEdgeUpdate:et,onEdgeUpdateStart:Ft,onEdgeUpdateEnd:Pa,onReconnect:za,onReconnectStart:Ha,onReconnectEnd:Fa,reconnectRadius:Va=10,edgeUpdaterRadius:Ba=10,onNodesChange:Ga,onEdgesChange:Ya,noDragClassName:Xa="nodrag",noWheelClassName:Wa="nowheel",noPanClassName:es="nopan",fitView:Ua=!1,fitViewOptions:qa,connectOnClick:Ka=!0,attributionPosition:Za,proOptions:Qa,defaultEdgeOptions:Ja,elevateNodesOnSelect:ec=!0,elevateEdgesOnSelect:tc=!1,disableKeyboardA11y:ts=!1,autoPanOnConnect:nc=!0,autoPanOnNodeDrag:rc=!0,connectionRadius:sc=20,isValidConnection:oc,onError:ic,style:ac,id:ns,nodeDragThreshold:cc,...lc},uc)=>{const Un=ns||"1";return A.createElement("div",{...lc,style:{...ac,...om},ref:uc,className:Me(["react-flow",s]),"data-testid":"rf__wrapper",id:ns},A.createElement(Qi,null,A.createElement(Qh,{onInit:u,onMove:l,onMoveStart:d,onMoveEnd:m,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:E,onNodeMouseMove:M,onNodeMouseLeave:b,onNodeContextMenu:$,onNodeDoubleClick:j,nodeTypes:o,edgeTypes:i,connectionLineType:T,connectionLineStyle:P,connectionLineComponent:z,connectionLineContainerStyle:U,selectionKeyCode:Q,selectionOnDrag:te,selectionMode:se,deleteKeyCode:W,multiSelectionKeyCode:ae,panActivationKeyCode:J,zoomActivationKeyCode:oe,onlyRenderVisibleElements:Ee,selectNodesOnDrag:ve,defaultViewport:Ye,translateExtent:je,minZoom:$e,maxZoom:Ae,preventScrolling:Re,zoomOnScroll:X,zoomOnPinch:V,zoomOnDoubleClick:re,panOnScroll:Z,panOnScrollSpeed:Y,panOnScrollMode:G,panOnDrag:xe,onPaneClick:ee,onPaneMouseEnter:ne,onPaneMouseMove:ie,onPaneMouseLeave:pe,onPaneScroll:Ie,onPaneContextMenu:Le,onSelectionContextMenu:S,onSelectionStart:O,onSelectionEnd:D,onEdgeContextMenu:Ne,onEdgeDoubleClick:He,onEdgeMouseEnter:lt,onEdgeMouseMove:Ht,onEdgeMouseLeave:de,onReconnect:za??et,onReconnectStart:Ha??Ft,onReconnectEnd:Fa??Pa,reconnectRadius:Va??Ba,defaultMarkerColor:F,noDragClassName:Xa,noWheelClassName:Wa,noPanClassName:es,elevateEdgesOnSelect:tc,rfId:Un,disableKeyboardA11y:ts,nodeOrigin:q,nodeExtent:ze}),A.createElement(Uf,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:f,onConnectStart:p,onConnectEnd:x,onClickConnectStart:v,onClickConnectEnd:g,nodesDraggable:ue,nodesConnectable:ge,nodesFocusable:le,edgesFocusable:fe,edgesUpdatable:Oe,elementsSelectable:Ke,elevateNodesOnSelect:ec,minZoom:$e,maxZoom:Ae,nodeExtent:ze,onNodesChange:Ga,onEdgesChange:Ya,snapToGrid:he,snapGrid:ye,connectionMode:k,translateExtent:je,connectOnClick:Ka,defaultEdgeOptions:Ja,fitView:Ua,fitViewOptions:qa,onNodesDelete:I,onEdgesDelete:L,onNodeDragStart:_,onNodeDrag:R,onNodeDragStop:N,onSelectionDrag:y,onSelectionDragStart:H,onSelectionDragStop:C,noPanClassName:es,nodeOrigin:q,rfId:Un,autoPanOnConnect:nc,autoPanOnNodeDrag:rc,onError:ic,connectionRadius:sc,isValidConnection:oc,nodeDragThreshold:cc}),A.createElement(Xf,{onSelectionChange:B}),Te,A.createElement(wf,{proOptions:Qa,position:Za}),A.createElement(Jf,{rfId:Un,disableKeyboardA11y:ts})))});Ji.displayName="ReactFlow";const ea=({id:e,x:t,y:n,width:r,height:s,style:o,color:i,strokeColor:a,strokeWidth:c,className:u,borderRadius:l,shapeRendering:d,onClick:m,selected:f})=>{const{background:p,backgroundColor:x}=o||{},v=i||p||x;return A.createElement("rect",{className:Me(["react-flow__minimap-node",{selected:f},u]),x:t,y:n,rx:l,ry:l,width:r,height:s,fill:v,stroke:a,strokeWidth:c,shapeRendering:d,onClick:m?g=>m(g,e):void 0})};ea.displayName="MiniMapNode";var im=w.memo(ea);const am=e=>e.nodeOrigin,cm=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),or=e=>e instanceof Function?e:()=>e;function lm({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:o=im,onClick:i}){const a=me(cm,Ce),c=me(am),u=or(t),l=or(e),d=or(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return A.createElement(A.Fragment,null,a.map(f=>{const{x:p,y:x}=Et(f,c).positionAbsolute;return A.createElement(o,{key:f.id,x:p,y:x,width:f.width,height:f.height,style:f.style,selected:f.selected,className:d(f),color:u(f),borderRadius:r,strokeColor:l(f),strokeWidth:s,shapeRendering:m,onClick:i,id:f.id})}))}var um=w.memo(lm);const dm=200,fm=150,hm=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?_f(ln(t,e.nodeOrigin),n):n,rfId:e.rfId}},mm="react-flow__minimap-desc";function ta({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:o=5,nodeStrokeWidth:i=2,nodeComponent:a,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:u="none",maskStrokeWidth:l=1,position:d="bottom-right",onClick:m,onNodeClick:f,pannable:p=!1,zoomable:x=!1,ariaLabel:v="React Flow mini map",inversePan:g=!1,zoomStep:E=10,offsetScale:M=5}){const b=ke(),$=w.useRef(null),{boundingRect:j,viewBB:_,rfId:R}=me(hm,Ce),N=(e==null?void 0:e.width)??dm,I=(e==null?void 0:e.height)??fm,L=j.width/N,B=j.height/I,H=Math.max(L,B),y=H*N,C=H*I,S=M*H,O=j.x-(y-j.width)/2-S,D=j.y-(C-j.height)/2-S,k=y+S*2,T=C+S*2,P=`${mm}-${R}`,z=w.useRef(0);z.current=H,w.useEffect(()=>{if($.current){const Q=Fe($.current),te=ae=>{const{transform:oe,d3Selection:he,d3Zoom:ye}=b.getState();if(ae.sourceEvent.type!=="wheel"||!he||!ye)return;const Ee=-ae.sourceEvent.deltaY*(ae.sourceEvent.deltaMode===1?.05:ae.sourceEvent.deltaMode?1:.002)*E,ve=oe[2]*Math.pow(2,Ee);ye.scaleTo(he,ve)},se=ae=>{const{transform:oe,d3Selection:he,d3Zoom:ye,translateExtent:Ee,width:ve,height:ue}=b.getState();if(ae.sourceEvent.type!=="mousemove"||!he||!ye)return;const ge=z.current*Math.max(1,oe[2])*(g?-1:1),le={x:oe[0]-ae.sourceEvent.movementX*ge,y:oe[1]-ae.sourceEvent.movementY*ge},q=[[0,0],[ve,ue]],fe=ot.translate(le.x,le.y).scale(oe[2]),Oe=ye.constrain()(fe,q,Ee);ye.transform(he,Oe)},J=li().on("zoom",p?se:null).on("zoom.wheel",x?te:null);return Q.call(J),()=>{Q.on("zoom",null)}}},[p,x,g,E]);const U=m?Q=>{const te=Xe(Q);m(Q,{x:te[0],y:te[1]})}:void 0,W=f?(Q,te)=>{const se=b.getState().nodeInternals.get(te);f(Q,se)}:void 0;return A.createElement(Dr,{position:d,style:e,className:Me(["react-flow__minimap",t]),"data-testid":"rf__minimap"},A.createElement("svg",{width:N,height:I,viewBox:`${O} ${D} ${k} ${T}`,role:"img","aria-labelledby":P,ref:$,onClick:U},v&&A.createElement("title",{id:P},v),A.createElement(um,{onClick:W,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:o,nodeClassName:s,nodeStrokeWidth:i,nodeComponent:a}),A.createElement("path",{className:"react-flow__minimap-mask",d:`M${O-S},${D-S}h${k+S*2}v${T+S*2}h${-k-S*2}z + M${_.x},${_.y}h${_.width}v${_.height}h${-_.width}z`,fill:c,fillRule:"evenodd",stroke:u,strokeWidth:l,pointerEvents:"none"})))}ta.displayName="MiniMap";var pm=w.memo(ta);function gm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},A.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function ym(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},A.createElement("path",{d:"M0 0h32v4.2H0z"}))}function xm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},A.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function wm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function bm(){return A.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},A.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const qt=({children:e,className:t,...n})=>A.createElement("button",{type:"button",className:Me(["react-flow__controls-button",t]),...n},e);qt.displayName="ControlButton";const vm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),na=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:o,onZoomOut:i,onFitView:a,onInteractiveChange:c,className:u,children:l,position:d="bottom-left"})=>{const m=ke(),[f,p]=w.useState(!1),{isInteractive:x,minZoomReached:v,maxZoomReached:g}=me(vm,Ce),{zoomIn:E,zoomOut:M,fitView:b}=un();if(w.useEffect(()=>{p(!0)},[]),!f)return null;const $=()=>{E(),o==null||o()},j=()=>{M(),i==null||i()},_=()=>{b(s),a==null||a()},R=()=>{m.setState({nodesDraggable:!x,nodesConnectable:!x,elementsSelectable:!x}),c==null||c(!x)};return A.createElement(Dr,{className:Me(["react-flow__controls",u]),position:d,style:e,"data-testid":"rf__controls"},t&&A.createElement(A.Fragment,null,A.createElement(qt,{onClick:$,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:g},A.createElement(gm,null)),A.createElement(qt,{onClick:j,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:v},A.createElement(ym,null))),n&&A.createElement(qt,{className:"react-flow__controls-fitview",onClick:_,title:"fit view","aria-label":"fit view"},A.createElement(xm,null)),r&&A.createElement(qt,{className:"react-flow__controls-interactive",onClick:R,title:"toggle interactivity","aria-label":"toggle interactivity"},x?A.createElement(bm,null):A.createElement(wm,null)),l)};na.displayName="Controls";var _m=w.memo(na),Be;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Be||(Be={}));function Em({color:e,dimensions:t,lineWidth:n}){return A.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function Nm({color:e,radius:t}){return A.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const Sm={[Be.Dots]:"#91919a",[Be.Lines]:"#eee",[Be.Cross]:"#e2e2e2"},km={[Be.Dots]:1,[Be.Lines]:1,[Be.Cross]:6},jm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function ra({id:e,variant:t=Be.Dots,gap:n=20,size:r,lineWidth:s=1,offset:o=2,color:i,style:a,className:c}){const u=w.useRef(null),{transform:l,patternId:d}=me(jm,Ce),m=i||Sm[t],f=r||km[t],p=t===Be.Dots,x=t===Be.Cross,v=Array.isArray(n)?n:[n,n],g=[v[0]*l[2]||1,v[1]*l[2]||1],E=f*l[2],M=x?[E,E]:g,b=p?[E/o,E/o]:[M[0]/o,M[1]/o];return A.createElement("svg",{className:Me(["react-flow__background",c]),style:{...a,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:u,"data-testid":"rf__background"},A.createElement("pattern",{id:d+e,x:l[0]%g[0],y:l[1]%g[1],width:g[0],height:g[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`},p?A.createElement(Nm,{color:m,radius:E/o}):A.createElement(Em,{dimensions:M,color:m,lineWidth:s})),A.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${d+e})`}))}ra.displayName="Background";var Cm=w.memo(ra);const Wr=(()=>{const e=window.location.pathname.match(/^(\/view\/[^/]+)(?:\/|$)/);return e?e[1]:""})();function Ln(e){return Wr+e}async function be(e){const t=await fetch(Ln(e));if(!t.ok)throw new Error(`${e}: ${t.status} ${await t.text()}`);return await t.json()}async function ct(e,t){const n=await fetch(Ln(e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw new sa(r.error??`${e}: ${n.status}`,n.status);return r}class sa extends Error{constructor(n,r){super(n);_e(this,"status");this.status=r}}const Hx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),Fx=()=>be("/api/diagnostics"),oa=(e,t)=>be(`/api/ontology/search?q=${encodeURIComponent(e)}`+(t?`&within=${encodeURIComponent(t)}`:"")),ia=()=>be("/api/ontology/ontologies"),Mm=e=>be(`/api/ontology/term?ref=${encodeURIComponent(e)}`),$m=()=>be("/api/ontology/stack"),Am=()=>be("/api/ontology/coverage"),Rm=(e,t,n)=>ct("/api/command",{op:e,payload:t,fingerprint:n??""}),Im=()=>be("/api/git/status"),Tm=()=>be("/api/git/diff"),Om=e=>ct("/api/git/commit",{message:e}),Lm=()=>ct("/api/git/discard",{}),Dm=()=>be("/api/decisions"),Xs=(e,t)=>ct(`/api/decisions/${e}/verdict`,{verdict:t}),Vx=(e={})=>{const t=new URLSearchParams;return e.subject_area&&t.set("subject_area",e.subject_area),e.q&&t.set("q",e.q),be(`/api/glossary/terms?${t.toString()}`)},Bx=()=>be("/api/glossary/config"),Gx=e=>ct("/api/git/propose",e),Yx=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Xx=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),Wx=e=>ct("/api/git/classify",{changes:e}),Ux=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),qx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Kx=(e="")=>be(`/api/git/proposals?user=${encodeURIComponent(e)}`),Pm=()=>be("/api/export"),zm=(e,t)=>{const n=t?`?dialect=${encodeURIComponent(t)}`:"";return`${Wr}/api/export/${encodeURIComponent(e)}${n}`},Hm=(e,t,n)=>ct("/api/import",{format:e,content:t,dialect:n}),Fm=(e,t)=>ct("/api/import/preview",{format:e,content:t}),Zx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Qx=async(e,t=!1)=>{for(const n of e)try{await Rm(n.op,n.payload)}catch(r){if(t&&r instanceof Error&&/already exists/i.test(r.message))continue;throw r}},Jx=(e,t,n)=>fetch(`${Wr}/api/preview`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({changes:e,subject_area:t??""}),signal:n}).then(async r=>{if(!r.ok)throw new sa(await r.text(),r.status);return await r.json()}),ew=()=>be("/api/glossary/subject-areas"),tw=e=>be(`/api/glossary/subject-area/${e}`),nw=(e,t)=>ct(`/api/glossary/subject-area/${e}/expand`,t);function rw(){return{async load(e){try{const t=await be(`/api/layout?view=${encodeURIComponent(e)}`);return{nodes:t.nodes??{},edges:t.edges??{}}}catch{return{nodes:{},edges:{}}}},async save(e,t){try{await fetch(Ln("/api/layout"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({view:e,nodes:t.nodes,edges:t.edges})})}catch{}},async reset(e){try{const t=e?`?view=${encodeURIComponent(e)}`:"";await fetch(Ln(`/api/layout${t}`),{method:"DELETE"})}catch{}}}}const Vm={business_key:"🔑",surrogate_key:"#",measure:"Σ",attribute:""};function Bm(e){return e??""}const Ur="__entity_source",qr="__entity_target",Gm=w.memo(function({data:t,selected:n}){var j;const{entity:r,color:s,dimmed:o,highlighted:i,showTypes:a,collapseDetail:c,expanded:u,onToggleExpand:l,endpointAttrs:d,highlightAttrs:m,dimAttrs:f,onHoverAttr:p}=t,x=_=>_.role==="business_key"?0:d!=null&&d.has(_.id)?1:2,v=[...r.attributes].map((_,R)=>({a:_,i:R})).sort((_,R)=>x(_.a)-x(R.a)||_.i-R.i).map(_=>_.a),g=v.filter(_=>_.role==="business_key");let E=v.filter(_=>_.role!=="business_key");const M=!!c&&!u;let b=0;if(M){const _=E.filter(R=>d==null?void 0:d.has(R.id));b=E.length-_.length,E=_}const $=(_,R)=>{const N="attr-row"+(m!=null&&m.has(_.id)?" rel-hit":"")+(f!=null&&f.has(_.id)?" rel-dim":"")+(d!=null&&d.has(_.id)?" endpoint":"");return h.jsxs("div",{className:N,onMouseEnter:p?()=>p(_.id):void 0,onMouseLeave:p?()=>p(null):void 0,children:[h.jsx(pt,{id:_.id,type:"target",position:K.Left,className:"port attr-port"}),h.jsx(pt,{id:_.id,type:"source",position:K.Right,className:"port attr-port"}),h.jsx("span",{className:"attr-icon",children:Vm[_.role]}),h.jsx("span",{className:"attr-name"+(R?" pk":""),children:_.name}),a&&h.jsx("span",{className:"attr-type",children:Bm(_.domain)}),!_.nullable&&h.jsx("span",{className:"attr-notnull",title:"not null",children:"●"})]},_.id)};return h.jsxs("div",{className:"entity-node"+(n?" selected":"")+(o?" dimmed":"")+(i?" highlighted":""),style:{borderTopColor:s},children:[h.jsx(pt,{id:qr,type:"target",position:K.Left,className:"port"}),h.jsx(pt,{id:Ur,type:"source",position:K.Right,className:"port"}),h.jsxs("div",{className:"entity-header",children:[h.jsx("span",{className:"entity-name",title:((j=r.conceptual)==null?void 0:j.definition)??void 0,children:r.name}),h.jsxs("span",{className:"entity-badges",children:[r.pattern&&h.jsx("span",{className:"badge pattern",children:r.pattern}),(()=>{var N;const _=(((N=r.conceptual)==null?void 0:N.ontology_refs)??[]).filter(I=>I.uri);if(_.length===0)return null;const R=_.map(I=>I.uri).join(` +`);return h.jsxs("span",{className:"badge ontology",title:R,children:["⚙",_.length>1?` ${_.length}`:""]})})()]})]}),g.length>0&&h.jsx("div",{className:"attr-section keys",children:g.map(_=>$(_,!0))}),h.jsxs("div",{className:"attr-section",children:[E.map(_=>$(_,!1)),r.attributes.length===0&&h.jsx("div",{className:"attr-row empty",children:"no attributes"}),b>0&&h.jsx("div",{className:"attr-row more",title:"Show all columns",onClick:l?()=>l(r.id):void 0,children:`+${b} more`}),u&&!!c&&h.jsx("div",{className:"attr-row more",title:"Collapse to keys",onClick:l?()=>l(r.id):void 0,children:"− collapse"})]})]})}),Ym=["string","integer","bigint","decimal","boolean","date","timestamp"];function Xm({entity:e,doc:t,caps:n,exec:r,onClose:s,onFocusEntity:o,onAlign:i,onEditMapping:a}){var m,f,p,x,v,g,E,M,b,$,j,_,R;const c=!n.canEdit,u=e.conceptual,l=t.relationships.filter(N=>N.from.entity===e.id||N.to.entity===e.id),d=N=>{var I;return((I=t.entities.find(L=>L.id===N))==null?void 0:I.name)??N};return h.jsxs("aside",{className:"detail-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("div",{style:{flex:1},children:[h.jsx(nt,{value:e.name,className:"entity-title-input",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,name:N})}),(e.physical_name||!c)&&h.jsxs("div",{className:"physical-name-row",title:"Physical table name (erwin Physical_Name)",children:[h.jsx("span",{className:"physical-label",children:"physical"}),h.jsx(nt,{value:e.physical_name??"",className:"physical-name-input",placeholder:c?"—":"physical table name…",readOnly:c,onCommit:N=>r("rename_entity",{id:e.id,physical_name:N})})]}),h.jsxs("div",{children:[h.jsx(Um,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Km,{entity:e,readOnly:c,exec:r}),e.category&&h.jsx("span",{className:"cat-badge "+e.category.role,title:e.category.role==="supertype"?`Supertype of category "${e.category.category}"`:`Subtype in "${e.category.category}" (${e.category.materialization})`,children:e.category.role==="supertype"?"◆ supertype":"◇ subtype"})]})]}),h.jsx("button",{className:"icon-btn",onClick:s,title:"Close",children:"✕"})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Definition"}),h.jsx(nt,{value:((m=u==null?void 0:u.definition)==null?void 0:m.trim())??"",multiline:!0,placeholder:c?"—":"add a business definition…",className:"definition-input",readOnly:c,onCommit:N=>r("set_definition",{id:e.id,definition:N})})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Ontology",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>i(e),children:(((f=u==null?void 0:u.ontology_refs)==null?void 0:f.length)??0)>0?"Add / re-align…":"Align…"}),(((p=u==null?void 0:u.ontology_refs)==null?void 0:p.length)??0)>0&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e.id}),title:"Clear every alignment on this object",children:"Clear all"})]})]}),(u==null?void 0:u.ontology_layer)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"layer"}),h.jsx("span",{className:`chip layer-${u.ontology_layer}`,children:u.ontology_layer}),u.no_industry_equivalent&&h.jsx("span",{className:"chip",title:"reviewed: no industry equivalent",children:"no industry equivalent"})]}),h.jsx(Wm,{entityId:e.id,refs:(u==null?void 0:u.ontology_refs)??[],caps:n,exec:r})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Knowledge Graph mapping",!c&&h.jsxs("span",{className:"h3-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(e),children:(x=e.term_map)!=null&&x.subject_template||(v=e.term_map)!=null&&v.class_iri?"Edit mapping…":"Map…"}),(((g=e.term_map)==null?void 0:g.subject_template)||((E=e.term_map)==null?void 0:E.class_iri))&&h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_term_map",{id:e.id}),children:"Clear"})]})]}),(M=e.term_map)!=null&&M.subject_template||(b=e.term_map)!=null&&b.class_iri?h.jsxs(h.Fragment,{children:[(($=e.term_map)==null?void 0:$.class_iri)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"class IRI"}),h.jsx("code",{className:"v",children:e.term_map.class_iri})]}),((j=e.term_map)==null?void 0:j.subject_template)&&h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"subject"}),h.jsx("code",{className:"v",children:e.term_map.subject_template})]})]}):h.jsxs("p",{className:"empty-hint",children:["uses the default R2RML term-map (base IRI",t.project.kg_base_iri?` ${t.project.kg_base_iri}`:""," + primary key)"]})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Stewardship"}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"owner"}),h.jsx(nt,{value:((_=u==null?void 0:u.stewardship)==null?void 0:_.owner)??"",placeholder:"—",readOnly:c,onCommit:N=>{var I;return r("set_stewardship",{id:e.id,owner:N,steward:((I=u==null?void 0:u.stewardship)==null?void 0:I.steward)??null})}})]}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"steward"}),h.jsx(nt,{value:((R=u==null?void 0:u.stewardship)==null?void 0:R.steward)??"",placeholder:"—",readOnly:c,onCommit:N=>{var I;return r("set_stewardship",{id:e.id,owner:((I=u==null?void 0:u.stewardship)==null?void 0:I.owner)??null,steward:N})}})]})]}),h.jsxs("section",{children:[h.jsxs("h3",{children:["Attributes (",e.attributes.length,")"]}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:e.attributes.map(N=>h.jsx(Qm,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(Jm,{entity:e,exec:r})]}),e.key_groups&&e.key_groups.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Keys (",e.key_groups.length,")"]}),e.key_groups.map(N=>{const I=N.members.map(L=>{var B;return((B=e.attributes.find(H=>H.id===L))==null?void 0:B.name)??"?"}).join(", ");return h.jsxs("div",{className:"key-row",children:[h.jsx("span",{className:"key-badge "+N.type,children:N.type.toUpperCase()}),h.jsx("span",{className:"key-name",children:N.name}),h.jsx("span",{className:"key-cols",children:I})]},N.id)})]}),e.udp&&Object.keys(e.udp).length>0&&h.jsxs("section",{children:[h.jsx("h3",{children:"Properties (UDP)"}),h.jsx("table",{className:"attr-table",children:h.jsx("tbody",{children:Object.entries(e.udp).map(([N,I])=>h.jsxs("tr",{className:"udp-row",children:[h.jsx("td",{className:"udp-key",children:N}),h.jsx("td",{className:"udp-val",children:String(I)})]},N))})})]}),l.length>0&&h.jsxs("section",{children:[h.jsxs("h3",{children:["Relationships (",l.length,")"]}),l.map(N=>{const I=N.from.entity===e.id?N.to.entity:N.from.entity;return h.jsxs("div",{className:"rel-row",children:[h.jsxs("div",{className:"rel-main",children:[h.jsxs("button",{className:"rel-link",onClick:()=>o(I),children:[h.jsx("span",{className:"rel-card",children:ep(N,e.id)}),d(I)]}),(N.verb_phrase||N.inverse_verb_phrase||!c)&&h.jsxs("div",{className:"verb-phrases",title:"erwin verb phrases (parent → child, and inverse)",children:[h.jsx(nt,{value:N.verb_phrase??"",className:"verb-input",placeholder:c?"":"verb phrase…",readOnly:c,onCommit:L=>r("update_relationship",{id:N.id,verb_phrase:L})}),h.jsx("span",{className:"verb-sep",children:"/"}),h.jsx(nt,{value:N.inverse_verb_phrase??"",className:"verb-input",placeholder:c?"":"inverse…",readOnly:c,onCommit:L=>r("update_relationship",{id:N.id,inverse_verb_phrase:L})})]})]}),!c&&h.jsx("button",{className:"mini-btn danger",title:`delete ${N.name}`,onClick:()=>r("delete_relationship",{id:N.id}),children:"✕"})]},N.id)})]}),h.jsxs("section",{children:[h.jsx("h3",{children:"Identity"}),h.jsx("code",{className:"ulid",title:"Immutable ULID — click to copy",onClick:()=>{var N;return(N=navigator.clipboard)==null?void 0:N.writeText(e.id)},children:e.id}),!c&&h.jsx("div",{style:{marginTop:12},children:h.jsx("button",{className:"mini-btn danger",onClick:()=>{confirm(`Delete entity '${e.name}' (and its relationships)?`)&&r("delete_entity",{id:e.id,cascade:!0}).then(s)},children:"Delete entity…"})})]})]})}function Wm({entityId:e,refs:t,caps:n,exec:r}){const s=!n.canEdit,o=t.filter(i=>i.uri);return o.length===0?h.jsx("p",{className:"empty-hint",children:"not aligned to any ontology term"}):h.jsx("div",{className:"ref-list",children:o.map((i,a)=>{const c=i.status==="proposed";return h.jsxs("div",{className:"ref-card"+(c?" proposed":""),children:[h.jsxs("div",{className:"ref-head",children:[h.jsx("code",{className:"ref-uri",title:i.uri??void 0,children:i.uri}),h.jsx("span",{className:"ref-status "+(c?"proposed":"accepted"),children:c?"proposed":"accepted"})]}),h.jsxs("div",{className:"ref-meta",children:[i.predicate&&h.jsx("span",{className:"ref-pill",children:i.predicate}),i.layer&&h.jsx("span",{className:`chip layer-${i.layer}`,children:i.layer}),i.resolved_via&&h.jsxs("span",{className:"ref-via",title:"resolver that found this term",children:["via ",i.resolved_via]}),typeof i.confidence=="number"&&h.jsxs("span",{className:"ref-via",children:["conf ",Math.round(i.confidence*100),"%"]})]}),!s&&h.jsxs("div",{className:"ref-actions",children:[c&&n.canArbitrate&&h.jsx("button",{className:"mini-btn",onClick:()=>r("promote_alignment",{id:e,uri:i.uri}),title:"Accept this proposed alignment (architect action)",children:"Promote"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>r("clear_alignment",{id:e,uri:i.uri}),title:"Remove this alignment",children:"Remove"})]})]},`${i.uri}-${a}`)})})}function nt({value:e,onCommit:t,readOnly:n,multiline:r=!1,placeholder:s="",className:o=""}){const[i,a]=w.useState(e);w.useEffect(()=>a(e),[e]);const c=()=>{i.trim()!==e.trim()&&t(i.trim())};return n?h.jsx("span",{className:o,children:e||s}):r?h.jsx("textarea",{className:`edit-input ${o}`,value:i,placeholder:s,rows:3,onChange:u=>a(u.target.value),onBlur:c}):h.jsx("input",{className:`edit-input ${o}`,value:i,placeholder:s,onChange:u=>a(u.target.value),onBlur:c,onKeyDown:u=>u.key==="Enter"&&u.target.blur()})}function Um({entity:e,doc:t,readOnly:n,exec:r}){var o,i,a;const s=((i=(o=e.conceptual)==null?void 0:o.subject_area)==null?void 0:i.id)??"";return n?(a=e.conceptual)!=null&&a.subject_area?h.jsx("span",{className:"chip",children:e.conceptual.subject_area.name}):null:h.jsxs("select",{className:"chip-select",value:s,onChange:c=>r("set_subject_area",{id:e.id,subject_area:c.target.value||null}),children:[h.jsx("option",{value:"",children:"no subject area"}),t.subject_areas.map(c=>h.jsx("option",{value:c.id,children:c.name},c.id))]})}const qm=["","scd2","hub","link","satellite","bridge"];function Km({entity:e,readOnly:t,exec:n}){return t?e.pattern?h.jsx("span",{className:"chip pattern",children:e.pattern}):null:h.jsx("select",{className:"chip-select",value:e.pattern??"",onChange:r=>n("set_pattern",{id:e.id,pattern:r.target.value||null}),children:qm.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Zm=["attribute","business_key","measure","surrogate_key"];function Qm({a:e,entity:t,doc:n,readOnly:r,exec:s}){if(r)return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[e.name,e.physical_name&&e.physical_name!==e.name&&h.jsx("span",{className:"physical-col",title:"Physical column name",children:e.physical_name}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:e.domain??""}),h.jsx("td",{className:"null",children:e.nullable?"":"NN"})]});const o=i=>s("update_attribute",{entity_id:t.id,attribute_id:e.id,...i});return h.jsxs("tr",{children:[h.jsxs("td",{className:e.role==="business_key"?"pk":"",children:[h.jsx(nt,{value:e.name,readOnly:!1,onCommit:i=>o({name:i})}),(e.physical_name||!1)&&h.jsx(nt,{value:e.physical_name??"",className:"physical-col-input",placeholder:"physical…",readOnly:!1,onCommit:i=>o({physical_name:i})}),e.enum_values&&e.enum_values.length>0&&h.jsx("span",{className:"enum-badge",title:`Allowed: ${e.enum_values.join(", ")}`,children:"enum"})]}),h.jsx("td",{className:"type",children:h.jsx("select",{className:"cell-select",value:e.domain??"string",onChange:i=>o({domain:i.target.value}),children:[...new Set([...Ym,...n.domains??[],e.domain??"string"])].sort().map(i=>h.jsx("option",{value:i,children:i},i))})}),h.jsx("td",{children:h.jsx("select",{className:"cell-select",value:e.role,onChange:i=>o({role:i.target.value}),title:"role",children:Zm.map(i=>h.jsx("option",{value:i,children:i==="business_key"?"🔑 key":i==="measure"?"Σ measure":i},i))})}),h.jsx("td",{className:"null",children:h.jsx("input",{type:"checkbox",checked:!e.nullable,title:"not null",onChange:i=>o({nullable:!i.target.checked})})}),h.jsx("td",{children:h.jsx("button",{className:"mini-btn danger",title:"delete attribute",onClick:()=>s("delete_attribute",{entity_id:t.id,attribute_id:e.id}),children:"✕"})})]})}function Jm({entity:e,exec:t}){const[n,r]=w.useState(""),s=()=>{n.trim()&&t("add_attribute",{entity_id:e.id,name:n,domain:"string"}).then(()=>r(""))};return h.jsxs("div",{className:"add-attr",children:[h.jsx("input",{className:"edit-input",placeholder:"+ add attribute…",value:n,onChange:o=>r(o.target.value),onKeyDown:o=>o.key==="Enter"&&s()}),n&&h.jsx("button",{className:"mini-btn",onClick:s,children:"Add"})]})}function ep(e,t){const n=e.from.entity===t;switch(e.cardinality){case"many_to_one":return n?"N:1 →":"1:N ←";case"one_to_many":return n?"1:N →":"N:1 ←";case"one_to_one":return"1:1";default:return"N:M"}}var tp="\0",xt="\0",Ws="";let np=class{constructor(t){_e(this,"_isDirected",!0);_e(this,"_isMultigraph",!1);_e(this,"_isCompound",!1);_e(this,"_label");_e(this,"_defaultNodeLabelFn",()=>{});_e(this,"_defaultEdgeLabelFn",()=>{});_e(this,"_nodes",{});_e(this,"_in",{});_e(this,"_preds",{});_e(this,"_out",{});_e(this,"_sucs",{});_e(this,"_edgeObjs",{});_e(this,"_edgeLabels",{});_e(this,"_nodeCount",0);_e(this,"_edgeCount",0);_e(this,"_parent");_e(this,"_children");t&&(this._isDirected=Object.hasOwn(t,"directed")?t.directed:!0,this._isMultigraph=Object.hasOwn(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.hasOwn(t,"compound")?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[xt]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return this._defaultNodeLabelFn=t,typeof t!="function"&&(this._defaultNodeLabelFn=()=>t),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var t=this;return this.nodes().filter(n=>Object.keys(t._in[n]).length===0)}sinks(){var t=this;return this.nodes().filter(n=>Object.keys(t._out[n]).length===0)}setNodes(t,n){var r=arguments,s=this;return t.forEach(function(o){r.length>1?s.setNode(o,n):s.setNode(o)}),this}setNode(t,n){return Object.hasOwn(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=n),this):(this._nodes[t]=arguments.length>1?n:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=xt,this._children[t]={},this._children[xt][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.hasOwn(this._nodes,t)}removeNode(t){var n=this;if(Object.hasOwn(this._nodes,t)){var r=s=>n.removeEdge(n._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(function(s){n.setParent(s)}),delete this._children[t]),Object.keys(this._in[t]).forEach(r),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(r),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,n){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(n===void 0)n=xt;else{n+="";for(var r=n;r!==void 0;r=this.parent(r))if(r===t)throw new Error("Setting "+n+" as parent of "+t+" would create a cycle");this.setNode(n)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=n,this._children[n][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var n=this._parent[t];if(n!==xt)return n}}children(t=xt){if(this._isCompound){var n=this._children[t];if(n)return Object.keys(n)}else{if(t===xt)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var n=this._preds[t];if(n)return Object.keys(n)}successors(t){var n=this._sucs[t];if(n)return Object.keys(n)}neighbors(t){var n=this.predecessors(t);if(n){const s=new Set(n);for(var r of this.successors(t))s.add(r);return Array.from(s.values())}}isLeaf(t){var n;return this.isDirected()?n=this.successors(t):n=this.neighbors(t),n.length===0}filterNodes(t){var n=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});n.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([i,a]){t(i)&&n.setNode(i,a)}),Object.values(this._edgeObjs).forEach(function(i){n.hasNode(i.v)&&n.hasNode(i.w)&&n.setEdge(i,r.edge(i))});var s={};function o(i){var a=r.parent(i);return a===void 0||n.hasNode(a)?(s[i]=a,a):a in s?s[a]:o(a)}return this._isCompound&&n.nodes().forEach(i=>n.setParent(i,o(i))),n}setDefaultEdgeLabel(t){return this._defaultEdgeLabelFn=t,typeof t!="function"&&(this._defaultEdgeLabelFn=()=>t),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,n){var r=this,s=arguments;return t.reduce(function(o,i){return s.length>1?r.setEdge(o,i,n):r.setEdge(o,i),i}),this}setEdge(){var t,n,r,s,o=!1,i=arguments[0];typeof i=="object"&&i!==null&&"v"in i?(t=i.v,n=i.w,r=i.name,arguments.length===2&&(s=arguments[1],o=!0)):(t=i,n=arguments[1],r=arguments[3],arguments.length>2&&(s=arguments[2],o=!0)),t=""+t,n=""+n,r!==void 0&&(r=""+r);var a=Kt(this._isDirected,t,n,r);if(Object.hasOwn(this._edgeLabels,a))return o&&(this._edgeLabels[a]=s),this;if(r!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(n),this._edgeLabels[a]=o?s:this._defaultEdgeLabelFn(t,n,r);var c=rp(this._isDirected,t,n,r);return t=c.v,n=c.w,Object.freeze(c),this._edgeObjs[a]=c,Us(this._preds[n],t),Us(this._sucs[t],n),this._in[n][a]=c,this._out[t][a]=c,this._edgeCount++,this}edge(t,n,r){var s=arguments.length===1?ir(this._isDirected,arguments[0]):Kt(this._isDirected,t,n,r);return this._edgeLabels[s]}edgeAsObj(){const t=this.edge(...arguments);return typeof t!="object"?{label:t}:t}hasEdge(t,n,r){var s=arguments.length===1?ir(this._isDirected,arguments[0]):Kt(this._isDirected,t,n,r);return Object.hasOwn(this._edgeLabels,s)}removeEdge(t,n,r){var s=arguments.length===1?ir(this._isDirected,arguments[0]):Kt(this._isDirected,t,n,r),o=this._edgeObjs[s];return o&&(t=o.v,n=o.w,delete this._edgeLabels[s],delete this._edgeObjs[s],qs(this._preds[n],t),qs(this._sucs[t],n),delete this._in[n][s],delete this._out[t][s],this._edgeCount--),this}inEdges(t,n){var r=this._in[t];if(r){var s=Object.values(r);return n?s.filter(o=>o.v===n):s}}outEdges(t,n){var r=this._out[t];if(r){var s=Object.values(r);return n?s.filter(o=>o.w===n):s}}nodeEdges(t,n){var r=this.inEdges(t,n);if(r)return r.concat(this.outEdges(t,n))}};function Us(e,t){e[t]?e[t]++:e[t]=1}function qs(e,t){--e[t]||delete e[t]}function Kt(e,t,n,r){var s=""+t,o=""+n;if(!e&&s>o){var i=s;s=o,o=i}return s+Ws+o+Ws+(r===void 0?tp:r)}function rp(e,t,n,r){var s=""+t,o=""+n;if(!e&&s>o){var i=s;s=o,o=i}var a={v:s,w:o};return r&&(a.name=r),a}function ir(e,t){return Kt(e,t.v,t.w,t.name)}var Kr=np,sp="2.2.4",op={Graph:Kr,version:sp},ip=Kr,ap={write:cp,read:dp};function cp(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:lp(e),edges:up(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function lp(e){return e.nodes().map(function(t){var n=e.node(t),r=e.parent(t),s={v:t};return n!==void 0&&(s.value=n),r!==void 0&&(s.parent=r),s})}function up(e){return e.edges().map(function(t){var n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function dp(e){var t=new ip(e.options).setGraph(e.value);return e.nodes.forEach(function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var fp=hp;function hp(e){var t={},n=[],r;function s(o){Object.hasOwn(t,o)||(t[o]=!0,r.push(o),e.successors(o).forEach(s),e.predecessors(o).forEach(s))}return e.nodes().forEach(function(o){r=[],s(o),r.length&&n.push(r)}),n}let mp=class{constructor(){_e(this,"_arr",[]);_e(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(t){return t.key})}has(t){return Object.hasOwn(this._keyIndices,t)}priority(t){var n=this._keyIndices[t];if(n!==void 0)return this._arr[n].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,n){var r=this._keyIndices;if(t=String(t),!Object.hasOwn(r,t)){var s=this._arr,o=s.length;return r[t]=o,s.push({key:t,priority:n}),this._decrease(o),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,n){var r=this._keyIndices[t];if(n>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+t+" Old: "+this._arr[r].priority+" New: "+n);this._arr[r].priority=n,this._decrease(r)}_heapify(t){var n=this._arr,r=2*t,s=r+1,o=t;r>1,!(n[s].priority1;function yp(e,t,n,r){return xp(e,String(t),n||gp,r||function(s){return e.outEdges(s)})}function xp(e,t,n,r){var s={},o=new pp,i,a,c=function(u){var l=u.v!==i?u.v:u.w,d=s[l],m=n(u),f=a.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+u+" Weight: "+m);f0&&(i=o.removeMin(),a=s[i],a.distance!==Number.POSITIVE_INFINITY);)r(i).forEach(c);return s}var wp=ca,bp=vp;function vp(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=wp(e,s,t,n),r},{})}var la=_p;function _p(e){var t=0,n=[],r={},s=[];function o(i){var a=r[i]={onStack:!0,lowlink:t,index:t++};if(n.push(i),e.successors(i).forEach(function(l){Object.hasOwn(r,l)?r[l].onStack&&(a.lowlink=Math.min(a.lowlink,r[l].index)):(o(l),a.lowlink=Math.min(a.lowlink,r[l].lowlink))}),a.lowlink===a.index){var c=[],u;do u=n.pop(),r[u].onStack=!1,c.push(u);while(i!==u);s.push(c)}}return e.nodes().forEach(function(i){Object.hasOwn(r,i)||o(i)}),s}var Ep=la,Np=Sp;function Sp(e){return Ep(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var kp=Cp,jp=()=>1;function Cp(e,t,n){return Mp(e,t||jp,n||function(r){return e.outEdges(r)})}function Mp(e,t,n){var r={},s=e.nodes();return s.forEach(function(o){r[o]={},r[o][o]={distance:0},s.forEach(function(i){o!==i&&(r[o][i]={distance:Number.POSITIVE_INFINITY})}),n(o).forEach(function(i){var a=i.v===o?i.w:i.v,c=t(i);r[o][a]={distance:c,predecessor:o}})}),s.forEach(function(o){var i=r[o];s.forEach(function(a){var c=r[a];s.forEach(function(u){var l=c[o],d=i[u],m=c[u],f=l.distance+d.distance;fe.successors(a):a=>e.neighbors(a),s=n==="post"?Ip:Tp,o=[],i={};return t.forEach(a=>{if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);s(a,r,i,o)}),o}function Ip(e,t,n,r){for(var s=[[e,!1]];s.length>0;){var o=s.pop();o[1]?r.push(o[0]):Object.hasOwn(n,o[0])||(n[o[0]]=!0,s.push([o[0],!0]),ha(t(o[0]),i=>s.push([i,!1])))}}function Tp(e,t,n,r){for(var s=[e];s.length>0;){var o=s.pop();Object.hasOwn(n,o)||(n[o]=!0,r.push(o),ha(t(o),i=>s.push(i)))}}function ha(e,t){for(var n=e.length;n--;)t(e[n],n,e);return e}var Op=fa,Lp=Dp;function Dp(e,t){return Op(e,t,"post")}var Pp=fa,zp=Hp;function Hp(e,t){return Pp(e,t,"pre")}var Fp=Kr,Vp=aa,Bp=Gp;function Gp(e,t){var n=new Fp,r={},s=new Vp,o;function i(c){var u=c.v===o?c.w:c.v,l=s.priority(u);if(l!==void 0){var d=t(c);d0;){if(o=s.removeMin(),Object.hasOwn(r,o))n.setEdge(o,r[o]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(o).forEach(i)}return n}var Yp={components:fp,dijkstra:ca,dijkstraAll:bp,findCycles:Np,floydWarshall:kp,isAcyclic:$p,postorder:Lp,preorder:zp,prim:Bp,tarjan:la,topsort:da},Zs=op,qe={Graph:Zs.Graph,json:ap,alg:Yp,version:Zs.version};let Xp=class{constructor(){let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,n=t._prev;if(n!==t)return Qs(n),n}enqueue(t){let n=this._sentinel;t._prev&&t._next&&Qs(t),t._next=n._next,n._next._prev=t,n._next=t,t._prev=n}toString(){let t=[],n=this._sentinel,r=n._prev;for(;r!==n;)t.push(JSON.stringify(r,Wp)),r=r._prev;return"["+t.join(", ")+"]"}};function Qs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Wp(e,t){if(e!=="_next"&&e!=="_prev")return t}var Up=Xp;let qp=qe.Graph,Kp=Up;var Zp=Jp;let Qp=()=>1;function Jp(e,t){if(e.nodeCount()<=1)return[];let n=tg(e,t||Qp);return eg(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function eg(e,t,n){let r=[],s=t[t.length-1],o=t[0],i;for(;e.nodeCount();){for(;i=o.dequeue();)ar(e,t,n,i);for(;i=s.dequeue();)ar(e,t,n,i);if(e.nodeCount()){for(let a=t.length-2;a>0;--a)if(i=t[a].dequeue(),i){r=r.concat(ar(e,t,n,i,!0));break}}}return r}function ar(e,t,n,r,s){let o=s?[]:void 0;return e.inEdges(r.v).forEach(i=>{let a=e.edge(i),c=e.node(i.v);s&&o.push({v:i.v,w:i.w}),c.out-=a,$r(t,n,c)}),e.outEdges(r.v).forEach(i=>{let a=e.edge(i),c=i.w,u=e.node(c);u.in-=a,$r(t,n,u)}),e.removeNode(r.v),o}function tg(e,t){let n=new qp,r=0,s=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let c=n.edge(a.v,a.w)||0,u=t(a),l=c+u;n.setEdge(a.v,a.w,l),s=Math.max(s,n.node(a.v).out+=u),r=Math.max(r,n.node(a.w).in+=u)});let o=ng(s+r+3).map(()=>new Kp),i=r+1;return n.nodes().forEach(a=>{$r(o,i,n.node(a))}),{graph:n,buckets:o,zeroIdx:i}}function $r(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}function ng(e){const t=[];for(let n=0;nt.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},s=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t}function sg(e){let t=new ma({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function og(e){let t=e.nodes().map(n=>{let r={};return e.outEdges(n).forEach(s=>{r[s.w]=(r[s.w]||0)+e.edge(s).weight}),r});return Zr(e.nodes(),t)}function ig(e){let t=e.nodes().map(n=>{let r={};return e.inEdges(n).forEach(s=>{r[s.v]=(r[s.v]||0)+e.edge(s).weight}),r});return Zr(e.nodes(),t)}function ag(e,t){let n=e.x,r=e.y,s=t.x-n,o=t.y-r,i=e.width/2,a=e.height/2;if(!s&&!o)throw new Error("Not possible to find intersection inside of the rectangle");let c,u;return Math.abs(o)*i>Math.abs(s)*a?(o<0&&(a=-a),c=a*s/o,u=a):(s<0&&(i=-i),c=i,u=i*o/s),{x:n+c,y:r+u}}function cg(e){let t=wa(ya(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),s=r.rank;s!==void 0&&(t[s][r.order]=n)}),t}function lg(e){let t=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MAX_VALUE:s}),n=Xn(Math.min,t);e.nodes().forEach(r=>{let s=e.node(r);Object.hasOwn(s,"rank")&&(s.rank-=n)})}function ug(e){let t=e.nodes().map(i=>e.node(i).rank),n=Xn(Math.min,t),r=[];e.nodes().forEach(i=>{let a=e.node(i).rank-n;r[a]||(r[a]=[]),r[a].push(i)});let s=0,o=e.graph().nodeRankFactor;Array.from(r).forEach((i,a)=>{i===void 0&&a%o!==0?--s:i!==void 0&&s&&i.forEach(c=>e.node(c).rank+=s)})}function dg(e,t,n,r){let s={width:0,height:0};return arguments.length>=4&&(s.rank=n,s.order=r),pa(e,"border",s,t)}function fg(e,t=ga){const n=[];for(let r=0;rga){const n=fg(t);return e.apply(null,n.map(r=>e.apply(null,r)))}else return e.apply(null,t)}function ya(e){const n=e.nodes().map(r=>{let s=e.node(r).rank;return s===void 0?Number.MIN_VALUE:s});return Xn(Math.max,n)}function hg(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function mg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function pg(e,t){return t()}let gg=0;function xa(e){var t=++gg;return e+(""+t)}function wa(e,t,n=1){t==null&&(t=e,e=0);let r=o=>otr[t]),Object.entries(e).reduce((r,[s,o])=>(r[s]=n(o,s),r),{})}function Zr(e,t){return e.reduce((n,r,s)=>(n[r]=t[s],n),{})}let wg=Zp,bg=Se.uniqueId;var vg={run:_g,undo:Ng};function _g(e){(e.graph().acyclicer==="greedy"?wg(e,n(e)):Eg(e)).forEach(r=>{let s=e.edge(r);e.removeEdge(r),s.forwardName=r.name,s.reversed=!0,e.setEdge(r.w,r.v,s,bg("rev"))});function n(r){return s=>r.edge(s).weight}}function Eg(e){let t=[],n={},r={};function s(o){Object.hasOwn(r,o)||(r[o]=!0,n[o]=!0,e.outEdges(o).forEach(i=>{Object.hasOwn(n,i.w)?t.push(i):s(i.w)}),delete n[o])}return e.nodes().forEach(s),t}function Ng(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}let Sg=Se;var kg={run:jg,undo:Mg};function jg(e){e.graph().dummyChains=[],e.edges().forEach(t=>Cg(e,t))}function Cg(e,t){let n=t.v,r=e.node(n).rank,s=t.w,o=e.node(s).rank,i=t.name,a=e.edge(t),c=a.labelRank;if(o===r+1)return;e.removeEdge(t);let u,l,d;for(d=0,++r;r{let n=e.node(t),r=n.edgeLabel,s;for(e.setEdge(n.edgeObj,r);n.dummy;)s=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=s,n=e.node(t)})}const{applyWithChunking:$g}=Se;var Wn={longestPath:Ag,slack:Rg};function Ag(e){var t={};function n(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let o=e.outEdges(r).map(a=>a==null?Number.POSITIVE_INFINITY:n(a.w)-e.edge(a).minlen);var i=$g(Math.min,o);return i===Number.POSITIVE_INFINITY&&(i=0),s.rank=i}e.sources().forEach(n)}function Rg(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var Ig=qe.Graph,Dn=Wn.slack,ba=Tg;function Tg(e){var t=new Ig({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,o;Og(t,e){var o=s.v,i=r===o?s.w:o;!e.hasNode(i)&&!Dn(t,s)&&(e.setNode(i,{}),e.setEdge(r,i,{}),n(i))})}return e.nodes().forEach(n),e.nodeCount()}function Lg(e,t){return t.edges().reduce((r,s)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(o=Dn(t,s)),ot.node(r).rank+=n)}var Pg=ba,Js=Wn.slack,zg=Wn.longestPath,Hg=qe.alg.preorder,Fg=qe.alg.postorder,Vg=Se.simplify,Bg=kt;kt.initLowLimValues=Jr;kt.initCutValues=Qr;kt.calcCutValue=va;kt.leaveEdge=Ea;kt.enterEdge=Na;kt.exchangeEdges=Sa;function kt(e){e=Vg(e),zg(e);var t=Pg(e);Jr(t),Qr(t,e);for(var n,r;n=Ea(t);)r=Na(t,e,n),Sa(t,e,n,r)}function Qr(e,t){var n=Fg(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Gg(e,t,r))}function Gg(e,t,n){var r=e.node(n),s=r.parent;e.edge(n,s).cutvalue=va(e,t,n)}function va(e,t,n){var r=e.node(n),s=r.parent,o=!0,i=t.edge(n,s),a=0;return i||(o=!1,i=t.edge(s,n)),a=i.weight,t.nodeEdges(n).forEach(c=>{var u=c.v===n,l=u?c.w:c.v;if(l!==s){var d=u===o,m=t.edge(c).weight;if(a+=d?m:-m,Xg(e,n,l)){var f=e.edge(n,l).cutvalue;a+=d?-f:f}}}),a}function Jr(e,t){arguments.length<2&&(t=e.nodes()[0]),_a(e,{},1,t)}function _a(e,t,n,r,s){var o=n,i=e.node(r);return t[r]=!0,e.neighbors(r).forEach(a=>{Object.hasOwn(t,a)||(n=_a(e,t,n,a,r))}),i.low=o,i.lim=n++,s?i.parent=s:delete i.parent,n}function Ea(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function Na(e,t,n){var r=n.v,s=n.w;t.hasEdge(r,s)||(r=n.w,s=n.v);var o=e.node(r),i=e.node(s),a=o,c=!1;o.lim>i.lim&&(a=i,c=!0);var u=t.edges().filter(l=>c===eo(e,e.node(l.v),a)&&c!==eo(e,e.node(l.w),a));return u.reduce((l,d)=>Js(t,d)!t.node(s).parent),r=Hg(e,n);r=r.slice(1),r.forEach(s=>{var o=e.node(s).parent,i=t.edge(s,o),a=!1;i||(i=t.edge(o,s),a=!0),t.node(s).rank=t.node(o).rank+(a?i.minlen:-i.minlen)})}function Xg(e,t,n){return e.hasEdge(t,n)}function eo(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Wg=Wn,ka=Wg.longestPath,Ug=ba,qg=Bg,Kg=Zg;function Zg(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":to(e);break;case"tight-tree":Jg(e);break;case"longest-path":Qg(e);break;case"none":break;default:to(e)}}var Qg=ka;function Jg(e){ka(e),Ug(e)}function to(e){qg(e)}var ey=ty;function ty(e){let t=ry(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,o=ny(e,t,s.v,s.w),i=o.path,a=o.lca,c=0,u=i[c],l=!0;for(;n!==s.w;){if(r=e.node(n),l){for(;(u=i[c])!==a&&e.node(u).maxRanki||a>t[c].lim));for(u=c,c=r;(c=e.parent(c))!==u;)o.push(c);return{path:s.concat(o.reverse()),lca:u}}function ry(e){let t={},n=0;function r(s){let o=n;e.children(s).forEach(r),t[s]={low:o,lim:n++}}return e.children().forEach(r),t}let Pn=Se;var sy={run:oy,cleanup:cy};function oy(e){let t=Pn.addDummyNode(e,"root",{},"_root"),n=iy(e),r=Object.values(n),s=Pn.applyWithChunking(Math.max,r)-1,o=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=o);let i=ay(e)+1;e.children().forEach(a=>ja(e,t,o,i,s,n,a)),e.graph().nodeRankFactor=o}function ja(e,t,n,r,s,o,i){let a=e.children(i);if(!a.length){i!==t&&e.setEdge(t,i,{weight:0,minlen:n});return}let c=Pn.addBorderNode(e,"_bt"),u=Pn.addBorderNode(e,"_bb"),l=e.node(i);e.setParent(c,i),l.borderTop=c,e.setParent(u,i),l.borderBottom=u,a.forEach(d=>{ja(e,t,n,r,s,o,d);let m=e.node(d),f=m.borderTop?m.borderTop:d,p=m.borderBottom?m.borderBottom:d,x=m.borderTop?r:2*r,v=f!==p?1:s-o[i]+1;e.setEdge(c,f,{weight:x,minlen:v,nestingEdge:!0}),e.setEdge(p,u,{weight:x,minlen:v,nestingEdge:!0})}),e.parent(i)||e.setEdge(t,c,{weight:0,minlen:s+o[i]})}function iy(e){var t={};function n(r,s){var o=e.children(r);o&&o.length&&o.forEach(i=>n(i,s+1)),t[r]=s}return e.children().forEach(r=>n(r,1)),t}function ay(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function cy(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}let ly=Se;var uy=dy;function dy(e){function t(n){let r=e.children(n),s=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let o=s.minRank,i=s.maxRank+1;oro(e.node(t))),e.edges().forEach(t=>ro(e.edge(t)))}function ro(e){let t=e.width;e.width=e.height,e.height=t}function py(e){e.nodes().forEach(t=>cr(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(cr),Object.hasOwn(n,"y")&&cr(n)})}function cr(e){e.y=-e.y}function gy(e){e.nodes().forEach(t=>lr(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);n.points.forEach(lr),Object.hasOwn(n,"x")&&lr(n)})}function lr(e){let t=e.x;e.x=e.y,e.y=t}let so=Se;var yy=xy;function xy(e){let t={},n=e.nodes().filter(c=>!e.children(c).length),r=n.map(c=>e.node(c).rank),s=so.applyWithChunking(Math.max,r),o=so.range(s+1).map(()=>[]);function i(c){if(t[c])return;t[c]=!0;let u=e.node(c);o[u.rank].push(c),e.successors(c).forEach(i)}return n.sort((c,u)=>e.node(c).rank-e.node(u).rank).forEach(i),o}let wy=Se.zipObject;var by=vy;function vy(e,t){let n=0;for(let r=1;rl)),s=t.flatMap(u=>e.outEdges(u).map(l=>({pos:r[l.w],weight:e.edge(l).weight})).sort((l,d)=>l.pos-d.pos)),o=1;for(;o{let l=u.pos+o;a[l]+=u.weight;let d=0;for(;l>0;)l%2&&(d+=a[l+1]),l=l-1>>1,a[l]+=u.weight;c+=u.weight*d}),c}var Ey=Ny;function Ny(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(r.length){let s=r.reduce((o,i)=>{let a=e.edge(i),c=e.node(i.v);return{sum:o.sum+a.weight*c.order,weight:o.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:s.sum/s.weight,weight:s.weight}}else return{v:n}})}let Sy=Se;var ky=jy;function jy(e,t){let n={};e.forEach((s,o)=>{let i=n[s.v]={indegree:0,in:[],out:[],vs:[s.v],i:o};s.barycenter!==void 0&&(i.barycenter=s.barycenter,i.weight=s.weight)}),t.edges().forEach(s=>{let o=n[s.v],i=n[s.w];o!==void 0&&i!==void 0&&(i.indegree++,o.out.push(n[s.w]))});let r=Object.values(n).filter(s=>!s.indegree);return Cy(r)}function Cy(e){let t=[];function n(s){return o=>{o.merged||(o.barycenter===void 0||s.barycenter===void 0||o.barycenter>=s.barycenter)&&My(s,o)}}function r(s){return o=>{o.in.push(s),--o.indegree===0&&e.push(o)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(n(s)),s.out.forEach(r(s))}return t.filter(s=>!s.merged).map(s=>Sy.pick(s,["vs","i","barycenter","weight"]))}function My(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}let $y=Se;var Ay=Ry;function Ry(e,t){let n=$y.partition(e,l=>Object.hasOwn(l,"barycenter")),r=n.lhs,s=n.rhs.sort((l,d)=>d.i-l.i),o=[],i=0,a=0,c=0;r.sort(Iy(!!t)),c=oo(o,s,c),r.forEach(l=>{c+=l.vs.length,o.push(l.vs),i+=l.barycenter*l.weight,a+=l.weight,c=oo(o,s,c)});let u={vs:o.flat(!0)};return a&&(u.barycenter=i/a,u.weight=a),u}function oo(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function Iy(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Ty=Ey,Oy=ky,Ly=Ay;var Dy=Ma;function Ma(e,t,n,r){let s=e.children(t),o=e.node(t),i=o?o.borderLeft:void 0,a=o?o.borderRight:void 0,c={};i&&(s=s.filter(m=>m!==i&&m!==a));let u=Ty(e,s);u.forEach(m=>{if(e.children(m.v).length){let f=Ma(e,m.v,n,r);c[m.v]=f,Object.hasOwn(f,"barycenter")&&zy(m,f)}});let l=Oy(u,n);Py(l,c);let d=Ly(l,r);if(i&&(d.vs=[i,d.vs,a].flat(!0),e.predecessors(i).length)){let m=e.node(e.predecessors(i)[0]),f=e.node(e.predecessors(a)[0]);Object.hasOwn(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+m.order+f.order)/(d.weight+2),d.weight+=2}return d}function Py(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function zy(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}let Hy=qe.Graph,Fy=Se;var Vy=By;function By(e,t,n,r){r||(r=e.nodes());let s=Gy(e),o=new Hy({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(i=>e.node(i));return r.forEach(i=>{let a=e.node(i),c=e.parent(i);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(o.setNode(i),o.setParent(i,c||s),e[n](i).forEach(u=>{let l=u.v===i?u.w:u.v,d=o.edge(l,i),m=d!==void 0?d.weight:0;o.setEdge(l,i,{weight:e.edge(u).weight+m})}),Object.hasOwn(a,"minRank")&&o.setNode(i,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),o}function Gy(e){for(var t;e.hasNode(t=Fy.uniqueId("_root")););return t}var Yy=Xy;function Xy(e,t,n){let r={},s;n.forEach(o=>{let i=e.parent(o),a,c;for(;i;){if(a=e.parent(i),a?(c=r[a],r[a]=i):(c=s,s=i),c&&c!==i){t.setEdge(c,i);return}i=a}})}let Wy=yy,Uy=by,qy=Dy,Ky=Vy,Zy=Yy,Qy=qe.Graph,vn=Se;var Jy=$a;function $a(e,t){if(t&&typeof t.customOrder=="function"){t.customOrder(e,$a);return}let n=vn.maxRank(e),r=io(e,vn.range(1,n+1),"inEdges"),s=io(e,vn.range(n-1,-1,-1),"outEdges"),o=Wy(e);if(ao(e,o),t&&t.disableOptimalOrderHeuristic)return;let i=Number.POSITIVE_INFINITY,a;for(let c=0,u=0;u<4;++c,++u){e0(c%2?r:s,c%4>=2),o=vn.buildLayerMatrix(e);let l=Uy(e,o);l{r.has(o)||r.set(o,[]),r.get(o).push(i)};for(const o of e.nodes()){const i=e.node(o);if(typeof i.rank=="number"&&s(i.rank,o),typeof i.minRank=="number"&&typeof i.maxRank=="number")for(let a=i.minRank;a<=i.maxRank;a++)a!==i.rank&&s(a,o)}return t.map(function(o){return Ky(e,o,n,r.get(o)||[])})}function e0(e,t){let n=new Qy;e.forEach(function(r){let s=r.graph().root,o=qy(r,s,n,t);o.vs.forEach((i,a)=>r.node(i).order=a),Zy(r,n,o.vs)})}function ao(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let t0=qe.Graph,rt=Se;var n0={positionX:h0};function r0(e,t){let n={};function r(s,o){let i=0,a=0,c=s.length,u=o[o.length-1];return o.forEach((l,d)=>{let m=o0(e,l),f=m?e.node(m).order:c;(m||l===u)&&(o.slice(a,d+1).forEach(p=>{e.predecessors(p).forEach(x=>{let v=e.node(x),g=v.order;(g{l=o[d],e.node(l).dummy&&e.predecessors(l).forEach(m=>{let f=e.node(m);f.dummy&&(f.orderu)&&Aa(n,m,l)})})}function s(o,i){let a=-1,c,u=0;return i.forEach((l,d)=>{if(e.node(l).dummy==="border"){let m=e.predecessors(l);m.length&&(c=e.node(m[0]).order,r(i,u,d,a,c),u=d,a=c)}r(i,u,i.length,c,o.length)}),i}return t.length&&t.reduce(s),n}function o0(e,t){if(e.node(t).dummy)return e.predecessors(t).find(n=>e.node(n).dummy)}function Aa(e,t,n){if(t>n){let s=t;t=n,n=s}let r=e[t];r||(e[t]=r={}),r[n]=!0}function i0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function a0(e,t,n,r){let s={},o={},i={};return t.forEach(a=>{a.forEach((c,u)=>{s[c]=c,o[c]=c,i[c]=u})}),t.forEach(a=>{let c=-1;a.forEach(u=>{let l=r(u);if(l.length){l=l.sort((m,f)=>i[m]-i[f]);let d=(l.length-1)/2;for(let m=Math.floor(d),f=Math.ceil(d);m<=f;++m){let p=l[m];o[u]===u&&cMath.max(m,o[f.v]+i.edge(f)),0)}function l(d){let m=i.outEdges(d).reduce((p,x)=>Math.min(p,o[x.w]-i.edge(x)),Number.POSITIVE_INFINITY),f=e.node(d);m!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(o[d]=Math.max(o[d],m))}return c(u,i.predecessors.bind(i)),c(l,i.successors.bind(i)),Object.keys(r).forEach(d=>o[d]=o[n[d]]),o}function l0(e,t,n,r){let s=new t0,o=e.graph(),i=m0(o.nodesep,o.edgesep,r);return t.forEach(a=>{let c;a.forEach(u=>{let l=n[u];if(s.setNode(l),c){var d=n[c],m=s.edge(d,l);s.setEdge(d,l,Math.max(i(e,u,c),m||0))}c=u})}),s}function u0(e,t){return Object.values(t).reduce((n,r)=>{let s=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,c])=>{let u=p0(e,a)/2;s=Math.max(c+u,s),o=Math.min(c-u,o)});const i=s-o;return i{["l","r"].forEach(i=>{let a=o+i,c=e[a];if(c===t)return;let u=Object.values(c),l=r-rt.applyWithChunking(Math.min,u);i!=="l"&&(l=s-rt.applyWithChunking(Math.max,u)),l&&(e[a]=rt.mapValues(c,d=>d+l))})})}function f0(e,t){return rt.mapValues(e.ul,(n,r)=>{if(t)return e[t.toLowerCase()][r];{let s=Object.values(e).map(o=>o[r]).sort((o,i)=>o-i);return(s[1]+s[2])/2}})}function h0(e){let t=rt.buildLayerMatrix(e),n=Object.assign(r0(e,t),s0(e,t)),r={},s;["u","d"].forEach(i=>{s=i==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(s=s.map(d=>Object.values(d).reverse()));let c=(i==="u"?e.predecessors:e.successors).bind(e),u=a0(e,s,n,c),l=c0(e,s,u.root,u.align,a==="r");a==="r"&&(l=rt.mapValues(l,d=>-d)),r[i+a]=l})});let o=u0(e,r);return d0(r,o),f0(r,e.graph().align)}function m0(e,t,n){return(r,s,o)=>{let i=r.node(s),a=r.node(o),c=0,u;if(c+=i.width/2,Object.hasOwn(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":u=-i.width/2;break;case"r":u=i.width/2;break}if(u&&(c+=n?u:-u),u=0,c+=(i.dummy?t:e)/2,c+=(a.dummy?t:e)/2,c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":u=a.width/2;break;case"r":u=-a.width/2;break}return u&&(c+=n?u:-u),u=0,c}}function p0(e,t){return e.node(t).width}let Ra=Se,g0=n0.positionX;var y0=x0;function x0(e){e=Ra.asNonCompoundGraph(e),w0(e),Object.entries(g0(e)).forEach(([t,n])=>e.node(t).x=n)}function w0(e){let t=Ra.buildLayerMatrix(e),n=e.graph().ranksep,r=0;t.forEach(s=>{const o=s.reduce((i,a)=>{const c=e.node(a).height;return i>c?i:c},0);s.forEach(i=>e.node(i).y=r+o/2),r+=o+n})}let co=vg,lo=kg,b0=Kg,v0=Se.normalizeRanks,_0=ey,E0=Se.removeEmptyRanks,uo=sy,N0=uy,fo=fy,S0=Jy,k0=y0,Ge=Se,j0=qe.Graph;var C0=M0;function M0(e,t){let n=t&&t.debugTiming?Ge.time:Ge.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>z0(e));n(" runLayout",()=>$0(r,n,t)),n(" updateInputGraph",()=>A0(e,r))})}function $0(e,t,n){t(" makeSpaceForEdgeLabels",()=>H0(e)),t(" removeSelfEdges",()=>q0(e)),t(" acyclic",()=>co.run(e)),t(" nestingGraph.run",()=>uo.run(e)),t(" rank",()=>b0(Ge.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>F0(e)),t(" removeEmptyRanks",()=>E0(e)),t(" nestingGraph.cleanup",()=>uo.cleanup(e)),t(" normalizeRanks",()=>v0(e)),t(" assignRankMinMax",()=>V0(e)),t(" removeEdgeLabelProxies",()=>B0(e)),t(" normalize.run",()=>lo.run(e)),t(" parentDummyChains",()=>_0(e)),t(" addBorderSegments",()=>N0(e)),t(" order",()=>S0(e,n)),t(" insertSelfEdges",()=>K0(e)),t(" adjustCoordinateSystem",()=>fo.adjust(e)),t(" position",()=>k0(e)),t(" positionSelfEdges",()=>Z0(e)),t(" removeBorderNodes",()=>U0(e)),t(" normalize.undo",()=>lo.undo(e)),t(" fixupEdgeLabelCoords",()=>X0(e)),t(" undoCoordinateSystem",()=>fo.undo(e)),t(" translateGraph",()=>G0(e)),t(" assignNodeIntersects",()=>Y0(e)),t(" reversePoints",()=>W0(e)),t(" acyclic.undo",()=>co.undo(e))}function A0(e,t){e.nodes().forEach(n=>{let r=e.node(n),s=t.node(n);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(n).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(n=>{let r=e.edge(n),s=t.edge(n);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}let R0=["nodesep","edgesep","ranksep","marginx","marginy"],I0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},T0=["acyclicer","ranker","rankdir","align"],O0=["width","height","rank"],ho={width:0,height:0},L0=["minlen","weight","width","height","labeloffset"],D0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},P0=["labelpos"];function z0(e){let t=new j0({multigraph:!0,compound:!0}),n=dr(e.graph());return t.setGraph(Object.assign({},I0,ur(n,R0),Ge.pick(n,T0))),e.nodes().forEach(r=>{let s=dr(e.node(r));const o=ur(s,O0);Object.keys(ho).forEach(i=>{o[i]===void 0&&(o[i]=ho[i])}),t.setNode(r,o),t.setParent(r,e.parent(r))}),e.edges().forEach(r=>{let s=dr(e.edge(r));t.setEdge(r,Object.assign({},D0,ur(s,L0),Ge.pick(s,P0)))}),t}function H0(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function F0(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),o={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};Ge.addDummyNode(e,"edge-proxy",o,"_ep")}})}function V0(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function B0(e){e.nodes().forEach(t=>{let n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function G0(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,s=0,o=e.graph(),i=o.marginx||0,a=o.marginy||0;function c(u){let l=u.x,d=u.y,m=u.width,f=u.height;t=Math.min(t,l-m/2),n=Math.max(n,l+m/2),r=Math.min(r,d-f/2),s=Math.max(s,d+f/2)}e.nodes().forEach(u=>c(e.node(u))),e.edges().forEach(u=>{let l=e.edge(u);Object.hasOwn(l,"x")&&c(l)}),t-=i,r-=a,e.nodes().forEach(u=>{let l=e.node(u);l.x-=t,l.y-=r}),e.edges().forEach(u=>{let l=e.edge(u);l.points.forEach(d=>{d.x-=t,d.y-=r}),Object.hasOwn(l,"x")&&(l.x-=t),Object.hasOwn(l,"y")&&(l.y-=r)}),o.width=n-t+i,o.height=s-r+a}function Y0(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),s=e.node(t.w),o,i;n.points?(o=n.points[0],i=n.points[n.points.length-1]):(n.points=[],o=s,i=r),n.points.unshift(Ge.intersectRect(r,o)),n.points.push(Ge.intersectRect(s,i))})}function X0(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function W0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function U0(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),s=e.node(n.borderBottom),o=e.node(n.borderLeft[n.borderLeft.length-1]),i=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(i.x-o.x),n.height=Math.abs(s.y-r.y),n.x=o.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function q0(e){e.edges().forEach(t=>{if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function K0(e){var t=Ge.buildLayerMatrix(e);t.forEach(n=>{var r=0;n.forEach((s,o)=>{var i=e.node(s);i.order=o+r,(i.selfEdges||[]).forEach(a=>{Ge.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:i.rank,order:o+ ++r,e:a.e,label:a.label},"_se")}),delete i.selfEdges})})}function Z0(e){e.nodes().forEach(t=>{var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),s=r.x+r.width/2,o=r.y,i=n.x-s,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:s+2*i/3,y:o-a},{x:s+5*i/6,y:o-a},{x:s+i,y:o},{x:s+5*i/6,y:o+a},{x:s+2*i/3,y:o+a}],n.label.x=n.x,n.label.y=n.y}})}function ur(e,t){return Ge.mapValues(Ge.pick(e,t),Number)}function dr(e){var t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}let Q0=Se,J0=qe.Graph;var ex={debugOrdering:tx};function tx(e){let t=Q0.buildLayerMatrix(e),n=new J0({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,s)=>{let o="layer"+s;n.setNode(o,{rank:"same"}),r.reduce((i,a)=>(n.setEdge(i,a,{style:"invis"}),a))}),n}var nx="1.1.8",rx={graphlib:qe,layout:C0,debug:ex,util:{time:Se.time,notime:Se.notime},version:nx};const mo=$o(rx),Qe=264,sx=44,ox=26,ix=14;function gt(e){const t=Math.max(e.attributes.length,1);return sx+t*ox+ix}const ax=40;function fr(e,t,n,r="auto",s,o="LR"){const i=cx(n,s);return r==="grid"?xo(e,n,i):r==="clustered"?yo(e,t,n,i,o):r==="hierarchical"||e.length<=ax?po(e,t,n,o):new Set(e.map(c=>i(c.id)).filter(Boolean)).size>1?yo(e,t,n,i,o):xo(e,n,i)}function cx(e,t){return n=>{var r,s,o;if(t){const i=t.get(n);if(i)return i.name}return((o=(s=(r=e.get(n))==null?void 0:r.conceptual)==null?void 0:s.subject_area)==null?void 0:o.name)??""}}function Ia(e,t,n,r=!1,s="LR"){const o=new mo.graphlib.Graph;o.setGraph({rankdir:s,nodesep:r?45:70,ranksep:r?110:150,edgesep:r?20:30,marginx:24,marginy:24,ranker:"network-simplex"}),o.setDefaultEdgeLabel(()=>({}));const i=new Set(e.map(l=>l.id));for(const l of e){const d=n.get(l.id);o.setNode(l.id,{width:Qe,height:d?gt(d):120})}for(const l of t)i.has(l.source)&&i.has(l.target)&&o.setEdge(l.source,l.target,{minlen:1,weight:2});mo.layout(o);let a=0,c=0;return{nodes:e.map(l=>{const d=o.node(l.id),m=n.get(l.id),f=m?gt(m):120,p=d.x-Qe/2,x=d.y-f/2;return a=Math.max(a,p+Qe),c=Math.max(c,x+f),{...l,position:{x:p,y:x}}}),width:a,height:c}}function po(e,t,n,r="LR"){return Ia(e,t,n,!1,r).nodes}function lx(e,t){const n=a=>{const c=t.get(a);return c?gt(c):120},r=Math.max(1,Math.round(Math.sqrt(e.length))),s=[];let o=0,i=0;for(let a=0;a{const d=l*(Qe+Ta);s.push({...u,position:{x:d,y:o}}),i=Math.max(i,d+Qe)}),o+=Math.max(...c.map(u=>n(u.id)))+Oa}return{nodes:s,width:i,height:o}}const go=120;function yo(e,t,n,r,s="LR"){const o=new Map;for(const m of e){const f=r(m.id);(o.get(f)??o.set(f,[]).get(f)).push(m)}const a=[...o.keys()].sort((m,f)=>m===""?1:f===""?-1:m.localeCompare(f)).map(m=>{const f=o.get(m),p=new Set(f.map(E=>E.id));let x=0;for(const E of t)p.has(E.source)&&p.has(E.target)&&x++;const g=f.length<=8&&x>=f.length-1?Ia(f,t,n,!0,s):lx(f,n);return{name:m,...g}}),c=Math.max(1,Math.ceil(Math.sqrt(a.length*1.6))),u=[];let l=0;for(let m=0;m[m.id,m.position]));return e.map(m=>({...m,position:d.get(m.id)??m.position}))}const Ta=40,Oa=40;function xo(e,t,n){const r=u=>{const l=t.get(u);return l?gt(l):120},s=[...e].sort((u,l)=>{var x,v;const d=n(u.id),m=n(l.id);if(d!==m)return d.localeCompare(m);const f=((x=t.get(u.id))==null?void 0:x.name)??u.id,p=((v=t.get(l.id))==null?void 0:v.name)??l.id;return f.localeCompare(p)}),o=Math.max(1,Math.round(Math.sqrt(s.length))),i=Array.from({length:o},(u,l)=>l*(Qe+Ta)),a=new Map;let c=0;for(let u=0;ua.set(m.id,{x:i[f],y:c}));const d=Math.max(...l.map(m=>r(m.id)));c+=d+Oa}return e.map(u=>({...u,position:a.get(u.id)??u.position}))}function dn({title:e,onClose:t,children:n,wide:r}){return h.jsx("div",{className:"modal-backdrop",onClick:t,children:h.jsxs("div",{className:"modal"+(r?" wide":""),onClick:s=>s.stopPropagation(),children:[h.jsxs("div",{className:"modal-header",children:[h.jsx("h2",{children:e}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),n]})})}const ux=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],La=["industry","core","domain","specialised"];function dx({entity:e,exec:t,onClose:n}){var b,$;const[r,s]=w.useState(((b=e.conceptual)==null?void 0:b.name)??e.name),[o,i]=w.useState([]),[a,c]=w.useState(null),[u,l]=w.useState(null),[d,m]=w.useState("skos:exactMatch"),[f,p]=w.useState((($=e.conceptual)==null?void 0:$.ontology_layer)??"core"),[x,v]=w.useState([]),[g,E]=w.useState("");w.useEffect(()=>{ia().then(j=>v(j.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const j=setTimeout(()=>{if(!r.trim())return i([]);oa(r,g||void 0).then(_=>{i(_.results),c(_.loaded_terms)}).catch(()=>i([]))},200);return()=>clearTimeout(j)},[r,g]);const M=()=>{u&&t("set_alignment",{id:e.id,aligns_to:u.prefixed,alignment:d,layer:f,resolved_via:u.source}).then(n)};return h.jsxs(dn,{title:`Align '${e.name}' to ontology`,onClose:n,wide:!0,children:[x.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(g===""?" active":""),onClick:()=>E(""),children:"all sources"}),x.map(j=>h.jsx("button",{className:"src-chip"+(g===j.id?" active":""),title:j.count!=null?`${j.count} terms`:"live resolver",onClick:()=>E(j.id),children:j.name},j.id))]}),h.jsx("input",{autoFocus:!0,className:"edit-input modal-search",placeholder:g?`Search within ${g}…`:"Search vocabulary terms…",value:r,onChange:j=>s(j.target.value)}),a===0&&x.length===0&&h.jsx("p",{className:"empty-hint",children:"No vocabulary loaded. Declare one in mdl-project.yaml's ontology_stack (or run `mdl ontology vendor fibo`)."}),h.jsxs("div",{className:"term-results",children:[o.map(j=>h.jsxs("button",{className:"term-card"+((u==null?void 0:u.iri)===j.iri?" picked":""),onClick:()=>l(j),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:j.label}),h.jsxs("span",{className:"term-source",children:[j.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",children:"glossary"}),j.source]})]}),h.jsx("code",{className:"term-iri",children:j.prefixed}),j.definition&&h.jsx("p",{className:"term-def",children:j.definition})]},j.iri)),r&&o.length===0&&a!==0&&h.jsxs("p",{className:"empty-hint",children:["no matches for “",r,"”"]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsxs("label",{children:["predicate",h.jsx("select",{value:d,onChange:j=>m(j.target.value),children:ux.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("label",{children:["layer",h.jsx("select",{value:f,onChange:j=>p(j.target.value),children:La.map(j=>h.jsx("option",{children:j},j))})]}),h.jsxs("button",{className:"primary-btn",disabled:!u,onClick:M,children:["Align",u?` to ${u.label}`:""]})]})]})}function fx({entity:e,doc:t,exec:n,onClose:r}){var b,$,j;const[s,o]=w.useState(((b=e.term_map)==null?void 0:b.subject_template)??""),[i,a]=w.useState((($=e.term_map)==null?void 0:$.class_iri)??""),c=new Set(e.attributes.map(_=>_.name)),l=Array.from(s.matchAll(/\{([^}]+)\}/g)).map(_=>_[1]).filter(_=>!c.has(_)),d=_=>!_||_.startsWith("http://")||_.startsWith("https://")||/^[^\s:]+:[^\s:]+/.test(_),m=l.length===0&&d(i),f=()=>{n("set_term_map",{id:e.id,subject_template:s.trim()||null,class_iri:i.trim()||null}).then(r)},p=(t.project.name||"").replace(/[^0-9a-zA-Z]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()||"modelith-model",x=t.project.kg_base_iri||`urn:${p}:`,v=(j=(e.key_groups??[]).find(_=>_.type==="pk"))==null?void 0:j.members.map(_=>{var R;return(R=e.attributes.find(N=>N.id===_))==null?void 0:R.name}).filter(Boolean),g=v&&v.length?`${x}${e.id}/${v.map(_=>`{${_}}`).join("_")}`:"(blank-node: entity has no primary key)",E=i.trim()||`${x}${e.id}`,M=s.trim()||g;return h.jsxs(dn,{title:`Knowledge Graph mapping — ${e.name}`,onClose:r,wide:!0,children:[h.jsx("p",{className:"empty-hint",style:{marginBottom:14},children:"Override the R2RML term-map for this entity. Leave a field blank to use the default (project base IRI + primary key)."}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-class",children:"Class IRI"}),h.jsx("input",{id:"tm-class",className:"edit-input",value:i,placeholder:"https://acme.com/Customer or fibo-fnd:Party",onChange:_=>a(_.target.value)}),d(i)?h.jsxs("code",{className:"form-preview",children:["rr:class ",E]}):h.jsx("span",{className:"form-error",children:"not a valid IRI or prefix:local CURIE"})]}),h.jsxs("div",{className:"form-row",children:[h.jsx("label",{htmlFor:"tm-subject",children:"Subject template"}),h.jsx("input",{id:"tm-subject",className:"edit-input",value:s,placeholder:"https://acme.com/id/customer/{customer_id}",onChange:_=>o(_.target.value)}),l.length>0?h.jsxs("span",{className:"form-error",children:["unknown column",l.length>1?"s":"",": ",l.join(", ")]}):h.jsxs("code",{className:"form-preview",children:["rr:template ",M]}),h.jsxs("span",{className:"form-hint",children:["Wrap a column in ","{ }"," to fill it from each row, e.g."," ","{"+((v==null?void 0:v[0])??"id")+"}",". Columns:"," ",e.attributes.map(_=>_.name).join(", ")]})]}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn",onClick:r,children:"Cancel"}),h.jsx("button",{className:"primary-btn",disabled:!m,onClick:f,children:"Save mapping"})]})]})}function hx({doc:e,exec:t,onClose:n,onCreated:r}){const[s,o]=w.useState(""),[i,a]=w.useState(""),[c,u]=w.useState(""),[l,d]=w.useState(""),m=()=>{s.trim()&&t("create_entity",{name:s,definition:i||null,subject_area:c||null,layer:l||null}).then(f=>{const p=f==null?void 0:f.created_id;n(),p&&r(p)})};return h.jsxs(dn,{title:"New entity",onClose:n,children:[h.jsxs("label",{className:"form-row",children:["name",h.jsx("input",{autoFocus:!0,className:"edit-input",placeholder:"e.g. custody_account",value:s,onChange:f=>o(f.target.value),onKeyDown:f=>f.key==="Enter"&&m()})]}),h.jsxs("label",{className:"form-row",children:["definition",h.jsx("textarea",{className:"edit-input",rows:2,placeholder:"business definition…",value:i,onChange:f=>a(f.target.value)})]}),h.jsxs("label",{className:"form-row",children:["subject area",h.jsxs("select",{value:c,onChange:f=>u(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),e.subject_areas.map(f=>h.jsx("option",{value:f.id,children:f.name},f.id))]})]}),h.jsxs("label",{className:"form-row",children:["ontology layer",h.jsxs("select",{value:l,onChange:f=>d(f.target.value),children:[h.jsx("option",{value:"",children:"none"}),La.map(f=>h.jsx("option",{children:f},f))]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",disabled:!s.trim(),onClick:m,children:"Create"})})]})}const Da=["many_to_one","one_to_many","one_to_one","many_to_many"];function mx({doc:e,fromId:t,toId:n,initialFromAttr:r,initialToAttr:s,exec:o,onClose:i}){const a=e.entities.find(b=>b.id===t),c=e.entities.find(b=>b.id===n),u=w.useMemo(()=>c==null?void 0:c.attributes.find(b=>b.role==="business_key"),[c]),[l,d]=w.useState(r??""),[m,f]=w.useState(s??(u==null?void 0:u.id)??""),[p,x]=w.useState("many_to_one"),[v,g]=w.useState("mandatory");if(!a||!c)return null;const E=l==="__new__",M=()=>o("create_relationship",{from_entity:a.id,to_entity:c.id,from_attribute:E?null:l||null,to_attribute:m||null,create_from_fk:E,cardinality:p,optionality:v}).then(i);return h.jsxs(dn,{title:`${a.name} → ${c.name}`,onClose:i,children:[h.jsxs("label",{className:"form-row",children:["cardinality (",a.name," : ",c.name,")",h.jsx("select",{value:p,onChange:b=>x(b.target.value),children:Da.map(b=>h.jsx("option",{children:b},b))})]}),h.jsxs("label",{className:"form-row",children:["foreign key on ",a.name,h.jsxs("select",{value:l,onChange:b=>d(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),h.jsxs("option",{value:"__new__",children:["➕ create column",u?` "${u.name}"`:""]}),a.attributes.map(b=>h.jsx("option",{value:b.id,children:b.name},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["references on ",c.name,h.jsxs("select",{value:m,onChange:b=>f(b.target.value),children:[h.jsx("option",{value:"",children:"(none)"}),c.attributes.map(b=>h.jsxs("option",{value:b.id,children:[b.name,b.role==="business_key"?" 🔑":""]},b.id))]})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:v,onChange:b=>g(b.target.value),children:[h.jsx("option",{children:"mandatory"}),h.jsx("option",{children:"optional"})]})]}),h.jsx("div",{className:"modal-footer",children:h.jsx("button",{className:"primary-btn",onClick:M,children:"Create relationship"})})]})}function px({rel:e,doc:t,exec:n,onClose:r}){const s=g=>{var E;return((E=t.entities.find(M=>M.id===g))==null?void 0:E.name)??"?"},[o,i]=w.useState(e.name),[a,c]=w.useState(e.cardinality),[u,l]=w.useState(e.optionality),[d,m]=w.useState(e.identifying),[f,p]=w.useState(!1),x=async()=>{o.trim()&&o.trim()!==e.name&&await n("rename_relationship",{id:e.id,name:o.trim()}),(a!==e.cardinality||u!==e.optionality||d!==e.identifying)&&await n("update_relationship",{id:e.id,cardinality:a,optionality:u,identifying:d}),r()},v=()=>n("delete_relationship",{id:e.id}).then(r);return h.jsxs(dn,{title:`${s(e.from.entity)} → ${s(e.to.entity)}`,onClose:r,children:[h.jsxs("label",{className:"form-row",children:["relationship name",h.jsx("input",{value:o,onChange:g=>i(g.target.value),autoFocus:!0})]}),h.jsxs("label",{className:"form-row",children:["cardinality",h.jsx("select",{value:a,onChange:g=>c(g.target.value),children:Da.map(g=>h.jsx("option",{children:g},g))})]}),h.jsxs("label",{className:"form-row",children:["optionality",h.jsxs("select",{value:u,onChange:g=>l(g.target.value),children:[h.jsx("option",{value:"mandatory",children:"mandatory"}),h.jsx("option",{value:"optional",children:"optional"})]})]}),h.jsxs("label",{className:"form-row",children:["identifying",h.jsxs("select",{value:d?"yes":"no",onChange:g=>m(g.target.value==="yes"),children:[h.jsx("option",{value:"no",children:"no — parent key is a plain reference"}),h.jsx("option",{value:"yes",children:"yes — parent key is part of the child's identity"})]})]}),h.jsxs("div",{className:"modal-footer",style:{justifyContent:"space-between"},children:[f?h.jsx("button",{className:"danger-btn",onClick:v,children:"Confirm delete"}):h.jsx("button",{className:"mini-btn danger",onClick:()=>p(!0),children:"Delete relationship"}),h.jsx("button",{className:"primary-btn",onClick:x,children:"Save"})]})]})}const wo=10,gx=6,Rt=24;function yx(e,t){return t?e:Math.round(e/wo)*wo}function xx(e,t,n){const r=[...t];for(const i of n)r.push(i.left-Rt,i.right+Rt);let s=e,o=gx;for(const i of r){const a=Math.abs(i-e);at.left&&ei.left&&no.left&&n=i.right?(l.push({x:n,y:t.y},{x:i.right,y:t.y}),m={ox:1,oy:0}):(l.push({x:n,y:t.y},{x:i.left,y:t.y}),m={ox:-1,oy:0});return{path:Nx(l),sourceOut:d,targetOut:m}}const dt=8;function kx(e,t,n){const r=Math.abs(e-n.left),s=Math.abs(e-n.right),o=Math.abs(t-n.top),i=Math.abs(t-n.bottom),a=Math.min(r,s,o,i),c=(u,l,d)=>Math.min(Math.max(u,l),d);return a===r?{side:"left",x:n.left,y:c(t,n.top+dt,n.bottom-dt)}:a===s?{side:"right",x:n.right,y:c(t,n.top+dt,n.bottom-dt)}:a===o?{side:"top",x:c(e,n.left+dt,n.right-dt),y:n.top}:{side:"bottom",x:c(e,n.left+dt,n.right-dt),y:n.bottom}}function vo(e,t){const n=(r,s,o)=>Math.min(Math.max(r,s),o);switch(e.side){case"left":return{x:t.left,y:n(e.y,t.top,t.bottom),out:{ox:-1,oy:0}};case"right":return{x:t.right,y:n(e.y,t.top,t.bottom),out:{ox:1,oy:0}};case"top":return{x:n(e.x??(t.left+t.right)/2,t.left,t.right),y:t.top,out:{ox:0,oy:-1}};default:return{x:n(e.x??(t.left+t.right)/2,t.left,t.right),y:t.bottom,out:{ox:0,oy:1}}}}const hr=3,jx=w.memo(function({id:t,source:n,target:r,sourceX:s,sourceY:o,targetX:i,targetY:a,sourcePosition:c,targetPosition:u,data:l,selected:d}){const{screenToFlowPosition:m}=un(),f=me(G=>G.transform[2]),p=me(G=>Eo(G.nodeInternals.get(n)),_o),x=me(G=>Eo(G.nodeInternals.get(r)),_o),[v,g]=w.useState(null),[E,M]=w.useState(null),b=w.useRef(!1),$=w.useRef(0),j=l==null?void 0:l.onRouteChange,_=!!j,R=v??(l==null?void 0:l.routeX),N=p??(l==null?void 0:l.sourceCard),I=x??(l==null?void 0:l.targetCard),L=(E==null?void 0:E.end)==="source"?E.a:l==null?void 0:l.sourceAnchor,B=(E==null?void 0:E.end)==="target"?E.a:l==null?void 0:l.targetAnchor,H=L&&N?vo(L,N):{x:s,y:o,out:null},y=B&&I?vo(B,I):{x:i,y:a,out:null},C=H.x,S=H.y,O=y.x,D=y.y,k=(L==null?void 0:L.side)==="right"?K.Right:(L==null?void 0:L.side)==="left"?K.Left:c,T=(B==null?void 0:B.side)==="right"?K.Right:(B==null?void 0:B.side)==="left"?K.Left:u,[P,z,U]=Tn({sourceX:C,sourceY:S,sourcePosition:k,targetX:O,targetY:D,targetPosition:T,borderRadius:10,...R!=null?{centerX:R}:{}}),W=N,Q=I,te=R!=null&&W&&Q?Sx({x:C,y:S},{y:D},R,k===K.Left?-1:1,T===K.Left?-1:1,W,Q):null,se=te?te.path:P,J=l==null?void 0:l.relationship,ae=(l==null?void 0:l.dimmed)??!1,oe=(J==null?void 0:J.cardinality)??"many_to_one",he=(J==null?void 0:J.optionality)==="optional",ye=(J==null?void 0:J.identifying)??!1,Ee=oe==="many_to_one"||oe==="many_to_many",ve=oe==="one_to_many"||oe==="many_to_many",ue="rel-edge"+(d||l!=null&&l.edgeSelected?" selected":"")+(ae?" dimmed":""),ge=((l==null?void 0:l.memberCount)??0)>1,le=l==null?void 0:l.onHoverEdge,q=R??z,fe=U,Oe=q,Ke=fe,Ye=te?te.sourceOut:H.out??{ox:k===K.Left?-1:1,oy:0},$e=te?te.targetOut:y.out??{ox:T===K.Left?-1:1,oy:0},Ae={x:C,y:S},je=te&&Q?$e.oy!==0?{x:R,y:$e.oy<0?Q.top:Q.bottom}:{x:$e.ox>0?Q.right:Q.left,y:D}:{x:O,y:D},Re=w.useCallback(G=>j&&J&&j(J.id,G),[j,J]),ze=w.useCallback(G=>{var Ie,Le;if(!_||G.button!==0)return;G.stopPropagation(),(Le=(Ie=G.target).setPointerCapture)==null||Le.call(Ie,G.pointerId),b.current=!0,$.current=0;const xe=m({x:G.clientX,y:G.clientY}).x;let ee=0,ne=R??q;const ie=Te=>{const Ne=m({x:Te.clientX,y:Te.clientY});$.current=Math.max($.current,Math.abs(Ne.x-xe)),ne=bx(Ne.x,{shift:Te.shiftKey,source:(l==null?void 0:l.sourceCard)??{left:s,right:s},target:(l==null?void 0:l.targetCard)??{left:i,right:i}}),ee||(ee=requestAnimationFrame(()=>{ee=0,g(ne)}))},pe=()=>{window.removeEventListener("pointermove",ie),window.removeEventListener("pointerup",pe),ee&&cancelAnimationFrame(ee),b.current=!1,g(null),$.current>=hr&&Re(ne)};window.addEventListener("pointermove",ie),window.addEventListener("pointerup",pe)},[_,m,R,q,l,s,i,Re]),F=w.useCallback(G=>{$.current>=hr&&(G.stopPropagation(),$.current=0)},[]),X=w.useCallback(G=>{_&&(G.stopPropagation(),Re(null))},[_,Re]),V=l==null?void 0:l.onAnchorChange,Z=w.useCallback(G=>re=>{var Le,Te;const xe=G==="source"?N:I;if(!V||!J||!xe||re.button!==0)return;re.stopPropagation(),(Te=(Le=re.target).setPointerCapture)==null||Te.call(Le,re.pointerId),$.current=0;const ee=m({x:re.clientX,y:re.clientY});let ne=0,ie=null;const pe=Ne=>{const He=m({x:Ne.clientX,y:Ne.clientY});$.current=Math.max($.current,Math.hypot(He.x-ee.x,He.y-ee.y)),ie=kx(He.x,He.y,xe),ne||(ne=requestAnimationFrame(()=>{ne=0,M({end:G,a:ie})}))},Ie=()=>{window.removeEventListener("pointermove",pe),window.removeEventListener("pointerup",Ie),ne&&cancelAnimationFrame(ne),M(null),$.current>=hr&&ie&&V(J.id,G,ie)};window.addEventListener("pointermove",pe),window.addEventListener("pointerup",Ie)},[V,J,N,I,m]),Y=w.useCallback(G=>re=>{!V||!J||(re.stopPropagation(),V(J.id,G,null))},[V,J]);return h.jsxs("g",{className:ue,onMouseEnter:le?()=>le(J.id):void 0,onMouseLeave:le?()=>le(null):void 0,children:[h.jsx("path",{id:t,className:"rel-path",d:se,fill:"none",strokeDasharray:ye?void 0:"6 4"}),h.jsx("path",{d:se,fill:"none",strokeWidth:16/f,stroke:"transparent"}),h.jsx(So,{x:Ae.x,y:Ae.y,out:Ye,many:Ee,optional:he}),h.jsx(So,{x:je.x,y:je.y,out:$e,many:ve,optional:!1}),!!V&&((l==null?void 0:l.hovered)||(l==null?void 0:l.edgeSelected)||d||E!=null)&&h.jsxs(h.Fragment,{children:[h.jsx(No,{x:Ae.x,y:Ae.y,zoom:f,onPointerDown:Z("source"),onDoubleClick:Y("source")}),h.jsx(No,{x:je.x,y:je.y,zoom:f,onPointerDown:Z("target"),onDoubleClick:Y("target")})]}),_&&((l==null?void 0:l.hovered)||(l==null?void 0:l.edgeSelected)||d||v!=null)&&h.jsxs("g",{className:"rel-handle",style:{cursor:"ew-resize"},onPointerDown:ze,onClickCapture:F,onDoubleClick:X,children:[h.jsx("rect",{x:q-20/f,y:Math.min(S,D),width:40/f,height:Math.max(Math.abs(D-S),24/f),fill:"transparent"}),h.jsx("rect",{className:"rel-grip",x:q-5.5/f,y:fe-11/f,width:11/f,height:22/f,rx:5/f,strokeWidth:1.5/f}),h.jsx("circle",{className:"rel-grip-dot",cx:q,cy:fe-4.5/f,r:1.1/f}),h.jsx("circle",{className:"rel-grip-dot",cx:q,cy:fe,r:1.1/f}),h.jsx("circle",{className:"rel-grip-dot",cx:q,cy:fe+4.5/f,r:1.1/f})]}),(d||ge)&&J&&h.jsxs("text",{className:"rel-label",x:Oe,y:Ke-8,children:[d?J.verb_phrase||J.name:"",ge?`${d?" ":""}(${l.memberCount})`:""]})]})});function _o(e,t){return e===t?!0:!e||!t?!1:e.left===t.left&&e.right===t.right&&e.top===t.top&&e.bottom===t.bottom}function Eo(e){if(!(e!=null&&e.positionAbsolute)||e.width==null||e.height==null)return null;const{x:t,y:n}=e.positionAbsolute;return{left:t,right:t+e.width,top:n,bottom:n+e.height}}function No({x:e,y:t,zoom:n,onPointerDown:r,onDoubleClick:s}){return h.jsxs("g",{className:"rel-endpoint",style:{cursor:"move"},onPointerDown:r,onDoubleClick:s,children:[h.jsx("circle",{cx:e,cy:t,r:10/n,fill:"transparent"}),h.jsx("circle",{className:"rel-endpoint-dot",cx:e,cy:t,r:3.5/n,strokeWidth:1.5/n})]})}function So({x:e,y:t,out:n,many:r,optional:s}){const{ox:a,oy:c}=n,u=-c,l=a,d=p=>({x:e+a*p,y:t+c*p}),m=(p,x)=>({x:e+a*p+u*x,y:t+c*p+l*x}),f=[];if(r){const p=d(12),x=m(0,-7),v=d(0),g=m(0,7);f.push(h.jsx("path",{className:"rel-glyph",d:`M ${p.x} ${p.y} L ${x.x} ${x.y} M ${p.x} ${p.y} L ${v.x} ${v.y} M ${p.x} ${p.y} L ${g.x} ${g.y}`,fill:"none"},"foot"))}else{const p=m(9,-7),x=m(9,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:x.x,y2:x.y},"one"))}if(s){const p=d(18);f.push(h.jsx("circle",{className:"rel-glyph ring",cx:p.x,cy:p.y,r:4},"opt"))}else{const p=m(17,-7),x=m(17,7);f.push(h.jsx("line",{className:"rel-glyph",x1:p.x,y1:p.y,x2:x.x,y2:x.y},"mand"))}return h.jsx(h.Fragment,{children:f})}const Cx={entity:Gm},Mx={relationship:jx},ko=["#e0a63a","#e8825a","#d98ba8","#c4a3e0","#7fb0d8","#7fc9a0","#e6c14a"],jo="#8a7d6a";function Co(e){return{side:e.side,y:Math.round(e.y),...e.x!=null?{x:Math.round(e.x)}:{}}}function $x(e,t,n){const s=Qe;let{x:o,y:i}=e,a=!0,c=0;for(;a&&c++<200;){a=!1;for(const u of n)ou.x&&iu.y&&(i=u.y+u.h+16,a=!0)}return{x:o,y:i}}function Ax(e,t){const n=(o,i)=>{var a;return!!i&&!!((a=t.get(o))!=null&&a.attributes.some(c=>c.id===i))},r=e.from.attributes[0],s=e.to.attributes[0];return{sourceHandle:n(e.from.entity,r)?r:Ur,targetHandle:n(e.to.entity,s)?s:qr}}function aw({doc:e,caps:t,exec:n,selectedId:r,onSelect:s,query:o="",showTypes:i=!0,collapseDetail:a=!1,expandedEntities:c,onToggleExpand:u,activeAreas:l,onError:d,handleRef:m,layoutStore:f}){const{fitView:p,fitBounds:x,getNodes:v}=un(),[g,E]=w.useState([]),[M,b]=w.useState([]),$=w.useRef(!1),j=w.useMemo(()=>{const F=l&&l.size>0?[...l].sort():null;return F?"sa:"+F.join("+"):"__all__"},[l]),_=w.useRef(null),[R,N]=w.useState(0),I=w.useRef(new Map),L=w.useRef(null);w.useEffect(()=>{if(!f){_.current=null;return}const F=I.current.get(j);if(F){_.current=F,$.current=!1,N(V=>V+1);return}let X=!1;return f.load(j).then(V=>{X||(I.current.set(j,V),_.current=V,$.current=!1,N(Z=>Z+1))}),()=>{X=!0}},[f,j]);const[B,H]=w.useState(null),[y,C]=w.useState(null),[S,O]=w.useState(!1),[D,k]=w.useState(null),[T,P]=w.useState(null),[z,U]=w.useState(null),[W,Q]=w.useState(null),[te,se]=w.useState(null),J=w.useRef({}),ae=!t.canEdit,oe=w.useRef(null),he=w.useCallback(()=>{f&&(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{const F={};for(const Z of v())Z.hidden||(F[Z.id]={x:Math.round(Z.position.x),y:Math.round(Z.position.y)});const X={};for(const[Z,Y]of Object.entries(J.current)){const G={};Y.routeX!=null&&(G.routeX=Math.round(Y.routeX)),Y.sourceAnchor&&(G.sourceAnchor=Co(Y.sourceAnchor)),Y.targetAnchor&&(G.targetAnchor=Co(Y.targetAnchor)),(G.routeX!=null||G.sourceAnchor||G.targetAnchor)&&(X[Z]=G)}const V={nodes:F,edges:X};I.current.set(j,V),_.current=V,f.save(j,V)},800))},[f,v,j]),ye=w.useCallback((F,X)=>{const V=J.current[F]??{};X==null?delete V.routeX:V.routeX=X,J.current[F]=V,b(Z=>Z.map(Y=>Y.id===F?{...Y,data:{...Y.data,routeX:X??void 0}}:Y)),he()},[he]),Ee=w.useCallback((F,X,V)=>{const Z=J.current[F]??{},Y=X==="source"?"sourceAnchor":"targetAnchor";V==null?delete Z[Y]:Z[Y]=V,J.current[F]=Z,b(G=>G.map(re=>re.id===F?{...re,data:{...re.data,[Y]:V??void 0}}:re)),he()},[he]),ve=w.useMemo(()=>{const F=new Map;return e.subject_areas.forEach((X,V)=>F.set(X.id,ko[V%ko.length])),F},[e]),ue=w.useMemo(()=>{const F=new Map;return e.entities.forEach(X=>F.set(X.id,X)),F},[e]),ge=w.useMemo(()=>{const F=new Map,X=new Map;return e.subject_areas.forEach(V=>{(V.members??[]).forEach(Z=>X.set(Z,{id:V.id,name:V.name}))}),e.entities.forEach(V=>{var re,xe;const Z=(re=V.conceptual)!=null&&re.id?X.get(V.conceptual.id):void 0,Y=(xe=V.conceptual)==null?void 0:xe.subject_area,G=Z??(Y?{id:Y.id,name:Y.name??Y.id}:void 0);G&&F.set(V.id,G)}),F},[e]),le=w.useCallback(F=>{var V;if(!l||l.size===0)return!1;const X=(V=ge.get(F))==null?void 0:V.id;return!(X&&l.has(X))},[l,ge]),q=w.useMemo(()=>{const F=new Map,X=(V,Z)=>{if(!Z.length)return;const Y=F.get(V)??new Set;Z.forEach(G=>Y.add(G)),F.set(V,Y)};for(const V of e.relationships)X(V.from.entity,V.from.attributes),X(V.to.entity,V.to.attributes);return F},[e]);w.useEffect(()=>{var xe;const F=o.trim().toLowerCase(),X=new Set;if(F)for(const ee of e.entities)(ee.name.toLowerCase()+" "+(((xe=ee.conceptual)==null?void 0:xe.name.toLowerCase())??"")+" "+ee.attributes.map(ie=>ie.name.toLowerCase()).join(" ")).includes(F)&&X.add(ee.id);const V=new Set;if(r){V.add(r);for(const ee of e.relationships)ee.from.entity===r&&V.add(ee.to.entity),ee.to.entity===r&&V.add(ee.from.entity)}const Z=e.entities.map(ee=>{const ne=F!==""&&!X.has(ee.id),ie=r!==null&&!V.has(ee.id);return{id:ee.id,type:"entity",position:{x:0,y:0},hidden:le(ee.id),data:{entity:ee,color:(()=>{const pe=ge.get(ee.id);return pe?ve.get(pe.id)??jo:jo})(),dimmed:ne||ie,highlighted:F!==""&&X.has(ee.id),showTypes:i,collapseDetail:a,expanded:(c==null?void 0:c.has(ee.id))??!1,onToggleExpand:u,endpointAttrs:q.get(ee.id),highlightAttrs:void 0,onHoverAttr:U}}}),Y=e.relationships.filter(ee=>ue.has(ee.from.entity)&&ue.has(ee.to.entity)).map(ee=>{const{sourceHandle:ne,targetHandle:ie}=Ax(ee,ue),pe=r!==null&&ee.from.entity!==r&&ee.to.entity!==r;return{id:ee.id,source:ee.from.entity,target:ee.to.entity,sourceHandle:ne,targetHandle:ie,type:"relationship",data:{relationship:ee,dimmed:pe,memberCount:Math.max(ee.from.attributes.length,ee.to.attributes.length),onHoverEdge:Q}}}),G=_.current;if(J.current={},G)for(const[ee,ne]of Object.entries(G.edges))J.current[ee]={...ne.routeX!=null?{routeX:ne.routeX}:{},...ne.sourceAnchor?{sourceAnchor:ne.sourceAnchor}:{},...ne.targetAnchor?{targetAnchor:ne.targetAnchor}:{}};const re=ee=>{const ne=new Map;for(const ie of ee)ne.set(ie.id,{left:ie.position.x,right:ie.position.x+Qe,top:ie.position.y,bottom:ie.position.y+gt(ie.data.entity)});b(Y.map(ie=>{const pe=J.current[ie.id]??{};return{...ie,data:{...ie.data,routeX:pe.routeX,sourceAnchor:pe.sourceAnchor,targetAnchor:pe.targetAnchor,onRouteChange:f?ye:void 0,onAnchorChange:f?Ee:void 0,sourceCard:ne.get(ie.source),targetCard:ne.get(ie.target)}}}))};E(ee=>{const ne=new Map(ee.map(de=>[de.id,de.position])),ie=Z.every(de=>ne.has(de.id)),pe=((l==null?void 0:l.size)??0)>0;if($.current&&ie&&ee.length>=Z.length&&!pe){const de=Z.map(et=>({...et,position:ne.get(et.id)??et.position}));return re(de),de}const Ie=pe?Z.filter(de=>!de.hidden):Z,Le=fr(Ie,Y,ue,"auto",ge),Te=new Map(Le.map(de=>[de.id,de.position])),Ne=(G==null?void 0:G.nodes)??{},He=Object.keys(Ne).length>0,lt=[],Ht=Z.map(de=>{const et=Ne[de.id];if(et){const Ft={x:et.x,y:et.y};return lt.push({x:Ft.x,y:Ft.y,w:Qe,h:gt(de.data.entity)}),{...de,position:Ft}}return Te.has(de.id)?{...de,position:Te.get(de.id)}:ne.has(de.id)&&$.current?{...de,position:ne.get(de.id)}:de});if(He)for(const de of Ht)Ne[de.id]||de.hidden||(de.position=$x(de.position,gt(de.data.entity),lt),lt.push({x:de.position.x,y:de.position.y,w:Qe,h:gt(de.data.entity)}));return $.current=!0,He||requestAnimationFrame(()=>p({padding:.15,duration:300})),re(Ht),Ht})},[e,o,r,i,a,c,u,ve,ue,ge,le,l,q,p,f,ye,Ee,R]);const fe=w.useMemo(()=>{const F=new Set,X=new Set,V=new Map,Z=(Y,G)=>{if(!G.length)return;const re=V.get(Y)??new Set;G.forEach(xe=>re.add(xe)),V.set(Y,re)};if(z)for(const Y of e.relationships)(Y.from.attributes.includes(z)||Y.to.attributes.includes(z))&&(F.add(Y.id),X.add(Y.from.entity),X.add(Y.to.entity),Z(Y.from.entity,Y.from.attributes),Z(Y.to.entity,Y.to.attributes));if(W){const Y=e.relationships.find(G=>G.id===W);Y&&(Z(Y.from.entity,Y.from.attributes),Z(Y.to.entity,Y.to.attributes))}return{active:z!==null,relsForAttr:F,entsForAttr:X,hitAttrsByEntity:V}},[e,z,W]);w.useEffect(()=>{var Z;const F=o.trim().toLowerCase(),X=new Set;if(F)for(const Y of e.entities)(Y.name.toLowerCase()+" "+(((Z=Y.conceptual)==null?void 0:Z.name.toLowerCase())??"")+" "+Y.attributes.map(re=>re.name.toLowerCase()).join(" ")).includes(F)&&X.add(Y.id);const V=new Set;if(r){V.add(r);for(const Y of e.relationships)Y.from.entity===r&&V.add(Y.to.entity),Y.to.entity===r&&V.add(Y.from.entity)}E(Y=>Y.map(G=>{const re=F!==""&&!X.has(G.id),xe=r!==null&&!V.has(G.id),ee=fe.active&&!fe.entsForAttr.has(G.id),ne=re||xe||ee,ie=F!==""&&X.has(G.id)||fe.active&&fe.entsForAttr.has(G.id),pe=fe.hitAttrsByEntity.get(G.id);return G.data.dimmed===ne&&G.data.highlighted===ie&&G.data.highlightAttrs===pe?G:{...G,data:{...G.data,dimmed:ne,highlighted:ie,highlightAttrs:pe}}})),b(Y=>Y.map(G=>{var Te,Ne,He,lt;const re=(Te=G.data)==null?void 0:Te.relationship,xe=r!==null&&re!==void 0&&re.from.entity!==r&&re.to.entity!==r,ee=fe.active&&!fe.relsForAttr.has(G.id),ne=xe||ee,ie=W===G.id,pe=te===G.id,Ie=r!==null&&re!==void 0&&(re.from.entity===r||re.to.entity===r),Le=ie||pe||Ie?1e3:0;return((Ne=G.data)==null?void 0:Ne.dimmed)===ne&&((He=G.data)==null?void 0:He.hovered)===ie&&((lt=G.data)==null?void 0:lt.edgeSelected)===pe&&G.zIndex===Le?G:{...G,zIndex:Le,data:{...G.data,dimmed:ne,hovered:ie,edgeSelected:pe}}}))},[fe,W,te,o,r,e]),w.useEffect(()=>{var Z;const F=o.trim().toLowerCase();if(!F)return;const X=new Set;for(const Y of e.entities)(Y.name.toLowerCase()+" "+(((Z=Y.conceptual)==null?void 0:Z.name.toLowerCase())??"")+" "+Y.attributes.map(re=>re.name.toLowerCase()).join(" ")).includes(F)&&X.add(Y.id);if(!X.size)return;const V=requestAnimationFrame(()=>{const Y=v().filter(re=>X.has(re.id));if(!Y.length)return;const G=Lf(Y);x(G,{padding:.35,duration:400})});return()=>cancelAnimationFrame(V)},[o,e,v,x]);const Oe=w.useCallback((F="auto",X="LR")=>{L.current=Object.fromEntries(v().map(V=>[V.id,{x:V.position.x,y:V.position.y}])),E(V=>fr(V,M,ue,F,ge,X)),requestAnimationFrame(()=>p({padding:.15,duration:300})),he()},[M,ue,ge,p,v,he]),Ke=w.useCallback(()=>{const F=L.current;F&&(E(X=>X.map(V=>F[V.id]?{...V,position:F[V.id]}:V)),L.current=null,he())},[he]),Ye=w.useCallback(()=>{f==null||f.reset(j),I.current.delete(j),_.current=null,J.current={},$.current=!1,b(F=>F.map(X=>({...X,data:{...X.data,routeX:void 0}}))),E(F=>{const X=fr(F,M,ue,"auto",ge);return requestAnimationFrame(()=>p({padding:.15,duration:300})),X})},[f,j,M,ue,ge,p]),$e=w.useCallback(F=>{s(F),E(X=>(X.find(Z=>Z.id===F)&&requestAnimationFrame(()=>p({nodes:[{id:F}],padding:.4,duration:400})),X))},[p,s]);w.useImperativeHandle(m,()=>({relayout:Oe,fitView:()=>p({padding:.15,duration:300}),focusEntity:$e,newEntity:()=>O(!0),resetLayout:Ye,undoRelayout:Ke}),[Oe,p,$e,Ye,Ke]);const Ae=w.useCallback(F=>{if(ae||!F.source||!F.target||F.source===F.target)return;const X=F.sourceHandle&&F.sourceHandle!==Ur?F.sourceHandle:void 0,V=F.targetHandle&&F.targetHandle!==qr?F.targetHandle:void 0;k({from:F.source,to:F.target,fromAttr:X,toAttr:V})},[ae]),je=w.useCallback(async(F,X)=>{try{return await n(F,X)}catch(V){throw d==null||d(V instanceof Error?V.message:String(V)),V}},[n,d]),Re=r?ue.get(r)??null:null,ze=e.relationships.find(F=>F.id===T)??null;return h.jsxs(h.Fragment,{children:[h.jsxs(Ji,{nodes:g,edges:M,nodeTypes:Cx,edgeTypes:Mx,onNodeClick:(F,X)=>{s(X.id),se(null)},onEdgeClick:(F,X)=>se(X.id),onEdgeDoubleClick:(F,X)=>!ae&&P(X.id),onPaneClick:()=>{s(null),se(null),P(null)},onNodeDragStop:(F,X)=>{E(V=>V.map(Z=>Z.id===X.id?{...Z,position:X.position}:Z)),he()},onConnect:Ae,nodesConnectable:!ae,minZoom:.05,onlyRenderVisibleElements:!0,proOptions:{hideAttribution:!0},fitView:!0,children:[h.jsx(Cm,{variant:Be.Dots,gap:22,size:1.5,color:"#33291f"}),h.jsx(pm,{pannable:!0,zoomable:!0,nodeColor:F=>{var X;return((X=F.data)==null?void 0:X.color)??"#5a4f42"},maskColor:"rgba(20, 17, 15, 0.75)"}),h.jsx(_m,{showInteractive:!1})]}),Re&&h.jsx(Xm,{entity:Re,doc:e,caps:t,exec:je,onClose:()=>s(null),onFocusEntity:$e,onAlign:H,onEditMapping:C}),B&&h.jsx(dx,{entity:B,exec:je,onClose:()=>H(null)}),y&&h.jsx(fx,{entity:y,doc:e,exec:je,onClose:()=>C(null)}),S&&h.jsx(hx,{doc:e,exec:je,onClose:()=>O(!1),onCreated:$e}),D&&h.jsx(mx,{doc:e,fromId:D.from,toId:D.to,initialFromAttr:D.fromAttr,initialToAttr:D.toAttr,exec:je,onClose:()=>k(null)}),ze&&h.jsx(px,{rel:ze,doc:e,exec:je,onClose:()=>P(null)})]})}function cw({tab:e,onClose:t,readOnly:n,refreshKey:r,onModelChanged:s,onFocusEntity:o}){return h.jsxs("aside",{className:"side-panel",children:[h.jsxs("div",{className:"detail-header",children:[h.jsxs("h2",{children:[e==="ontology"&&"Ontology",e==="layers"&&"Ontology layers",e==="changes"&&"Uncommitted changes",e==="decisions"&&"Decision ledger"]}),h.jsx("button",{className:"icon-btn",onClick:t,children:"✕"})]}),e==="ontology"&&h.jsx(Rx,{}),e==="layers"&&h.jsx(Tx,{refreshKey:r,onFocusEntity:o}),e==="changes"&&h.jsx(Ox,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Lx,{readOnly:n})]})}function Rx(){const[e,t]=w.useState(""),[n,r]=w.useState([]),[s,o]=w.useState({loaded:0,vocabs:[]}),[i,a]=w.useState(null),[c,u]=w.useState([]),[l,d]=w.useState("");w.useEffect(()=>{ia().then(f=>u(f.ontologies)).catch(()=>{})},[]),w.useEffect(()=>{const f=setTimeout(()=>{oa(e||"a",l||void 0).then(p=>{r(e?p.results:[]),o({loaded:p.loaded_terms,vocabs:p.vocabularies})}).catch(()=>{})},200);return()=>clearTimeout(f)},[e,l]);const m=w.useCallback(f=>{Mm(f).then(a).catch(()=>{})},[]);return i?h.jsxs("div",{className:"panel-body",children:[h.jsx("button",{className:"mini-btn",onClick:()=>a(null),children:"← back"}),h.jsx("h3",{style:{marginTop:12},children:i.label}),h.jsx("code",{className:"term-iri",children:i.prefixed}),i.definition&&h.jsx("p",{className:"term-def",children:i.definition}),h.jsxs("div",{className:"kv",children:[h.jsx("span",{className:"k",children:"source"}),h.jsx("span",{className:"v",children:i.source})]}),i.broader.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"broader"}),i.broader.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↑ ",f.label]},f.iri))]}),i.narrower.length>0&&h.jsxs(h.Fragment,{children:[h.jsx("h4",{children:"narrower"}),i.narrower.map(f=>h.jsxs("button",{className:"rel-link",onClick:()=>m(f.iri),children:["↓ ",f.label]},f.iri))]})]}):h.jsxs("div",{className:"panel-body",children:[c.length>0&&h.jsxs("div",{className:"src-picker",children:[h.jsx("button",{className:"src-chip"+(l===""?" active":""),onClick:()=>d(""),children:"all sources"}),c.map(f=>h.jsxs("button",{className:"src-chip"+(l===f.id?" active":""),title:(f.description??"")+(f.count!=null?` · ${f.count} terms`:" · live"),onClick:()=>d(f.id),children:[f.name,f.layer&&h.jsx("span",{className:`src-layer layer-${f.layer}`,children:f.layer})]},f.id))]}),h.jsx("input",{className:"edit-input",placeholder:l?`Search within ${l}…`:"Search vocabulary terms…",value:e,onChange:f=>t(f.target.value)}),h.jsx("p",{className:"meta-line",children:c.length>0?`${c.length} source${c.length>1?"s":""}: ${s.vocabs.join(", ")}`+(s.loaded>0?` · ${s.loaded} local terms indexed`:""):"no vocabulary loaded — declare ontology_stack in mdl-project.yaml or run `mdl ontology vendor fibo`"}),h.jsx("div",{className:"term-results",children:n.map(f=>h.jsxs("button",{className:"term-card",onClick:()=>m(f.prefixed),children:[h.jsxs("div",{className:"term-head",children:[h.jsx("span",{className:"term-label",children:f.label}),h.jsxs("span",{className:"term-source",children:[f.source_kind==="glossary-term"&&h.jsx("span",{className:"kind-badge",title:"glossary term",children:"glossary"}),f.source]})]}),h.jsx("code",{className:"term-iri",children:f.prefixed}),f.definition&&h.jsx("p",{className:"term-def",children:f.definition})]},f.iri))})]})}const Ix=["industry","core","domain","specialised"];function Tx({refreshKey:e,onFocusEntity:t}){const[n,r]=w.useState(null),[s,o]=w.useState(null);if(w.useEffect(()=>{$m().then(r).catch(()=>{}),Am().then(o).catch(()=>{})},[e]),!n)return h.jsx("div",{className:"panel-body",children:"loading…"});const i=new Set((s==null?void 0:s.core_uncovered)??[]);return h.jsxs("div",{className:"panel-body",children:[s&&h.jsxs("div",{className:"coverage-banner"+(s.coverage_pct<100?" warn":""),children:["industry alignment coverage: ",h.jsxs("b",{children:[s.coverage_pct,"%"]})," (",s.core_with_industry,"+",s.core_exempt,"/",s.total_core," core terms)"]}),h.jsxs("div",{className:"layer-band external",children:[h.jsx("h4",{children:"industry (external vocabularies)"}),n.external_terms.length===0&&h.jsx("p",{className:"empty-hint",children:"no aligned terms yet"}),n.external_terms.map(a=>h.jsxs("div",{className:"stack-term external",title:a.definition??void 0,children:[a.label,h.jsx("span",{className:"term-source",children:a.source})]},a.iri))]}),Ix.slice(1).map(a=>h.jsxs("div",{className:"layer-band",children:[h.jsx("h4",{children:a}),(n.layers[a]??[]).length===0&&h.jsx("p",{className:"empty-hint",children:"—"}),(n.layers[a]??[]).map(c=>{var u;return h.jsxs("button",{className:"stack-term"+(i.has(c.name)?" uncovered":""),title:c.definition??void 0,onClick:()=>t(c.id),children:[c.name,(c.aligned_refs??(c.aligned_to?[c.aligned_to]:[])).map((l,d)=>h.jsxs("span",{className:"align-arrow"+(l.resolved?"":" unresolved")+(l.status==="proposed"?" proposed":""),title:l.ref+(l.resolved_via?` (via ${l.resolved_via})`:""),children:["↑ ",l.label,l.status==="proposed"?" ·prop":""]},`${l.ref}-${d}`)),!c.aligned_to&&(((u=c.aligned_refs)==null?void 0:u.length)??0)===0&&!c.no_industry_equivalent&&h.jsx("span",{className:"align-arrow missing",children:"unaligned"})]},c.id)})]},a))]})}function Ox({readOnly:e,refreshKey:t,onModelChanged:n}){const[r,s]=w.useState(null),[o,i]=w.useState(""),[a,c]=w.useState(""),[u,l]=w.useState(!1),d=w.useCallback(()=>{Im().then(s).catch(()=>s(null)),Tm().then(m=>i([m.diff,...m.untracked].filter(Boolean).join(` `))).catch(()=>i(""))},[]);return w.useEffect(d,[d,t]),r!=null&&r.git?r.clean?h.jsx("div",{className:"panel-body ok",children:"✓ working tree clean"}):h.jsxs("div",{className:"panel-body",children:[h.jsx("ul",{className:"dirty-list",children:r.dirty.map(m=>h.jsxs("li",{children:[h.jsx("code",{className:"dirty-state",children:m.state})," ",m.path]},m.path))}),h.jsx("pre",{className:"diff-view",children:o.split(` `).map((m,f)=>h.jsx("span",{className:m.startsWith("+")&&!m.startsWith("+++")?"diff-add":m.startsWith("-")&&!m.startsWith("---")?"diff-del":m.startsWith("@@")?"diff-hunk":"",children:m+` -`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:u,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(l(!0),Lm().then(()=>{l(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:u||!a.trim(),onClick:()=>{l(!0),Om(a).then(()=>{l(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Ox({readOnly:e}){const[t,n]=w.useState([]),r=w.useCallback(()=>{Dm().then(o=>n(o.decisions)).catch(()=>n([]))},[]);if(w.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(o=>h.jsxs("div",{className:"decision "+o.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[o.verdict]}),h.jsx("span",{className:"chip",children:o.confidence}),h.jsx("span",{className:"chip",children:o.signal})]}),h.jsx("p",{className:"decision-subject",children:o.subject}),!e&&o.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Gs(o.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Gs(o.signal_key,"rejected").then(r),children:"Reject"})]})]},o.signal_key))})}function cw({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:o,openImport:i=!1,prefillImport:a="",onPreview:c}){const[u,l]=w.useState(i&&t?"import":null),[d,m]=w.useState([]),[f,p]=w.useState("postgres"),x=w.useRef(null);w.useEffect(()=>{Pm().then(g=>m(g.formats)).catch(()=>m([]))},[]),w.useEffect(()=>{if(!u)return;const g=E=>{x.current&&!x.current.contains(E.target)&&l(null)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[u]);const v=d.find(g=>g.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:x,children:[h.jsxs("button",{className:s+(u==="export"?" on":""),onClick:()=>l(u==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(u==="import"?" on":""),onClick:()=>l(u==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),u==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(v==null?void 0:v.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:g=>p(g.target.value),children:v.dialects.map(g=>h.jsx("option",{value:g,children:g},g))})]}),d.map(g=>h.jsx("a",{className:"ie-item",href:zm(g.id,g.id==="sql"?f:void 0),download:!0,onClick:()=>l(null),children:g.label},g.id))]}),u==="import"&&h.jsx(Lx,{exec:e,submitLabel:r,buttonClass:s,applyBatch:o,onClose:()=>l(null),onImported:g=>{l(null),n==null||n(g)},onPreview:c,prefillImport:a})]})}const jo=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function Lx({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:o,onPreview:i,prefillImport:a}){var j;const[c,u]=w.useState(i?"erwin":"sql"),[l,d]=w.useState("postgres"),[m,f]=w.useState(a??""),[p,x]=w.useState(!1),[v,g]=w.useState(null),[E,M]=w.useState([]);w.useEffect(()=>{a&&f(a)},[a]);const b=_=>{_&&_.text().then(f).catch(()=>g("could not read that file"))},$=async()=>{x(!0),g(null),M([]);try{if(i&&c==="erwin"){const R=await Fm(c,m);if(!R.changes.length){g(R.warnings[0]??"nothing to import from that document"),x(!1);return}s(),i(R),x(!1);return}const _=await Hm(c,m,c==="sql"?l:void 0);if(!_.changes.length){g(_.warnings[0]??"nothing to import from that document"),x(!1);return}if(r)await r(_.changes);else for(const R of _.changes)await e(R.op,R.payload);M(_.warnings),o(_.tables)}catch(_){g(_ instanceof Error?_.message:String(_))}finally{x(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:jo.map(_=>h.jsx("button",{className:"ie-tab"+(c===_.id?" active":""),onClick:()=>u(_.id),children:_.label},_.id))}),h.jsx("p",{className:"ie-hint",children:(j=jo.find(_=>_.id===c))==null?void 0:j.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:l,onChange:_=>d(_.target.value),children:["postgres","snowflake","mysql","duckdb"].map(_=>h.jsx("option",{children:_},_))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:_=>f(_.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:_=>{var R;return b(((R=_.target.files)==null?void 0:R[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((_,R)=>h.jsx("p",{className:"ie-warn",children:_},R)),v&&h.jsx("p",{className:"ie-error",children:v}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:p||!m.trim(),onClick:$,children:p?"Importing…":t})]})]})}export{na as A,Cm as B,_m as C,Gm as E,cw as I,Ix as L,iw as M,Ax as O,No as P,qi as R,aw as S,Hx as a,Zx as b,Ux as c,Jx as d,ew as e,zx as f,Im as g,nw as h,tw as i,qx as j,Bx as k,Gx as l,Yx as m,Wx as n,ra as o,Qx as p,Kx as q,Xx as r,Rm as s,Fx as t,Vx as u,ur as v,Zi as w,kx as x,pm as y}; +`},f))}),!e&&h.jsxs(h.Fragment,{children:[h.jsx("input",{className:"edit-input",placeholder:"commit message…",value:a,onChange:m=>c(m.target.value)}),h.jsxs("div",{className:"modal-footer",children:[h.jsx("button",{className:"mini-btn danger",disabled:u,onClick:()=>{confirm("Discard ALL uncommitted model changes?")&&(l(!0),Lm().then(()=>{l(!1),d(),n()}))},children:"Discard all"}),h.jsx("button",{className:"primary-btn",disabled:u||!a.trim(),onClick:()=>{l(!0),Om(a).then(()=>{l(!1),c(""),d()})},children:"Commit"})]})]})]}):h.jsx("div",{className:"panel-body",children:"model directory is not in a git repo"})}function Lx({readOnly:e}){const[t,n]=w.useState([]),r=w.useCallback(()=>{Dm().then(o=>n(o.decisions)).catch(()=>n([]))},[]);if(w.useEffect(r,[r]),t.length===0)return h.jsx("div",{className:"panel-body",children:"no recorded decisions (run `mdl reverse` to propose)"});const s={accepted:"✓",rejected:"✗",proposed:"?"};return h.jsx("div",{className:"panel-body",children:t.map(o=>h.jsxs("div",{className:"decision "+o.verdict,children:[h.jsxs("div",{className:"decision-head",children:[h.jsx("span",{className:"decision-mark",children:s[o.verdict]}),h.jsx("span",{className:"chip",children:o.confidence}),h.jsx("span",{className:"chip",children:o.signal})]}),h.jsx("p",{className:"decision-subject",children:o.subject}),!e&&o.verdict==="proposed"&&h.jsxs("div",{className:"decision-actions",children:[h.jsx("button",{className:"mini-btn",onClick:()=>Xs(o.signal_key,"accepted").then(r),children:"Accept"}),h.jsx("button",{className:"mini-btn danger",onClick:()=>Xs(o.signal_key,"rejected").then(r),children:"Reject"})]})]},o.signal_key))})}function lw({exec:e,canEdit:t,onImported:n,submitLabel:r="Import & review",buttonClass:s="erd-action ghost",applyBatch:o,openImport:i=!1,prefillImport:a="",onPreview:c}){const[u,l]=w.useState(i&&t?"import":null),[d,m]=w.useState([]),[f,p]=w.useState("postgres"),x=w.useRef(null);w.useEffect(()=>{Pm().then(g=>m(g.formats)).catch(()=>m([]))},[]),w.useEffect(()=>{if(!u)return;const g=E=>{x.current&&!x.current.contains(E.target)&&l(null)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[u]);const v=d.find(g=>g.id==="sql");return h.jsxs("div",{className:"ie-wrap",ref:x,children:[h.jsxs("button",{className:s+(u==="export"?" on":""),onClick:()=>l(u==="export"?null:"export"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↧"}),"Export ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),t&&h.jsxs("button",{className:s+(u==="import"?" on":""),onClick:()=>l(u==="import"?null:"import"),children:[h.jsx("span",{className:"erd-ico","aria-hidden":"true",children:"↥"}),"Import ",h.jsx("span",{className:"erd-caret",children:"▾"})]}),u==="export"&&h.jsxs("div",{className:"ie-menu",role:"menu",children:[(v==null?void 0:v.dialects)&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"SQL dialect"}),h.jsx("select",{value:f,onChange:g=>p(g.target.value),children:v.dialects.map(g=>h.jsx("option",{value:g,children:g},g))})]}),d.map(g=>h.jsx("a",{className:"ie-item",href:zm(g.id,g.id==="sql"?f:void 0),download:!0,onClick:()=>l(null),children:g.label},g.id))]}),u==="import"&&h.jsx(Dx,{exec:e,submitLabel:r,buttonClass:s,applyBatch:o,onClose:()=>l(null),onImported:g=>{l(null),n==null||n(g)},onPreview:c,prefillImport:a})]})}const Mo=[{id:"sql",label:"SQL DDL",hint:"CREATE TABLE … PRIMARY KEY / FOREIGN KEY"},{id:"mermaid",label:"Mermaid erDiagram",hint:"structural: entities, attributes, relationships"},{id:"json-schema",label:"JSON Schema",hint:"each object definition becomes an entity"},{id:"erwin",label:"erwin XML",hint:"entities, keys, relationships, subject areas, subtypes"}];function Dx({exec:e,submitLabel:t,buttonClass:n,applyBatch:r,onClose:s,onImported:o,onPreview:i,prefillImport:a}){var j;const[c,u]=w.useState(i?"erwin":"sql"),[l,d]=w.useState("postgres"),[m,f]=w.useState(a??""),[p,x]=w.useState(!1),[v,g]=w.useState(null),[E,M]=w.useState([]);w.useEffect(()=>{a&&f(a)},[a]);const b=_=>{_&&_.text().then(f).catch(()=>g("could not read that file"))},$=async()=>{x(!0),g(null),M([]);try{if(i&&c==="erwin"){const R=await Fm(c,m);if(!R.changes.length){g(R.warnings[0]??"nothing to import from that document"),x(!1);return}s(),i(R),x(!1);return}const _=await Hm(c,m,c==="sql"?l:void 0);if(!_.changes.length){g(_.warnings[0]??"nothing to import from that document"),x(!1);return}if(r)await r(_.changes);else for(const R of _.changes)await e(R.op,R.payload);M(_.warnings),o(_.tables)}catch(_){g(_ instanceof Error?_.message:String(_))}finally{x(!1)}};return h.jsxs("div",{className:"ie-menu ie-import",role:"dialog",children:[h.jsx("div",{className:"ie-tabs",children:Mo.map(_=>h.jsx("button",{className:"ie-tab"+(c===_.id?" active":""),onClick:()=>u(_.id),children:_.label},_.id))}),h.jsx("p",{className:"ie-hint",children:(j=Mo.find(_=>_.id===c))==null?void 0:j.hint}),c==="sql"&&h.jsxs("label",{className:"ie-dialect",children:[h.jsx("span",{children:"dialect"}),h.jsx("select",{value:l,onChange:_=>d(_.target.value),children:["postgres","snowflake","mysql","duckdb"].map(_=>h.jsx("option",{children:_},_))})]}),h.jsx("textarea",{className:"ie-textarea",placeholder:`Paste ${c} here, or choose a file…`,value:m,onChange:_=>f(_.target.value),rows:8}),h.jsx("input",{type:"file",className:"ie-file",accept:".sql,.mmd,.md,.json,.xml,.txt",onChange:_=>{var R;return b(((R=_.target.files)==null?void 0:R[0])??null)}}),c==="mermaid"&&h.jsx("p",{className:"ie-warn",children:"Mermaid is a diagram format: types and keys are approximate and relationships are inferred from the lines."}),E.map((_,R)=>h.jsx("p",{className:"ie-warn",children:_},R)),v&&h.jsx("p",{className:"ie-error",children:v}),h.jsxs("div",{className:"ie-foot",children:[h.jsx("button",{className:n,onClick:s,children:"Cancel"}),h.jsx("button",{className:n,disabled:p||!m.trim(),onClick:$,children:p?"Importing…":t})]})]})}export{sa as A,Cm as B,_m as C,Gm as E,lw as I,Tx as L,aw as M,Rx as O,ko as P,Zi as R,cw as S,Fx as a,Qx as b,qx as c,ew as d,tw as e,Hx as f,Im as g,rw as h,nw as i,Kx as j,Gx as k,Yx as l,Xx as m,Ux as n,oa as o,Jx as p,Zx as q,Wx as r,Rm as s,Vx as t,Bx as u,fr as v,Ji as w,jx as x,pm as y}; diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index d41f5eb..3c8d71c 100644 --- a/packages/server/src/mdl_server/static/index.html +++ b/packages/server/src/mdl_server/static/index.html @@ -4,10 +4,10 @@ Modelith - + - - + +
diff --git a/packages/server/src/mdl_server/static/sme.html b/packages/server/src/mdl_server/static/sme.html index de81992..2eb62d9 100644 --- a/packages/server/src/mdl_server/static/sme.html +++ b/packages/server/src/mdl_server/static/sme.html @@ -4,10 +4,10 @@ Modelith Glossary - + - - + + From a1471db6508e77fea5fc73ce4bc6a11f4990dcde Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Mon, 12 Oct 2026 19:39:14 +1100 Subject: [PATCH 12/14] test: prove layout isolation holds for the FULL sidecar (routeX + anchors + drift) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The isolation tests predated the endpoint-anchor fields and did not cover drift — the user-named backend feature. Strengthen them so the "layout is UI-only" promise is pinned for every field: - A rich-layout helper (node positions + edge routeX + source/target endpoint anchors), used to prove: - EVERY export format is byte-identical with/without the sidecar (new, covers all emitters at once, not just sql). - drift (model vs compiled manifest) is identical with/without the sidecar (new). - /api/model is identical. - The reverse-prune guard now writes a rich sidecar and asserts its content is untouched by a re-reverse. Verified manually on the real SDTM model too: dbt generate byte-identical, all 6 exports identical, validate identical, fingerprint identical. Test-only change; full backend suite + ruff green. --- .../tests/test_writer_prune_windows.py | 9 ++- packages/server/tests/test_layout_api.py | 57 +++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/packages/reverse/tests/test_writer_prune_windows.py b/packages/reverse/tests/test_writer_prune_windows.py index 99179a3..f745df8 100644 --- a/packages/reverse/tests/test_writer_prune_windows.py +++ b/packages/reverse/tests/test_writer_prune_windows.py @@ -32,10 +32,15 @@ def test_prune_never_touches_mdl_layout_sidecar(tmp_path): sidecar under .mdl/ must survive a re-reverse. Guards the isolation guarantee.""" (tmp_path / ".mdl").mkdir(parents=True, exist_ok=True) layout = tmp_path / ".mdl" / "layout.json" - layout.write_text('{"version": 1, "views": {}}', encoding="utf-8") + # a rich sidecar (positions + routeX + endpoint anchors) must survive untouched + content = ( + '{"version": 1, "views": {"__all__": {"nodes": {"e": {"x": 1, "y": 2}}, ' + '"edges": {"r": {"routeX": 5, "sourceAnchor": {"side": "left", "y": 3}}}}}}' + ) + layout.write_text(content, encoding="utf-8") write_model(_model(3), tmp_path) # a fresh write that prunes stale files assert layout.exists(), "re-reverse must not delete .mdl/layout.json" - assert layout.read_text(encoding="utf-8") == '{"version": 1, "views": {}}' + assert layout.read_text(encoding="utf-8") == content, "sidecar content must be untouched" def test_prune_stale_would_fail_with_naive_separator(tmp_path): diff --git a/packages/server/tests/test_layout_api.py b/packages/server/tests/test_layout_api.py index f8be37a..4bf9e0f 100644 --- a/packages/server/tests/test_layout_api.py +++ b/packages/server/tests/test_layout_api.py @@ -188,6 +188,63 @@ def test_export_identical_with_and_without_layout(client, model_dir): assert client.get("/api/export/sql").text == before +def _write_rich_layout(model_dir: Path) -> None: + """A FULLY-populated sidecar: node positions, an edge routeX, and both dragged + endpoint anchors. Isolation must hold for every field, not just positions.""" + from mdl_core.repo import ModelRepo + + model = ModelRepo.load(model_dir).model + ent = next(iter(model.logical_entities)) + rel = next(iter(model.relationships), None) + edges = {} + if rel: + edges[rel] = { + "routeX": 480, + "sourceAnchor": {"side": "right", "y": 200}, + "targetAnchor": {"side": "top", "y": 50, "x": 210}, + } + (model_dir / ".mdl").mkdir(parents=True, exist_ok=True) + (model_dir / ".mdl" / "layout.json").write_text( + json.dumps({"version": 1, "views": {"__all__": {"nodes": {ent: {"x": 120, "y": 340}}, "edges": edges}}}) + ) + + +def test_every_emitter_byte_identical_with_rich_layout(client, model_dir): + """The strongest isolation check: validation and EVERY export format produce + byte-identical output with and without a full (positions + routeX + anchors) + layout sidecar. If any backend ever reads the sidecar, one of these diverges.""" + formats = [f["id"] for f in client.get("/api/export").json()["formats"]] + before = {f: client.get(f"/api/export/{f}").text for f in formats} + before_model = client.get("/api/model").json() + _write_rich_layout(model_dir) + for f in formats: + assert client.get(f"/api/export/{f}").text == before[f], f"{f} export changed with layout" + assert client.get("/api/model").json() == before_model + + +def test_drift_identical_with_and_without_layout(model_dir): + """Drift (model vs compiled dbt manifest) must be identical with/without layout — + the user-facing backend feature the sidecar must never perturb.""" + import sys + + sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "reverse" / "tests")) + from mdl_core.repo import ModelRepo + from mdl_reverse.drift import compute_drift + from mdl_reverse.manifest import read_manifest_dict + + from manifest_fixtures import manifest_from_model + + proj = read_manifest_dict(manifest_from_model(ModelRepo.load(model_dir).model, "duckdb_dev")) + + def drift_items(): + rep = compute_drift(ModelRepo.load(model_dir).model, proj, "duckdb_dev") + return [(i.kind, i.severity, i.detail) for i in rep.items] + + before = drift_items() + _write_rich_layout(model_dir) + assert drift_items() == before + + # --- isolation: git never sees layout as dirty, never deletes it -------------- From 3c7cb478956effa9f7d06f36d0a12d7fccd1a1d3 Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Mon, 12 Oct 2026 20:49:31 +1100 Subject: [PATCH 13/14] canvas: opt-in team sharing of the layout sidecar (layout: {shared: true}) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A team can now commit the canvas layout to git. Set `layout: {shared: true}` in mdl-project.yaml and the server stops ignoring .mdl/layout.json (dropping its own auto-added ignore line), so the sidecar is committable and a teammate who opens the canvas on that checkout gets the same arrangement. The sharing flag is a visual-tooling preference, never model content. The setting is read straight from the project file (not through the model graph), and dir_fingerprint now canonicalises mdl-project.yaml with the `layout` key stripped, so toggling the flag does NOT move the model fingerprint. Whatever the setting is, validate / drift / diff / every emitter / the model doc are byte-identical — the same isolation the JSON sidecar already has by living outside every *.yaml glob. Tests: shared -> not gitignored; solo->shared drops the auto ignore line; and the guardrail that with shared:true + a rich sidecar every export, the model doc and the fingerprint are identical to a model with no layout. --- README.md | 9 ++++ packages/core/src/mdl_core/commands.py | 33 +++++++++++- .../server/src/mdl_server/layout_store.py | 42 +++++++++++++-- packages/server/tests/test_layout_api.py | 54 +++++++++++++++++++ 4 files changed, 134 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 063a4b3..31107d0 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,15 @@ invisible to `mdl validate`, drift, `mdl diff`, every emitter and the git status never shows up in a review, a diff or the generated dbt. "Reset layout" in the View menu clears a view's saved arrangement. +**Sharing a layout with your team.** Set `layout: {shared: true}` in `mdl-project.yaml` +to opt the sidecar into version control: Modelith then stops git-ignoring +`.mdl/layout.json` (dropping the auto-added ignore line) so you can commit it, and anyone +who opens the canvas on that checkout sees the same arrangement. The setting is a +visual-tooling preference only — whatever its value, the layout (and the setting itself) +stays invisible to every functional CLI feature: `mdl validate`, drift, `mdl diff` and the +emitters produce byte-identical output, and the model fingerprint is unchanged, whether +the layout is shared or ignored. + ![The ER canvas with a relationship line running from one entity's foreign-key attribute row to the referenced entity's primary-key row, with crow's-foot cardinality](docs/assets/canvas.png) ## Documentation diff --git a/packages/core/src/mdl_core/commands.py b/packages/core/src/mdl_core/commands.py index e0da026..8a93f1a 100644 --- a/packages/core/src/mdl_core/commands.py +++ b/packages/core/src/mdl_core/commands.py @@ -39,13 +39,21 @@ def dir_fingerprint(model_dir: Path) -> str: fired on EVERY edit on Windows — the canvas/LSP was effectively read-only. We now hash each file's content read in text mode (universal-newline normalises CRLF->LF), sorted by relative path for determinism, so the fingerprint depends on content, not on how - git happened to translate line endings.""" + git happened to translate line endings. + + The project file's `layout` key is a VISUAL-tooling preference (opt-in team sharing of + the canvas layout sidecar), never model content. It is stripped before hashing so that + toggling `layout: {shared: true}` does NOT move the fingerprint — the same isolation the + layout sidecar gets by living in JSON outside every `*.yaml` glob. Whatever the setting + is, every model-change detector (drift, the staleness guard) sees an identical model.""" h = hashlib.sha256() for p in sorted(Path(model_dir).rglob("*.yaml"), key=lambda q: q.as_posix()): try: text = p.read_text(encoding="utf-8") except (OSError, UnicodeDecodeError): continue + if p.name == PROJECT_FILE: + text = _project_text_without_layout(text) h.update(p.relative_to(model_dir).as_posix().encode("utf-8")) h.update(b"\0") h.update(text.encode("utf-8")) @@ -53,6 +61,29 @@ def dir_fingerprint(model_dir: Path) -> str: return h.hexdigest() +def _project_text_without_layout(text: str) -> str: + """A canonical form of the project file with any `layout` key removed, so a visual-only + setting cannot shift the fingerprint. + + The canonicalisation (parse → drop `layout` → re-dump) is applied WHETHER OR NOT the key + is present, so a file that gains or loses only `layout` hashes identically: the with-key + and without-key texts both reduce to the same dumped form. Falls back to the raw text if + the file does not parse as a mapping, so a corrupt file still fingerprints + deterministically.""" + try: + from mdl_core.yaml_io import dump_str, load_str + + doc = load_str(text) + if not isinstance(doc, dict): + return text + stripped = {k: v for k, v in doc.items() if k != "layout"} + # Normalise trailing blank lines: removing `layout` can leave a blank line that + # ruamel preserves as an extra trailing newline, which would still move the hash. + return dump_str(stripped).rstrip("\n") + "\n" + except Exception: # noqa: BLE001 - never let fingerprinting crash over a parse quirk + return text + + class StaleModelError(Exception): """The client's view of the repo is out of date.""" diff --git a/packages/server/src/mdl_server/layout_store.py b/packages/server/src/mdl_server/layout_store.py index e905167..742a877 100644 --- a/packages/server/src/mdl_server/layout_store.py +++ b/packages/server/src/mdl_server/layout_store.py @@ -187,12 +187,48 @@ def delete_view(model_dir: Path, view: str | None) -> None: _write_doc(model_dir, doc) +def _layout_shared(model_dir: Path) -> bool: + """Opt-in team sharing: `layout: {shared: true}` in mdl-project.yaml. When set, the + sidecar is NOT git-ignored so a team can commit it. Read directly from the project + file (never through the model graph), so `layout` stays invisible to every CLI + feature — validate/drift/export are identical whatever this setting is. Any read + error or missing key means the safe default: not shared (ignored).""" + try: + from mdl_core.yaml_io import load_file + + doc = load_file(model_dir / "mdl-project.yaml") or {} + layout = doc.get("layout") if isinstance(doc, dict) else None + return isinstance(layout, dict) and layout.get("shared") is True + except Exception: # noqa: BLE001 - never fail a layout write over the project file + return False + + def _ensure_gitignore(model_dir: Path) -> None: - """On first write, make sure layout.json is git-ignored. Create - `/.mdl/.gitignore` with `layout.json` when it is not already - ignored. Only inside a git work tree, and never beyond creating this file.""" + """Make the sidecar's git status match the project's sharing setting. + + Default (not shared): ensure `/.mdl/.gitignore` ignores `layout.json`, so + a solo user gets no noisy diffs. When `layout: {shared: true}` is set, do NOT ignore + it (and remove our own auto-added ignore line if present) so the team can commit it. + Only touches git state inside a work tree, and never edits a user's ignore file beyond + our one `layout.json` line.""" mdl = model_dir / ".mdl" gi = mdl / ".gitignore" + + if _layout_shared(model_dir): + # Shared: unlock committing by dropping OUR auto-added ignore line if it is there. + if gi.exists(): + try: + lines = gi.read_text(encoding="utf-8").splitlines() + if "layout.json" in lines: + kept = [ln for ln in lines if ln.strip() != "layout.json"] + if kept: + gi.write_text("\n".join(kept) + "\n", encoding="utf-8") + else: + gi.unlink() # the file only held our line + except OSError: + pass + return + if gi.exists(): try: if "layout.json" in gi.read_text(encoding="utf-8").splitlines(): diff --git a/packages/server/tests/test_layout_api.py b/packages/server/tests/test_layout_api.py index 4bf9e0f..9ae77fa 100644 --- a/packages/server/tests/test_layout_api.py +++ b/packages/server/tests/test_layout_api.py @@ -276,3 +276,57 @@ def test_gitignore_not_created_outside_git(model_dir): client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 1, "y": 2}}, "edges": {}}) assert not (model_dir / ".mdl" / ".gitignore").exists() assert (model_dir / ".mdl" / "layout.json").exists() # file still written + + +# --- team sharing: `layout: {shared: true}` opt-in ----------------------------- + + +def _set_shared(model_dir: Path) -> None: + p = model_dir / "mdl-project.yaml" + p.write_text(p.read_text() + "\nlayout:\n shared: true\n") + + +def test_shared_layout_is_not_gitignored(model_dir): + """With `layout: {shared: true}`, the sidecar is NOT ignored, so a team can commit it.""" + _init(model_dir) + _set_shared(model_dir) + client = TestClient(create_app(model_dir)) + ent = client.get("/api/model").json()["entities"][0]["id"] + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 1, "y": 2}}, "edges": {}}) + gi = model_dir / ".mdl" / ".gitignore" + # no ignore of layout.json -> committable + assert not (gi.exists() and "layout.json" in gi.read_text().splitlines()) + + +def test_switching_to_shared_removes_auto_ignore(model_dir): + """A project that was ignoring layout (solo) and later opts into sharing: the next + write drops OUR auto-added ignore line so the file becomes committable.""" + _init(model_dir) + client = TestClient(create_app(model_dir)) + ent = client.get("/api/model").json()["entities"][0]["id"] + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 1, "y": 2}}, "edges": {}}) + assert "layout.json" in (model_dir / ".mdl" / ".gitignore").read_text().splitlines() + _set_shared(model_dir) + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 3, "y": 4}}, "edges": {}}) + gi = model_dir / ".mdl" / ".gitignore" + assert not (gi.exists() and "layout.json" in gi.read_text().splitlines()) + + +def test_shared_setting_does_not_leak_into_cli_features(model_dir): + """THE guardrail the user named: whatever the sharing setting is, layout stays + invisible to every functional CLI feature. With `shared: true` AND a rich committed + sidecar, validate / every export / drift / the model doc are all identical to a model + with no layout and no setting.""" + client = TestClient(create_app(model_dir)) + formats = [f["id"] for f in client.get("/api/export").json()["formats"]] + before_exports = {f: client.get(f"/api/export/{f}").text for f in formats} + before_model = client.get("/api/model").json() + before_fp = commands.dir_fingerprint(model_dir) + # opt into sharing AND write a rich sidecar + _set_shared(model_dir) + _write_rich_layout(model_dir) + client2 = TestClient(create_app(model_dir)) + for f in formats: + assert client2.get(f"/api/export/{f}").text == before_exports[f], f + assert client2.get("/api/model").json() == before_model + assert commands.dir_fingerprint(model_dir) == before_fp From 68026467246b55f5d0046bebaf03de17509fa94d Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Mon, 12 Oct 2026 22:27:14 +1100 Subject: [PATCH 14/14] test: cover the git-dirtiness paths the layout sidecar added Two gaps in git_api.py were exercised by no test: - discard preserves the sidecar: /api/git/discard reverts MODEL edits (git checkout + clean) but keeps .mdl/layout.json via `clean -e`. The test writes a stray untracked model file + a layout, discards, and asserts the stray is gone while the layout survives and still reads back. - collapsed untracked .mdl/ dirtiness: when the whole .mdl/ dir is new, git porcelain collapses it to `?? .mdl/`. _mdl_only_layout must read that as CLEAN when it holds only layout artifacts, but DIRTY once real state (decisions.yaml) is present. The test pins both directions. Full suite 990 passed, 1 skipped. --- packages/server/tests/test_layout_api.py | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/server/tests/test_layout_api.py b/packages/server/tests/test_layout_api.py index 9ae77fa..770ce96 100644 --- a/packages/server/tests/test_layout_api.py +++ b/packages/server/tests/test_layout_api.py @@ -330,3 +330,51 @@ def test_shared_setting_does_not_leak_into_cli_features(model_dir): assert client2.get(f"/api/export/{f}").text == before_exports[f], f assert client2.get("/api/model").json() == before_model assert commands.dir_fingerprint(model_dir) == before_fp + + +# --- discard / dirtiness: the sidecar survives a model revert, and a layout-only ---- +# `.mdl/` never reads as dirty (the git_api.py filtering paths). + + +def test_discard_reverts_the_model_but_keeps_the_layout_sidecar(model_dir): + """`/api/git/discard` reverts MODEL edits (git checkout + clean) yet must preserve the + visual layout sidecar — it is excluded with `clean -e .mdl/layout.json`. Guards the + 'survive a revert' promise in this module's docstring.""" + _init(model_dir) + client = TestClient(create_app(model_dir)) + ent = client.get("/api/model").json()["entities"][0]["id"] + # a real, uncommitted MODEL change the discard should sweep. Use a non-object file + # (not under an *.yaml object glob) so writing it doesn't break ModelRepo.load, while + # still being an untracked file `git clean` must remove. + stray = model_dir / "_stray.txt" + stray.write_text("scratch\n", encoding="utf-8") + # and a layout the discard must NOT touch + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 7, "y": 8}}, "edges": {}}) + layout = model_dir / ".mdl" / "layout.json" + assert layout.exists() and stray.exists() + + r = client.post("/api/git/discard") + assert r.status_code == 200 and r.json()["ok"] is True + + assert not stray.exists(), "discard must revert the untracked model file" + assert layout.exists(), "discard must KEEP the visual layout sidecar" + assert client.get("/api/layout?view=__all__").json()["nodes"][ent] == {"x": 7, "y": 8} + + +def test_untracked_layout_only_mdl_dir_is_not_dirty_but_real_mdl_content_is(model_dir): + """When the whole `.mdl/` dir is new, `git status --porcelain` collapses it to a single + `?? .mdl/` line. That must read as CLEAN when the dir holds only layout artifacts, but + DIRTY when it also holds real state (e.g. decisions.yaml) — the `_mdl_only_layout` branch + in git_api.py. Here `.mdl/` is created by the first layout write AFTER the initial commit, + so it is entirely untracked (the collapsed case).""" + _init(model_dir) # commits the model BEFORE any .mdl/ exists -> .mdl/ is untracked + client = TestClient(create_app(model_dir)) + ent = client.get("/api/model").json()["entities"][0]["id"] + client.put("/api/layout", json={"view": "__all__", "nodes": {ent: {"x": 1, "y": 2}}, "edges": {}}) + st = client.get("/api/git/status").json() + assert st["git"] is True and st["clean"] is True, "layout-only .mdl/ must read clean" + + # now add REAL .mdl/ content: the same untracked dir must now read dirty + (model_dir / ".mdl" / "decisions.yaml").write_text("decisions: []\n", encoding="utf-8") + st2 = client.get("/api/git/status").json() + assert st2["clean"] is False, "real .mdl/ content must read dirty even alongside layout"