From 7bdf7be8fc271a24e8feef3bcf6bc3601c16c280 Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Wed, 14 Oct 2026 15:37:36 +1100 Subject: [PATCH 1/2] canvas: recolour a card in place when its subject-area membership changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An entity moved into or out of a subject area (via MCP add_subject_area_members, a direct YAML edit, or the picker) did not recolour on the canvas: the disk poll refreshed the model and the side drawer updated, but the card kept its old accent. Creating NEW entities in an area worked, because that grows the node set and forces a full re-layout; changing membership of EXISTING entities only moves data.color on nodes whose id and position are unchanged, and React Flow skipped repainting them. Fix (treat a colour delta as render-affecting, not structural): - EntityNode gets an explicit memo comparator keyed on the fields it actually renders (color, dimmed, highlighted, showTypes, collapseDetail, expanded, entity, the hover/highlight Sets, handlers, selected). A bare memo default-compared the whole data object by reference, which did not reliably repaint the accent. - The derivation's keep-positions fast path already carries the fresh colour; it now relies on that comparator so a membership change recolours WITHOUT reflowing. Plays well with saved layout: positions are untouched on a recolour (verified live — the card recolours in place at its exact translate()), so a committed/manual arrangement is preserved. New-entity placement and the subject-area filter are unchanged. Tests: canvas Vitest for the comparator (recolour re-renders; identical fields bail; dimmed/highlighted/expand/selected/entity/Set deltas re-render). Verified live: an out-of-band add_subject_area_members recolours interventions + events to the area colour within one poll, positions unchanged. --- canvas/src/EntityNode.test.tsx | 64 +++++++++++++++++++ canvas/src/EntityNode.tsx | 34 +++++++++- canvas/src/ModelCanvas.tsx | 6 ++ ...m-CxAF-B4F.js => ModelDiagram-iKtDWBmW.js} | 2 +- .../{main-BiJ4Tezc.js => main-Cj04gwM7.js} | 2 +- .../{sme-B1K9phBm.js => sme-BMwBdWVn.js} | 4 +- ...{styles-DqoimPMg.js => styles-DqdjcU5q.js} | 6 +- .../server/src/mdl_server/static/index.html | 4 +- .../server/src/mdl_server/static/sme.html | 4 +- 9 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 canvas/src/EntityNode.test.tsx rename packages/server/src/mdl_server/static/assets/{ModelDiagram-CxAF-B4F.js => ModelDiagram-iKtDWBmW.js} (97%) rename packages/server/src/mdl_server/static/assets/{main-BiJ4Tezc.js => main-Cj04gwM7.js} (99%) rename packages/server/src/mdl_server/static/assets/{sme-B1K9phBm.js => sme-BMwBdWVn.js} (99%) rename packages/server/src/mdl_server/static/assets/{styles-DqoimPMg.js => styles-DqdjcU5q.js} (63%) diff --git a/canvas/src/EntityNode.test.tsx b/canvas/src/EntityNode.test.tsx new file mode 100644 index 0000000..412c2ef --- /dev/null +++ b/canvas/src/EntityNode.test.tsx @@ -0,0 +1,64 @@ +import { describe, expect, it } from "vitest"; +import { type NodeProps } from "reactflow"; +import { entityNodePropsEqual, type EntityNodeData } from "./EntityNode"; +import type { Entity } from "./types"; + +const ENTITY: Entity = { + id: "01ENT00000000000000000000", + name: "interventions", + pattern: null, + conceptual: null, + attributes: [], +}; + +function data(over: Partial = {}): EntityNodeData { + return { + entity: ENTITY, + color: "#8a7d6a", // NO_SA grey + dimmed: false, + highlighted: false, + showTypes: true, + collapseDetail: false, + expanded: false, + ...over, + }; +} + +// Only `data` and `selected` are read by the comparator; the rest of NodeProps is +// irrelevant to the memo decision, so a bare cast keeps the fixtures minimal. +function props(d: EntityNodeData, selected = false): NodeProps { + return { data: d, selected } as NodeProps; +} + +describe("entityNodePropsEqual (memo comparator)", () => { + it("re-renders when the subject-area colour changes (the stale-recolor bug)", () => { + const grey = props(data({ color: "#8a7d6a" })); + const purple = props(data({ color: "#c4a3e0" })); + // false === NOT equal === React re-renders -> the accent repaints in place + expect(entityNodePropsEqual(grey, purple)).toBe(false); + }); + + it("skips re-render when nothing render-affecting changed (new data ref, same fields)", () => { + // the derivation hands a fresh data object every refresh; identical fields must bail + expect(entityNodePropsEqual(props(data()), props(data()))).toBe(true); + }); + + it("re-renders on dimmed / highlighted / expand / selected changes", () => { + const base = data(); + expect(entityNodePropsEqual(props(base), props(data({ dimmed: true })))).toBe(false); + expect(entityNodePropsEqual(props(base), props(data({ highlighted: true })))).toBe(false); + expect(entityNodePropsEqual(props(base), props(data({ expanded: true })))).toBe(false); + expect(entityNodePropsEqual(props(base, false), props(base, true))).toBe(false); + }); + + it("re-renders when the entity object identity changes (content edit)", () => { + const edited: Entity = { ...ENTITY, name: "renamed" }; + expect(entityNodePropsEqual(props(data()), props(data({ entity: edited })))).toBe(false); + }); + + it("re-renders when a hover/highlight Set identity changes", () => { + const base = data(); + const hovered = data({ highlightAttrs: new Set(["a"]) }); + expect(entityNodePropsEqual(props(base), props(hovered))).toBe(false); + }); +}); diff --git a/canvas/src/EntityNode.tsx b/canvas/src/EntityNode.tsx index c28f31c..97a8b4e 100644 --- a/canvas/src/EntityNode.tsx +++ b/canvas/src/EntityNode.tsx @@ -175,4 +175,36 @@ export const EntityNode = memo(function EntityNode({ data, selected }: NodeProps ); -}); +}, entityNodePropsEqual); + +/** Re-render the card exactly when a field it actually renders changes. A bare `memo` + * default-compares the whole `data` object by reference, which is fragile here: the + * derivation hands React Flow a fresh `data` object on every model refresh, yet the + * subject-area accent could still paint stale (a membership change only moves `color`). + * Comparing the render-affecting fields explicitly guarantees the accent — and the + * hover/search/expand state — repaint when, and only when, they change. `color` is the + * one this fixes: a node moved into or out of a subject area recolours in place without + * any reflow. Sets are compared by identity (the derivation makes a new Set on a real + * change), which is what the lightweight hover effect already relies on. */ +export function entityNodePropsEqual( + a: NodeProps, + b: NodeProps, +): boolean { + if (a.selected !== b.selected) return false; + const x = a.data; + const y = b.data; + return ( + x.entity === y.entity && + x.color === y.color && + x.dimmed === y.dimmed && + x.highlighted === y.highlighted && + x.showTypes === y.showTypes && + x.collapseDetail === y.collapseDetail && + x.expanded === y.expanded && + x.endpointAttrs === y.endpointAttrs && + x.highlightAttrs === y.highlightAttrs && + x.dimAttrs === y.dimAttrs && + x.onToggleExpand === y.onToggleExpand && + x.onHoverAttr === y.onHoverAttr + ); +} diff --git a/canvas/src/ModelCanvas.tsx b/canvas/src/ModelCanvas.tsx index ff8986e..f004df2 100644 --- a/canvas/src/ModelCanvas.tsx +++ b/canvas/src/ModelCanvas.tsx @@ -487,6 +487,12 @@ 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) { + // The entity SET is unchanged (same ids, no growth), so keep every saved/manual + // position — a recolour must never reflow a laid-out diagram (and must not fight the + // saved-layout restore). newNodes already carries the fresh subject-area colour; we + // only swap in the kept positions. React Flow then re-renders each node whose `data` + // reference changed, and EntityNode's memo comparator (which includes `color`) makes + // the accent repaint — so a membership change recolours in place without moving cards. const kept = newNodes.map((n) => ({ ...n, position: posById.get(n.id) ?? n.position })); emitEdges(kept); return kept; diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-CxAF-B4F.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-iKtDWBmW.js similarity index 97% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-CxAF-B4F.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-iKtDWBmW.js index 2a96951..94ec2b6 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-CxAF-B4F.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-iKtDWBmW.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-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}; +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-DqdjcU5q.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-BiJ4Tezc.js b/packages/server/src/mdl_server/static/assets/main-Cj04gwM7.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-BiJ4Tezc.js rename to packages/server/src/mdl_server/static/assets/main-Cj04gwM7.js index 2bc5622..2a0d2cc 100644 --- a/packages/server/src/mdl_server/static/assets/main-BiJ4Tezc.js +++ b/packages/server/src/mdl_server/static/assets/main-Cj04gwM7.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-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(` +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-DqdjcU5q.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-B1K9phBm.js b/packages/server/src/mdl_server/static/assets/sme-BMwBdWVn.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-B1K9phBm.js rename to packages/server/src/mdl_server/static/assets/sme-BMwBdWVn.js index f9f1e96..89634dd 100644 --- a/packages/server/src/mdl_server/static/assets/sme-B1K9phBm.js +++ b/packages/server/src/mdl_server/static/assets/sme-BMwBdWVn.js @@ -1,2 +1,2 @@ -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,{})})); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-iKtDWBmW.js","assets/client-DOmNpTln.js","assets/styles-DqdjcU5q.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-DqdjcU5q.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-iKtDWBmW.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-DqoimPMg.js b/packages/server/src/mdl_server/static/assets/styles-DqdjcU5q.js similarity index 63% rename from packages/server/src/mdl_server/static/assets/styles-DqoimPMg.js rename to packages/server/src/mdl_server/static/assets/styles-DqdjcU5q.js index 81542fa..5e73357 100644 --- a/packages/server/src/mdl_server/static/assets/styles-DqoimPMg.js +++ b/packages/server/src/mdl_server/static/assets/styles-DqdjcU5q.js @@ -15,9 +15,9 @@ 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 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(` + 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 Fx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),Vx=()=>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}),Bx=(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()}`)},Gx=()=>be("/api/glossary/config"),Yx=e=>ct("/api/git/propose",e),Xx=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Wx=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),Ux=e=>ct("/api/git/classify",{changes:e}),qx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Kx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Zx=(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}),Qx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Jx=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}},ew=(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()}),tw=()=>be("/api/glossary/subject-areas"),nw=e=>be(`/api/glossary/subject-area/${e}`),rw=(e,t)=>ct(`/api/glossary/subject-area/${e}/expand`,t);function sw(){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);function Ym(e,t){if(e.selected!==t.selected)return!1;const n=e.data,r=t.data;return n.entity===r.entity&&n.color===r.color&&n.dimmed===r.dimmed&&n.highlighted===r.highlighted&&n.showTypes===r.showTypes&&n.collapseDetail===r.collapseDetail&&n.expanded===r.expanded&&n.endpointAttrs===r.endpointAttrs&&n.highlightAttrs===r.highlightAttrs&&n.dimAttrs===r.dimAttrs&&n.onToggleExpand===r.onToggleExpand&&n.onHoverAttr===r.onHoverAttr}const Xm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Wm({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(qm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Zm,{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(Um,{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(Jm,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(ep,{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:tp(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 Um({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 qm({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 Km=["","scd2","hub","link","satellite","bridge"];function Zm({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:Km.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Qm=["attribute","business_key","measure","surrogate_key"];function Jm({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([...Xm,...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 ep({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 tp(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 np="\0",xt="\0",Ws="";let rp=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=sp(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?np:r)}function sp(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=rp,op="2.2.4",ip={Graph:Kr,version:op},ap=Kr,cp={write:lp,read:fp};function lp(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:up(e),edges:dp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function up(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 dp(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 fp(e){var t=new ap(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 hp=mp;function mp(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 pp=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 xp(e,t,n,r){return wp(e,String(t),n||yp,r||function(s){return e.outEdges(s)})}function wp(e,t,n,r){var s={},o=new gp,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 bp=ca,vp=_p;function _p(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=bp(e,s,t,n),r},{})}var la=Ep;function Ep(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 Np=la,Sp=kp;function kp(e){return Np(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var jp=Mp,Cp=()=>1;function Mp(e,t,n){return $p(e,t||Cp,n||function(r){return e.outEdges(r)})}function $p(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"?Tp:Op,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 Tp(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 Op(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 Lp=fa,Dp=Pp;function Pp(e,t){return Lp(e,t,"post")}var zp=fa,Hp=Fp;function Fp(e,t){return zp(e,t,"pre")}var Vp=Kr,Bp=aa,Gp=Yp;function Yp(e,t){var n=new Vp,r={},s=new Bp,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 Xp={components:hp,dijkstra:ca,dijkstraAll:vp,findCycles:Sp,floydWarshall:jp,isAcyclic:Ap,postorder:Dp,preorder:Hp,prim:Gp,tarjan:la,topsort:da},Zs=ip,qe={Graph:Zs.Graph,json:cp,alg:Xp,version:Zs.version};let Wp=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,Up)),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 Up(e,t){if(e!=="_next"&&e!=="_prev")return t}var qp=Wp;let Kp=qe.Graph,Zp=qp;var Qp=eg;let Jp=()=>1;function eg(e,t){if(e.nodeCount()<=1)return[];let n=ng(e,t||Jp);return tg(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function tg(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 ng(e,t){let n=new Kp,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=rg(s+r+3).map(()=>new Zp),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 rg(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 og(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 ig(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 ag(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 cg(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 lg(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 ug(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 dg(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 fg(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 hg(e,t=ga){const n=[];for(let r=0;rga){const n=hg(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 mg(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function pg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function gg(e,t){return t()}let yg=0;function xa(e){var t=++yg;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 bg=Qp,vg=Se.uniqueId;var _g={run:Eg,undo:Sg};function Eg(e){(e.graph().acyclicer==="greedy"?bg(e,n(e)):Ng(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,vg("rev"))});function n(r){return s=>r.edge(s).weight}}function Ng(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 Sg(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 kg=Se;var jg={run:Cg,undo:$g};function Cg(e){e.graph().dummyChains=[],e.edges().forEach(t=>Mg(e,t))}function Mg(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:Ag}=Se;var Wn={longestPath:Rg,slack:Ig};function Rg(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=Ag(Math.min,o);return i===Number.POSITIVE_INFINITY&&(i=0),s.rank=i}e.sources().forEach(n)}function Ig(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var Tg=qe.Graph,Dn=Wn.slack,ba=Og;function Og(e){var t=new Tg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,o;Lg(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 Dg(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 zg=ba,Js=Wn.slack,Hg=Wn.longestPath,Fg=qe.alg.preorder,Vg=qe.alg.postorder,Bg=Se.simplify,Gg=kt;kt.initLowLimValues=Jr;kt.initCutValues=Qr;kt.calcCutValue=va;kt.leaveEdge=Ea;kt.enterEdge=Na;kt.exchangeEdges=Sa;function kt(e){e=Bg(e),Hg(e);var t=zg(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=Vg(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Yg(e,t,r))}function Yg(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,Wg(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=Fg(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 Wg(e,t,n){return e.hasEdge(t,n)}function eo(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Ug=Wn,ka=Ug.longestPath,qg=ba,Kg=Gg,Zg=Qg;function Qg(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":ey(e);break;case"longest-path":Jg(e);break;case"none":break;default:to(e)}}var Jg=ka;function ey(e){ka(e),qg(e)}function to(e){Kg(e)}var ty=ny;function ny(e){let t=sy(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,o=ry(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 sy(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 oy={run:iy,cleanup:ly};function iy(e){let t=Pn.addDummyNode(e,"root",{},"_root"),n=ay(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=cy(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 ay(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 cy(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function ly(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 uy=Se;var dy=fy;function fy(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 gy(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 yy(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 xy=wy;function wy(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 by=Se.zipObject;var vy=_y;function _y(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 Ny=Sy;function Sy(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 ky=Se;var jy=Cy;function Cy(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 My(r)}function My(e){let t=[];function n(s){return o=>{o.merged||(o.barycenter===void 0||s.barycenter===void 0||o.barycenter>=s.barycenter)&&$y(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=>ky.pick(s,["vs","i","barycenter","weight"]))}function $y(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 Ay=Se;var Ry=Iy;function Iy(e,t){let n=Ay.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(Ty(!!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 Ty(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Oy=Ny,Ly=jy,Dy=Ry;var Py=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=Oy(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")&&Hy(m,f)}});let l=Ly(u,n);zy(l,c);let d=Dy(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 zy(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function Hy(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 Fy=qe.Graph,Vy=Se;var By=Gy;function Gy(e,t,n,r){r||(r=e.nodes());let s=Yy(e),o=new Fy({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 Yy(e){for(var t;e.hasNode(t=Vy.uniqueId("_root")););return t}var Xy=Wy;function Wy(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 Uy=xy,qy=vy,Ky=Py,Zy=By,Qy=Xy,Jy=qe.Graph,vn=Se;var e0=$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=Uy(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){t0(c%2?r:s,c%4>=2),o=vn.buildLayerMatrix(e);let l=qy(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 Zy(e,o,n,r.get(o)||[])})}function t0(e,t){let n=new Jy;e.forEach(function(r){let s=r.graph().root,o=Ky(r,s,n,t);o.vs.forEach((i,a)=>r.node(i).order=a),Qy(r,n,o.vs)})}function ao(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let n0=qe.Graph,rt=Se;var r0={positionX:m0};function s0(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=i0(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 i0(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 a0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function c0(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 u0(e,t,n,r){let s=new n0,o=e.graph(),i=p0(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 d0(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=g0(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 h0(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 m0(e){let t=rt.buildLayerMatrix(e),n=Object.assign(s0(e,t),o0(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=c0(e,s,n,c),l=l0(e,s,u.root,u.align,a==="r");a==="r"&&(l=rt.mapValues(l,d=>-d)),r[i+a]=l})});let o=d0(e,r);return f0(r,o),h0(r,e.graph().align)}function p0(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 g0(e,t){return e.node(t).width}let Ra=Se,y0=r0.positionX;var x0=w0;function w0(e){e=Ra.asNonCompoundGraph(e),b0(e),Object.entries(y0(e)).forEach(([t,n])=>e.node(t).x=n)}function b0(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=_g,lo=jg,v0=Zg,_0=Se.normalizeRanks,E0=ty,N0=Se.removeEmptyRanks,uo=oy,S0=dy,fo=hy,k0=e0,j0=x0,Ge=Se,C0=qe.Graph;var M0=$0;function $0(e,t){let n=t&&t.debugTiming?Ge.time:Ge.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>H0(e));n(" runLayout",()=>A0(r,n,t)),n(" updateInputGraph",()=>R0(e,r))})}function A0(e,t,n){t(" makeSpaceForEdgeLabels",()=>F0(e)),t(" removeSelfEdges",()=>K0(e)),t(" acyclic",()=>co.run(e)),t(" nestingGraph.run",()=>uo.run(e)),t(" rank",()=>v0(Ge.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>V0(e)),t(" removeEmptyRanks",()=>N0(e)),t(" nestingGraph.cleanup",()=>uo.cleanup(e)),t(" normalizeRanks",()=>_0(e)),t(" assignRankMinMax",()=>B0(e)),t(" removeEdgeLabelProxies",()=>G0(e)),t(" normalize.run",()=>lo.run(e)),t(" parentDummyChains",()=>E0(e)),t(" addBorderSegments",()=>S0(e)),t(" order",()=>k0(e,n)),t(" insertSelfEdges",()=>Z0(e)),t(" adjustCoordinateSystem",()=>fo.adjust(e)),t(" position",()=>j0(e)),t(" positionSelfEdges",()=>Q0(e)),t(" removeBorderNodes",()=>q0(e)),t(" normalize.undo",()=>lo.undo(e)),t(" fixupEdgeLabelCoords",()=>W0(e)),t(" undoCoordinateSystem",()=>fo.undo(e)),t(" translateGraph",()=>Y0(e)),t(" assignNodeIntersects",()=>X0(e)),t(" reversePoints",()=>U0(e)),t(" acyclic.undo",()=>co.undo(e))}function R0(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 I0=["nodesep","edgesep","ranksep","marginx","marginy"],T0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},O0=["acyclicer","ranker","rankdir","align"],L0=["width","height","rank"],ho={width:0,height:0},D0=["minlen","weight","width","height","labeloffset"],P0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},z0=["labelpos"];function H0(e){let t=new C0({multigraph:!0,compound:!0}),n=dr(e.graph());return t.setGraph(Object.assign({},T0,ur(n,I0),Ge.pick(n,O0))),e.nodes().forEach(r=>{let s=dr(e.node(r));const o=ur(s,L0);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({},P0,ur(s,D0),Ge.pick(s,z0)))}),t}function F0(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 V0(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 B0(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 G0(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 Y0(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 X0(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 W0(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 U0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function q0(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 K0(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 Z0(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 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 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 J0=Se,ex=qe.Graph;var tx={debugOrdering:nx};function nx(e){let t=J0.buildLayerMatrix(e),n=new ex({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 rx="1.1.8",sx={graphlib:qe,layout:M0,debug:tx,util:{time:Se.time,notime:Se.notime},version:rx};const mo=$o(sx),Qe=264,ox=44,ix=26,ax=14;function gt(e){const t=Math.max(e.attributes.length,1);return ox+t*ix+ax}const cx=40;function fr(e,t,n,r="auto",s,o="LR"){const i=lx(n,s);return r==="grid"?xo(e,n,i):r==="clustered"?yo(e,t,n,i,o):r==="hierarchical"||e.length<=cx?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 lx(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 ux(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):ux(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 dx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],La=["industry","core","domain","specialised"];function fx({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:dx.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 hx({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 mx({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 px({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 gx({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,yx=6,Rt=24;function xx(e,t){return t?e:Math.round(e/wo)*wo}function wx(e,t,n){const r=[...t];for(const i of n)r.push(i.left-Rt,i.right+Rt);let s=e,o=yx;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:Sx(l),sourceOut:d,targetOut:m}}const dt=8;function jx(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,Cx=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?kx({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=vx(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=jx(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 Mx={entity:Gm},$x={relationship:Cx},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 Ax(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 Rx(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 cw({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}=Rx(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=Ax(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:Mx,edgeTypes:$x,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(Wm,{entity:Re,doc:e,caps:t,exec:je,onClose:()=>s(null),onFocusEntity:$e,onAlign:H,onEditMapping:C}),B&&h.jsx(fx,{entity:B,exec:je,onClose:()=>H(null)}),y&&h.jsx(hx,{entity:y,doc:e,exec:je,onClose:()=>C(null)}),S&&h.jsx(mx,{doc:e,exec:je,onClose:()=>O(!1),onCreated:$e}),D&&h.jsx(px,{doc:e,fromId:D.from,toId:D.to,initialFromAttr:D.fromAttr,initialToAttr:D.toAttr,exec:je,onClose:()=>k(null)}),ze&&h.jsx(gx,{rel:ze,doc:e,exec:je,onClose:()=>P(null)})]})}function lw({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(Ix,{}),e==="layers"&&h.jsx(Ox,{refreshKey:r,onFocusEntity:o}),e==="changes"&&h.jsx(Lx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Dx,{readOnly:n})]})}function Ix(){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 Tx=["industry","core","domain","specialised"];function Ox({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))]}),Tx.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 Lx({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 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}; +`},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 Dx({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 uw({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(Px,{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 Px({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,uw as I,Ox as L,cw as M,Ix as O,ko as P,Zi as R,lw as S,Vx as a,Jx as b,Kx as c,tw as d,nw as e,Fx as f,Im as g,sw as h,rw as i,Zx as j,Yx as k,Xx as l,Wx as m,qx as n,oa as o,ew as p,Qx as q,Ux as r,Rm as s,Bx as t,Gx as u,fr as v,Ji as w,Cx 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 3c8d71c..b8771a1 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 2eb62d9..aa86f7a 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 bf2268f73941e949f5281dadb5cbf72f38975df4 Mon Sep 17 00:00:00 2001 From: Debasish Bose Date: Thu, 15 Oct 2026 15:54:26 +1100 Subject: [PATCH 2/2] canvas: closing the Inspector while filtered no longer zooms out or loses drags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Repro: with a subject-area filter active and zoomed in, repositioning entities then accidentally clicking one opened the Inspector; closing it zoomed the viewport out AND reverted the just-moved cards. Cause: the keep-positions fast path in the node derivation was gated on !filtering, so while a filter was active EVERY re-run of the derivation — including a selection change like opening or closing the Inspector — fell through to the full re-layout path, which re-fits the viewport (fitView) and re-lays-out the visible subset (dropping any not-yet-saved manual drag). The !filtering gate exists so ticking a filter re-fits the focused domain, but that is a VIEW change, which already resets layoutedRef to false via the view-load effect — not every re-derivation. Fix: key the fast path on layoutedRef alone (drop !filtering). Every entity is always present in newNodes (hidden ones flagged, never removed), so the id/length checks hold across a filter switch too; layoutedRef is what distinguishes 'view changed' (re-layout + fit) from 'selection changed' (keep positions). A real filter toggle still re-fits because its view-load reset makes layoutedRef false. Verified live: filter active + zoomed, open/close Inspector holds both the zoom and every card position. tsc clean; canvas Vitest 55 passed. --- canvas/src/ModelCanvas.tsx | 24 ++++++++++++------- ...m-iKtDWBmW.js => ModelDiagram-B1wZqxU3.js} | 2 +- .../{main-Cj04gwM7.js => main-D9iylR5x.js} | 2 +- .../{sme-BMwBdWVn.js => sme-BaPx07pq.js} | 4 ++-- ...{styles-DqdjcU5q.js => styles-Bal0oVyo.js} | 4 ++-- .../server/src/mdl_server/static/index.html | 4 ++-- .../server/src/mdl_server/static/sme.html | 4 ++-- 7 files changed, 26 insertions(+), 18 deletions(-) rename packages/server/src/mdl_server/static/assets/{ModelDiagram-iKtDWBmW.js => ModelDiagram-B1wZqxU3.js} (97%) rename packages/server/src/mdl_server/static/assets/{main-Cj04gwM7.js => main-D9iylR5x.js} (99%) rename packages/server/src/mdl_server/static/assets/{sme-BMwBdWVn.js => sme-BaPx07pq.js} (99%) rename packages/server/src/mdl_server/static/assets/{styles-DqdjcU5q.js => styles-Bal0oVyo.js} (94%) diff --git a/canvas/src/ModelCanvas.tsx b/canvas/src/ModelCanvas.tsx index f004df2..8af5f82 100644 --- a/canvas/src/ModelCanvas.tsx +++ b/canvas/src/ModelCanvas.tsx @@ -484,19 +484,27 @@ export function ModelCanvas({ const known = newNodes.every((n) => posById.has(n.id)); // When a subject-area filter is active, lay out ONLY the visible nodes so the focused // domain fills the canvas (a stale full-model layout would leave it in a far corner). - // 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) { + // That re-layout belongs to a VIEW CHANGE (ticking a filter) — which resets + // layoutedRef to false via the view-load effect — NOT to every re-derivation. Once a + // view is laid out (layoutedRef true), an incidental re-run (search, SELECTING or + // closing the Inspector, a recolour) must keep positions and must not re-fit, filter + // active or not. Keying only on layoutedRef (not `filtering`) fixes the bug where + // closing the Inspector while filtered zoomed out and reset in-filter manual drags: + // every entity is always present in newNodes (hidden ones flagged, never removed), so + // `known` and the length check hold across a filter switch too — layoutedRef is the + // only thing that distinguishes "view changed" from "selection changed". + if (layoutedRef.current && known && prev.length >= newNodes.length) { // The entity SET is unchanged (same ids, no growth), so keep every saved/manual - // position — a recolour must never reflow a laid-out diagram (and must not fight the - // saved-layout restore). newNodes already carries the fresh subject-area colour; we - // only swap in the kept positions. React Flow then re-renders each node whose `data` - // reference changed, and EntityNode's memo comparator (which includes `color`) makes - // the accent repaint — so a membership change recolours in place without moving cards. + // position — a recolour/selection must never reflow a laid-out diagram (and must not + // fight the saved-layout restore). newNodes already carries the fresh subject-area + // colour and hidden flags; we only swap in the kept positions. React Flow then + // re-renders each node whose `data` reference changed, and EntityNode's memo + // comparator (which includes `color`) makes the accent repaint. const kept = newNodes.map((n) => ({ ...n, position: posById.get(n.id) ?? n.position })); emitEdges(kept); return kept; } + const filtering = (activeAreas?.size ?? 0) > 0; 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])); diff --git a/packages/server/src/mdl_server/static/assets/ModelDiagram-iKtDWBmW.js b/packages/server/src/mdl_server/static/assets/ModelDiagram-B1wZqxU3.js similarity index 97% rename from packages/server/src/mdl_server/static/assets/ModelDiagram-iKtDWBmW.js rename to packages/server/src/mdl_server/static/assets/ModelDiagram-B1wZqxU3.js index 94ec2b6..0989fd3 100644 --- a/packages/server/src/mdl_server/static/assets/ModelDiagram-iKtDWBmW.js +++ b/packages/server/src/mdl_server/static/assets/ModelDiagram-B1wZqxU3.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-DqdjcU5q.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-Bal0oVyo.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-Cj04gwM7.js b/packages/server/src/mdl_server/static/assets/main-D9iylR5x.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/main-Cj04gwM7.js rename to packages/server/src/mdl_server/static/assets/main-D9iylR5x.js index 2a0d2cc..3aea4cf 100644 --- a/packages/server/src/mdl_server/static/assets/main-Cj04gwM7.js +++ b/packages/server/src/mdl_server/static/assets/main-D9iylR5x.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-DqdjcU5q.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-Bal0oVyo.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-BMwBdWVn.js b/packages/server/src/mdl_server/static/assets/sme-BaPx07pq.js similarity index 99% rename from packages/server/src/mdl_server/static/assets/sme-BMwBdWVn.js rename to packages/server/src/mdl_server/static/assets/sme-BaPx07pq.js index 89634dd..5aff5e6 100644 --- a/packages/server/src/mdl_server/static/assets/sme-BMwBdWVn.js +++ b/packages/server/src/mdl_server/static/assets/sme-BaPx07pq.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelDiagram-iKtDWBmW.js","assets/client-DOmNpTln.js","assets/styles-DqdjcU5q.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-DqdjcU5q.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-iKtDWBmW.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-B1wZqxU3.js","assets/client-DOmNpTln.js","assets/styles-Bal0oVyo.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-Bal0oVyo.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-B1wZqxU3.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-DqdjcU5q.js b/packages/server/src/mdl_server/static/assets/styles-Bal0oVyo.js similarity index 94% rename from packages/server/src/mdl_server/static/assets/styles-DqdjcU5q.js rename to packages/server/src/mdl_server/static/assets/styles-Bal0oVyo.js index 5e73357..2041053 100644 --- a/packages/server/src/mdl_server/static/assets/styles-DqdjcU5q.js +++ b/packages/server/src/mdl_server/static/assets/styles-Bal0oVyo.js @@ -14,9 +14,9 @@ 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 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 + */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:pe,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,pe),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 pe=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:pe}]),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:pe,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(),pe=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,ge=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:ge,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:pe,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:pe,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:pe,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:pe,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:ge,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:ge,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:pe,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 pe=z.current*Math.max(1,oe[2])*(g?-1:1),le={x:oe[0]-ae.sourceEvent.movementX*pe,y:oe[1]-ae.sourceEvent.movementY*pe},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 Fx=e=>be(e?`/api/model?subject_area=${encodeURIComponent(e)}`:"/api/model"),Vx=()=>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}),Bx=(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()}`)},Gx=()=>be("/api/glossary/config"),Yx=e=>ct("/api/git/propose",e),Xx=(e="HEAD")=>be(`/api/git/diff/model?base=${encodeURIComponent(e)}`),Wx=(e="HEAD")=>be(`/api/git/classify?base=${encodeURIComponent(e)}`),Ux=e=>ct("/api/git/classify",{changes:e}),qx=e=>be(`/api/git/conflicts?base=${encodeURIComponent(e)}`),Kx=(e="")=>be(`/api/git/context?user=${encodeURIComponent(e)}`),Zx=(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}),Qx=e=>be(`/api/import/stash/${encodeURIComponent(e)}`),Jx=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}},ew=(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()}),tw=()=>be("/api/glossary/subject-areas"),nw=e=>be(`/api/glossary/subject-area/${e}`),rw=(e,t)=>ct(`/api/glossary/subject-area/${e}/expand`,t);function sw(){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);function Ym(e,t){if(e.selected!==t.selected)return!1;const n=e.data,r=t.data;return n.entity===r.entity&&n.color===r.color&&n.dimmed===r.dimmed&&n.highlighted===r.highlighted&&n.showTypes===r.showTypes&&n.collapseDetail===r.collapseDetail&&n.expanded===r.expanded&&n.endpointAttrs===r.endpointAttrs&&n.highlightAttrs===r.highlightAttrs&&n.dimAttrs===r.dimAttrs&&n.onToggleExpand===r.onToggleExpand&&n.onHoverAttr===r.onHoverAttr}const Xm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Wm({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(qm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Zm,{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(Um,{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(Jm,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(ep,{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:tp(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 Um({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 qm({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 Km=["","scd2","hub","link","satellite","bridge"];function Zm({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:Km.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Qm=["attribute","business_key","measure","surrogate_key"];function Jm({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([...Xm,...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 ep({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 tp(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 np="\0",xt="\0",Ws="";let rp=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=sp(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?np:r)}function sp(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=rp,op="2.2.4",ip={Graph:Kr,version:op},ap=Kr,cp={write:lp,read:fp};function lp(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:up(e),edges:dp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function up(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 dp(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 fp(e){var t=new ap(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 hp=mp;function mp(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 pp=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 xp(e,t,n,r){return wp(e,String(t),n||yp,r||function(s){return e.outEdges(s)})}function wp(e,t,n,r){var s={},o=new gp,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 bp=ca,vp=_p;function _p(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=bp(e,s,t,n),r},{})}var la=Ep;function Ep(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 Np=la,Sp=kp;function kp(e){return Np(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var jp=Mp,Cp=()=>1;function Mp(e,t,n){return $p(e,t||Cp,n||function(r){return e.outEdges(r)})}function $p(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"?Tp:Op,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 Tp(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 Op(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 Lp=fa,Dp=Pp;function Pp(e,t){return Lp(e,t,"post")}var zp=fa,Hp=Fp;function Fp(e,t){return zp(e,t,"pre")}var Vp=Kr,Bp=aa,Gp=Yp;function Yp(e,t){var n=new Vp,r={},s=new Bp,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 Xp={components:hp,dijkstra:ca,dijkstraAll:vp,findCycles:Sp,floydWarshall:jp,isAcyclic:Ap,postorder:Dp,preorder:Hp,prim:Gp,tarjan:la,topsort:da},Zs=ip,qe={Graph:Zs.Graph,json:cp,alg:Xp,version:Zs.version};let Wp=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,Up)),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 Up(e,t){if(e!=="_next"&&e!=="_prev")return t}var qp=Wp;let Kp=qe.Graph,Zp=qp;var Qp=eg;let Jp=()=>1;function eg(e,t){if(e.nodeCount()<=1)return[];let n=ng(e,t||Jp);return tg(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function tg(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 ng(e,t){let n=new Kp,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=rg(s+r+3).map(()=>new Zp),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 rg(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 og(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 ig(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 ag(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 cg(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 lg(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 ug(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 dg(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 fg(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 hg(e,t=ga){const n=[];for(let r=0;rga){const n=hg(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 mg(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function pg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function gg(e,t){return t()}let yg=0;function xa(e){var t=++yg;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 bg=Qp,vg=Se.uniqueId;var _g={run:Eg,undo:Sg};function Eg(e){(e.graph().acyclicer==="greedy"?bg(e,n(e)):Ng(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,vg("rev"))});function n(r){return s=>r.edge(s).weight}}function Ng(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 Sg(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 kg=Se;var jg={run:Cg,undo:$g};function Cg(e){e.graph().dummyChains=[],e.edges().forEach(t=>Mg(e,t))}function Mg(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:Ag}=Se;var Wn={longestPath:Rg,slack:Ig};function Rg(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=Ag(Math.min,o);return i===Number.POSITIVE_INFINITY&&(i=0),s.rank=i}e.sources().forEach(n)}function Ig(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var Tg=qe.Graph,Dn=Wn.slack,ba=Og;function Og(e){var t=new Tg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,o;Lg(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 Dg(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 zg=ba,Js=Wn.slack,Hg=Wn.longestPath,Fg=qe.alg.preorder,Vg=qe.alg.postorder,Bg=Se.simplify,Gg=kt;kt.initLowLimValues=Jr;kt.initCutValues=Qr;kt.calcCutValue=va;kt.leaveEdge=Ea;kt.enterEdge=Na;kt.exchangeEdges=Sa;function kt(e){e=Bg(e),Hg(e);var t=zg(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=Vg(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Yg(e,t,r))}function Yg(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,Wg(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=Fg(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 Wg(e,t,n){return e.hasEdge(t,n)}function eo(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Ug=Wn,ka=Ug.longestPath,qg=ba,Kg=Gg,Zg=Qg;function Qg(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":ey(e);break;case"longest-path":Jg(e);break;case"none":break;default:to(e)}}var Jg=ka;function ey(e){ka(e),qg(e)}function to(e){Kg(e)}var ty=ny;function ny(e){let t=sy(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,o=ry(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 sy(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 oy={run:iy,cleanup:ly};function iy(e){let t=Pn.addDummyNode(e,"root",{},"_root"),n=ay(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=cy(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 ay(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 cy(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function ly(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 uy=Se;var dy=fy;function fy(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 gy(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 yy(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 xy=wy;function wy(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 by=Se.zipObject;var vy=_y;function _y(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 Ny=Sy;function Sy(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 ky=Se;var jy=Cy;function Cy(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 My(r)}function My(e){let t=[];function n(s){return o=>{o.merged||(o.barycenter===void 0||s.barycenter===void 0||o.barycenter>=s.barycenter)&&$y(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=>ky.pick(s,["vs","i","barycenter","weight"]))}function $y(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 Ay=Se;var Ry=Iy;function Iy(e,t){let n=Ay.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(Ty(!!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 Ty(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Oy=Ny,Ly=jy,Dy=Ry;var Py=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=Oy(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")&&Hy(m,f)}});let l=Ly(u,n);zy(l,c);let d=Dy(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 zy(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function Hy(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 Fy=qe.Graph,Vy=Se;var By=Gy;function Gy(e,t,n,r){r||(r=e.nodes());let s=Yy(e),o=new Fy({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 Yy(e){for(var t;e.hasNode(t=Vy.uniqueId("_root")););return t}var Xy=Wy;function Wy(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 Uy=xy,qy=vy,Ky=Py,Zy=By,Qy=Xy,Jy=qe.Graph,vn=Se;var e0=$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=Uy(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){t0(c%2?r:s,c%4>=2),o=vn.buildLayerMatrix(e);let l=qy(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 Zy(e,o,n,r.get(o)||[])})}function t0(e,t){let n=new Jy;e.forEach(function(r){let s=r.graph().root,o=Ky(r,s,n,t);o.vs.forEach((i,a)=>r.node(i).order=a),Qy(r,n,o.vs)})}function ao(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let n0=qe.Graph,rt=Se;var r0={positionX:m0};function s0(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=i0(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 i0(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 a0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function c0(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 u0(e,t,n,r){let s=new n0,o=e.graph(),i=p0(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 d0(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=g0(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 h0(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 m0(e){let t=rt.buildLayerMatrix(e),n=Object.assign(s0(e,t),o0(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=c0(e,s,n,c),l=l0(e,s,u.root,u.align,a==="r");a==="r"&&(l=rt.mapValues(l,d=>-d)),r[i+a]=l})});let o=d0(e,r);return f0(r,o),h0(r,e.graph().align)}function p0(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 g0(e,t){return e.node(t).width}let Ra=Se,y0=r0.positionX;var x0=w0;function w0(e){e=Ra.asNonCompoundGraph(e),b0(e),Object.entries(y0(e)).forEach(([t,n])=>e.node(t).x=n)}function b0(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=_g,lo=jg,v0=Zg,_0=Se.normalizeRanks,E0=ty,N0=Se.removeEmptyRanks,uo=oy,S0=dy,fo=hy,k0=e0,j0=x0,Ge=Se,C0=qe.Graph;var M0=$0;function $0(e,t){let n=t&&t.debugTiming?Ge.time:Ge.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>H0(e));n(" runLayout",()=>A0(r,n,t)),n(" updateInputGraph",()=>R0(e,r))})}function A0(e,t,n){t(" makeSpaceForEdgeLabels",()=>F0(e)),t(" removeSelfEdges",()=>K0(e)),t(" acyclic",()=>co.run(e)),t(" nestingGraph.run",()=>uo.run(e)),t(" rank",()=>v0(Ge.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>V0(e)),t(" removeEmptyRanks",()=>N0(e)),t(" nestingGraph.cleanup",()=>uo.cleanup(e)),t(" normalizeRanks",()=>_0(e)),t(" assignRankMinMax",()=>B0(e)),t(" removeEdgeLabelProxies",()=>G0(e)),t(" normalize.run",()=>lo.run(e)),t(" parentDummyChains",()=>E0(e)),t(" addBorderSegments",()=>S0(e)),t(" order",()=>k0(e,n)),t(" insertSelfEdges",()=>Z0(e)),t(" adjustCoordinateSystem",()=>fo.adjust(e)),t(" position",()=>j0(e)),t(" positionSelfEdges",()=>Q0(e)),t(" removeBorderNodes",()=>q0(e)),t(" normalize.undo",()=>lo.undo(e)),t(" fixupEdgeLabelCoords",()=>W0(e)),t(" undoCoordinateSystem",()=>fo.undo(e)),t(" translateGraph",()=>Y0(e)),t(" assignNodeIntersects",()=>X0(e)),t(" reversePoints",()=>U0(e)),t(" acyclic.undo",()=>co.undo(e))}function R0(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 I0=["nodesep","edgesep","ranksep","marginx","marginy"],T0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},O0=["acyclicer","ranker","rankdir","align"],L0=["width","height","rank"],ho={width:0,height:0},D0=["minlen","weight","width","height","labeloffset"],P0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},z0=["labelpos"];function H0(e){let t=new C0({multigraph:!0,compound:!0}),n=dr(e.graph());return t.setGraph(Object.assign({},T0,ur(n,I0),Ge.pick(n,O0))),e.nodes().forEach(r=>{let s=dr(e.node(r));const o=ur(s,L0);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({},P0,ur(s,D0),Ge.pick(s,z0)))}),t}function F0(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 V0(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 B0(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 G0(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 Y0(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 X0(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 W0(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 U0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function q0(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 K0(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 Z0(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 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 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 J0=Se,ex=qe.Graph;var tx={debugOrdering:nx};function nx(e){let t=J0.buildLayerMatrix(e),n=new ex({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 rx="1.1.8",sx={graphlib:qe,layout:M0,debug:tx,util:{time:Se.time,notime:Se.notime},version:rx};const mo=$o(sx),Qe=264,ox=44,ix=26,ax=14;function gt(e){const t=Math.max(e.attributes.length,1);return ox+t*ix+ax}const cx=40;function fr(e,t,n,r="auto",s,o="LR"){const i=lx(n,s);return r==="grid"?xo(e,n,i):r==="clustered"?yo(e,t,n,i,o):r==="hierarchical"||e.length<=cx?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 lx(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 ux(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):ux(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 dx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],La=["industry","core","domain","specialised"];function fx({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:dx.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 hx({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 mx({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 px({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 gx({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,yx=6,Rt=24;function xx(e,t){return t?e:Math.round(e/wo)*wo}function wx(e,t,n){const r=[...t];for(const i of n)r.push(i.left-Rt,i.right+Rt);let s=e,o=yx;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:Sx(l),sourceOut:d,targetOut:m}}const dt=8;function jx(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,Cx=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?kx({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=vx(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=jx(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 Mx={entity:Gm},$x={relationship:Cx},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 Ax(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 Rx(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 cw({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}=Rx(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=Ax(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:Mx,edgeTypes:$x,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(Wm,{entity:Re,doc:e,caps:t,exec:je,onClose:()=>s(null),onFocusEntity:$e,onAlign:H,onEditMapping:C}),B&&h.jsx(fx,{entity:B,exec:je,onClose:()=>H(null)}),y&&h.jsx(hx,{entity:y,doc:e,exec:je,onClose:()=>C(null)}),S&&h.jsx(mx,{doc:e,exec:je,onClose:()=>O(!1),onCreated:$e}),D&&h.jsx(px,{doc:e,fromId:D.from,toId:D.to,initialFromAttr:D.fromAttr,initialToAttr:D.toAttr,exec:je,onClose:()=>k(null)}),ze&&h.jsx(gx,{rel:ze,doc:e,exec:je,onClose:()=>P(null)})]})}function lw({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(Ix,{}),e==="layers"&&h.jsx(Ox,{refreshKey:r,onFocusEntity:o}),e==="changes"&&h.jsx(Lx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Dx,{readOnly:n})]})}function Ix(){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 Tx=["industry","core","domain","specialised"];function Ox({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))]}),Tx.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 Lx({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(` +`);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);function Ym(e,t){if(e.selected!==t.selected)return!1;const n=e.data,r=t.data;return n.entity===r.entity&&n.color===r.color&&n.dimmed===r.dimmed&&n.highlighted===r.highlighted&&n.showTypes===r.showTypes&&n.collapseDetail===r.collapseDetail&&n.expanded===r.expanded&&n.endpointAttrs===r.endpointAttrs&&n.highlightAttrs===r.highlightAttrs&&n.dimAttrs===r.dimAttrs&&n.onToggleExpand===r.onToggleExpand&&n.onHoverAttr===r.onHoverAttr}const Xm=["string","integer","bigint","decimal","boolean","date","timestamp"];function Wm({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(qm,{entity:e,doc:t,readOnly:c,exec:r}),h.jsx(Zm,{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(Um,{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(Jm,{a:N,entity:e,doc:t,readOnly:c,exec:r},N.id))})}),!c&&h.jsx(ep,{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:tp(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 Um({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 qm({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 Km=["","scd2","hub","link","satellite","bridge"];function Zm({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:Km.map(r=>h.jsx("option",{value:r,children:r||"no pattern"},r))})}const Qm=["attribute","business_key","measure","surrogate_key"];function Jm({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([...Xm,...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 ep({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 tp(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 np="\0",xt="\0",Ws="";let rp=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=sp(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?np:r)}function sp(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=rp,op="2.2.4",ip={Graph:Kr,version:op},ap=Kr,cp={write:lp,read:fp};function lp(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:up(e),edges:dp(e)};return e.graph()!==void 0&&(t.value=structuredClone(e.graph())),t}function up(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 dp(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 fp(e){var t=new ap(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 hp=mp;function mp(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 pp=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 xp(e,t,n,r){return wp(e,String(t),n||yp,r||function(s){return e.outEdges(s)})}function wp(e,t,n,r){var s={},o=new gp,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 bp=ca,vp=_p;function _p(e,t,n){return e.nodes().reduce(function(r,s){return r[s]=bp(e,s,t,n),r},{})}var la=Ep;function Ep(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 Np=la,Sp=kp;function kp(e){return Np(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var jp=Mp,Cp=()=>1;function Mp(e,t,n){return $p(e,t||Cp,n||function(r){return e.outEdges(r)})}function $p(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"?Tp:Op,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 Tp(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 Op(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 Lp=fa,Dp=Pp;function Pp(e,t){return Lp(e,t,"post")}var zp=fa,Hp=Fp;function Fp(e,t){return zp(e,t,"pre")}var Vp=Kr,Bp=aa,Gp=Yp;function Yp(e,t){var n=new Vp,r={},s=new Bp,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 Xp={components:hp,dijkstra:ca,dijkstraAll:vp,findCycles:Sp,floydWarshall:jp,isAcyclic:Ap,postorder:Dp,preorder:Hp,prim:Gp,tarjan:la,topsort:da},Zs=ip,qe={Graph:Zs.Graph,json:cp,alg:Xp,version:Zs.version};let Wp=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,Up)),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 Up(e,t){if(e!=="_next"&&e!=="_prev")return t}var qp=Wp;let Kp=qe.Graph,Zp=qp;var Qp=eg;let Jp=()=>1;function eg(e,t){if(e.nodeCount()<=1)return[];let n=ng(e,t||Jp);return tg(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w))}function tg(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 ng(e,t){let n=new Kp,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=rg(s+r+3).map(()=>new Zp),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 rg(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 og(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 ig(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 ag(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 cg(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 lg(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 ug(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 dg(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 fg(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 hg(e,t=ga){const n=[];for(let r=0;rga){const n=hg(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 mg(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function pg(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function gg(e,t){return t()}let yg=0;function xa(e){var t=++yg;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 bg=Qp,vg=Se.uniqueId;var _g={run:Eg,undo:Sg};function Eg(e){(e.graph().acyclicer==="greedy"?bg(e,n(e)):Ng(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,vg("rev"))});function n(r){return s=>r.edge(s).weight}}function Ng(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 Sg(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 kg=Se;var jg={run:Cg,undo:$g};function Cg(e){e.graph().dummyChains=[],e.edges().forEach(t=>Mg(e,t))}function Mg(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:Ag}=Se;var Wn={longestPath:Rg,slack:Ig};function Rg(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=Ag(Math.min,o);return i===Number.POSITIVE_INFINITY&&(i=0),s.rank=i}e.sources().forEach(n)}function Ig(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var Tg=qe.Graph,Dn=Wn.slack,ba=Og;function Og(e){var t=new Tg({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var s,o;Lg(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 Dg(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 zg=ba,Js=Wn.slack,Hg=Wn.longestPath,Fg=qe.alg.preorder,Vg=qe.alg.postorder,Bg=Se.simplify,Gg=kt;kt.initLowLimValues=Jr;kt.initCutValues=Qr;kt.calcCutValue=va;kt.leaveEdge=Ea;kt.enterEdge=Na;kt.exchangeEdges=Sa;function kt(e){e=Bg(e),Hg(e);var t=zg(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=Vg(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>Yg(e,t,r))}function Yg(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,Wg(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=Fg(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 Wg(e,t,n){return e.hasEdge(t,n)}function eo(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Ug=Wn,ka=Ug.longestPath,qg=ba,Kg=Gg,Zg=Qg;function Qg(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":ey(e);break;case"longest-path":Jg(e);break;case"none":break;default:to(e)}}var Jg=ka;function ey(e){ka(e),qg(e)}function to(e){Kg(e)}var ty=ny;function ny(e){let t=sy(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),s=r.edgeObj,o=ry(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 sy(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 oy={run:iy,cleanup:ly};function iy(e){let t=Pn.addDummyNode(e,"root",{},"_root"),n=ay(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=cy(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 ay(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 cy(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function ly(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 uy=Se;var dy=fy;function fy(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 gy(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 yy(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 xy=wy;function wy(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 by=Se.zipObject;var vy=_y;function _y(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 Ny=Sy;function Sy(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 ky=Se;var jy=Cy;function Cy(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 My(r)}function My(e){let t=[];function n(s){return o=>{o.merged||(o.barycenter===void 0||s.barycenter===void 0||o.barycenter>=s.barycenter)&&$y(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=>ky.pick(s,["vs","i","barycenter","weight"]))}function $y(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 Ay=Se;var Ry=Iy;function Iy(e,t){let n=Ay.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(Ty(!!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 Ty(e){return(t,n)=>t.barycentern.barycenter?1:e?n.i-t.i:t.i-n.i}let Oy=Ny,Ly=jy,Dy=Ry;var Py=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=Oy(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")&&Hy(m,f)}});let l=Ly(u,n);zy(l,c);let d=Dy(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 zy(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function Hy(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 Fy=qe.Graph,Vy=Se;var By=Gy;function Gy(e,t,n,r){r||(r=e.nodes());let s=Yy(e),o=new Fy({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 Yy(e){for(var t;e.hasNode(t=Vy.uniqueId("_root")););return t}var Xy=Wy;function Wy(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 Uy=xy,qy=vy,Ky=Py,Zy=By,Qy=Xy,Jy=qe.Graph,vn=Se;var e0=$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=Uy(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){t0(c%2?r:s,c%4>=2),o=vn.buildLayerMatrix(e);let l=qy(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 Zy(e,o,n,r.get(o)||[])})}function t0(e,t){let n=new Jy;e.forEach(function(r){let s=r.graph().root,o=Ky(r,s,n,t);o.vs.forEach((i,a)=>r.node(i).order=a),Qy(r,n,o.vs)})}function ao(e,t){Object.values(t).forEach(n=>n.forEach((r,s)=>e.node(r).order=s))}let n0=qe.Graph,rt=Se;var r0={positionX:m0};function s0(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=i0(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 i0(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 a0(e,t,n){if(t>n){let r=t;t=n,n=r}return!!e[t]&&Object.hasOwn(e[t],n)}function c0(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 u0(e,t,n,r){let s=new n0,o=e.graph(),i=p0(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 d0(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=g0(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 h0(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 m0(e){let t=rt.buildLayerMatrix(e),n=Object.assign(s0(e,t),o0(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=c0(e,s,n,c),l=l0(e,s,u.root,u.align,a==="r");a==="r"&&(l=rt.mapValues(l,d=>-d)),r[i+a]=l})});let o=d0(e,r);return f0(r,o),h0(r,e.graph().align)}function p0(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 g0(e,t){return e.node(t).width}let Ra=Se,y0=r0.positionX;var x0=w0;function w0(e){e=Ra.asNonCompoundGraph(e),b0(e),Object.entries(y0(e)).forEach(([t,n])=>e.node(t).x=n)}function b0(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=_g,lo=jg,v0=Zg,_0=Se.normalizeRanks,E0=ty,N0=Se.removeEmptyRanks,uo=oy,S0=dy,fo=hy,k0=e0,j0=x0,Ge=Se,C0=qe.Graph;var M0=$0;function $0(e,t){let n=t&&t.debugTiming?Ge.time:Ge.notime;n("layout",()=>{let r=n(" buildLayoutGraph",()=>H0(e));n(" runLayout",()=>A0(r,n,t)),n(" updateInputGraph",()=>R0(e,r))})}function A0(e,t,n){t(" makeSpaceForEdgeLabels",()=>F0(e)),t(" removeSelfEdges",()=>K0(e)),t(" acyclic",()=>co.run(e)),t(" nestingGraph.run",()=>uo.run(e)),t(" rank",()=>v0(Ge.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>V0(e)),t(" removeEmptyRanks",()=>N0(e)),t(" nestingGraph.cleanup",()=>uo.cleanup(e)),t(" normalizeRanks",()=>_0(e)),t(" assignRankMinMax",()=>B0(e)),t(" removeEdgeLabelProxies",()=>G0(e)),t(" normalize.run",()=>lo.run(e)),t(" parentDummyChains",()=>E0(e)),t(" addBorderSegments",()=>S0(e)),t(" order",()=>k0(e,n)),t(" insertSelfEdges",()=>Z0(e)),t(" adjustCoordinateSystem",()=>fo.adjust(e)),t(" position",()=>j0(e)),t(" positionSelfEdges",()=>Q0(e)),t(" removeBorderNodes",()=>q0(e)),t(" normalize.undo",()=>lo.undo(e)),t(" fixupEdgeLabelCoords",()=>W0(e)),t(" undoCoordinateSystem",()=>fo.undo(e)),t(" translateGraph",()=>Y0(e)),t(" assignNodeIntersects",()=>X0(e)),t(" reversePoints",()=>U0(e)),t(" acyclic.undo",()=>co.undo(e))}function R0(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 I0=["nodesep","edgesep","ranksep","marginx","marginy"],T0={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},O0=["acyclicer","ranker","rankdir","align"],L0=["width","height","rank"],ho={width:0,height:0},D0=["minlen","weight","width","height","labeloffset"],P0={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},z0=["labelpos"];function H0(e){let t=new C0({multigraph:!0,compound:!0}),n=dr(e.graph());return t.setGraph(Object.assign({},T0,ur(n,I0),Ge.pick(n,O0))),e.nodes().forEach(r=>{let s=dr(e.node(r));const o=ur(s,L0);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({},P0,ur(s,D0),Ge.pick(s,z0)))}),t}function F0(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 V0(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 B0(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 G0(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 Y0(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 X0(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 W0(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 U0(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function q0(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 K0(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 Z0(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 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 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 J0=Se,ex=qe.Graph;var tx={debugOrdering:nx};function nx(e){let t=J0.buildLayerMatrix(e),n=new ex({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 rx="1.1.8",sx={graphlib:qe,layout:M0,debug:tx,util:{time:Se.time,notime:Se.notime},version:rx};const mo=$o(sx),Qe=264,ox=44,ix=26,ax=14;function gt(e){const t=Math.max(e.attributes.length,1);return ox+t*ix+ax}const cx=40;function fr(e,t,n,r="auto",s,o="LR"){const i=lx(n,s);return r==="grid"?xo(e,n,i):r==="clustered"?yo(e,t,n,i,o):r==="hierarchical"||e.length<=cx?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 lx(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 ux(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):ux(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 dx=["skos:exactMatch","skos:closeMatch","skos:broadMatch","skos:narrowMatch","skos:relatedMatch"],La=["industry","core","domain","specialised"];function fx({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:dx.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 hx({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 mx({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 px({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 gx({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,yx=6,Rt=24;function xx(e,t){return t?e:Math.round(e/wo)*wo}function wx(e,t,n){const r=[...t];for(const i of n)r.push(i.left-Rt,i.right+Rt);let s=e,o=yx;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:Sx(l),sourceOut:d,targetOut:m}}const dt=8;function jx(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,Cx=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?kx({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":""),pe=((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=vx(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)}))},ge=()=>{window.removeEventListener("pointermove",ie),window.removeEventListener("pointerup",ge),ee&&cancelAnimationFrame(ee),b.current=!1,g(null),$.current>=hr&&Re(ne)};window.addEventListener("pointermove",ie),window.addEventListener("pointerup",ge)},[_,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 ge=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=jx(He.x,He.y,xe),ne||(ne=requestAnimationFrame(()=>{ne=0,M({end:G,a:ie})}))},Ie=()=>{window.removeEventListener("pointermove",ge),window.removeEventListener("pointerup",Ie),ne&&cancelAnimationFrame(ne),M(null),$.current>=hr&&ie&&V(J.id,G,ie)};window.addEventListener("pointermove",ge),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||pe)&&J&&h.jsxs("text",{className:"rel-label",x:Oe,y:Ke-8,children:[d?J.verb_phrase||J.name:"",pe?`${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 Mx={entity:Gm},$x={relationship:Cx},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 Ax(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 Rx(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 cw({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]),pe=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=pe.get(F))==null?void 0:V.id;return!(X&&l.has(X))},[l,pe]),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 ge=pe.get(ee.id);return ge?ve.get(ge.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}=Rx(ee,ue),ge=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:ge,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 ge=J.current[ie.id]??{};return{...ie,data:{...ie.data,routeX:ge.routeX,sourceAnchor:ge.sourceAnchor,targetAnchor:ge.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));if($.current&&ie&&ee.length>=Z.length){const de=Z.map(et=>({...et,position:ne.get(et.id)??et.position}));return re(de),de}const Ie=((l==null?void 0:l.size)??0)>0?Z.filter(de=>!de.hidden):Z,Le=fr(Ie,Y,ue,"auto",pe),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=Ax(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,pe,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),ge=fe.hitAttrsByEntity.get(G.id);return G.data.dimmed===ne&&G.data.highlighted===ie&&G.data.highlightAttrs===ge?G:{...G,data:{...G.data,dimmed:ne,highlighted:ie,highlightAttrs:ge}}})),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,ge=te===G.id,Ie=r!==null&&re!==void 0&&(re.from.entity===r||re.to.entity===r),Le=ie||ge||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)===ge&&G.zIndex===Le?G:{...G,zIndex:Le,data:{...G.data,dimmed:ne,hovered:ie,edgeSelected:ge}}}))},[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,pe,X)),requestAnimationFrame(()=>p({padding:.15,duration:300})),he()},[M,ue,pe,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",pe);return requestAnimationFrame(()=>p({padding:.15,duration:300})),X})},[f,j,M,ue,pe,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:Mx,edgeTypes:$x,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(Wm,{entity:Re,doc:e,caps:t,exec:je,onClose:()=>s(null),onFocusEntity:$e,onAlign:H,onEditMapping:C}),B&&h.jsx(fx,{entity:B,exec:je,onClose:()=>H(null)}),y&&h.jsx(hx,{entity:y,doc:e,exec:je,onClose:()=>C(null)}),S&&h.jsx(mx,{doc:e,exec:je,onClose:()=>O(!1),onCreated:$e}),D&&h.jsx(px,{doc:e,fromId:D.from,toId:D.to,initialFromAttr:D.fromAttr,initialToAttr:D.toAttr,exec:je,onClose:()=>k(null)}),ze&&h.jsx(gx,{rel:ze,doc:e,exec:je,onClose:()=>P(null)})]})}function lw({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(Ix,{}),e==="layers"&&h.jsx(Ox,{refreshKey:r,onFocusEntity:o}),e==="changes"&&h.jsx(Lx,{readOnly:n,refreshKey:r,onModelChanged:s}),e==="decisions"&&h.jsx(Dx,{readOnly:n})]})}function Ix(){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 Tx=["industry","core","domain","specialised"];function Ox({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))]}),Tx.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 Lx({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+` diff --git a/packages/server/src/mdl_server/static/index.html b/packages/server/src/mdl_server/static/index.html index b8771a1..a158efc 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 aa86f7a..bad7935 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 - + - +