@coralai/sps-cli 0.72.0 → 0.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ShowcasePage-B191_5uD.js","assets/ShowcasePage-EkuegwaP.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ShowcasePage-Hrjahug0.js","assets/ShowcasePage-EkuegwaP.css"])))=>i.map(i=>d[i]);
2
2
  var _4=Object.defineProperty;var TN=e=>{throw TypeError(e)};var C4=(e,t,n)=>t in e?_4(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _b=(e,t,n)=>C4(e,typeof t!="symbol"?t+"":t,n),Cb=(e,t,n)=>t.has(e)||TN("Cannot "+n);var J=(e,t,n)=>(Cb(e,t,"read from private field"),n?n.call(e):t.get(e)),st=(e,t,n)=>t.has(e)?TN("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),qe=(e,t,n,i)=>(Cb(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),kt=(e,t,n)=>(Cb(e,t,"access private method"),n);var Hh=(e,t,n,i)=>({set _(s){qe(e,t,s,n)},get _(){return J(e,t,i)}});function gA(e,t){for(var n=0;n<t.length;n++){const i=t[n];if(typeof i!="string"&&!Array.isArray(i)){for(const s in i)if(s!=="default"&&!(s in e)){const r=Object.getOwnPropertyDescriptor(i,s);r&&Object.defineProperty(e,s,r.get?r:{enumerable:!0,get:()=>i[s]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function n(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerPolicy&&(r.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?r.credentials="include":s.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(s){if(s.ep)return;s.ep=!0;const r=n(s);fetch(s.href,r)}})();function eu(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var jb={exports:{}},nd={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -840,7 +840,7 @@ description: ...
840
840
 
841
841
  # ...`,"aria-label":t("skills.import.body")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:f.isPending||!d||!o.trim(),onClick:()=>f.mutate(),children:[f.isPending?u.jsx(ht,{size:14,className:"animate-spin"}):u.jsx(h1,{size:14,strokeWidth:3}),t("skills.import.submit")]})]})})}function pse({onClose:e,onSubmit:t}){const n=Ye(),[i,s]=_.useState(""),[r,o]=_.useState(""),c=/^[a-z0-9][a-z0-9-]*$/.test(i);return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[u.jsx(ao,{size:16,strokeWidth:2.5}),n("skills.ai.title")]}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:u.jsx(vn,{size:14,strokeWidth:3})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.name")}),u.jsx("input",{type:"text",value:i,onChange:d=>s(d.target.value),placeholder:"rust-error-handling",className:"nb-input w-full font-[family-name:var(--font-mono)]","aria-label":n("skills.ai.name")})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.intent")}),u.jsx("textarea",{value:r,onChange:d=>o(d.target.value),placeholder:n("skills.ai.placeholder"),rows:5,className:"nb-input w-full text-sm","aria-label":n("skills.ai.intent")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!c||!r.trim(),onClick:()=>t(i,r),children:[u.jsx(ao,{size:14,strokeWidth:2.5}),n("skills.ai.submit")]})]})})})}async function mse(e){const{files:t}=await rie(e),n=t["SKILL.md"]??"",i=new Blob([n],{type:"text/markdown"}),s=URL.createObjectURL(i),r=document.createElement("a");r.href=s,r.download=`${e}.SKILL.md`,r.click(),URL.revokeObjectURL(s)}const gse=[{value:"all",labelKey:"skills.category.all"},{value:"language",labelKey:"skills.category.language"},{value:"domain",labelKey:"skills.category.domain"},{value:"persona",labelKey:"skills.category.persona"},{value:"workflow",labelKey:"skills.category.workflow"},{value:"engine",labelKey:"skills.category.engine"},{value:"genre",labelKey:"skills.category.genre"},{value:"platform",labelKey:"skills.category.platform"},{value:"review",labelKey:"skills.category.review"},{value:"meta",labelKey:"skills.category.meta"},{value:"other",labelKey:"skills.category.other"}],yse={language:"var(--color-accent-purple)",domain:"var(--color-secondary)",persona:"var(--color-primary)",workflow:"var(--color-accent-mint)",engine:"var(--color-accent-yellow)",genre:"var(--color-accent-pink)",platform:"var(--color-secondary-dark)",review:"var(--color-primary-dark)",meta:"var(--surface-control)",other:"var(--surface-control)"};function bse(){var F,V;const e=Ye(),[t,n]=_.useState("all"),[i,s]=_.useState([]),[r,o]=_.useState(""),[c,d]=_.useState(null),[f,m]=_.useState(!1),[p,b]=_.useState(!1),y=Xt(),v=(((F=Je({queryKey:["gen-jobs"],queryFn:kI,refetchInterval:3e3}).data)==null?void 0:F.data)??[]).filter(D=>D.kind==="skill"),w=v.filter(D=>D.status!=="done"),k=_.useRef(new Set);_.useEffect(()=>{for(const D of v)(D.status==="done"||D.status==="error")&&!k.current.has(D.id)&&(k.current.add(D.id),y.invalidateQueries({queryKey:["skills"]}),y.invalidateQueries({queryKey:["skill-updates"]}))},[v,y]);const C=(D,I)=>{aie(D,I).then(()=>y.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},j=(((V=Je({queryKey:["skill-updates"],queryFn:iie}).data)==null?void 0:V.data)??[]).filter(D=>D.status!=="same").length,{data:T,isLoading:A}=Je({queryKey:["skills"],queryFn:()=>fg()}),M=Je({queryKey:["projects"],queryFn:fo}),R=_.useMemo(()=>((T==null?void 0:T.data)??[]).filter(I=>!(t!=="all"&&I.category!==t||i.length>0&&!I.tags.some(z=>i.includes(z))||r&&!I.name.toLowerCase().includes(r.toLowerCase()))),[T,t,i,r]),P=_.useMemo(()=>{const D=(T==null?void 0:T.data)??[],I={all:D.length};for(const z of D)I[z.category]=(I[z.category]??0)+1;return I},[T]),O=_.useMemo(()=>{const D=new Map;for(const I of(T==null?void 0:T.data)??[])for(const z of I.tags)D.set(z,(D.get(z)??0)+1);return[...D.entries()].sort((I,z)=>z[1]-I[1]||I[0].localeCompare(z[0]))},[T]),B=D=>s(I=>I.includes(D)?I.filter(z=>z!==D):[...I,D]);return u.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[u.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[u.jsxs("div",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:"Skills"}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:A?e("common.loading"):e("skills.subtitleCount",{count:(T==null?void 0:T.data.length)??0})})]}),u.jsxs("div",{className:"flex gap-3 items-center",children:[j>0&&u.jsx("span",{className:"nb-badge text-[10px]",title:e("skills.updates.badge",{count:String(j)}),children:e("skills.updates.badge",{count:String(j)})}),u.jsxs("button",{className:"nb-btn",onClick:()=>b(!0),type:"button",children:[u.jsx(ao,{size:14,strokeWidth:2.5}),e("skills.ai")]}),u.jsxs("button",{className:"nb-btn",onClick:()=>m(!0),type:"button",children:[u.jsx(h1,{size:14,strokeWidth:2.5}),e("skills.import")]}),u.jsxs("button",{className:"nb-btn nb-btn-mint",onClick:async()=>{await eie(),y.invalidateQueries({queryKey:["skills"]}),y.invalidateQueries({queryKey:["skill-updates"]})},type:"button",children:[u.jsx(ro,{size:14,strokeWidth:2.5}),"Sync bundled"]})]})]}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("div",{className:"relative shrink-0 w-full max-w-xs",children:[u.jsx(gf,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),u.jsx("input",{className:"nb-input pl-9 w-full",placeholder:e("skills.search.placeholder"),value:r,onChange:D=>o(D.target.value),"aria-label":e("skills.search.aria")})]}),u.jsx(uu,{ariaLabel:"skill categories",className:"flex-1 min-w-0",value:t,onChange:n,options:gse.filter(D=>D.value==="all"||(P[D.value]??0)>0).map(D=>({value:D.value,label:u.jsxs(u.Fragment,{children:[e(D.labelKey)," ",P[D.value]??0]})}))})]}),O.length>0&&u.jsxs("div",{className:"flex items-start gap-2 flex-wrap",children:[u.jsx("span",{className:"text-xs font-bold text-[var(--color-text-muted)] pt-1.5 uppercase tracking-wider",children:e("skills.tags.title")}),u.jsxs("div",{className:"flex flex-wrap gap-1.5 flex-1",children:[O.map(([D,I])=>{const z=i.includes(D);return u.jsxs("button",{type:"button",onClick:()=>B(D),className:["px-2.5 py-1 rounded-full text-xs font-[family-name:var(--font-mono)] border-2 border-[var(--color-text)] transition-colors",z?"bg-[var(--color-text)] text-[var(--color-bg)] font-bold":"bg-[var(--surface-control)] text-[var(--color-text-muted)] hover:bg-[var(--surface-control-hover)]"].join(" "),children:[D," ",u.jsx("span",{className:"opacity-60",children:I})]},D)}),i.length>0&&u.jsx("button",{type:"button",onClick:()=>s([]),className:"px-2.5 py-1 rounded-full text-xs font-bold text-[var(--color-crashed)] hover:underline",children:e("skills.tags.clear")})]})]}),u.jsxs("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:[w.map(D=>u.jsxs("div",{className:`nb-card flex items-center gap-2 ${D.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,children:[D.status==="running"?u.jsx(ht,{size:14,className:"animate-spin"}):u.jsx(vn,{size:14,strokeWidth:3}),u.jsx("span",{className:"text-sm text-[var(--color-text-muted)] truncate",children:D.status==="running"?`${D.label} · ${e("skills.ai.wait")}`:`${D.label}: ${D.error??e("skills.ai.error")}`})]},D.id)),R.map(D=>{var I;return u.jsx(xse,{skill:D,projectCount:((I=M.data)==null?void 0:I.data.length)??0,onOpen:()=>d(D.name),onExport:()=>void mse(D.name)},D.name)})]}),c&&u.jsx(iI,{name:c,onClose:()=>d(null)}),f&&u.jsx(hse,{onClose:()=>m(!1)}),p&&u.jsx(pse,{onClose:()=>b(!1),onSubmit:(D,I)=>{C(D,I),b(!1)}})]})}function xse({skill:e,projectCount:t,onOpen:n,onExport:i}){const s=Ye(),r=yse[e.category];return u.jsxs("article",{className:"nb-card nb-card-interactive relative flex flex-col gap-3",children:[u.jsx("button",{type:"button",onClick:n,"aria-label":`Open ${e.name}`,className:"absolute inset-0 cursor-pointer rounded-[inherit] border-0 bg-transparent"}),u.jsxs("div",{className:"flex items-start justify-between gap-3",children:[u.jsx("h3",{className:"min-w-0 flex-1 overflow-hidden break-all font-[family-name:var(--font-heading)] text-lg font-bold leading-6 line-clamp-2",children:e.name}),u.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[u.jsx("button",{type:"button",className:"nb-btn relative z-10 p-1",onClick:i,"aria-label":s("skills.export"),title:s("skills.export"),children:u.jsx(sM,{size:12,strokeWidth:2.5})}),u.jsx("span",{className:"nb-badge text-[10px]",style:{background:r},children:e.category})]})]}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] leading-5 line-clamp-3",children:e.description||"(no description)"}),e.tags.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(o=>u.jsx("span",{className:"text-[10px] font-[family-name:var(--font-mono)] px-1.5 py-0.5 rounded-full bg-[var(--surface-control)] border border-[var(--control-border)]",children:o},o))}),u.jsxs("div",{className:"flex items-center justify-between text-xs font-[family-name:var(--font-mono)] pt-2 border-t-[1.5px] border-dashed border-[var(--color-border-light)] mt-auto",children:[u.jsx("span",{className:"font-bold",children:e.linkedProjects.length>0?`● linked in ${e.linkedProjects.length}`:"○ not linked"}),u.jsxs("span",{className:"text-[var(--color-text-subtle)]",children:[t," projects"]})]})]})}function vse(e){return wt("/api/prompts")}function SI(e){return wt(`/api/prompts/${encodeURIComponent(e)}`)}function wse(e){return jr("/api/prompts",e)}function Ese(e,t){return bf(`/api/prompts/${encodeURIComponent(e)}`,t)}function kse(e){return m1(`/api/prompts/${encodeURIComponent(e)}`)}function Sse(e){return jr("/api/prompts/generate",{intent:e})}function NI(e){const t=new Set,n=[];for(const i of e.matchAll(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}/g)){const s=i[1];s&&!t.has(s)&&(t.add(s),n.push(s))}return n}function Nse(){var M,R;const e=Ye(),[t,n]=oa("prompts.last",""),[i,s]=_.useState(null),[r,o]=_.useState(!1),[c,d]=_.useState(""),[f,m]=_.useState(new Set),p=Xt(),b=Je({queryKey:["prompts"],queryFn:()=>vse()}),y=((M=b.data)==null?void 0:M.data)??[],x=_.useMemo(()=>[...new Set(y.flatMap(P=>P.tags))].sort(),[y]),w=(((R=Je({queryKey:["gen-jobs"],queryFn:kI,refetchInterval:3e3}).data)==null?void 0:R.data)??[]).filter(P=>P.kind==="prompt"),k=w.filter(P=>P.status!=="done"),C=_.useRef(new Set),S=_.useRef(null);_.useEffect(()=>{for(const P of w)(P.status==="done"||P.status==="error")&&!C.current.has(P.id)&&(C.current.add(P.id),p.invalidateQueries({queryKey:["prompts"]}),P.status==="done"&&P.result&&n(P.result))},[w,p,n]);const j=P=>{Sse(P).then(()=>p.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},T=_.useMemo(()=>{const P=c.trim().toLowerCase();return y.filter(O=>!(f.size&&![...f].every(B=>O.tags.includes(B))||P&&!(O.name.toLowerCase().includes(P)||O.description.toLowerCase().includes(P)||O.tags.some(F=>F.toLowerCase().includes(P)))))},[y,f,c]);_.useEffect(()=>{t&&y.length&&!y.some(P=>P.name===t)&&n("")},[t,y,n]);const A=P=>m(O=>{const B=new Set(O);return B.has(P)?B.delete(P):B.add(P),B});return u.jsxs("div",{className:"flex flex-col flex-1 min-h-0 w-full gap-3",children:[u.jsxs("div",{className:"shrink-0 flex items-center justify-between gap-3",children:[u.jsxs("div",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("prompts.title")}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.desc")})]}),u.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[u.jsxs("button",{className:"nb-btn",type:"button",onClick:()=>o(!0),children:[u.jsx(ao,{size:14,strokeWidth:2.5}),e("prompts.ai")]}),u.jsxs("button",{className:"nb-btn nb-btn-mint",type:"button",onClick:()=>s({mode:"new"}),children:[u.jsx(Bn,{size:14,strokeWidth:3}),e("prompts.new")]})]})]}),u.jsxs("div",{className:"shrink-0 flex flex-col gap-2",children:[u.jsxs("label",{className:"nb-input flex items-center gap-2 w-full",children:[u.jsx(gf,{size:14}),u.jsx("input",{type:"text",value:c,onChange:P=>d(P.target.value),placeholder:e("prompts.search"),className:"bg-transparent outline-none flex-1 text-sm","aria-label":e("prompts.search")})]}),x.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:x.map(P=>u.jsx("button",{type:"button",onClick:()=>A(P),className:`nb-btn px-2 py-0.5 text-xs ${f.has(P)?"nb-btn-mint":""}`,children:P},P))})]}),u.jsxs("div",{className:"flex gap-5 flex-1 min-h-0",children:[u.jsx("aside",{className:"w-80 shrink-0 nb-card p-3 overflow-hidden flex h-full min-h-0 flex-col gap-2",children:u.jsxs("div",{ref:S,className:"edge-scroll-list flex-1 min-h-0 overflow-y-auto flex flex-col gap-0.5",children:[k.map(P=>u.jsxs("div",{className:`nb-card flex items-center gap-2 ${P.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,style:{padding:"8px 10px"},children:[P.status==="running"?u.jsx(ht,{size:12,className:"animate-spin"}):u.jsx(vn,{size:12,strokeWidth:3}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)] truncate",children:P.status==="running"?e("prompts.ai.wait"):`${e("prompts.ai.error")}: ${P.error??""}`})]},P.id)),b.isLoading?u.jsx("div",{className:"nb-card",children:u.jsx(ht,{size:14,className:"animate-spin"})}):T.length===0?u.jsx("div",{className:"nb-card",children:u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.empty")})}):T.map((P,O)=>u.jsx(cu,{index:O,root:S,children:u.jsxs("button",{type:"button",onClick:()=>n(P.name),className:["dimension-menu-item w-full min-w-0 flex-col items-stretch gap-1 px-3 py-2 pl-4 text-left",t===P.name?"dimension-menu-item-active":""].join(" "),children:[u.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[P.favorite&&u.jsx(hM,{size:12,fill:"currentColor",className:"shrink-0"}),u.jsx("code",{className:"min-w-0 max-w-full truncate font-[family-name:var(--font-mono)] text-sm font-bold",children:P.name})]}),P.description&&u.jsx("span",{className:"block w-full min-w-0 truncate text-xs text-[var(--color-text-muted)]",children:P.description})]})},P.name))]})}),u.jsx("div",{className:"flex-1 min-w-0 min-h-0",children:t?u.jsx(Cse,{name:t,onEdit:()=>s({mode:"edit",name:t}),onDeleted:()=>n("")},t):u.jsx("div",{className:"nb-card",children:u.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("prompts.selectHint")})})})]}),i&&u.jsx(Tse,{name:i.mode==="edit"?i.name:null,onClose:()=>s(null),onSaved:P=>{s(null),n(P)}}),r&&u.jsx(_se,{onClose:()=>o(!1),onSubmit:P=>{j(P),o(!1)}})]})}function _se({onClose:e,onSubmit:t}){const n=Ye(),[i,s]=_.useState("");return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[u.jsx(ao,{size:16,strokeWidth:2.5}),n("prompts.ai.title")]}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:u.jsx(vn,{size:14,strokeWidth:3})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("prompts.ai.intent")}),u.jsx("textarea",{value:i,onChange:r=>s(r.target.value),placeholder:n("prompts.ai.placeholder"),rows:5,className:"nb-input w-full text-sm","aria-label":n("prompts.ai.intent")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!i.trim(),onClick:()=>t(i),children:[u.jsx(ao,{size:14,strokeWidth:2.5}),n("prompts.ai.submit")]})]})})})}function Cse({name:e,onEdit:t,onDeleted:n}){const i=Ye(),s=Xt(),{confirm:r}=Un(),o=Je({queryKey:["prompt",e],queryFn:()=>SI(e)}),c=At({mutationFn:()=>kse(e),onSuccess:()=>{s.invalidateQueries({queryKey:["prompts"]}),n()}});if(o.isLoading)return u.jsx("div",{className:"nb-card",children:u.jsx(ht,{size:14,className:"animate-spin"})});const d=o.data;if(!d)return null;const f=NI(d.body);return u.jsxs("div",{className:"nb-card flex flex-col gap-3 h-full min-h-0",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3 shrink-0",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold flex items-center gap-2",children:[d.favorite&&u.jsx(hM,{size:16,fill:"currentColor"}),u.jsx("code",{className:"font-[family-name:var(--font-mono)] truncate",children:d.name})]}),d.description&&u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:d.description})]}),u.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:t,children:[u.jsx(u1,{size:14,strokeWidth:3}),i("common.edit")]}),u.jsx("button",{type:"button",className:"nb-btn",disabled:c.isPending,onClick:async()=>{await r({title:i("prompts.delete"),body:i("prompts.deleteConfirm",{name:e})})&&c.mutate()},"aria-label":i("prompts.delete"),children:u.jsx(us,{size:14,strokeWidth:3})})]})]}),d.tags.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 shrink-0",children:d.tags.map(m=>u.jsx("span",{className:"nb-badge px-2 py-0.5 text-xs",children:m},m))}),u.jsx("pre",{className:"flex-1 bg-surface-input min-h-0 overflow-auto text-sm font-[family-name:var(--font-mono)] whitespace-pre-wrap break-words bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded p-3",children:d.body}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)] shrink-0",children:f.length?i("prompts.vars",{names:f.join(", ")}):i("prompts.noVars")})]})}function jse({tags:e,onChange:t}){const n=Ye(),[i,s]=_.useState(""),r=()=>{const o=i.trim();o&&!e.includes(o)&&t([...e,o]),s("")};return u.jsxs("div",{className:"nb-input w-full flex flex-wrap gap-1.5 items-center",children:[e.map(o=>u.jsxs("span",{className:"inline-flex items-center gap-1 text-xs bg-[var(--color-accent-mint)] border-2 border-[var(--color-text)] rounded px-1.5 py-0.5",children:[o,u.jsx("button",{type:"button",onClick:()=>t(e.filter(c=>c!==o)),"aria-label":`remove ${o}`,children:u.jsx(vn,{size:10,strokeWidth:3})})]},o)),u.jsx("input",{className:"flex-1 min-w-[90px] bg-transparent outline-none text-sm",value:i,onChange:o=>s(o.target.value),onKeyDown:o=>{o.key==="Enter"?(o.preventDefault(),r()):o.key==="Backspace"&&!i&&e.length&&t(e.slice(0,-1))},placeholder:e.length?"":n("prompts.tagAdd"),"aria-label":n("prompts.tags")})]})}function Tse({name:e,onClose:t,onSaved:n}){const i=Ye(),s=Xt(),{alert:r}=Un(),o=e===null,c=Je({queryKey:["prompt",e],queryFn:()=>SI(e),enabled:!o}),[d,f]=_.useState(o?{name:"",description:"",tags:[],body:"",favorite:!1}:null);_.useEffect(()=>{if(!o&&c.data&&d===null){const y=c.data;f({name:y.name,description:y.description,tags:y.tags,body:y.body,favorite:y.favorite})}},[o,c.data,d]);const m=At({mutationFn:()=>{if(!d)throw new Error("no form");const y={description:d.description||void 0,tags:d.tags,favorite:d.favorite,body:d.body};return o?wse({name:d.name,...y}):Ese(e,y)},onSuccess:y=>{s.invalidateQueries({queryKey:["prompts"]}),s.invalidateQueries({queryKey:["prompt",y.name]}),n(y.name)},onError:y=>void r({title:i("prompts.saveError"),body:y instanceof Error?y.message:String(y)})}),p=_.useMemo(()=>d?/^[a-z0-9][a-z0-9-]*$/.test(d.name):!1,[d]),b=_.useMemo(()=>d?NI(d.body):[],[d]);return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-2xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold",children:o?i("prompts.new"):e}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:t,"aria-label":"close",children:u.jsx(vn,{size:14,strokeWidth:3})})]}),!o&&c.isLoading?u.jsx(ht,{size:14,className:"animate-spin"}):d?u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:i("prompts.name")}),u.jsx("input",{type:"text",value:d.name,disabled:!o,onChange:y=>f({...d,name:y.target.value}),placeholder:i("prompts.namePlaceholder"),className:"nb-input w-full","aria-label":i("prompts.name")}),o&&d.name&&!p&&u.jsx("span",{className:"text-xs text-[var(--color-crashed)]",children:i("prompts.nameError")})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:i("prompts.description")}),u.jsx("input",{type:"text",value:d.description,onChange:y=>f({...d,description:y.target.value}),className:"nb-input w-full","aria-label":i("prompts.description")})]})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:i("prompts.tags")}),u.jsx(jse,{tags:d.tags,onChange:y=>f({...d,tags:y})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:i("prompts.body")}),u.jsx("textarea",{value:d.body,onChange:y=>f({...d,body:y.target.value}),placeholder:i("prompts.bodyPlaceholder"),rows:12,className:"nb-input w-full font-[family-name:var(--font-mono)] text-sm","aria-label":i("prompts.body")}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:b.length?i("prompts.vars",{names:b.join(", ")}):i("prompts.noVars")})]}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",disabled:m.isPending||o&&!p||!d.body.trim(),onClick:()=>m.mutate(),children:[m.isPending?u.jsx(ht,{size:14,className:"animate-spin"}):u.jsx(cs,{size:14,strokeWidth:3}),i("prompts.save")]}),u.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[u.jsx("input",{type:"checkbox",checked:d.favorite,onChange:y=>f({...d,favorite:y.target.checked})}),i("prompts.favorite")]})]})]}):null]})})})}function Ase(){return wt("/api/processes").then(e=>e.data)}function Mse(e){return jr(`/api/processes/${e}/kill`)}function Rse(){return wt("/api/processes/reclaim")}async function Dse(e){const t=await fetch("/api/processes/reclaim",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({idleMinutes:e})});if(!t.ok)throw new Error(`${t.status}: ${await t.text()}`);return t.json()}const Ose="nb-card";function Lse(e){if(!e)return"—";const t=Date.now()-new Date(e).getTime();if(!Number.isFinite(t)||t<0)return"—";const n=Math.floor(t/6e4);if(n<1)return"<1m";if(n<60)return`${n}m`;const i=Math.floor(n/60);return i<24?`${i}h${n%60?` ${n%60}m`:""}`:`${Math.floor(i/24)}d${i%24?` ${i%24}h`:""}`}function Fx(e){return e.project?e.project:e.cwd?e.cwd.split("/").filter(Boolean).pop()??e.slot:e.slot}function Rj(e){const t=/^session-chat-(.+)$/.exec(e.slot);return(t==null?void 0:t[1])??null}function Ise({p:e}){const t=e.alive?e.sessionState??"alive":"offline",n=e.alive?"bg-[var(--color-accent-mint)]":"bg-[var(--color-bg-cream)] text-[var(--color-text)]/60";return u.jsx("span",{className:`nb-status font-[family-name:var(--font-mono)] ${n}`,children:t})}function Pse({embedded:e}={}){var v;const t=Ye(),n=Xt(),[i,s]=_.useState(null),[r,o]=_.useState("all"),c=Je({queryKey:["processes"],queryFn:Ase,refetchInterval:5e3}),d=At({mutationFn:Mse,onSuccess:w=>{s(w.message),n.invalidateQueries({queryKey:["processes"]})},onError:w=>s(w instanceof Error?w.message:String(w))}),f=Je({queryKey:["reclaim"],queryFn:Rse}),[m,p]=_.useState("");_.useEffect(()=>{f.data&&m===""&&p(String(f.data.idleMinutes))},[f.data,m]);const b=At({mutationFn:w=>Dse(w),onSuccess:w=>{s(`自动回收已设为 ${w.idleMinutes} 分钟空闲`),n.invalidateQueries({queryKey:["reclaim"]})},onError:w=>s(w instanceof Error?w.message:String(w))}),x=(c.data??[]).filter(w=>r==="all"?!0:w.kind===r);return u.jsxs("div",{className:"max-w-full flex-1 min-h-0 flex flex-col",children:[!e&&u.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl mb-2 shrink-0",children:t("processes.title")}),i&&u.jsx("div",{className:"nb-card mb-3 px-3 py-2 text-sm font-mono",children:i}),u.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap",children:[["all","worker","chat"].map(w=>u.jsx("button",{type:"button","aria-pressed":r===w,onClick:()=>o(w),className:`nb-btn px-3 py-1 text-sm ${r===w?"nb-btn-primary":""}`,children:t(`processes.kind.${w}`)},w)),u.jsxs("button",{type:"button","aria-label":t("processes.refresh"),onClick:()=>n.invalidateQueries({queryKey:["processes"]}),className:"nb-btn px-3 py-1 text-sm",children:[c.isFetching?u.jsx(ht,{size:14,className:"animate-spin"}):u.jsx(ro,{size:14}),t("processes.refresh")]}),u.jsxs("div",{className:`${Ose} px-3 py-1 flex items-center gap-2 shrink-0 ml-auto`,title:"自动回收:会话空闲 N 分钟自动停,下次访问 durable resume 续上,不丢上下文",children:[u.jsx(lF,{size:15,strokeWidth:2.5}),u.jsx("input",{type:"number",min:1,max:1440,value:m,onChange:w=>p(w.target.value),className:"nb-input w-14 px-2 py-1 font-[family-name:var(--font-mono)] text-sm","aria-label":"自动回收空闲分钟数"}),u.jsx("button",{type:"button",disabled:b.isPending||m===""||Number(m)===((v=f.data)==null?void 0:v.idleMinutes),onClick:()=>b.mutate(Math.round(Number(m))),className:"nb-btn nb-btn-primary text-sm disabled:opacity-50",style:{padding:"4px 8px"},"aria-label":"保存自动回收设置",title:"保存自动回收设置",children:b.isPending?u.jsx(ht,{size:14,className:"animate-spin"}):u.jsx(cs,{size:14,strokeWidth:3})})]})]}),u.jsxs("div",{className:"rounded-2xl border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] flex-1 min-h-0 overflow-hidden flex flex-col text-sm",children:[u.jsxs("div",{className:"shrink-0 grid grid-cols-[130px_minmax(140px,1.2fr)_minmax(140px,1.5fr)_80px_110px_90px_90px_100px] bg-[var(--surface-table-head)] font-[family-name:var(--font-heading)] border-b-2 border-[var(--color-text)]/15",children:[u.jsx("div",{className:"px-3 py-2",children:t("processes.col.kind")}),u.jsx("div",{className:"px-3 py-2",children:t("processes.col.slot")}),u.jsx("div",{className:"px-3 py-2",children:t("processes.col.project")}),u.jsx("div",{className:"px-3 py-2",children:"PID"}),u.jsx("div",{className:"px-3 py-2",children:t("processes.col.state")}),u.jsx("div",{className:"px-3 py-2",children:t("processes.col.memory")}),u.jsx("div",{className:"px-3 py-2",children:"运行时间"}),u.jsx("div",{className:"px-3 py-2",children:t("processes.col.action")})]}),u.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto font-[family-name:var(--font-mono)]",children:[x.length===0&&u.jsx("div",{className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:t("processes.empty")}),x.map(w=>u.jsxs("div",{className:"grid grid-cols-[130px_minmax(140px,1.2fr)_minmax(140px,1.5fr)_80px_110px_90px_90px_100px] border-t border-[var(--color-text)]/10 items-center",title:w.cwd??"",children:[u.jsxs("div",{className:"px-3 py-2 flex flex-col gap-0.5",children:[u.jsx("span",{className:`nb-badge text-xs whitespace-nowrap ${w.kind==="worker"?"bg-[var(--color-accent-yellow)]":"bg-[var(--color-accent-purple)]"}`,children:t(`processes.kind.${w.kind}`)}),u.jsx("span",{className:"text-[10px] uppercase tracking-wide text-[var(--color-text)]/45",children:w.tool})]}),u.jsx("div",{className:"px-3 py-2 truncate",children:w.slot}),u.jsx("div",{className:"px-3 py-2 truncate",children:w.kind==="chat"&&Rj(w)?u.jsxs(Fc,{to:`/chat/${Rj(w)}`,className:"inline-flex items-center gap-1 font-semibold text-[var(--color-text)] underline decoration-2 underline-offset-2 hover:opacity-70",title:"打开对话窗口",children:[u.jsx(x6,{size:12,strokeWidth:2.5})," ",Fx(w)]}):w.kind==="worker"&&w.project?u.jsxs(Fc,{to:`/board?project=${encodeURIComponent(w.project)}`,className:"inline-flex items-center gap-1 font-semibold text-[var(--color-text)] underline decoration-2 underline-offset-2 hover:opacity-70",title:"打开该项目看板",children:[u.jsx(zU,{size:12,strokeWidth:2.5})," ",Fx(w)]}):u.jsx("span",{children:Fx(w)})}),u.jsx("div",{className:"px-3 py-2",children:w.pid??"—"}),u.jsx("div",{className:"px-3 py-2",children:u.jsx(Ise,{p:w})}),u.jsx("div",{className:"px-3 py-2",children:w.memoryMB!=null?`${w.memoryMB} MB`:"—"}),u.jsx("div",{className:"px-3 py-2",children:Lse(w.startedAt)}),u.jsx("div",{className:"px-3 py-2",children:w.alive&&w.pid!=null?u.jsxs("button",{type:"button","aria-label":`${t("processes.kill")} ${w.slot}`,onClick:()=>{confirm(t("processes.killConfirm").replace("{slot}",w.slot))&&d.mutate(w.pid)},className:"nb-btn nb-btn-danger px-2.5 py-1 text-xs",children:[u.jsx(nM,{size:13})," ",t("processes.kill")]}):u.jsx("span",{className:"text-[var(--color-text)]/40 text-xs",children:"—"})})]},w.slot))]})]})]})}function zse(e={}){const t=new URLSearchParams;e.project&&t.set("project",e.project),e.action&&t.set("action",e.action);const n=t.toString();return wt(`/api/audit${n?`?${n}`:""}`).then(i=>i.data)}const Bse={create:"bg-[var(--color-accent-mint)]",modify:"bg-[var(--color-accent-yellow)]",delete:"bg-[var(--color-accent-pink)]",daemon:"bg-[var(--color-accent-purple)]"};function Use({embedded:e}={}){const t=Ye(),n=Xt(),[i,s]=_.useState(""),r=Je({queryKey:["audit",i],queryFn:()=>zse(i?{action:i}:{}),refetchInterval:8e3}),o=r.data??[],c=d=>t(`audit.action.${d}`);return u.jsxs("div",{className:"max-w-full flex-1 min-h-0 flex flex-col",children:[!e&&u.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl mb-2 shrink-0",children:t("audit.title")}),u.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap shrink-0",children:[["","create","modify","delete","daemon"].map(d=>u.jsx("button",{type:"button","aria-pressed":i===d,onClick:()=>s(d),className:`nb-btn px-3 py-1 text-sm ${i===d?"nb-btn-primary":""}`,children:d?c(d):t("audit.filter.all")},d||"all")),u.jsxs("button",{type:"button","aria-label":t("audit.refresh"),onClick:()=>n.invalidateQueries({queryKey:["audit"]}),className:"nb-btn px-3 py-1 text-sm ml-auto",children:[r.isFetching?u.jsx(ht,{size:14,className:"animate-spin"}):u.jsx(ro,{size:14}),t("audit.refresh")]})]}),u.jsxs("div",{className:"rounded-2xl border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] flex-1 min-h-0 overflow-hidden flex flex-col text-sm",children:[u.jsxs("div",{className:"shrink-0 grid grid-cols-[180px_120px_minmax(100px,1fr)_minmax(160px,2fr)] bg-[var(--surface-table-head)] font-[family-name:var(--font-heading)] border-b-2 border-[var(--color-text)]/15",children:[u.jsx("div",{className:"px-3 py-2",children:t("audit.col.time")}),u.jsx("div",{className:"px-3 py-2",children:t("audit.col.action")}),u.jsx("div",{className:"px-3 py-2",children:t("audit.col.project")}),u.jsx("div",{className:"px-3 py-2",children:t("audit.col.detail")})]}),u.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto font-[family-name:var(--font-mono)]",children:[o.length===0&&u.jsx("div",{className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:t("audit.empty")}),o.map((d,f)=>u.jsxs("div",{className:"grid grid-cols-[180px_120px_minmax(100px,1fr)_minmax(160px,2fr)] border-t border-[var(--color-text)]/10 items-center",children:[u.jsx("div",{className:"px-3 py-2 whitespace-nowrap",children:new Date(d.ts).toLocaleString()}),u.jsx("div",{className:"px-3 py-2",children:u.jsx("span",{className:`nb-badge text-xs whitespace-nowrap ${Bse[d.action]}`,children:c(d.action)})}),u.jsx("div",{className:"px-3 py-2 truncate",title:d.project,children:d.project}),u.jsx("div",{className:"px-3 py-2 text-[var(--color-text)]/70 truncate",title:d.detail??"",children:d.detail??(d.source?`(${d.source})`:"—")})]},`${d.ts}-${f}`))]})]})]})}const _I=[{id:"git",fields:[{key:"GITLAB_URL",type:"text",placeholder:"https://gitlab.com"},{key:"GITLAB_TOKEN",type:"text"}]},{id:"matrix",fields:[{key:"MATRIX_HOMESERVER",type:"text",placeholder:"https://matrix.example.com"},{key:"MATRIX_ACCESS_TOKEN",type:"text"},{key:"MATRIX_ROOM_ID",type:"text",placeholder:"!room:example.com"}]},{id:"memory",fields:[{key:"SPS_MEMORY_MODE",type:"select",defaultValue:"local",options:["local","local+external","external","none"]},{key:"SPS_MEMORY_EXTERNAL_URL",type:"text",placeholder:"http://127.0.0.1:3111"},{key:"SPS_MEMORY_DISTILL",type:"select",options:["","on","off"]},{key:"SPS_MEMORY_IMPORT",type:"select",options:["","on","off"]},{key:"SPS_MEMORY_REDACT",type:"select",options:["","on","off"]}]},{id:"daemon",fields:[{key:"SPS_OPENAI_SANDBOX_PROVIDER",type:"select",options:["","unix_local","docker"]},{key:"SPS_DAEMON_MAX_CONCURRENT_RUNS",type:"number",placeholder:"按内存自动推导"},{key:"SPS_DAEMON_ORIGIN_QUOTAS",type:"text",placeholder:"coral-platform=30,gameforge=20"},{key:"SPS_DAEMON_QUEUE_WAIT_S",type:"number",defaultValue:"20"},{key:"SPS_DAEMON_MAX_QUEUE",type:"number",defaultValue:"200"},{key:"SPS_RUN_IDLE_MINUTES",type:"number",defaultValue:"5"},{key:"SPS_RUN_TOOL_IDLE_MINUTES",type:"number",defaultValue:"12"},{key:"SPS_STUCK_RUN_MINUTES",type:"number",defaultValue:"20"}]},{id:"console",fields:[{key:"SPS_CONSOLE_TOKEN",type:"text"},{key:"SPS_CONSOLE_MEMORY_VIEWER_URL",type:"text",placeholder:"https://memory.example.com"}]}],Fse=_I.flatMap(e=>e.fields),Dj=new Set(Fse.map(e=>e.key)),$se=[{value:"config",labelKey:"system.tab.config"},{value:"processes",labelKey:"system.tab.processes"},{value:"doctor",labelKey:"system.tab.doctor"},{value:"audit",labelKey:"system.tab.audit"}];function qse(){var s,r;const e=Ye(),t=Je({queryKey:["system-info"],queryFn:kM}),[n,i]=oa("system.tab","config");return u.jsxs("div",{className:"system-page-shell flex flex-col flex-1 min-h-0 w-full",children:[u.jsxs("header",{className:"system-page-header shrink-0 flex items-center justify-between gap-3 flex-wrap",children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("system.h1")}),u.jsx(Hse,{platform:(s=t.data)==null?void 0:s.platform,current:(r=t.data)==null?void 0:r.version})]}),u.jsx(uu,{ariaLabel:e("system.h1"),className:"max-w-full",value:n,onChange:i,options:$se.map(o=>({value:o.value,label:e(o.labelKey)}))}),u.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[n==="config"&&u.jsx(Vse,{}),n==="processes"&&u.jsx(Pse,{embedded:!0}),n==="doctor"&&u.jsx(Gse,{}),n==="audit"&&u.jsx(Use,{embedded:!0})]})]})}function Hse({platform:e,current:t}){const n=Ye(),{confirm:i,alert:s}=Un(),[r,o]=_.useState(!1),c=Je({queryKey:["latest-version"],queryFn:HF,enabled:!1}),d=async()=>{const m=(await c.refetch()).data;if(!m)return;if(m.upToDate){s({title:n("system.upgrade.checkUpdate"),body:n("system.upgrade.upToDate",{version:t??"?"})});return}if(await i({title:n("system.upgrade.confirm.title"),body:n("system.upgrade.confirm.body",{current:t??"?",latest:m.latest}),confirm:n("system.upgrade.confirm.button")})){o(!0);try{const b=await VF();s({title:b.ok?n("system.upgrade.success.title"):n("system.upgrade.notEffective.title"),body:b.ok?n("system.upgrade.success.body",{version:b.installedVersion??"?"}):b.output||""})}catch(b){s({title:n("system.upgrade.error.title"),body:b.message})}finally{o(!1)}}};return u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"text-xs font-[family-name:var(--font-mono)] text-[var(--color-text-muted)] whitespace-nowrap",children:[e??"—",t?` · v${t}`:""]}),u.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:d,disabled:r||c.isFetching||!t,type:"button","aria-label":n("system.upgrade.checkUpdate"),children:[r||c.isFetching?u.jsx(ht,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(ro,{size:12,strokeWidth:2.5}),n("system.upgrade.checkUpdate")]})]})}function Vse(){const e=Ye(),t=Xt(),{alert:n}=Un(),{data:i,isLoading:s,isError:r,error:o,dataUpdatedAt:c}=Je({queryKey:["system-env-raw"],queryFn:BF}),[d,f]=_.useState(null),[m,p]=_.useState(""),[b,y]=_.useState(""),x=i?`${i.etag}:${c}`:null;_.useEffect(()=>{if(!i||x===null)return;const P=d!==null&&d.content!==d.baseContent;(d===null||!P&&d.sourceKey!==x)&&(f({content:i.content,baseContent:i.content,etag:i.etag,sourceKey:x}),p(""),y(""))},[i,d,x]);const v=d,w=v!==null&&v.content!==v.baseContent,k=(v==null?void 0:v.content)??(i==null?void 0:i.content)??"",C=(v==null?void 0:v.etag)??(i==null?void 0:i.etag)??null,S=uI(k,Dj),j=m.trim().toUpperCase(),T=fI(j)&&!Dj.has(j)&&!S.some(P=>P.key===j),A=(P,O)=>{f(B=>{const F=B??$x(i,x);return{...F,content:Sm(F.content,P.key,O,P)}})},M=(P,O)=>{f(B=>{const F=B??$x(i,x);return{...F,content:Sm(F.content,P,O)}})},R=At({mutationFn:()=>{if(v===null)throw new Error("no draft");return UF(v.content,v.etag)},onSuccess:P=>{f(O=>O===null?O:{...O,baseContent:O.content,etag:P.etag,sourceKey:`${P.etag}:saved`}),t.invalidateQueries({queryKey:["system-env"]}),t.invalidateQueries({queryKey:["system-env-raw"]})},onError:P=>{const O=P.status;n({title:e(O===409?"system.env.error.conflict.title":"system.env.error.save.title"),body:O===409?e("system.env.error.conflict.body"):P instanceof Error?P.message:String(P)})}});return s?u.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("common.loading")}):r?u.jsx("div",{className:"bg-[var(--color-crashed-bg)] border-2 border-[var(--color-crashed)] rounded-lg p-3",children:u.jsx("p",{className:"text-sm",children:o instanceof Error?o.message:String(o)})}):u.jsxs("div",{className:"system-env-settings-editor",children:[u.jsxs("div",{className:"project-config-toolbar",children:[u.jsxs("div",{children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-base font-bold mb-1",children:e("system.tab.config")}),u.jsx("p",{className:"text-xs text-[var(--color-stuck)] font-bold",children:e("system.env.warning")}),C&&u.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] mt-1",children:["etag: ",C,w?e("system.env.dirtyMark"):""]})]}),u.jsx("div",{className:"flex gap-2",children:u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px"},onClick:()=>R.mutate(),disabled:!w||R.isPending,type:"button","aria-label":e("system.env.save.aria"),children:[R.isPending?u.jsx(ht,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(cs,{size:12,strokeWidth:3}),e("system.env.save")]})})]}),u.jsxs("div",{className:"project-config-settings","aria-label":e("system.env.settingsAria"),children:[_I.map(P=>u.jsxs("section",{className:"project-config-section",children:[u.jsxs("div",{className:"project-config-section-head",children:[u.jsx("h3",{children:e(`system.env.section.${P.id}`)}),u.jsx("p",{children:e(`system.env.section.${P.id}.hint`)})]}),u.jsx("div",{className:"project-config-grid",children:P.fields.map(O=>u.jsx(Kse,{field:O,value:cI(k,O),rawValue:Wd(k,O.key),onChange:B=>A(O,B)},O.key))})]},P.id)),u.jsxs("section",{className:"project-config-section",children:[u.jsxs("div",{className:"project-config-section-head",children:[u.jsx("h3",{children:e("system.env.section.custom")}),u.jsx("p",{children:e("system.env.section.custom.hint")})]}),u.jsxs("div",{className:"project-config-custom-list",children:[S.length===0?u.jsx("p",{className:"project-config-empty",children:e("system.env.custom.empty")}):S.map(P=>u.jsxs("div",{className:"project-config-custom-row",children:[u.jsx("code",{children:P.key}),u.jsx("input",{className:"nb-input",value:P.value,onChange:O=>M(P.key,O.target.value),"aria-label":e("system.env.custom.valueAria",{key:P.key})}),u.jsx("button",{type:"button",className:"nb-btn",onClick:()=>f(O=>{const B=O??$x(i,x);return{...B,content:dI(B.content,P.key)}}),"aria-label":e("system.env.custom.removeAria",{key:P.key}),children:u.jsx(vn,{size:12,strokeWidth:3})})]},P.key)),u.jsxs("div",{className:"project-config-custom-row project-config-custom-add",children:[u.jsx("input",{className:"nb-input",value:m,onChange:P=>p(P.target.value),placeholder:e("system.env.custom.keyPlaceholder"),"aria-label":e("system.env.custom.keyAria")}),u.jsx("input",{className:"nb-input",value:b,onChange:P=>y(P.target.value),placeholder:e("system.env.custom.valuePlaceholder"),"aria-label":e("system.env.custom.newValueAria")}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",disabled:!T||!b,onClick:()=>{M(j,b),p(""),y("")},children:[u.jsx(Bn,{size:12,strokeWidth:3}),e("system.env.custom.add")]})]})]})]})]})]})}function $x(e,t){const n=(e==null?void 0:e.content)??"",i=(e==null?void 0:e.etag)??"";return{content:n,baseContent:n,etag:i,sourceKey:t??`${i}:empty`}}function Kse({field:e,value:t,rawValue:n,onChange:i}){const s=Ye(),r=s(`system.env.field.${e.key}`),o=s(`system.env.field.${e.key}.help`),c=e.type==="boolean",d=(n||e.defaultValue||"").toLowerCase()==="true";return u.jsxs("div",{className:["project-config-field",c?"project-config-field-toggle":""].join(" "),children:[u.jsxs("span",{className:"project-config-label",children:[u.jsx("span",{children:r}),u.jsx("code",{children:e.key})]}),c?u.jsxs("span",{className:"project-config-toggle-row",children:[u.jsx("input",{type:"checkbox",checked:d,onChange:f=>i(String(f.target.checked))}),u.jsx("span",{children:s(d?"common.yes":"common.no")})]}):e.type==="select"?u.jsx("select",{className:"nb-input",value:t,onChange:f=>i(f.target.value),"aria-label":r,children:(e.options??[]).map(f=>u.jsx("option",{value:f,children:f||s("projectDetail.config.option.empty")},f||"__empty"))}):u.jsx("input",{className:"nb-input",type:e.type==="number"?"number":"text",min:e.type==="number"?0:void 0,value:t,onChange:f=>i(f.target.value),placeholder:e.placeholder,"aria-label":r}),u.jsx("span",{className:"project-config-help",children:o})]})}function Gse(){var b;const e=Ye(),{alert:t}=Un(),n=Je({queryKey:["projects"],queryFn:fo}),[i,s]=_.useState({}),[r,o]=_.useState({}),[c,d]=_.useState(null),f=(((b=n.data)==null?void 0:b.data)??[]).map(y=>({project:y.name})),m=async(y,x)=>{o(v=>({...v,[y]:x?"fix":"check"}));try{const v=await KF(y,x);s(w=>({...w,[y]:v})),d(y)}catch(v){t({title:e(x?"system.diagnostics.error.fix":"system.diagnostics.error.check"),body:v instanceof Error?v.message:String(v)})}finally{o(v=>({...v,[y]:null}))}},p=async()=>{for(const y of f)await m(y.project,!1)};return u.jsxs("section",{className:"nb-card system-panel system-panel-doctor flex-1 min-h-0",children:[u.jsxs("div",{className:"system-panel-titlebar",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:e("system.diagnostics.title")}),u.jsxs("button",{className:"nb-btn nb-btn-mint",style:{padding:"6px 12px",fontSize:12},onClick:()=>{p()},disabled:f.length===0||Object.values(r).some(Boolean),type:"button",children:[u.jsx(ro,{size:12,strokeWidth:2.5}),e("system.diagnostics.checkAll")]})]}),u.jsx("div",{className:"system-panel-body",children:f.length===0?u.jsx("p",{className:"text-[var(--color-text-muted)] text-sm",children:e("system.diagnostics.empty")}):u.jsx("ul",{className:"system-diagnostics-list",children:f.map(y=>{const x=i[y.project],v=r[y.project],w=x?x.checks.filter(j=>j.status==="fail").length:0,k=x?x.checks.filter(j=>j.status==="warn").length:0,C=c===y.project,S=x!=null;return u.jsxs("li",{className:["system-diagnostics-item",C?"system-diagnostics-item-expanded":""].join(" "),children:[u.jsxs("div",{className:"system-diagnostics-row",children:[u.jsxs("button",{type:"button",onClick:()=>d(C?null:y.project),disabled:!S,className:"system-diagnostics-summary","aria-label":e(C?"system.diagnostics.collapseAria":"system.diagnostics.expandAria"),"aria-expanded":S?C:void 0,children:[u.jsxs("span",{className:"system-diagnostics-project-main",children:[S&&x.ok?u.jsx(wv,{size:16,className:"text-[var(--color-running)] shrink-0",strokeWidth:2.5}):S?u.jsx(zd,{size:16,className:"text-[var(--color-stuck)] shrink-0",strokeWidth:2.5}):u.jsx(wv,{size:16,className:"text-[var(--color-text-subtle)] shrink-0",strokeWidth:2.5}),S&&(C?u.jsx(uo,{size:12}):u.jsx(mf,{size:12})),u.jsx("span",{className:"system-diagnostics-project-name",children:y.project})]}),S?x.ok?u.jsx("span",{className:"system-diagnostics-status system-diagnostics-status-ok",children:"OK"}):u.jsxs("span",{className:"system-diagnostics-status system-diagnostics-status-warn",children:[w," fail · ",k," warn"]}):u.jsx("span",{className:"system-diagnostics-never",children:e("system.diagnostics.never")})]}),u.jsxs("div",{className:"system-diagnostics-actions",children:[u.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:11},onClick:()=>{m(y.project,!1)},disabled:!!v,type:"button","aria-label":e("system.diagnostics.checkAria"),children:[v==="check"?u.jsx(ht,{size:11,strokeWidth:3,className:"animate-spin"}):u.jsx(ro,{size:11,strokeWidth:2.5}),e("system.diagnostics.check")]}),u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 10px",fontSize:11},onClick:()=>{m(y.project,!0)},disabled:!!v||S&&x.ok,type:"button","aria-label":e("system.diagnostics.fixAria"),title:S&&x.ok?e("system.diagnostics.noFixesNeeded"):e("system.diagnostics.fix.tip"),children:[v==="fix"?u.jsx(ht,{size:11,strokeWidth:3,className:"animate-spin"}):u.jsx(mM,{size:11,strokeWidth:2.5}),e("system.diagnostics.fix")]})]})]}),C&&S&&u.jsxs("div",{className:"system-diagnostics-detail",children:[u.jsx("ul",{className:"system-diagnostics-checks",children:x.checks.map((j,T)=>u.jsx(Wse,{check:j},`${j.name}-${T}`))}),x.fixes.length>0&&u.jsxs("div",{className:"mt-3 bg-[var(--color-running-bg)] border-2 border-[var(--color-running)] rounded p-2",children:[u.jsx("div",{className:"text-xs font-bold text-[var(--color-running)] mb-1",children:e("system.diagnostics.fixed")}),u.jsx("ul",{className:"text-xs list-disc pl-4",children:x.fixes.map((j,T)=>u.jsx("li",{children:j},T))})]})]})]},y.project)})})})]})}function Wse({check:e}){const t=e.status==="pass"?u.jsx(wv,{size:12,className:"text-[var(--color-running)]",strokeWidth:2.5}):e.status==="fail"?u.jsx(zd,{size:12,className:"text-[var(--color-crashed)]",strokeWidth:2.5}):e.status==="warn"?u.jsx(zd,{size:12,className:"text-[var(--color-stuck)]",strokeWidth:2.5}):u.jsx("span",{className:"system-diagnostics-info-dot"});return u.jsxs("li",{className:"system-diagnostics-check-row",children:[u.jsx("span",{className:"system-diagnostics-check-icon",children:t}),u.jsx("span",{className:"system-diagnostics-check-name",children:e.name}),u.jsx("span",{className:"system-diagnostics-check-message",children:e.message})]})}function Nc({value:e,onChange:t,options:n,ariaLabel:i,disabled:s,className:r="",placeholder:o="选择…",align:c="left"}){var k;const[d,f]=_.useState(!1),m=_.useRef(null),p=_.useRef(null),b=_.useRef(null),[y,x]=_.useState(null),v=()=>{var S;const C=(S=m.current)==null?void 0:S.getBoundingClientRect();C&&x({top:C.bottom+6,left:C.left,right:window.innerWidth-C.right,width:C.width})};_.useLayoutEffect(()=>{d&&v()},[d]),_.useEffect(()=>{if(!d)return;const C=()=>v(),S=j=>{var T,A;(T=m.current)!=null&&T.contains(j.target)||(A=p.current)!=null&&A.contains(j.target)||f(!1)};return window.addEventListener("scroll",C,!0),window.addEventListener("resize",C),document.addEventListener("mousedown",S),()=>{window.removeEventListener("scroll",C,!0),window.removeEventListener("resize",C),document.removeEventListener("mousedown",S)}},[d]);const w=((k=n.find(C=>C.value===e))==null?void 0:k.label)??o;return u.jsxs("div",{className:`relative ${r}`,children:[u.jsxs("button",{ref:m,type:"button",disabled:s,"aria-label":i,"aria-expanded":d,className:"nb-btn w-full justify-between text-sm disabled:opacity-50",onClick:()=>f(C=>!C),children:[u.jsx("span",{className:"truncate",children:w}),u.jsx(uo,{size:14,strokeWidth:2.5,className:["shrink-0 transition-transform",d?"rotate-180":""].join(" ")})]}),d&&y&&ZA.createPortal(u.jsx("div",{ref:p,style:{position:"fixed",top:y.top,left:c==="right"?void 0:y.left,right:c==="right"?y.right:void 0,minWidth:y.width},className:"z-[100] nb-card p-1 overflow-hidden bg-[var(--surface-menu)]",children:u.jsx("div",{ref:b,className:"max-h-[60vh] overflow-y-auto",children:n.map((C,S)=>u.jsx(cu,{index:S,root:b,delay:.02,children:u.jsx("button",{type:"button",onClick:()=>{t(C.value),f(!1)},className:["dimension-menu-item w-full text-left px-4 py-2 text-sm font-semibold flex items-center gap-2 whitespace-nowrap",C.value===e?"dimension-menu-item-active":""].join(" "),children:C.label})},C.value))})}),document.body)]})}const Yse=["convention","decision","gotcha","pattern","reference","note"],Xse=["local","local+external","external","none"];function Dw(e){return e!=null&&typeof e=="object"?e:{}}function _c(e){return Array.isArray(e)?e:[]}function Qse(e){switch(e){case"none":return"none";case"agentmemory":case"custom":return"external";case"builtin":default:return"local"}}function Oj(e){const t=Dw(e);return{mode:typeof t.mode=="string"&&t.mode?t.mode:Qse(t.provider),externalUrl:typeof t.externalUrl=="string"?t.externalUrl:typeof t.url=="string"?t.url:"",modeOptions:_c(t.modeOptions).length>0?_c(t.modeOptions):Xse}}function Zse(e){const t=Dw(e),n=t.scope==="global"||t.scope==="project"||t.scope==="agent"?t.scope:null;return n?{scope:n,project:typeof t.project=="string"?t.project:void 0,agentId:typeof t.agentId=="string"?t.agentId:void 0,count:typeof t.count=="number"?t.count:0,updated:typeof t.updated=="string"?t.updated:""}:null}function Jse(e){const t=Dw(e);if(typeof t.id!="string")return null;const n=t.scope==="global"||t.scope==="project"||t.scope==="agent"?t.scope:"global";return{id:t.id,title:typeof t.title=="string"?t.title:t.id,scope:n,category:typeof t.category=="string"?t.category:"note",tags:_c(t.tags),salience:typeof t.salience=="number"?t.salience:3,source:typeof t.source=="string"?t.source:"human",project:typeof t.project=="string"?t.project:void 0,agentId:typeof t.agentId=="string"?t.agentId:void 0,created:typeof t.created=="string"?t.created:"",updated:typeof t.updated=="string"?t.updated:"",body:typeof t.body=="string"?t.body:""}}function Po(e){return`${e.scope}:${e.project??e.agentId??""}`}function gp(e){return e.scope==="global"?`全局 (${e.count})`:e.scope==="project"?`项目:${e.project} (${e.count})`:`会话:${e.agentId} (${e.count})`}function zo(e){const t={scope:e.scope};return e.project&&(t.project=e.project),e.agentId&&(t.agentId=e.agentId),t}async function hr(e,t){const n=await fetch(e,t);if(!n.ok){const i=await n.json().catch(()=>null);throw new Error((i==null?void 0:i.detail)||(i==null?void 0:i.title)||`HTTP ${n.status}`)}return await n.json()}const ere=()=>({title:"",body:"",category:"note",tags:"",salience:3});function tre(){var le,pe,Te;const e=Ye(),[t,n]=_.useState([]),[i,s]=_.useState(null),[r,o]=_.useState(!1),[c,d]=_.useState([]),[f,m]=_.useState(null),[p,b]=_.useState(!1),[y,x]=_.useState(""),[v,w]=_.useState(!0),[k,C]=_.useState([]),[S,j]=_.useState(null),[T,A]=_.useState(null),[M,R]=_.useState(null),[P,O]=_.useState(null),[B,F]=_.useState(""),[V,D]=_.useState(""),I=_.useCallback(async()=>{try{const{scopes:ne}=await hr("/api/memory/scopes"),oe=_c(ne).map(Zse).filter(xe=>xe!=null);n(oe),s(xe=>xe??oe[0]??null)}catch(ne){m(ne instanceof Error?ne.message:String(ne))}},[]),z=_.useCallback(async ne=>{try{const oe=new URLSearchParams(zo(ne)).toString(),{data:xe}=await hr(`/api/memory/entries?${oe}`);d(_c(xe).map(Jse).filter(fe=>fe!=null))}catch(oe){m(oe instanceof Error?oe.message:String(oe))}},[]);_.useEffect(()=>{I(),hr("/api/system/memory").then(ne=>{const oe=Oj(ne);O(oe),F(oe.mode),D(oe.externalUrl)}).catch(()=>{})},[I]),_.useEffect(()=>{i&&z(i),(i==null?void 0:i.scope)==="project"&&i.project?hr(`/api/memory/external?project=${encodeURIComponent(i.project)}`).then(ne=>R(ne)).catch(()=>R(null)):R(null)},[i,z]);const W=_.useCallback(async()=>{if(!y.trim()){C([]);return}b(!0),m(null);try{const ne=new URLSearchParams({q:y,limit:"20"});if(v)ne.set("all","1");else if(i)for(const[xe,fe]of Object.entries(zo(i)))ne.set(xe,fe);const{results:oe}=await hr(`/api/memory/recall?${ne.toString()}`);C(_c(oe))}catch(ne){m(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}},[y,v,i]),X=_.useCallback(async()=>{if(!(!i||!S)){b(!0),m(null);try{await hr("/api/memory/entries",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...zo(i),id:S.id,title:S.title,body:S.body,category:S.category,tags:S.tags.split(",").map(ne=>ne.trim()).filter(Boolean),salience:S.salience})}),j(null),await Promise.all([z(i),I()])}catch(ne){m(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}}},[i,S,z,I]),G=_.useCallback(async ne=>{if(i){b(!0),m(null);try{const oe=new URLSearchParams(zo(i)).toString();await hr(`/api/memory/entries/${encodeURIComponent(ne)}?${oe}`,{method:"DELETE"}),await Promise.all([z(i),I()])}catch(oe){m(oe instanceof Error?oe.message:String(oe))}finally{b(!1)}}},[i,z,I]),U=_.useCallback(async(ne,oe,xe)=>{if(i){b(!0),m(null);try{await hr("/api/memory/promote",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({from:zo(i),id:ne.id,to:zo(oe),move:xe})}),A(null),await Promise.all([z(i),I()])}catch(fe){m(fe instanceof Error?fe.message:String(fe))}finally{b(!1)}}},[i,z,I]),q=_.useCallback(async()=>{if(i){b(!0),m(null);try{const oe=(await hr("/api/memory/gc",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(zo(i))})).results[0];oe&&m(`收敛完成:清 tombstone ${oe.purged}、去重 ${oe.deduped}、剩余 ${oe.kept}`),await Promise.all([z(i),I()])}catch(ne){m(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}}},[i,z,I]),Y=_.useCallback(async()=>{b(!0),m(null);try{const ne=Oj(await hr("/api/system/memory",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({mode:B,externalUrl:V})}));O(ne),F(ne.mode),D(ne.externalUrl),m("模式已保存(重启 worker 生效)")}catch(ne){m(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}},[B,V]),$=P!=null&&(B!==P.mode||V!==P.externalUrl),ie=B==="external"||B==="local+external",be=_.useMemo(()=>T?t.filter(ne=>Po(ne)!==Po(i??{scope:""})):[],[T,t,i]),ce=Array.isArray((le=M==null?void 0:M.profile)==null?void 0:le.topConcepts)?M.profile.topConcepts:[],_e=Array.isArray((pe=M==null?void 0:M.graph)==null?void 0:pe.edges)?M.graph.edges.length:0;return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl text-[var(--color-text)]",children:e("nav.memory")}),u.jsx("span",{className:"text-xs text-[var(--color-text)] opacity-60",children:"本地记忆 v2 · markdown 真源"})]}),P&&u.jsxs("section",{className:"nb-card flex flex-wrap items-end gap-3",children:[u.jsxs("div",{className:"flex flex-col gap-1 text-sm",children:[u.jsx("span",{className:"font-bold",children:"记忆模式"}),u.jsx(Nc,{value:B,onChange:F,ariaLabel:"记忆模式",options:P.modeOptions.map(ne=>({value:ne,label:ne}))})]}),ie&&u.jsxs("label",{className:"flex flex-col gap-1 text-sm flex-1 min-w-[220px]",children:[u.jsx("span",{className:"font-bold",children:"外部后端地址"}),u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",value:V,onChange:ne=>D(ne.target.value),placeholder:"http://127.0.0.1:3113",spellCheck:!1,"aria-label":"外部后端地址"})]}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:Y,disabled:p||!$,"aria-label":"保存模式",children:"保存模式"})]}),(()=>{const ne=new Date(Date.now()-6048e5).toISOString(),oe=i?Po(i):"",xe=r?t:t.filter(te=>te.scope!=="project"||te.updated>=ne||Po(te)===oe),fe=t.length-xe.length;return u.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[u.jsx("input",{value:y,onChange:te=>x(te.target.value),onKeyDown:te=>te.key==="Enter"&&W(),placeholder:"检索记忆…","aria-label":"检索记忆",className:"nb-input flex-1 min-w-[200px] font-[family-name:var(--font-mono)] text-sm"}),u.jsxs("label",{className:"flex items-center gap-1 text-sm font-semibold",children:[u.jsx("input",{type:"checkbox",checked:v,onChange:te=>w(te.target.checked),"aria-label":"全局检索"}),"全局"]}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:W,disabled:p,"aria-label":"检索",children:p?"…":"检索"}),u.jsx(Nc,{className:"min-w-[180px]",value:oe,onChange:te=>s(t.find(we=>Po(we)===te)??null),ariaLabel:"选择作用域",placeholder:"选择作用域",options:xe.map(te=>({value:Po(te),label:gp(te)}))}),(fe>0||r)&&u.jsx("button",{type:"button",className:"nb-btn text-xs",onClick:()=>o(te=>!te),"aria-label":r?"收起更早项目":"显示更早项目",children:r?"收起更早":`含更早 (${fe})`}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>j(ere()),disabled:!i,"aria-label":"新建记忆",children:"+ 新建"}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-yellow",onClick:q,disabled:p||!i,"aria-label":"收敛去重",children:"收敛"})]})})(),f&&u.jsxs("div",{className:"text-sm text-[var(--color-text)] font-semibold nb-card py-2",children:["ℹ ",f]}),k.length>0&&u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:["检索结果(",k.length,")"]}),k.map(ne=>u.jsxs("div",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)]",children:[u.jsx("span",{className:"nb-badge",children:ne.source==="external"?"🌐 外部":"📁 本地"}),u.jsx("span",{children:ne.source==="external"?ne.type??"":ne.scope==="project"?`项目:${ne.project}`:ne.scope}),ne.category&&u.jsxs(u.Fragment,{children:[u.jsx("span",{children:"·"}),u.jsx("span",{children:ne.category})]})]}),u.jsx("div",{className:"font-bold text-sm mt-1",children:ne.title}),u.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:ne.snippet.slice(0,300)})]},ne.id))]}),M&&(ce.length||_e)?u.jsxs("section",{className:"nb-card flex flex-col gap-1",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:"🌐 外部智能(agentmemory)"}),ce.length?u.jsxs("div",{className:"text-xs",children:[u.jsx("span",{className:"font-bold",children:"概念:"}),ce.slice(0,8).map(ne=>u.jsx("span",{className:"nb-badge ml-1",children:ne.concept},ne.concept))]}):null,u.jsxs("div",{className:"text-xs opacity-70 font-[family-name:var(--font-mono)]",children:["知识图谱 ",_e," 条边 · 观测 ",((Te=M.profile)==null?void 0:Te.totalObservations)??0]})]}):null,S&&u.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-40 flex items-center justify-center p-6 bg-black/30 overflow-hidden",onMouseDown:ne=>{ne.target===ne.currentTarget&&j(null)},children:u.jsxs("div",{className:"nb-card w-full max-w-2xl flex flex-col gap-2",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:S.id?"编辑记忆":"新建记忆"}),u.jsx("input",{className:"nb-input text-sm",value:S.title,onChange:ne=>j({...S,title:ne.target.value}),placeholder:"标题","aria-label":"标题"}),u.jsxs("div",{className:"flex gap-2 flex-wrap items-end",children:[u.jsx(Nc,{className:"min-w-[140px]",value:S.category,onChange:ne=>j({...S,category:ne}),ariaLabel:"类别",options:Yse.map(ne=>({value:ne,label:ne}))}),u.jsx("input",{className:"nb-input flex-1 min-w-[160px] text-sm",value:S.tags,onChange:ne=>j({...S,tags:ne.target.value}),placeholder:"标签(逗号分隔)","aria-label":"标签"}),u.jsxs("label",{className:"flex items-center gap-1 text-sm",children:["显著度",u.jsx("input",{className:"nb-input w-16",type:"number",min:1,max:5,value:S.salience,onChange:ne=>j({...S,salience:Number(ne.target.value)}),"aria-label":"显著度"})]})]}),u.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm min-h-[120px]",value:S.body,onChange:ne=>j({...S,body:ne.target.value}),placeholder:"正文","aria-label":"正文"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:X,disabled:p||!S.title.trim()||!S.body.trim(),"aria-label":"保存",children:"保存"}),u.jsx("button",{type:"button",className:"nb-btn",onClick:()=>j(null),"aria-label":"取消",children:"取消"})]})]})}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:i?gp(i):"条目"}),c.length===0&&u.jsx("div",{className:"nb-card text-sm opacity-60",children:"(无记忆)"}),c.map(ne=>u.jsxs("div",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)] flex-wrap",children:[u.jsx("span",{className:"nb-badge",children:ne.category}),u.jsxs("span",{children:["s",ne.salience]}),u.jsx("span",{children:"·"}),u.jsx("span",{children:ne.source}),ne.tags.map(oe=>u.jsxs("span",{children:["#",oe]},oe))]}),u.jsx("div",{className:"font-bold text-sm mt-1",children:ne.title}),u.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:ne.body.slice(0,400)}),u.jsxs("div",{className:"flex gap-2 mt-2",children:[u.jsx("button",{type:"button",className:"nb-btn nb-btn-blue text-xs",onClick:()=>j({id:ne.id,title:ne.title,body:ne.body,category:ne.category,tags:ne.tags.join(", "),salience:ne.salience}),"aria-label":"编辑",children:"编辑"}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-purple text-xs",onClick:()=>A(ne),"aria-label":"提升",children:"提升"}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-danger text-xs",onClick:()=>G(ne.id),"aria-label":"删除",children:"删除"})]}),(T==null?void 0:T.id)===ne.id&&u.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 border-t-[3px] border-[var(--color-text)] pt-2",children:[u.jsx("span",{className:"text-xs font-bold",children:"提升到:"}),be.map(oe=>u.jsx("button",{type:"button",className:"nb-btn nb-btn-mint text-xs",onClick:()=>U(ne,oe,!1),"aria-label":`复制到${gp(oe)}`,children:gp(oe)},Po(oe))),be.length===0&&u.jsx("span",{className:"text-xs opacity-60",children:"(无其它作用域)"}),u.jsx("button",{type:"button",className:"nb-btn text-xs",onClick:()=>A(null),"aria-label":"取消提升",children:"取消"})]})]},ne.id))]})]})}async function CI(){return(await wt("/api/plugins")).data??[]}async function nre(e,t){return jr("/api/plugins",{spec:e})}async function ire(e,t){return zF(`/api/plugins/${encodeURIComponent(e)}`,{disabled:t})}async function sre(e){return PF(`/api/plugins/${encodeURIComponent(e)}`)}async function rre(e,t){return bf(`/api/plugins/${encodeURIComponent(e)}/config`,{config:t})}const T0=1,ll=new Map,A0=new Set;function Cm(){for(const e of A0)e()}function are(e){return A0.add(e),()=>A0.delete(e)}function ore(){return[...ll.values()]}function lre(e){return t=>{switch(t){case"react":return D4;case"react/jsx-runtime":return M4;case"@coralai/console-slots":return{registerSlot:(n,i)=>b0(n,{owner:e,order:i.order??100,...typeof i.match=="function"?{match:i.match}:{},render:i.render}),contractVersion:T0};default:throw new Error(`插件 ${e} 要的模块 "${t}" 不在宿主模块表里(可用:react、react/jsx-runtime、@coralai/console-slots)`)}}}function cre(){const e=globalThis;e.__SpsModuleLoader__||(e.__SpsModuleLoader__={load(t){const n=t.contractVersion??1;if(n!==T0){ll.set(t.id,{id:t.id,ok:!1,error:`插槽契约版本不匹配:插件按 v${n} 编译,当前是 v${T0}`}),Cm();return}try{t.factory(lre(t.id)),ll.set(t.id,{id:t.id,ok:!0})}catch(i){ote(t.id),ll.set(t.id,{id:t.id,ok:!1,error:i instanceof Error?i.message:String(i)})}Cm()}})}function ure(e){return new Promise(t=>{const n=document.createElement("script");n.src=`/api/plugins/${encodeURIComponent(e)}/client.js`,n.async=!0,n.dataset.spsPlugin=e,n.onerror=()=>{ll.set(e,{id:e,ok:!1,error:"脚本加载失败"}),Cm(),t()},n.onload=()=>{ll.has(e)||(ll.set(e,{id:e,ok:!1,error:"脚本跑完了但没有调用 __SpsModuleLoader__.load()"}),Cm()),t()},document.head.append(n)})}const dre={slots:0};let Lj=new Map,Ij="";function Pj(){const e=ore(),t=ute(),n=JSON.stringify([e,t]);if(n===Ij)return Lj;const i=new Map;for(const s of e)i.set(s.id,{ok:s.ok,...s.error?{error:s.error}:{},slots:0});for(const s of t)for(const r of s.owners){const o=i.get(r)??{slots:0};i.set(r,{...o,slots:o.slots+1})}return Lj=i,Ij=n,i}function fre(e){const t=are(e),n=iL(e);return()=>{t(),n()}}function jI(e){return _.useSyncExternalStore(fre,Pj,Pj).get(e)??dre}function hre(e){return!!e&&typeof e=="object"&&"refs"in e&&"uid"in e}const Wo=(e,t)=>t===void 0?void 0:e.refs[String(t)];function pre(e){const t=Wo(e,e.uid);return!t||t.type!=="object"||!t.dict?!1:Object.values(t.dict).every(n=>{var s;const i=Wo(e,n);return i?["string","number","boolean"].includes(i.type)?!0:i.type==="union"?(i.list??[]).every(r=>{var o;return((o=Wo(e,r))==null?void 0:o.type)==="const"}):i.type==="array"?((s=Wo(e,i.inner))==null?void 0:s.type)==="string":!1:!1})}function mre({schema:e,value:t,onChange:n}){const i=hre(e)?e:null,s=_.useMemo(()=>i?pre(i):!1,[i]),[r,o]=_.useState(()=>JSON.stringify(t??{},null,2)),[c,d]=_.useState(null);if(!i||!s)return u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx("label",{htmlFor:"plugin-config-raw",className:"text-sm font-bold",children:"配置(JSON)"}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:i?"这个插件的配置里有通用表单认不出来的类型,先用 JSON 编辑。":"这个插件没有声明 Config —— 仍然可以直接写 JSON。"}),u.jsx("textarea",{id:"plugin-config-raw",className:"nb-input min-h-[180px] font-[family-name:var(--font-mono)] text-xs",value:r,onChange:p=>{o(p.target.value);try{n(JSON.parse(p.target.value||"{}")),d(null)}catch(b){d(b instanceof Error?b.message:String(b))}}}),c?u.jsxs("span",{className:"text-xs text-[var(--color-danger)]",children:["JSON 有误:",c]}):null]});const f=Wo(i,i.uid),m=(p,b)=>n({...t,[p]:b});return u.jsx("div",{className:"flex flex-col gap-4",children:Object.entries(f.dict??{}).map(([p,b])=>{var C,S,j,T,A,M,R;const y=Wo(i,b),x=t[p]??((C=y.meta)==null?void 0:C.default),v=u.jsxs("span",{className:"text-sm font-bold",children:[p,(S=y.meta)!=null&&S.required?u.jsx("span",{className:"text-[var(--color-danger)]",children:" *"}):null]}),w=(j=y.meta)!=null&&j.description?u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:y.meta.description}):null;if(y.type==="boolean")return u.jsxs("label",{className:"flex items-center gap-2",children:[u.jsx("input",{type:"checkbox",checked:!!x,onChange:P=>m(p,P.target.checked)}),u.jsxs("span",{className:"flex flex-col",children:[v,w]})]},p);if(y.type==="union"){const P=(y.list??[]).map(O=>{var B;return(B=Wo(i,O))==null?void 0:B.value}).filter(O=>O!==void 0);return u.jsxs("label",{className:"flex flex-col gap-1",children:[v,w,u.jsx("select",{className:"nb-input text-sm",value:String(x??""),onChange:O=>m(p,O.target.value),children:P.map(O=>u.jsx("option",{value:String(O),children:String(O)},String(O)))})]},p)}if(y.type==="array"){const P=Array.isArray(x)?x:[];return u.jsxs("label",{className:"flex flex-col gap-1",children:[v,u.jsxs("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:[(T=y.meta)!=null&&T.description?`${y.meta.description} · `:"","一行一个"]}),u.jsx("textarea",{className:"nb-input min-h-[80px] font-[family-name:var(--font-mono)] text-xs",value:P.join(`
842
842
  `),onChange:O=>m(p,O.target.value.split(`
843
- `).map(B=>B.trim()).filter(Boolean))})]},p)}const k=((A=y.meta)==null?void 0:A.role)==="secret";return u.jsxs("label",{className:"flex flex-col gap-1",children:[v,w,u.jsx("input",{className:"nb-input text-sm",type:k?"password":y.type==="number"?"number":"text",value:x==null?"":String(x),...y.type==="number"?{min:(M=y.meta)==null?void 0:M.min,max:(R=y.meta)==null?void 0:R.max}:{},onChange:P=>m(p,y.type==="number"?Number(P.target.value):P.target.value)})]},p)})})}function Vp(e){if(e instanceof wM&&e.detail&&typeof e.detail=="object"){const t=e.detail;if(t.error)return{error:t.error,kind:t.kind??"unknown",detail:t.detail}}return{error:e instanceof Error?e.message:String(e),kind:"unknown"}}const zj={network:"装不上是网络问题 —— 检查代理或 registry 后重试。",auth:"registry 要凭据 —— 配好 npm 认证再试。","not-found":"这个名字或版本在 registry 上不存在。","not-plugin":"它装上了,但不是 Cordis 插件(没有 apply 导出)。装配档没有被改。",apply:"插件自己的代码抛了 —— 这是插件作者的问题。",conflict:"和已有的插件撞了(同名 id,或它提供的服务已经被别人占了)。"};function Bj({fail:e,title:t}){const[n,i]=_.useState(!1);return u.jsx("div",{className:"nb-card !border-[var(--color-danger)] text-sm",children:u.jsxs("div",{className:"flex items-start gap-2",children:[u.jsx(dF,{size:16,className:"mt-0.5 shrink-0 text-[var(--color-danger)]"}),u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsxs("p",{className:"font-medium",children:[t,":",e.error]}),u.jsxs("p",{className:"mt-1 text-[var(--color-text-muted)]",children:[u.jsx("code",{className:"text-xs",children:e.kind}),zj[e.kind]?` · ${zj[e.kind]}`:""]}),e.detail?u.jsxs(u.Fragment,{children:[u.jsx("button",{type:"button",className:"mt-2 text-xs underline text-[var(--color-text-muted)]",onClick:()=>i(s=>!s),children:n?"收起原文":"展开原文"}),n?u.jsx("pre",{className:"mt-2 max-h-64 overflow-auto whitespace-pre-wrap rounded bg-black/20 p-2 text-xs",children:e.detail}):null]}):null]})]})})}const gre=[{key:"user",title:"已装扩展",hint:"你自己装的插件。"},{key:"backend",title:"可换后端",hint:"换一行 name 就换掉实现;消费方一行不改。"},{key:"builtin",title:"内建能力包",hint:"把内建实现注册进对应的注册表。停用 = 那一类内建全部让路(比如让第三方生图适配器独占)。"},{key:"registry",title:"注册表(插座)",hint:"别人往里注册东西的挂载点,本身不需要配置。停用会让插在上面的一起失效。"}],yre=new Set(["tools","agents","repo","capabilities","media","im"]);function bre(e){return e.layer==="user"?"user":yre.has(e.key)?"registry":e.key.endsWith("-builtin")||e.key.startsWith("capabilities-")?"builtin":"backend"}function xre(e,t){return!!(t!=null&&t(e))||e.schema!==null}function vre({panelFor:e}){const t=Xt(),[n,i]=_.useState(""),[s,r]=_.useState(null),[o,c]=_.useState(null),[d,f]=_.useState(null),{data:m=[],isLoading:p}=Je({queryKey:["plugins"],queryFn:CI}),b=d?m.find(C=>C.key===d)??null:null,y=C=>{r(null),c(C??null),t.invalidateQueries({queryKey:["plugins"]})},x=At({mutationFn:()=>nre(n.trim()),onSuccess:C=>{i(""),y(C.warning)},onError:C=>r({title:"安装失败",fail:Vp(C)})}),v=At({mutationFn:({key:C,disabled:S})=>ire(C,S),onSuccess:C=>y(C.warning),onError:C=>r({title:"启停失败",fail:Vp(C)})}),w=At({mutationFn:C=>sre(C),onSuccess:C=>y(C.warning),onError:C=>r({title:"卸载失败",fail:Vp(C)})}),k=x.isPending||v.isPending||w.isPending;return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"nb-card",children:[u.jsx("label",{htmlFor:"plugin-spec",className:"text-sm font-medium",children:"装一个插件"}),u.jsxs("p",{className:"mt-1 text-xs text-[var(--color-text-muted)]",children:["填 npm 包名(可带 ",u.jsx("code",{children:"@版本"}),")或本地路径。装完**当场生效**,不用重启。"]}),u.jsxs("div",{className:"mt-3 flex gap-2",children:[u.jsx("input",{id:"plugin-spec",value:n,onChange:C=>i(C.target.value),placeholder:"@scope/coral-plugin-xxx",className:"nb-input flex-1 text-sm",disabled:k}),u.jsxs("button",{type:"button",onClick:()=>x.mutate(),disabled:k||!n.trim(),className:"nb-btn nb-btn-primary",children:[x.isPending?u.jsx(ht,{size:16,className:"animate-spin"}):u.jsx(Bn,{size:16}),"安装"]})]})]}),s?u.jsx(Bj,{fail:s.fail,title:s.title}):null,o?u.jsx(Bj,{fail:o,title:"操作完成,但有一件事没做成"}):null,p?u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:"读取中…"}):gre.map(C=>{const S=m.filter(j=>bre(j)===C.key);return S.length===0?null:u.jsxs("section",{className:"flex flex-col gap-3",children:[u.jsxs("header",{children:[u.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-base font-bold",children:C.title}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:C.hint})]}),u.jsx("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:S.map(j=>u.jsx(Ere,{row:j,busy:k,hasConfig:xre(j,e),onConfig:()=>f(j.key),onToggle:()=>v.mutate({key:j.key,disabled:!j.disabled}),onRemove:()=>w.mutate(j.key)},j.key))})]},C.key)}),b?u.jsx(Ow,{onClose:()=>f(null),children:u.jsxs("div",{className:"flex max-h-[88vh] w-full max-w-[min(1040px,94vw)] flex-col gap-2 overflow-y-auto",children:[u.jsxs("div",{className:"nb-card sticky top-0 z-10 flex shrink-0 items-center justify-between gap-4 !py-2",children:[u.jsx("span",{className:"min-w-0 truncate font-[family-name:var(--font-heading)] text-base font-bold",children:b.key}),u.jsx("button",{type:"button",onClick:()=>f(null),"aria-label":"关闭",title:"关闭",className:"nb-btn shrink-0 !px-2 !py-1",children:u.jsx(vn,{size:14,strokeWidth:2.5})})]}),(e==null?void 0:e(b))??(b.schema!==null?u.jsx(kre,{row:b,onSaved:C=>{f(null),y(C)},onFail:r}):null),u.jsx(wre,{row:b})]})}):null]})}function wre({row:e}){const t=jI(e.key),n=[["包",e.pkg??e.name],["版本",e.version??"—"],["来源",e.layer==="factory"?"内建(随包出厂,只能停用)":"你装的"],["分类",e.category??"—"],["状态",e.disabled?"已停用":e.mounted?"运行中":"未挂上(装配档里有,但没启动起来)"],["界面",e.clientFormat===null?"没有浏览器半区":e.clientFormat==="dsh"?"dsh 格式,没有装(需要移植)":t.ok===!1?`没加载起来:${t.error}`:`已加载 · 贡献了 ${t.slots} 个界面块`]];return u.jsxs("section",{className:"nb-card flex flex-col gap-2",children:[u.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-base font-bold",children:"插件信息"}),u.jsx("p",{className:"text-sm leading-5 text-[var(--color-text-muted)]",children:e.description||"(这个插件没写简介)"}),u.jsx("dl",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-xs",children:n.map(([i,s])=>u.jsxs(_.Fragment,{children:[u.jsx("dt",{className:"text-[var(--color-text-subtle)]",children:i}),u.jsx("dd",{className:"break-all font-[family-name:var(--font-mono)]",children:s})]},i))}),e.schema===null?u.jsx("p",{className:"text-xs text-[var(--color-text-subtle)]",children:"这个插件没有声明可配置项 —— 只能开关。"}):null]})}function Ere({row:e,busy:t,hasConfig:n,onConfig:i,onToggle:s,onRemove:r}){const o=jI(e.key),c=e.disabled?{text:"已停用",cls:"bg-[var(--color-text-muted)]/15 text-[var(--color-text-muted)]"}:e.mounted?{text:"运行中",cls:"bg-[var(--color-success)]/20 text-[var(--color-success)]"}:{text:"未挂上",cls:"bg-[var(--color-danger)]/20 text-[var(--color-danger)]"};return u.jsxs("article",{className:"nb-card nb-card-interactive relative flex flex-col gap-3",children:[u.jsx("button",{type:"button",onClick:i,"aria-label":`${n?"配置":"查看"} ${e.key}`,className:"absolute inset-0 cursor-pointer rounded-[inherit] border-0 bg-transparent"}),u.jsxs("div",{className:"flex items-start justify-between gap-2",children:[u.jsx("h3",{className:"min-w-0 flex-1 overflow-hidden break-all font-[family-name:var(--font-heading)] text-base font-bold",children:e.key}),u.jsx("span",{className:`nb-badge shrink-0 text-[10px] ${c.cls}`,title:e.disabled?"人主动停用的":e.mounted?"这个进程里正挂着":"装配档里有它,但没挂起来 —— 多半是它启动时抛了",children:c.text})]}),u.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.category?u.jsx("span",{className:"nb-badge text-[10px]",children:e.category}):null,u.jsx("span",{className:"nb-badge text-[10px] opacity-70",children:e.layer==="factory"?"内建":"已装"})]}),u.jsx("p",{className:"line-clamp-3 text-sm leading-5 text-[var(--color-text-muted)]",children:e.description||"(无简介)"}),e.clientFormat==="dsh"?u.jsxs("div",{className:"rounded-md border border-[var(--color-border-light)] bg-[var(--color-bg-soft)] px-2 py-1.5",children:[u.jsx("p",{className:"text-[11px] font-bold",children:"界面部分是 dsh 格式,没有装"}),u.jsxs("p",{className:"mt-0.5 text-[10px] text-[var(--color-text-muted)]",children:["它调 ",u.jsx("code",{children:"__ModuleLoader__"})," 并用 dsh 的槽名,需要移植。",u.jsx("b",{children:"工具/宿主部分不受影响。"})]})]}):o.ok===!1?u.jsxs("div",{className:"rounded-md border border-[var(--color-danger)] bg-[var(--color-danger)]/10 px-2 py-1.5",children:[u.jsx("p",{className:"text-[11px] font-bold",children:"界面部分没加载起来"}),u.jsx("p",{className:"mt-0.5 break-words text-[10px] text-[var(--color-text-muted)]",children:o.error})]}):o.slots>0?u.jsxs("p",{className:"text-[11px] text-[var(--color-text-muted)]",children:["贡献了 ",o.slots," 个界面块"]}):null,e.takeovers.length>0?u.jsxs("div",{className:"rounded-md border border-[var(--color-warning,#c90)] bg-[var(--color-warning,#c90)]/10 px-2 py-1.5",children:[u.jsxs("p",{className:"text-[11px] font-bold",children:["接管了 ",e.takeovers.length," 条宿主路由"]}),u.jsx("ul",{className:"mt-0.5 font-[family-name:var(--font-mono)] text-[10px] text-[var(--color-text-muted)]",children:e.takeovers.map(d=>u.jsx("li",{className:"truncate",children:d.kind==="prefix"?`${d.path}/*`:d.path},`${d.kind}:${d.path}`))})]}):null,u.jsxs("div",{className:"flex items-center justify-between gap-2 border-t border-[var(--color-border-light)] pt-2",children:[u.jsxs("span",{className:"min-w-0 flex-1 truncate font-[family-name:var(--font-mono)] text-[11px] text-[var(--color-text-subtle)]",title:e.pkg??e.name,children:[e.pkg??e.name,e.version?` · ${e.version}`:""]}),u.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n?u.jsx(Q6,{size:13,strokeWidth:2.5,"aria-hidden":!0,className:"text-[var(--color-text-subtle)]"}):null,u.jsx("button",{type:"button",className:"nb-btn relative z-10 !px-2 !py-1",onClick:s,disabled:t,"aria-label":e.disabled?`启用 ${e.key}`:`停用 ${e.key}`,title:e.disabled?"启用":"停用",children:u.jsx(I6,{size:13,strokeWidth:2.5})}),u.jsx("button",{type:"button",className:"nb-btn relative z-10 !px-2 !py-1",onClick:r,disabled:t||e.layer==="factory","aria-label":`卸载 ${e.key}`,title:e.layer==="factory"?"内建插件不能卸载,只能停用":"卸载",children:u.jsx(us,{size:13,strokeWidth:2.5})})]})]})]})}function kre({row:e,onSaved:t,onFail:n}){const[i,s]=_.useState(()=>e.config&&typeof e.config=="object"?{...e.config}:{}),r=At({mutationFn:()=>rre(e.key,i),onSuccess:o=>t(o.warning),onError:o=>n({title:"保存配置失败",fail:Vp(o)})});return u.jsxs("section",{className:"nb-card flex flex-col gap-4",children:[u.jsxs("header",{className:"flex items-start justify-between gap-3",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:e.key}),u.jsx("p",{className:"mt-1 text-xs text-[var(--color-text-muted)]",children:e.description||"(无简介)"})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-primary shrink-0",disabled:r.isPending,onClick:()=>r.mutate(),"aria-label":`保存 ${e.key} 的配置`,children:[r.isPending?u.jsx(ht,{size:14,className:"animate-spin"}):u.jsx(cs,{size:14,strokeWidth:2.5}),"保存"]})]}),u.jsx(mre,{schema:e.schema,value:i,onChange:s}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"保存后**当场重挂**这个插件 —— 配置只在挂载那一刻读一次,不重挂等于没改。"})]})}async function Sre(){return(await wt("/api/channels")).data??{console:{},adapters:[]}}async function Nre(e){return(await bf("/api/channels",e)).data}function _re(e){return wt(`/api/media-providers?capability=${encodeURIComponent(e)}`)}async function Cre(e){const t=await fetch("/api/media-providers",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`${t.status}: ${await t.text()}`);return t.json()}function jre(e){return m1(`/api/media-providers/${encodeURIComponent(e)}`)}async function Tre(e,t){const n=await fetch(`/api/media-providers/default/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`${n.status}: ${await n.text()}`);return n.json()}const M0={image:"图片",video:"视频",music:"音乐",voice:"语音","3d":"3D",embedding:"向量(Embedding)",rerank:"重排(Rerank)"},Are={image:["codex","openai","volcengine","minimax","tripo","agnes","bailian","openrouter"],video:["volcengine"],music:["minimax"],voice:["doubao"],"3d":["tripo"],embedding:["openai-compatible"],rerank:["openai-compatible"]},TI={codex:"",openai:"https://api.openai.com/v1",tripo:"https://openapi.tripo3d.ai",volcengine:"https://ark.cn-beijing.volces.com/api/v3",minimax:"https://api.minimaxi.com",doubao:"https://openspeech.bytedance.com",agnes:"https://apihub.agnes-ai.com",bailian:"https://dashscope.aliyuncs.com",openrouter:"https://openrouter.ai/api/v1","openai-compatible":""},Mre=new Set(["codex"]);function Rre({capability:e}){var w,k,C;const t=Xt(),{alert:n,confirm:i}=Un(),s=Je({queryKey:["media-providers",e],queryFn:()=>_re(e)}),[r,o]=_.useState(null),c=Are[e]??[],d=((w=s.data)==null?void 0:w.providers)??[],f=(C=(k=s.data)==null?void 0:k.defaults)==null?void 0:C[e],m=At({mutationFn:S=>Cre(S),onSuccess:()=>{o(null),t.invalidateQueries({queryKey:["media-providers",e]})},onError:S=>void n({title:"保存失败",body:S instanceof Error?S.message:String(S)})}),p=At({mutationFn:S=>jre(S),onSuccess:()=>void t.invalidateQueries({queryKey:["media-providers",e]}),onError:S=>void n({title:"删除失败",body:S instanceof Error?S.message:String(S)})}),b=At({mutationFn:S=>Tre(e,S),onSuccess:()=>void t.invalidateQueries({queryKey:["media-providers",e]}),onError:S=>void n({title:"设默认失败",body:S instanceof Error?S.message:String(S)})}),y=(S,j)=>(f==null?void 0:f.providerId)===S&&(f==null?void 0:f.model)===j,x=()=>o({isNew:!0,entry:{id:"",name:"",capability:e,adapter:c[0]??"",baseUrl:c[0]?TI[c[0]]??"":"",apiKey:"",models:[]}}),v=S=>o({isNew:!1,entry:{id:S.id,name:S.name,capability:e,adapter:S.adapter,baseUrl:S.baseUrl,apiKey:"",models:S.models}});return u.jsxs("section",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[u.jsxs("div",{children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:[M0[e],"供应商"]}),u.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["增删该能力的第三方生成端点(adapter + Base URL + key + models)。**点模型标签设为该能力默认**;✓ = 当前默认。",f?u.jsxs(u.Fragment,{children:[" ","当前默认:",u.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:f.providerId}),f.model?u.jsxs(u.Fragment,{children:[" · ",u.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:f.model})]}):null]}):" 当前默认:未设置"]})]}),u.jsxs("button",{className:"nb-btn nb-btn-primary shrink-0",style:{padding:"8px 16px"},type:"button",onClick:x,"aria-label":`添加${M0[e]}供应商`,children:[u.jsx(Bn,{size:14,strokeWidth:3})," 添加供应商"]})]}),u.jsxs("div",{className:"flex flex-col gap-2 mt-4",children:[s.isLoading&&u.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[u.jsx(ht,{size:14,strokeWidth:3,className:"animate-spin"})," 加载中…"]}),!s.isLoading&&d.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无供应商)"}),d.map(S=>u.jsxs("div",{className:"rounded-lg px-3 py-2 border-2 border-[var(--color-text)]",children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:S.id}),u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",S.name]}),u.jsx("span",{className:"ml-2 text-[10px] font-bold px-2 py-0.5 rounded-md border-2 border-[var(--color-text)] bg-[var(--color-accent-yellow)]",children:S.adapter}),u.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[S.baseUrl," · key ",S.keyMasked||"未设置"]})]}),u.jsxs("div",{className:"flex gap-1 shrink-0",children:[u.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>v(S),"aria-label":`编辑 ${S.id}`,children:u.jsx(d1,{size:12,strokeWidth:3})}),u.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await i({title:"删除供应商",body:`删除 ${S.id}?`,danger:!0})&&p.mutate(S.id)},"aria-label":`删除 ${S.id}`,children:u.jsx(us,{size:12,strokeWidth:3})})]})]}),S.models.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:S.models.map(j=>{const T=y(S.id,j);return u.jsxs("button",{type:"button",onClick:()=>b.mutate({providerId:S.id,model:j}),disabled:b.isPending,"aria-pressed":T,className:["nb-btn px-2 py-0.5 text-xs font-[family-name:var(--font-mono)]",T?"nb-btn-mint":""].join(" "),title:T?"当前默认":"设为该能力默认",children:[j,T?" ✓":""]},j)})})]},S.id))]}),r&&u.jsx(Ow,{onClose:()=>o(null),children:u.jsx(Ore,{state:r,adapters:c,onChange:S=>o({...r,entry:S}),onCancel:()=>o(null),onSave:S=>m.mutate(S),saving:m.isPending})})]})}function Dre(e,t){const n=[...e];for(const i of t.split(/[,,\n\r]+/)){const s=i.trim();s&&!n.includes(s)&&n.push(s)}return n}function Ore({state:e,adapters:t,onChange:n,onCancel:i,onSave:s,saving:r}){const o=e.entry,[c,d]=_.useState(""),f=y=>n({...o,...y}),m=Mre.has(o.adapter),p=/^[a-zA-Z0-9_-]+$/.test(o.id)&&!!o.name.trim()&&!!o.adapter.trim()&&(m||!!o.baseUrl.trim()),b=y=>{f({adapter:y,baseUrl:TI[y]??""})};return u.jsxs("div",{className:"border-[3px] border-[var(--color-text)] rounded-2xl p-6 bg-[var(--color-bg-cream)] shadow-[6px_6px_0_var(--color-text)] flex flex-col gap-4 w-[min(92vw,640px)] max-h-[88vh] overflow-y-auto",children:[u.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增供应商":`编辑 ${o.id}`,u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:[" (",M0[o.capability],")"]})]}),u.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:o.id,disabled:!e.isNew,onChange:y=>f({id:y.target.value}),placeholder:"如 my-tripo",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",u.jsx("input",{className:"nb-input",value:o.name,onChange:y=>f({name:y.target.value}),placeholder:"显示名"})]})]}),u.jsxs("div",{className:"flex flex-col gap-1 text-sm font-bold",children:["adapter",u.jsx(Nc,{value:o.adapter,onChange:b,ariaLabel:"adapter",options:t.map(y=>({value:y,label:y}))})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",m&&"(订阅无需,可留空)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:o.baseUrl,onChange:y=>f({baseUrl:y.target.value}),placeholder:m?"订阅走本地凭据,无需填":"https://api.example.com",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",m?"(订阅无需)":!e.isNew&&"(留空=保留)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:o.apiKey??"",onChange:y=>f({apiKey:y.target.value}),placeholder:m?"订阅无需":e.isNew?"sk-...":"留空保留",spellCheck:!1})]}),u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("label",{htmlFor:"provider-models",className:"text-sm font-bold",children:"Models"}),u.jsx(AI,{models:o.models,draft:c,onModelsChange:y=>f({models:y}),onDraftChange:d}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"输入模型名,按 Enter 或逗号添加"})]}),u.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[u.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:i,children:"取消"}),u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!p||r,onClick:()=>s({...o,models:Dre(o.models,c)}),children:[r?u.jsx(ht,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(cs,{size:14,strokeWidth:3})," 保存"]})]})]})}async function Lre(){return(await wt("/api/mcp-tools")).tools}const Ire=[{key:"plugin",labelKey:"plugins.tab.plugin"},{key:"model",labelKey:"plugins.tab.model"},{key:"tool",labelKey:"plugins.tab.tool"}];function Pre(e){return lte("plugin.config",{pluginKey:e.key})?u.jsx(mw,{name:"plugin.config",props:{pluginKey:e.key}}):null}function zre(){const e=Ye(),[t,n]=_.useState("plugin");return u.jsxs("div",{className:"flex flex-col gap-6 w-full",children:[u.jsxs("header",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("plugins.h1")}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:e("plugins.desc")})]}),u.jsx(uu,{ariaLabel:e("plugins.h1"),className:"",value:t,onChange:n,options:Ire.map(i=>({value:i.key,label:e(i.labelKey)}))}),u.jsx("div",{role:"tabpanel",children:t==="plugin"?u.jsx(vre,{panelFor:Pre}):t==="model"?u.jsx($re,{}):u.jsx(Qre,{})})]})}function Bre(){var x,v,w;const e=Ye(),t=Xt(),{alert:n}=Un(),i=Je({queryKey:["system-memory"],queryFn:FF}),[s,r]=_.useState(null),[o,c]=_.useState(null);_.useEffect(()=>{i.data&&s===null&&(r(i.data.provider),c(i.data.url))},[i.data,s]);const d=s??((x=i.data)==null?void 0:x.provider)??"agentmemory",f=o??((v=i.data)==null?void 0:v.url)??"",m=i.data!=null&&(d!==i.data.provider||d==="custom"&&f!==i.data.url),p=k=>{const C=`system.memory.opt.${k}`;return e(C)},b=At({mutationFn:()=>$F(d,d==="custom"?f:""),onSuccess:()=>{t.invalidateQueries({queryKey:["system-memory"]}),t.invalidateQueries({queryKey:["system-env"]})},onError:k=>{n({title:e("system.memory.error"),body:k instanceof Error?k.message:String(k)})}}),y=((w=i.data)==null?void 0:w.options)??["none","builtin","agentmemory","custom"];return u.jsxs("section",{className:"nb-card",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:e("system.memory.title")}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-3",children:e("system.memory.desc")}),u.jsxs("div",{className:"flex flex-col gap-3 max-w-md",children:[u.jsxs("div",{className:"flex flex-col gap-1 text-sm",children:[u.jsx("span",{className:"font-bold",children:e("system.memory.provider")}),u.jsx(Nc,{value:d,onChange:r,ariaLabel:e("system.memory.provider"),options:y.map(k=>({value:k,label:p(k)}))})]}),d==="custom"&&u.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[u.jsx("span",{className:"font-bold",children:e("system.memory.url")}),u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",type:"text",value:f,onChange:k=>c(k.target.value),placeholder:e("system.memory.url.placeholder"),spellCheck:!1,"aria-label":e("system.memory.url")})]}),u.jsx("div",{className:"flex justify-end",children:u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px",fontSize:12},onClick:()=>b.mutate(),disabled:!m||b.isPending,type:"button","aria-label":e("system.memory.save.aria"),children:[b.isPending?u.jsx(ht,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(cs,{size:12,strokeWidth:3}),b.isSuccess&&!m?e("system.memory.saved"):e("system.memory.save")]})})]})]})}const Ure=[{key:"llm",label:"sps agent"},{key:"image",label:"图片"},{key:"video",label:"视频"},{key:"music",label:"音乐"},{key:"voice",label:"语音"},{key:"3d",label:"3D"},{key:"embedding",label:"Embedding"},{key:"rerank",label:"Rerank"}];function Fre(){const e=Ye(),t=Xt(),n=_.useRef(null),[i,s]=_.useState(!1),r=async()=>{s(!0);try{const c=await wt("/api/model-config/export"),d=new Blob([JSON.stringify(c,null,2)],{type:"application/json"}),f=document.createElement("a");f.href=URL.createObjectURL(d),f.download=`sps-model-config-${new Date().toISOString().slice(0,10)}.json`,f.click(),URL.revokeObjectURL(f.href)}catch(c){window.alert(`${e("plugins.model.export.failed")}: ${c instanceof Error?c.message:String(c)}`)}finally{s(!1)}},o=async c=>{s(!0);try{const d=JSON.parse(await c.text());if(!window.confirm(e("plugins.model.import.confirm")))return;const m=(await jr("/api/model-config/import",d)).summary;window.alert(e("plugins.model.import.done",{llm:String(Number(m.llmAnthropic??0)+Number(m.llmOpenai??0)),media:String(m.media??0),skipped:String(m.skipped??0)})),t.invalidateQueries()}catch(d){window.alert(`${e("plugins.model.import.failed")}: ${d instanceof Error?d.message:String(d)}`)}finally{s(!1),n.current&&(n.current.value="")}};return u.jsxs("div",{className:"flex gap-2 items-center ml-auto",children:[u.jsxs("button",{type:"button",className:"nb-btn",style:{padding:"6px 12px"},disabled:i,onClick:()=>void r(),title:e("plugins.model.export.hint"),children:[u.jsx(sM,{size:14,strokeWidth:2.5})," ",e("plugins.model.export")]}),u.jsxs("button",{type:"button",className:"nb-btn",style:{padding:"6px 12px"},disabled:i,onClick:()=>{var c;return(c=n.current)==null?void 0:c.click()},title:e("plugins.model.import.hint"),children:[u.jsx(h1,{size:14,strokeWidth:2.5})," ",e("plugins.model.import")]}),u.jsx("input",{ref:n,type:"file",accept:"application/json,.json",className:"hidden",onChange:c=>{var f;const d=(f=c.target.files)==null?void 0:f[0];d&&o(d)}})]})}function $re(){const[e,t]=_.useState("llm");return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"flex flex-wrap gap-2 items-center",role:"tablist","aria-label":"模型/资源供应商",children:[Ure.map(n=>{const i=e===n.key;return u.jsx("button",{type:"button",role:"tab","aria-selected":i,onClick:()=>t(n.key),className:["nb-btn",i?"nb-btn-primary":""].join(" "),style:{padding:"6px 14px"},children:n.label},n.key)}),u.jsx(Fre,{})]}),e==="llm"?u.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:["Anthropic 兼容 ",u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"· 含 Claude 订阅"})]}),u.jsx(Uj,{only:"anthropic"})]}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:["OpenAI 兼容 ",u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"· 含 codex 订阅"})]}),u.jsx(Uj,{only:"openai"})]})]}):u.jsx(Rre,{capability:e})]})}function Uj({only:e}={}){var C,S,j;const t=Xt(),{alert:n,confirm:i}=Un(),s=Je({queryKey:["providers"],queryFn:B1}),o=(C=Je({queryKey:["system-agents"],queryFn:g1}).data)==null?void 0:C.agents,[c,d]=_.useState(null),f=At({mutationFn:T=>VY(c.kind,T),onSuccess:()=>{d(null),t.invalidateQueries({queryKey:["providers"]})},onError:T=>void n({title:"保存失败",body:T instanceof Error?T.message:String(T)})}),m=At({mutationFn:T=>KY(T.kind,T.id),onSuccess:()=>void t.invalidateQueries({queryKey:["providers"]}),onError:T=>void n({title:"删除失败",body:T instanceof Error?T.message:String(T)})}),p=At({mutationFn:T=>qF(T),onSuccess:()=>void t.invalidateQueries({queryKey:["system-agents"]}),onError:T=>void n({title:"设默认失败",body:T instanceof Error?T.message:String(T)})}),b=(T,A,M)=>{if(!o)return!1;const R=T==="anthropic"?o.worker:o.reviewer;return(R.providerId||"official")===A&&R.model===M},y=(T,A,M)=>{if(!o)return;let R;if(T==="anthropic"){const P={...o.worker,model:M};A==="official"?delete P.providerId:P.providerId=A,R={...o,worker:P}}else R={...o,reviewer:{...o.reviewer,providerId:A,model:M}};p.mutate(R)},x=[{kind:"anthropic",title:"Anthropic 兼容(worker / claude)",items:((S=s.data)==null?void 0:S.anthropic)??[]},{kind:"openai",title:"OpenAI 兼容(reviewer / openai agent)",items:((j=s.data)==null?void 0:j.openai)??[]}],v=e?x.filter(T=>T.kind===e):x,w=T=>d({kind:T,isNew:!0,entry:{id:"",name:"",baseUrl:"",apiKey:"",models:[]}}),k=(T,A)=>d({kind:T,isNew:!1,entry:{id:A.id,name:A.name,baseUrl:A.baseUrl,apiKey:"",transport:A.transport,models:A.models}});return u.jsxs("section",{className:"nb-card",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:"模型 API 端点"}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-4",children:"本地官方订阅(已登录验证)自动置顶,不可编辑;下方可增删第三方兼容端点。**点模型标签设为默认**(anthropic→worker / openai→监工);✓ = 当前默认。"}),u.jsx("div",{className:["grid grid-cols-1 gap-5",e?"":"lg:grid-cols-2"].join(" "),children:v.map(T=>u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("span",{className:"font-bold text-sm",children:T.title}),u.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:()=>w(T.kind),"aria-label":`添加 ${T.title} 端点`,children:[u.jsx(Bn,{size:12,strokeWidth:3})," 添加"]})]}),T.items.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无端点)"}),T.items.map(A=>u.jsxs("div",{className:["rounded-lg px-3 py-2 border-2",(A.builtin,"border-[var(--color-text)]")].join(" "),children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:A.id}),u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",A.name]}),A.builtin?u.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:["本地订阅",A.detail?` · ${A.detail}`:""," · 已验证可用"]}):u.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[A.baseUrl," · key ",A.hasKey?A.apiKey:"未设置"]})]}),A.builtin?u.jsx("span",{className:"shrink-0 text-[10px] font-bold px-2 py-0.5 rounded-md border-2 border-[var(--color-text)] bg-[var(--color-accent-yellow)]",children:"内置"}):u.jsxs("div",{className:"flex gap-1 shrink-0",children:[u.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>k(T.kind,A),"aria-label":`编辑 ${A.id}`,children:u.jsx(d1,{size:12,strokeWidth:3})}),u.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await i({title:"删除端点",body:`删除 ${A.id}?`,danger:!0})&&m.mutate({kind:T.kind,id:A.id})},"aria-label":`删除 ${A.id}`,children:u.jsx(us,{size:12,strokeWidth:3})})]})]}),A.models.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:A.models.map(M=>{const R=b(T.kind,A.id,M);return u.jsxs("button",{type:"button",onClick:()=>y(T.kind,A.id,M),disabled:p.isPending,"aria-pressed":R,className:["nb-btn px-2 py-0.5 text-xs font-[family-name:var(--font-mono)]",R?"nb-btn-mint":""].join(" "),title:R?"当前默认":"设为默认",children:[M,R?" ✓":""]},M)})})]},A.id))]},T.kind))}),c&&u.jsx(Ow,{onClose:()=>d(null),children:u.jsx(qre,{state:c,onChange:T=>d({...c,entry:T}),onCancel:()=>d(null),onSave:T=>f.mutate(T),saving:f.isPending})})]})}function R0(e,t){const n=[...e];for(const i of t.split(/[,,\n\r]+/)){const s=i.trim();s&&!n.includes(s)&&n.push(s)}return n}function AI({models:e,draft:t,onModelsChange:n,onDraftChange:i}){const s=r=>{n(R0(e,r)),i("")};return u.jsxs("div",{className:"nb-input min-h-[46px] w-full flex flex-wrap gap-1.5 items-center px-2.5 py-2",children:[e.map(r=>u.jsxs("span",{className:"inline-flex max-w-full items-center gap-1.5 rounded-md border border-[var(--color-border-light)] bg-[var(--surface-control)] px-2 py-1 text-xs font-[family-name:var(--font-mono)]",children:[u.jsx("span",{className:"max-w-[480px] truncate",children:r}),u.jsx("button",{type:"button",className:"shrink-0 text-[var(--color-text-muted)] hover:text-[var(--color-text)]",onClick:()=>n(e.filter(o=>o!==r)),"aria-label":`删除模型 ${r}`,children:u.jsx(vn,{size:12,strokeWidth:2.5})})]},r)),u.jsx("input",{id:"provider-models",className:"min-w-[180px] flex-1 bg-transparent px-1 py-0.5 text-sm outline-none font-[family-name:var(--font-mono)]",value:t,onChange:r=>{const o=r.target.value,c=o.split(/[,,\n\r]/);if(c.length===1){i(o);return}const d=c.pop()??"";n(R0(e,c.join(","))),i(d)},onKeyDown:r=>{r.key==="Enter"&&!r.nativeEvent.isComposing?(r.preventDefault(),s(t)):r.key==="Backspace"&&!t&&e.length>0&&n(e.slice(0,-1))},placeholder:e.length>0?"继续添加模型":"输入模型名后按 Enter","aria-label":"Models",spellCheck:!1})]})}function qre({state:e,onChange:t,onCancel:n,onSave:i,saving:s}){const r=e.entry,[o,c]=_.useState(""),d=m=>t({...r,...m}),f=/^[a-zA-Z0-9_-]+$/.test(r.id)&&r.name.trim()&&r.baseUrl.trim();return u.jsxs("div",{className:"border-[3px] border-[var(--color-text)] rounded-2xl p-6 bg-[var(--color-bg-cream)] shadow-[6px_6px_0_var(--color-text)] flex flex-col gap-4 w-[min(92vw,640px)] max-h-[88vh] overflow-y-auto",children:[u.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增端点":`编辑 ${r.id}`,u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:["(",e.kind,")"]})]}),u.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:r.id,disabled:!e.isNew,onChange:m=>d({id:m.target.value}),placeholder:"如 my-openai",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",u.jsx("input",{className:"nb-input",value:r.name,onChange:m=>d({name:m.target.value}),placeholder:"显示名"})]})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:r.baseUrl,onChange:m=>d({baseUrl:m.target.value}),placeholder:"https://api.example.com/v1",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",!e.isNew&&"(留空=保留)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:r.apiKey??"",onChange:m=>d({apiKey:m.target.value}),placeholder:e.isNew?"sk-...":"••••(留空不改)",spellCheck:!1})]}),e.kind==="openai"&&u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["请求方言",u.jsxs("select",{className:"nb-input text-sm",value:r.transport??"chat_completions",onChange:m=>d({transport:m.target.value}),children:[u.jsx("option",{value:"chat_completions",children:"Chat Completions(/v1/chat/completions,默认)"}),u.jsx("option",{value:"responses",children:"Responses(/v1/responses)"})]}),u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"走 codex 订阅的网关端点(如 gpt-*)必须选 Responses,否则上游 400。"})]}),u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("label",{htmlFor:"provider-models",className:"text-sm font-bold",children:"Models"}),u.jsx(AI,{models:r.models,draft:o,onModelsChange:m=>d({models:m}),onDraftChange:c}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"输入模型名,按 Enter 或逗号添加"})]}),u.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[u.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:n,children:"取消"}),u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!f||s,onClick:()=>i({...r,models:R0(r.models,o)}),children:[s?u.jsx(ht,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(cs,{size:14,strokeWidth:3})," 保存"]})]})]})}function Ow({children:e,onClose:t}){return ZA.createPortal(u.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/50 p-4",onClick:t,children:u.jsx("div",{onClick:n=>n.stopPropagation(),children:e})}),document.body)}const Hre=["telegram","dingtalk","matrix","slack","discord","feishu"],Yd={telegram:"Telegram",dingtalk:"钉钉 (Stream)",matrix:"Matrix",slack:"Slack",discord:"Discord",feishu:"飞书 / Lark"},Vre={telegram:[{key:"token",label:"Bot Token(@BotFather)",type:"password",placeholder:"123456:ABC-..."},{key:"allowedChatIds",label:"允许的 Chat ID(白名单,空=全放)",type:"list",placeholder:"逗号/换行分隔"}],dingtalk:[{key:"clientId",label:"Client ID(AppKey)",type:"text"},{key:"clientSecret",label:"Client Secret(AppSecret)",type:"password"},{key:"allowedConversations",label:"允许的会话 ID(白名单,空=全放)",type:"list"}],matrix:[{key:"homeserver",label:"Homeserver URL",type:"text",placeholder:"https://matrix.org"},{key:"accessToken",label:"Access Token",type:"password"},{key:"allowedRooms",label:"允许的 Room ID(白名单,空=全放)",type:"list"}],slack:[{key:"appToken",label:"App Token(xapp-,Socket Mode)",type:"password",placeholder:"xapp-..."},{key:"botToken",label:"Bot Token(xoxb-)",type:"password",placeholder:"xoxb-..."},{key:"allowedChannels",label:"允许的 Channel(白名单,空=全放)",type:"list"}],discord:[{key:"token",label:"Bot Token",type:"password"},{key:"allowedChannels",label:"允许的 Channel ID(白名单,空=全放)",type:"list"}],feishu:[{key:"appId",label:"App ID",type:"text"},{key:"appSecret",label:"App Secret",type:"password"},{key:"verificationToken",label:"Verification Token",type:"text"},{key:"encryptKey",label:"Encrypt Key(设了则事件 AES 解密)",type:"password"},{key:"port",label:"本机监听端口(默认 9800)",type:"number",placeholder:"9800"},{key:"path",label:"监听路径(默认 /feishu)",type:"text",placeholder:"/feishu"},{key:"allowedChats",label:"允许的 chat_id(白名单,空=全放)",type:"list"}]};function Kre(){var x,v,w;const e=Xt(),{alert:t}=Un(),n=Je({queryKey:["channels"],queryFn:Sre}),[i,s]=_.useState(null),[r,o]=_.useState({type:"console"});_.useEffect(()=>{n.data&&!i&&s({console:n.data.console??{},adapters:n.data.adapters??[]})},[n.data,i]);const c=At({mutationFn:()=>Nre(i),onSuccess:k=>{s({console:k.console??{},adapters:k.adapters??[]}),e.invalidateQueries({queryKey:["channels"]})},onError:k=>void t({title:"保存失败",body:k instanceof Error?k.message:String(k)})});if(!i)return u.jsx("section",{className:"nb-card",children:u.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[u.jsx(ht,{size:14,strokeWidth:3,className:"animate-spin"})," 加载频道配置…"]})});const d=i.adapters??[],f=JSON.stringify(i)!==JSON.stringify({console:((x=n.data)==null?void 0:x.console)??{},adapters:((v=n.data)==null?void 0:v.adapters)??[]}),m=k=>{const C=[...d,{kind:k,enabled:!0}];s({...i,adapters:C}),o({type:"adapter",index:C.length-1})},p=k=>{const C=d.filter((S,j)=>j!==k);s({...i,adapters:C}),o({type:"console"})},b=(k,C)=>{const S=d.map((j,T)=>T===k?{...j,...C}:j);s({...i,adapters:S})},y=k=>s({...i,console:{...i.console,...k}});return u.jsxs("section",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[u.jsxs("div",{children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:"频道(IM 网关)"}),u.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["接入 Telegram / 钉钉 / 飞书 / Slack / Discord / Matrix。左侧选频道,右侧改设置。保存后 ",u.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:"sps im"})," 重启生效。"]})]}),u.jsxs("button",{className:"nb-btn nb-btn-primary shrink-0",style:{padding:"8px 16px"},type:"button",disabled:!f||c.isPending,onClick:()=>c.mutate(),"aria-label":"保存频道配置",children:[c.isPending?u.jsx(ht,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(cs,{size:14,strokeWidth:3})," 保存"]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[220px_1fr] gap-5 mt-4",children:[u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"rounded-2xl border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] p-2 flex flex-col gap-1",children:[u.jsx(Fj,{label:"console 桥接",sub:((w=i.console)==null?void 0:w.url)||"未配置",active:r.type==="console",onClick:()=>o({type:"console"})}),u.jsx("div",{className:"h-px bg-[var(--color-text)] opacity-15 my-0.5"}),d.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] px-2 py-1",children:"(无频道)"}),d.map((k,C)=>u.jsx(Fj,{label:Yd[k.kind]??k.kind,sub:k.enabled===!1?"已停用":"启用",active:r.type==="adapter"&&r.index===C,onClick:()=>o({type:"adapter",index:C})},C))]}),u.jsx(Gre,{onAdd:m})]}),u.jsx("div",{className:"border-2 bg-surface-input border-[var(--color-text)] rounded-xl p-4 bg-[var(--color-bg-cream)]",children:(()=>{if(r.type!=="adapter")return u.jsx($j,{console:i.console??{},onChange:y});const k=d[r.index];if(!k)return u.jsx($j,{console:i.console??{},onChange:y});const C=r.index;return u.jsx(Wre,{adapter:k,onChange:S=>b(C,S),onRemove:()=>p(C)})})()})]})]})}function Gre({onAdd:e}){const[t,n]=_.useState(!1),i=_.useRef(null),s=_.useRef(null);return _.useEffect(()=>{const r=o=>{var c;(c=i.current)!=null&&c.contains(o.target)||n(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[]),u.jsxs("div",{className:"relative",ref:i,children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-primary w-full justify-center",onClick:()=>n(r=>!r),"aria-expanded":t,"aria-label":"添加频道",children:[u.jsx(Bn,{size:13,strokeWidth:3})," 添加频道",u.jsx(uo,{size:13,strokeWidth:2.5,className:["transition-transform",t?"rotate-180":""].join(" ")})]}),t&&u.jsx("div",{className:"mt-2 min-w-full nb-card p-1 overflow-hidden bg-[var(--surface-menu)]",children:u.jsx("div",{ref:s,className:"max-h-[50vh] overflow-y-auto",children:Hre.map((r,o)=>u.jsx(cu,{index:o,root:s,delay:.02,children:u.jsxs("button",{type:"button",className:"dimension-menu-item w-full text-left px-4 py-2 text-sm font-semibold flex items-center gap-2",onClick:()=>{e(r),n(!1)},"aria-label":`添加 ${Yd[r]} 频道`,children:[u.jsx(Bn,{size:12,strokeWidth:3,className:"shrink-0"})," ",Yd[r]]})},r))})})]})}function Fj({label:e,sub:t,active:n,onClick:i}){return u.jsxs("button",{type:"button",onClick:i,"aria-pressed":n,className:["dimension-menu-item flex-col items-start gap-0.5 px-3 py-2 text-left",n?"dimension-menu-item-active":""].join(" "),children:[u.jsx("div",{className:"font-bold text-sm",children:e}),u.jsx("div",{className:"text-xs text-[var(--color-text-muted)] truncate w-full font-[family-name:var(--font-mono)]",children:t})]})}function $j({console:e,onChange:t}){return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{children:[u.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"console 桥接"}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:"IM 纯文本消息桥接到项目 agent 对话。设了 URL 才启用桥接;token 为 console 鉴权令牌。"})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console URL",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:e.url??"",onChange:n=>t({url:n.target.value}),placeholder:"http://localhost:4321",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console Token(SPS_CONSOLE_TOKEN)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:e.token??"",onChange:n=>t({token:n.target.value}),placeholder:"鉴权令牌(可空)",spellCheck:!1})]}),u.jsxs("div",{className:"flex flex-col gap-1 text-sm font-bold",children:["对话后端",u.jsx(Nc,{value:e.agentKind??"claude",onChange:n=>t({agentKind:n}),ariaLabel:"对话后端",options:[{value:"claude",label:"claude"},{value:"openai",label:"openai"}]})]})]})}function Wre({adapter:e,onChange:t,onRemove:n}){const{confirm:i}=Un(),s=Vre[e.kind]??[],r=e.enabled!==!1;return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"flex items-start justify-between gap-2",children:[u.jsxs("div",{children:[u.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:Yd[e.kind]??e.kind}),u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-[family-name:var(--font-mono)]",children:[" · ",e.kind]})]}),u.jsxs("button",{className:"nb-btn nb-btn-danger shrink-0",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:async()=>{await i({title:"删除频道",body:`删除 ${Yd[e.kind]??e.kind} 频道?`,danger:!0})&&n()},"aria-label":"删除频道",children:[u.jsx(us,{size:12,strokeWidth:3})," 删除"]})]}),u.jsxs("label",{className:"flex items-center gap-2 text-sm font-bold",children:[u.jsx("input",{type:"checkbox",checked:r,onChange:o=>t({enabled:o.target.checked})}),"启用此频道"]}),s.map(o=>u.jsx(Yre,{spec:o,value:e[o.key],onChange:c=>t({[o.key]:c})},o.key))]})}function Yre({spec:e,value:t,onChange:n}){if(e.type==="list"){const i=Array.isArray(t)?t.map(String):[];return u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,u.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",rows:2,value:i.join(", "),onChange:s=>{const r=s.target.value.split(/[,\n]/).map(o=>o.trim()).filter(Boolean);n(r.length?r:void 0)},placeholder:e.placeholder,spellCheck:!1})]})}return u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:e.type==="password"?"password":"text",value:t==null?"":String(t),onChange:i=>{const s=i.target.value;e.type==="number"?n(s.trim()===""?void 0:Number(s)):n(s===""?void 0:s)},placeholder:e.placeholder,spellCheck:!1})]})}const Xre=["skill","asset","project","interaction","memory","agent","other"];function Qre(){const e=Ye(),t=Je({queryKey:["mcp-tools"],queryFn:Lre});if(t.isLoading)return u.jsx("section",{className:"nb-card",children:u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("plugins.tool.loading")})});if(t.isError)return u.jsx("section",{className:"nb-card",children:u.jsxs("p",{className:"text-sm text-[var(--color-crashed)]",children:[e("plugins.tool.failed"),":",t.error instanceof Error?t.error.message:String(t.error)]})});const n=t.data??[],i=Xre.map(s=>({key:s,items:n.filter(r=>r.group===s)})).filter(s=>s.items.length>0);return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx("section",{className:"nb-card",children:u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("plugins.tool.desc",{count:String(n.length)})})}),i.map(s=>u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:[e(`plugins.tool.group.${s.key}`),u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)] ml-2",children:s.items.length})]}),u.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:s.items.map(r=>u.jsxs("section",{className:"nb-card flex flex-col gap-2",children:[u.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-sm font-bold",children:r.name}),!r.viaMcpOnOpenai&&u.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded-lg border-2 border-[var(--color-text)] bg-[var(--color-secondary)]",children:e("plugins.tool.nativeOnOpenai")})]}),u.jsx("p",{className:"text-sm leading-5",children:r.description}),r.params.length>0&&u.jsx("ul",{className:"flex flex-col gap-1 m-0 p-0 list-none",children:r.params.map(o=>u.jsxs("li",{className:"text-xs text-[var(--color-text-muted)] leading-4",children:[u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[var(--color-text)]",children:o.name}),u.jsx("span",{className:"ml-1",children:o.type}),o.required&&u.jsx("span",{className:"ml-1 font-bold",children:e("plugins.tool.required")}),o.description&&u.jsxs("span",{className:"ml-1",children:["— ",o.description]})]},o.name))}),u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[11px] text-[var(--color-text-subtle)]",children:r.qualifiedName})]},r.name))})]},s.key))]})}function Wn(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,i;n<e.length;n++)(i=Wn(e[n]))!==""&&(t+=(t&&" ")+i);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var Zre={value:()=>{}};function mg(){for(var e=0,t=arguments.length,n={},i;e<t;++e){if(!(i=arguments[e]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new Kp(n)}function Kp(e){this._=e}function Jre(e,t){return e.trim().split(/^|\s+/).map(function(n){var i="",s=n.indexOf(".");if(s>=0&&(i=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}Kp.prototype=mg.prototype={constructor:Kp,on:function(e,t){var n=this._,i=Jre(e+"",n),s,r=-1,o=i.length;if(arguments.length<2){for(;++r<o;)if((s=(e=i[r]).type)&&(s=eae(n[s],e.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++r<o;)if(s=(e=i[r]).type)n[s]=qj(n[s],e.name,t);else if(t==null)for(s in n)n[s]=qj(n[s],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new Kp(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),i=0,s,r;i<s;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(r=this._[e],i=0,s=r.length;i<s;++i)r[i].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],s=0,r=i.length;s<r;++s)i[s].value.apply(t,n)}};function eae(e,t){for(var n=0,i=e.length,s;n<i;++n)if((s=e[n]).name===t)return s.value}function qj(e,t,n){for(var i=0,s=e.length;i<s;++i)if(e[i].name===t){e[i]=Zre,e=e.slice(0,i).concat(e.slice(i+1));break}return n!=null&&e.push({name:t,value:n}),e}var D0="http://www.w3.org/1999/xhtml";const Hj={svg:"http://www.w3.org/2000/svg",xhtml:D0,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function gg(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Hj.hasOwnProperty(t)?{space:Hj[t],local:e}:e}function tae(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===D0&&t.documentElement.namespaceURI===D0?t.createElement(e):t.createElementNS(n,e)}}function nae(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function MI(e){var t=gg(e);return(t.local?nae:tae)(t)}function iae(){}function Lw(e){return e==null?iae:function(){return this.querySelector(e)}}function sae(e){typeof e!="function"&&(e=Lw(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=new Array(o),d,f,m=0;m<o;++m)(d=r[m])&&(f=e.call(d,d.__data__,m,r))&&("__data__"in d&&(f.__data__=d.__data__),c[m]=f);return new os(i,this._parents)}function rae(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function aae(){return[]}function RI(e){return e==null?aae:function(){return this.querySelectorAll(e)}}function oae(e){return function(){return rae(e.apply(this,arguments))}}function lae(e){typeof e=="function"?e=oae(e):e=RI(e);for(var t=this._groups,n=t.length,i=[],s=[],r=0;r<n;++r)for(var o=t[r],c=o.length,d,f=0;f<c;++f)(d=o[f])&&(i.push(e.call(d,d.__data__,f,o)),s.push(d));return new os(i,s)}function DI(e){return function(){return this.matches(e)}}function OI(e){return function(t){return t.matches(e)}}var cae=Array.prototype.find;function uae(e){return function(){return cae.call(this.children,e)}}function dae(){return this.firstElementChild}function fae(e){return this.select(e==null?dae:uae(typeof e=="function"?e:OI(e)))}var hae=Array.prototype.filter;function pae(){return Array.from(this.children)}function mae(e){return function(){return hae.call(this.children,e)}}function gae(e){return this.selectAll(e==null?pae:mae(typeof e=="function"?e:OI(e)))}function yae(e){typeof e!="function"&&(e=DI(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=[],d,f=0;f<o;++f)(d=r[f])&&e.call(d,d.__data__,f,r)&&c.push(d);return new os(i,this._parents)}function LI(e){return new Array(e.length)}function bae(){return new os(this._enter||this._groups.map(LI),this._parents)}function jm(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}jm.prototype={constructor:jm,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function xae(e){return function(){return e}}function vae(e,t,n,i,s,r){for(var o=0,c,d=t.length,f=r.length;o<f;++o)(c=t[o])?(c.__data__=r[o],i[o]=c):n[o]=new jm(e,r[o]);for(;o<d;++o)(c=t[o])&&(s[o]=c)}function wae(e,t,n,i,s,r,o){var c,d,f=new Map,m=t.length,p=r.length,b=new Array(m),y;for(c=0;c<m;++c)(d=t[c])&&(b[c]=y=o.call(d,d.__data__,c,t)+"",f.has(y)?s[c]=d:f.set(y,d));for(c=0;c<p;++c)y=o.call(e,r[c],c,r)+"",(d=f.get(y))?(i[c]=d,d.__data__=r[c],f.delete(y)):n[c]=new jm(e,r[c]);for(c=0;c<m;++c)(d=t[c])&&f.get(b[c])===d&&(s[c]=d)}function Eae(e){return e.__data__}function kae(e,t){if(!arguments.length)return Array.from(this,Eae);var n=t?wae:vae,i=this._parents,s=this._groups;typeof e!="function"&&(e=xae(e));for(var r=s.length,o=new Array(r),c=new Array(r),d=new Array(r),f=0;f<r;++f){var m=i[f],p=s[f],b=p.length,y=Sae(e.call(m,m&&m.__data__,f,i)),x=y.length,v=c[f]=new Array(x),w=o[f]=new Array(x),k=d[f]=new Array(b);n(m,p,v,w,k,y,t);for(var C=0,S=0,j,T;C<x;++C)if(j=v[C]){for(C>=S&&(S=C+1);!(T=w[S])&&++S<x;);j._next=T||null}}return o=new os(o,i),o._enter=c,o._exit=d,o}function Sae(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Nae(){return new os(this._exit||this._groups.map(LI),this._parents)}function _ae(e,t,n){var i=this.enter(),s=this,r=this.exit();return typeof e=="function"?(i=e(i),i&&(i=i.selection())):i=i.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?r.remove():n(r),i&&s?i.merge(s).order():s}function Cae(e){for(var t=e.selection?e.selection():e,n=this._groups,i=t._groups,s=n.length,r=i.length,o=Math.min(s,r),c=new Array(s),d=0;d<o;++d)for(var f=n[d],m=i[d],p=f.length,b=c[d]=new Array(p),y,x=0;x<p;++x)(y=f[x]||m[x])&&(b[x]=y);for(;d<s;++d)c[d]=n[d];return new os(c,this._parents)}function jae(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var i=e[t],s=i.length-1,r=i[s],o;--s>=0;)(o=i[s])&&(r&&o.compareDocumentPosition(r)^4&&r.parentNode.insertBefore(o,r),r=o);return this}function Tae(e){e||(e=Aae);function t(p,b){return p&&b?e(p.__data__,b.__data__):!p-!b}for(var n=this._groups,i=n.length,s=new Array(i),r=0;r<i;++r){for(var o=n[r],c=o.length,d=s[r]=new Array(c),f,m=0;m<c;++m)(f=o[m])&&(d[m]=f);d.sort(t)}return new os(s,this._parents).order()}function Aae(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Mae(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Rae(){return Array.from(this)}function Dae(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],s=0,r=i.length;s<r;++s){var o=i[s];if(o)return o}return null}function Oae(){let e=0;for(const t of this)++e;return e}function Lae(){return!this.node()}function Iae(e){for(var t=this._groups,n=0,i=t.length;n<i;++n)for(var s=t[n],r=0,o=s.length,c;r<o;++r)(c=s[r])&&e.call(c,c.__data__,r,s);return this}function Pae(e){return function(){this.removeAttribute(e)}}function zae(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Bae(e,t){return function(){this.setAttribute(e,t)}}function Uae(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Fae(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function $ae(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function qae(e,t){var n=gg(e);if(arguments.length<2){var i=this.node();return n.local?i.getAttributeNS(n.space,n.local):i.getAttribute(n)}return this.each((t==null?n.local?zae:Pae:typeof t=="function"?n.local?$ae:Fae:n.local?Uae:Bae)(n,t))}function II(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Hae(e){return function(){this.style.removeProperty(e)}}function Vae(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Kae(e,t,n){return function(){var i=t.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,n)}}function Gae(e,t,n){return arguments.length>1?this.each((t==null?Hae:typeof t=="function"?Kae:Vae)(e,t,n??"")):Wc(this.node(),e)}function Wc(e,t){return e.style.getPropertyValue(t)||II(e).getComputedStyle(e,null).getPropertyValue(t)}function Wae(e){return function(){delete this[e]}}function Yae(e,t){return function(){this[e]=t}}function Xae(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Qae(e,t){return arguments.length>1?this.each((t==null?Wae:typeof t=="function"?Xae:Yae)(e,t)):this.node()[e]}function PI(e){return e.trim().split(/^|\s+/)}function Iw(e){return e.classList||new zI(e)}function zI(e){this._node=e,this._names=PI(e.getAttribute("class")||"")}zI.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 BI(e,t){for(var n=Iw(e),i=-1,s=t.length;++i<s;)n.add(t[i])}function UI(e,t){for(var n=Iw(e),i=-1,s=t.length;++i<s;)n.remove(t[i])}function Zae(e){return function(){BI(this,e)}}function Jae(e){return function(){UI(this,e)}}function eoe(e,t){return function(){(t.apply(this,arguments)?BI:UI)(this,e)}}function toe(e,t){var n=PI(e+"");if(arguments.length<2){for(var i=Iw(this.node()),s=-1,r=n.length;++s<r;)if(!i.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?eoe:t?Zae:Jae)(n,t))}function noe(){this.textContent=""}function ioe(e){return function(){this.textContent=e}}function soe(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function roe(e){return arguments.length?this.each(e==null?noe:(typeof e=="function"?soe:ioe)(e)):this.node().textContent}function aoe(){this.innerHTML=""}function ooe(e){return function(){this.innerHTML=e}}function loe(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function coe(e){return arguments.length?this.each(e==null?aoe:(typeof e=="function"?loe:ooe)(e)):this.node().innerHTML}function uoe(){this.nextSibling&&this.parentNode.appendChild(this)}function doe(){return this.each(uoe)}function foe(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function hoe(){return this.each(foe)}function poe(e){var t=typeof e=="function"?e:MI(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function moe(){return null}function goe(e,t){var n=typeof e=="function"?e:MI(e),i=t==null?moe:typeof t=="function"?t:Lw(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})}function yoe(){var e=this.parentNode;e&&e.removeChild(this)}function boe(){return this.each(yoe)}function xoe(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function voe(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function woe(e){return this.select(e?voe:xoe)}function Eoe(e){return arguments.length?this.property("__data__",e):this.node().__data__}function koe(e){return function(t){e.call(this,t,this.__data__)}}function Soe(e){return e.trim().split(/^|\s+/).map(function(t){var n="",i=t.indexOf(".");return i>=0&&(n=t.slice(i+1),t=t.slice(0,i)),{type:t,name:n}})}function Noe(e){return function(){var t=this.__on;if(t){for(var n=0,i=-1,s=t.length,r;n<s;++n)r=t[n],(!e.type||r.type===e.type)&&r.name===e.name?this.removeEventListener(r.type,r.listener,r.options):t[++i]=r;++i?t.length=i:delete this.__on}}}function _oe(e,t,n){return function(){var i=this.__on,s,r=koe(t);if(i){for(var o=0,c=i.length;o<c;++o)if((s=i[o]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=r,s.options=n),s.value=t;return}}this.addEventListener(e.type,r,n),s={type:e.type,name:e.name,value:t,listener:r,options:n},i?i.push(s):this.__on=[s]}}function Coe(e,t,n){var i=Soe(e+""),s,r=i.length,o;if(arguments.length<2){var c=this.node().__on;if(c){for(var d=0,f=c.length,m;d<f;++d)for(s=0,m=c[d];s<r;++s)if((o=i[s]).type===m.type&&o.name===m.name)return m.value}return}for(c=t?_oe:Noe,s=0;s<r;++s)this.each(c(i[s],t,n));return this}function FI(e,t,n){var i=II(e),s=i.CustomEvent;typeof s=="function"?s=new s(t,n):(s=i.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function joe(e,t){return function(){return FI(this,e,t)}}function Toe(e,t){return function(){return FI(this,e,t.apply(this,arguments))}}function Aoe(e,t){return this.each((typeof t=="function"?Toe:joe)(e,t))}function*Moe(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],s=0,r=i.length,o;s<r;++s)(o=i[s])&&(yield o)}var $I=[null];function os(e,t){this._groups=e,this._parents=t}function Af(){return new os([[document.documentElement]],$I)}function Roe(){return this}os.prototype=Af.prototype={constructor:os,select:sae,selectAll:lae,selectChild:fae,selectChildren:gae,filter:yae,data:kae,enter:bae,exit:Nae,join:_ae,merge:Cae,selection:Roe,order:jae,sort:Tae,call:Mae,nodes:Rae,node:Dae,size:Oae,empty:Lae,each:Iae,attr:qae,style:Gae,property:Qae,classed:toe,text:roe,html:coe,raise:doe,lower:hoe,append:poe,insert:goe,remove:boe,clone:woe,datum:Eoe,on:Coe,dispatch:Aoe,[Symbol.iterator]:Moe};function ss(e){return typeof e=="string"?new os([[document.querySelector(e)]],[document.documentElement]):new os([[e]],$I)}function Doe(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Gs(e,t){if(e=Doe(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var i=n.createSVGPoint();return i.x=e.clientX,i.y=e.clientY,i=i.matrixTransform(t.getScreenCTM().inverse()),[i.x,i.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[e.clientX-s.left-t.clientLeft,e.clientY-s.top-t.clientTop]}}return[e.pageX,e.pageY]}const Ooe={passive:!1},Xd={capture:!0,passive:!1};function qx(e){e.stopImmediatePropagation()}function Cc(e){e.preventDefault(),e.stopImmediatePropagation()}function qI(e){var t=e.document.documentElement,n=ss(e).on("dragstart.drag",Cc,Xd);"onselectstart"in t?n.on("selectstart.drag",Cc,Xd):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function HI(e,t){var n=e.document.documentElement,i=ss(e).on("dragstart.drag",null);t&&(i.on("click.drag",Cc,Xd),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in n?i.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const yp=e=>()=>e;function O0(e,{sourceEvent:t,subject:n,target:i,identifier:s,active:r,x:o,y:c,dx:d,dy:f,dispatch:m}){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:i,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:r,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:c,enumerable:!0,configurable:!0},dx:{value:d,enumerable:!0,configurable:!0},dy:{value:f,enumerable:!0,configurable:!0},_:{value:m}})}O0.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Loe(e){return!e.ctrlKey&&!e.button}function Ioe(){return this.parentNode}function Poe(e,t){return t??{x:e.x,y:e.y}}function zoe(){return navigator.maxTouchPoints||"ontouchstart"in this}function VI(){var e=Loe,t=Ioe,n=Poe,i=zoe,s={},r=mg("start","drag","end"),o=0,c,d,f,m,p=0;function b(j){j.on("mousedown.drag",y).filter(i).on("touchstart.drag",w).on("touchmove.drag",k,Ooe).on("touchend.drag touchcancel.drag",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function y(j,T){if(!(m||!e.call(this,j,T))){var A=S(this,t.call(this,j,T),j,T,"mouse");A&&(ss(j.view).on("mousemove.drag",x,Xd).on("mouseup.drag",v,Xd),qI(j.view),qx(j),f=!1,c=j.clientX,d=j.clientY,A("start",j))}}function x(j){if(Cc(j),!f){var T=j.clientX-c,A=j.clientY-d;f=T*T+A*A>p}s.mouse("drag",j)}function v(j){ss(j.view).on("mousemove.drag mouseup.drag",null),HI(j.view,f),Cc(j),s.mouse("end",j)}function w(j,T){if(e.call(this,j,T)){var A=j.changedTouches,M=t.call(this,j,T),R=A.length,P,O;for(P=0;P<R;++P)(O=S(this,M,j,T,A[P].identifier,A[P]))&&(qx(j),O("start",j,A[P]))}}function k(j){var T=j.changedTouches,A=T.length,M,R;for(M=0;M<A;++M)(R=s[T[M].identifier])&&(Cc(j),R("drag",j,T[M]))}function C(j){var T=j.changedTouches,A=T.length,M,R;for(m&&clearTimeout(m),m=setTimeout(function(){m=null},500),M=0;M<A;++M)(R=s[T[M].identifier])&&(qx(j),R("end",j,T[M]))}function S(j,T,A,M,R,P){var O=r.copy(),B=Gs(P||A,T),F,V,D;if((D=n.call(j,new O0("beforestart",{sourceEvent:A,target:b,identifier:R,active:o,x:B[0],y:B[1],dx:0,dy:0,dispatch:O}),M))!=null)return F=D.x-B[0]||0,V=D.y-B[1]||0,function I(z,W,X){var G=B,U;switch(z){case"start":s[R]=I,U=o++;break;case"end":delete s[R],--o;case"drag":B=Gs(X||W,T),U=o;break}O.call(z,j,new O0(z,{sourceEvent:W,subject:D,target:b,identifier:R,active:U,x:B[0]+F,y:B[1]+V,dx:B[0]-G[0],dy:B[1]-G[1],dispatch:O}),M)}}return b.filter=function(j){return arguments.length?(e=typeof j=="function"?j:yp(!!j),b):e},b.container=function(j){return arguments.length?(t=typeof j=="function"?j:yp(j),b):t},b.subject=function(j){return arguments.length?(n=typeof j=="function"?j:yp(j),b):n},b.touchable=function(j){return arguments.length?(i=typeof j=="function"?j:yp(!!j),b):i},b.on=function(){var j=r.on.apply(r,arguments);return j===r?b:j},b.clickDistance=function(j){return arguments.length?(p=(j=+j)*j,b):Math.sqrt(p)},b}function Pw(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function KI(e,t){var n=Object.create(e.prototype);for(var i in t)n[i]=t[i];return n}function Mf(){}var Qd=.7,Tm=1/Qd,jc="\\s*([+-]?\\d+)\\s*",Zd="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Sr="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Boe=/^#([0-9a-f]{3,8})$/,Uoe=new RegExp(`^rgb\\(${jc},${jc},${jc}\\)$`),Foe=new RegExp(`^rgb\\(${Sr},${Sr},${Sr}\\)$`),$oe=new RegExp(`^rgba\\(${jc},${jc},${jc},${Zd}\\)$`),qoe=new RegExp(`^rgba\\(${Sr},${Sr},${Sr},${Zd}\\)$`),Hoe=new RegExp(`^hsl\\(${Zd},${Sr},${Sr}\\)$`),Voe=new RegExp(`^hsla\\(${Zd},${Sr},${Sr},${Zd}\\)$`),Vj={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Pw(Mf,gl,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Kj,formatHex:Kj,formatHex8:Koe,formatHsl:Goe,formatRgb:Gj,toString:Gj});function Kj(){return this.rgb().formatHex()}function Koe(){return this.rgb().formatHex8()}function Goe(){return GI(this).formatHsl()}function Gj(){return this.rgb().formatRgb()}function gl(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=Boe.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Wj(t):n===3?new Hi(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?bp(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?bp(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=Uoe.exec(e))?new Hi(t[1],t[2],t[3],1):(t=Foe.exec(e))?new Hi(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=$oe.exec(e))?bp(t[1],t[2],t[3],t[4]):(t=qoe.exec(e))?bp(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Hoe.exec(e))?Qj(t[1],t[2]/100,t[3]/100,1):(t=Voe.exec(e))?Qj(t[1],t[2]/100,t[3]/100,t[4]):Vj.hasOwnProperty(e)?Wj(Vj[e]):e==="transparent"?new Hi(NaN,NaN,NaN,0):null}function Wj(e){return new Hi(e>>16&255,e>>8&255,e&255,1)}function bp(e,t,n,i){return i<=0&&(e=t=n=NaN),new Hi(e,t,n,i)}function Woe(e){return e instanceof Mf||(e=gl(e)),e?(e=e.rgb(),new Hi(e.r,e.g,e.b,e.opacity)):new Hi}function L0(e,t,n,i){return arguments.length===1?Woe(e):new Hi(e,t,n,i??1)}function Hi(e,t,n,i){this.r=+e,this.g=+t,this.b=+n,this.opacity=+i}Pw(Hi,L0,KI(Mf,{brighter(e){return e=e==null?Tm:Math.pow(Tm,e),new Hi(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Qd:Math.pow(Qd,e),new Hi(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Hi(cl(this.r),cl(this.g),cl(this.b),Am(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:Yj,formatHex:Yj,formatHex8:Yoe,formatRgb:Xj,toString:Xj}));function Yj(){return`#${Yo(this.r)}${Yo(this.g)}${Yo(this.b)}`}function Yoe(){return`#${Yo(this.r)}${Yo(this.g)}${Yo(this.b)}${Yo((isNaN(this.opacity)?1:this.opacity)*255)}`}function Xj(){const e=Am(this.opacity);return`${e===1?"rgb(":"rgba("}${cl(this.r)}, ${cl(this.g)}, ${cl(this.b)}${e===1?")":`, ${e})`}`}function Am(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function cl(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Yo(e){return e=cl(e),(e<16?"0":"")+e.toString(16)}function Qj(e,t,n,i){return i<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ws(e,t,n,i)}function GI(e){if(e instanceof Ws)return new Ws(e.h,e.s,e.l,e.opacity);if(e instanceof Mf||(e=gl(e)),!e)return new Ws;if(e instanceof Ws)return e;e=e.rgb();var t=e.r/255,n=e.g/255,i=e.b/255,s=Math.min(t,n,i),r=Math.max(t,n,i),o=NaN,c=r-s,d=(r+s)/2;return c?(t===r?o=(n-i)/c+(n<i)*6:n===r?o=(i-t)/c+2:o=(t-n)/c+4,c/=d<.5?r+s:2-r-s,o*=60):c=d>0&&d<1?0:o,new Ws(o,c,d,e.opacity)}function Xoe(e,t,n,i){return arguments.length===1?GI(e):new Ws(e,t,n,i??1)}function Ws(e,t,n,i){this.h=+e,this.s=+t,this.l=+n,this.opacity=+i}Pw(Ws,Xoe,KI(Mf,{brighter(e){return e=e==null?Tm:Math.pow(Tm,e),new Ws(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Qd:Math.pow(Qd,e),new Ws(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,i=n+(n<.5?n:1-n)*t,s=2*n-i;return new Hi(Hx(e>=240?e-240:e+120,s,i),Hx(e,s,i),Hx(e<120?e+240:e-120,s,i),this.opacity)},clamp(){return new Ws(Zj(this.h),xp(this.s),xp(this.l),Am(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=Am(this.opacity);return`${e===1?"hsl(":"hsla("}${Zj(this.h)}, ${xp(this.s)*100}%, ${xp(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Zj(e){return e=(e||0)%360,e<0?e+360:e}function xp(e){return Math.max(0,Math.min(1,e||0))}function Hx(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 zw=e=>()=>e;function Qoe(e,t){return function(n){return e+n*t}}function Zoe(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(i){return Math.pow(e+i*t,n)}}function Joe(e){return(e=+e)==1?WI:function(t,n){return n-t?Zoe(t,n,e):zw(isNaN(t)?n:t)}}function WI(e,t){var n=t-e;return n?Qoe(e,n):zw(isNaN(e)?t:e)}const Mm=(function e(t){var n=Joe(t);function i(s,r){var o=n((s=L0(s)).r,(r=L0(r)).r),c=n(s.g,r.g),d=n(s.b,r.b),f=WI(s.opacity,r.opacity);return function(m){return s.r=o(m),s.g=c(m),s.b=d(m),s.opacity=f(m),s+""}}return i.gamma=e,i})(1);function ele(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,i=t.slice(),s;return function(r){for(s=0;s<n;++s)i[s]=e[s]*(1-r)+t[s]*r;return i}}function tle(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function nle(e,t){var n=t?t.length:0,i=e?Math.min(n,e.length):0,s=new Array(i),r=new Array(n),o;for(o=0;o<i;++o)s[o]=Dd(e[o],t[o]);for(;o<n;++o)r[o]=t[o];return function(c){for(o=0;o<i;++o)r[o]=s[o](c);return r}}function ile(e,t){var n=new Date;return e=+e,t=+t,function(i){return n.setTime(e*(1-i)+t*i),n}}function wr(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function sle(e,t){var n={},i={},s;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(s in t)s in e?n[s]=Dd(e[s],t[s]):i[s]=t[s];return function(r){for(s in n)i[s]=n[s](r);return i}}var I0=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Vx=new RegExp(I0.source,"g");function rle(e){return function(){return e}}function ale(e){return function(t){return e(t)+""}}function YI(e,t){var n=I0.lastIndex=Vx.lastIndex=0,i,s,r,o=-1,c=[],d=[];for(e=e+"",t=t+"";(i=I0.exec(e))&&(s=Vx.exec(t));)(r=s.index)>n&&(r=t.slice(n,r),c[o]?c[o]+=r:c[++o]=r),(i=i[0])===(s=s[0])?c[o]?c[o]+=s:c[++o]=s:(c[++o]=null,d.push({i:o,x:wr(i,s)})),n=Vx.lastIndex;return n<t.length&&(r=t.slice(n),c[o]?c[o]+=r:c[++o]=r),c.length<2?d[0]?ale(d[0].x):rle(t):(t=d.length,function(f){for(var m=0,p;m<t;++m)c[(p=d[m]).i]=p.x(f);return c.join("")})}function Dd(e,t){var n=typeof t,i;return t==null||n==="boolean"?zw(t):(n==="number"?wr:n==="string"?(i=gl(t))?(t=i,Mm):YI:t instanceof gl?Mm:t instanceof Date?ile:tle(t)?ele:Array.isArray(t)?nle:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?sle:wr)(e,t)}var Jj=180/Math.PI,P0={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function XI(e,t,n,i,s,r){var o,c,d;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(d=e*n+t*i)&&(n-=e*d,i-=t*d),(c=Math.sqrt(n*n+i*i))&&(n/=c,i/=c,d/=c),e*i<t*n&&(e=-e,t=-t,d=-d,o=-o),{translateX:s,translateY:r,rotate:Math.atan2(t,e)*Jj,skewX:Math.atan(d)*Jj,scaleX:o,scaleY:c}}var vp;function ole(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?P0:XI(t.a,t.b,t.c,t.d,t.e,t.f)}function lle(e){return e==null||(vp||(vp=document.createElementNS("http://www.w3.org/2000/svg","g")),vp.setAttribute("transform",e),!(e=vp.transform.baseVal.consolidate()))?P0:(e=e.matrix,XI(e.a,e.b,e.c,e.d,e.e,e.f))}function QI(e,t,n,i){function s(f){return f.length?f.pop()+" ":""}function r(f,m,p,b,y,x){if(f!==p||m!==b){var v=y.push("translate(",null,t,null,n);x.push({i:v-4,x:wr(f,p)},{i:v-2,x:wr(m,b)})}else(p||b)&&y.push("translate("+p+t+b+n)}function o(f,m,p,b){f!==m?(f-m>180?m+=360:m-f>180&&(f+=360),b.push({i:p.push(s(p)+"rotate(",null,i)-2,x:wr(f,m)})):m&&p.push(s(p)+"rotate("+m+i)}function c(f,m,p,b){f!==m?b.push({i:p.push(s(p)+"skewX(",null,i)-2,x:wr(f,m)}):m&&p.push(s(p)+"skewX("+m+i)}function d(f,m,p,b,y,x){if(f!==p||m!==b){var v=y.push(s(y)+"scale(",null,",",null,")");x.push({i:v-4,x:wr(f,p)},{i:v-2,x:wr(m,b)})}else(p!==1||b!==1)&&y.push(s(y)+"scale("+p+","+b+")")}return function(f,m){var p=[],b=[];return f=e(f),m=e(m),r(f.translateX,f.translateY,m.translateX,m.translateY,p,b),o(f.rotate,m.rotate,p,b),c(f.skewX,m.skewX,p,b),d(f.scaleX,f.scaleY,m.scaleX,m.scaleY,p,b),f=m=null,function(y){for(var x=-1,v=b.length,w;++x<v;)p[(w=b[x]).i]=w.x(y);return p.join("")}}}var cle=QI(ole,"px, ","px)","deg)"),ule=QI(lle,", ",")",")"),dle=1e-12;function eT(e){return((e=Math.exp(e))+1/e)/2}function fle(e){return((e=Math.exp(e))-1/e)/2}function hle(e){return((e=Math.exp(2*e))-1)/(e+1)}const Gp=(function e(t,n,i){function s(r,o){var c=r[0],d=r[1],f=r[2],m=o[0],p=o[1],b=o[2],y=m-c,x=p-d,v=y*y+x*x,w,k;if(v<dle)k=Math.log(b/f)/t,w=function(M){return[c+M*y,d+M*x,f*Math.exp(t*M*k)]};else{var C=Math.sqrt(v),S=(b*b-f*f+i*v)/(2*f*n*C),j=(b*b-f*f-i*v)/(2*b*n*C),T=Math.log(Math.sqrt(S*S+1)-S),A=Math.log(Math.sqrt(j*j+1)-j);k=(A-T)/t,w=function(M){var R=M*k,P=eT(T),O=f/(n*C)*(P*hle(t*R+T)-fle(T));return[c+O*y,d+O*x,f*P/eT(t*R+T)]}}return w.duration=k*1e3*t/Math.SQRT2,w}return s.rho=function(r){var o=Math.max(.001,+r),c=o*o,d=c*c;return e(o,c,d)},s})(Math.SQRT2,2,4);var Yc=0,wd=0,hd=0,ZI=1e3,Rm,Ed,Dm=0,yl=0,yg=0,Jd=typeof performance=="object"&&performance.now?performance:Date,JI=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Bw(){return yl||(JI(ple),yl=Jd.now()+yg)}function ple(){yl=0}function Om(){this._call=this._time=this._next=null}Om.prototype=eP.prototype={constructor:Om,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Bw():+n)+(t==null?0:+t),!this._next&&Ed!==this&&(Ed?Ed._next=this:Rm=this,Ed=this),this._call=e,this._time=n,z0()},stop:function(){this._call&&(this._call=null,this._time=1/0,z0())}};function eP(e,t,n){var i=new Om;return i.restart(e,t,n),i}function mle(){Bw(),++Yc;for(var e=Rm,t;e;)(t=yl-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Yc}function tT(){yl=(Dm=Jd.now())+yg,Yc=wd=0;try{mle()}finally{Yc=0,yle(),yl=0}}function gle(){var e=Jd.now(),t=e-Dm;t>ZI&&(yg-=t,Dm=e)}function yle(){for(var e,t=Rm,n,i=1/0;t;)t._call?(i>t._time&&(i=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Rm=n);Ed=e,z0(i)}function z0(e){if(!Yc){wd&&(wd=clearTimeout(wd));var t=e-yl;t>24?(e<1/0&&(wd=setTimeout(tT,e-Jd.now()-yg)),hd&&(hd=clearInterval(hd))):(hd||(Dm=Jd.now(),hd=setInterval(gle,ZI)),Yc=1,JI(tT))}}function nT(e,t,n){var i=new Om;return t=t==null?0:+t,i.restart(s=>{i.stop(),e(s+t)},t,n),i}var ble=mg("start","end","cancel","interrupt"),xle=[],tP=0,iT=1,B0=2,Wp=3,sT=4,U0=5,Yp=6;function bg(e,t,n,i,s,r){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;vle(e,n,{name:t,index:i,group:s,on:ble,tween:xle,time:r.time,delay:r.delay,duration:r.duration,ease:r.ease,timer:null,state:tP})}function Uw(e,t){var n=sr(e,t);if(n.state>tP)throw new Error("too late; already scheduled");return n}function Ar(e,t){var n=sr(e,t);if(n.state>Wp)throw new Error("too late; already running");return n}function sr(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function vle(e,t,n){var i=e.__transition,s;i[t]=n,n.timer=eP(r,0,n.time);function r(f){n.state=iT,n.timer.restart(o,n.delay,n.time),n.delay<=f&&o(f-n.delay)}function o(f){var m,p,b,y;if(n.state!==iT)return d();for(m in i)if(y=i[m],y.name===n.name){if(y.state===Wp)return nT(o);y.state===sT?(y.state=Yp,y.timer.stop(),y.on.call("interrupt",e,e.__data__,y.index,y.group),delete i[m]):+m<t&&(y.state=Yp,y.timer.stop(),y.on.call("cancel",e,e.__data__,y.index,y.group),delete i[m])}if(nT(function(){n.state===Wp&&(n.state=sT,n.timer.restart(c,n.delay,n.time),c(f))}),n.state=B0,n.on.call("start",e,e.__data__,n.index,n.group),n.state===B0){for(n.state=Wp,s=new Array(b=n.tween.length),m=0,p=-1;m<b;++m)(y=n.tween[m].value.call(e,e.__data__,n.index,n.group))&&(s[++p]=y);s.length=p+1}}function c(f){for(var m=f<n.duration?n.ease.call(null,f/n.duration):(n.timer.restart(d),n.state=U0,1),p=-1,b=s.length;++p<b;)s[p].call(e,m);n.state===U0&&(n.on.call("end",e,e.__data__,n.index,n.group),d())}function d(){n.state=Yp,n.timer.stop(),delete i[t];for(var f in i)return;delete e.__transition}}function Xp(e,t){var n=e.__transition,i,s,r=!0,o;if(n){t=t==null?null:t+"";for(o in n){if((i=n[o]).name!==t){r=!1;continue}s=i.state>B0&&i.state<U0,i.state=Yp,i.timer.stop(),i.on.call(s?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete n[o]}r&&delete e.__transition}}function wle(e){return this.each(function(){Xp(this,e)})}function Ele(e,t){var n,i;return function(){var s=Ar(this,e),r=s.tween;if(r!==n){i=n=r;for(var o=0,c=i.length;o<c;++o)if(i[o].name===t){i=i.slice(),i.splice(o,1);break}}s.tween=i}}function kle(e,t,n){var i,s;if(typeof n!="function")throw new Error;return function(){var r=Ar(this,e),o=r.tween;if(o!==i){s=(i=o).slice();for(var c={name:t,value:n},d=0,f=s.length;d<f;++d)if(s[d].name===t){s[d]=c;break}d===f&&s.push(c)}r.tween=s}}function Sle(e,t){var n=this._id;if(e+="",arguments.length<2){for(var i=sr(this.node(),n).tween,s=0,r=i.length,o;s<r;++s)if((o=i[s]).name===e)return o.value;return null}return this.each((t==null?Ele:kle)(n,e,t))}function Fw(e,t,n){var i=e._id;return e.each(function(){var s=Ar(this,i);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return sr(s,i).value[t]}}function nP(e,t){var n;return(typeof t=="number"?wr:t instanceof gl?Mm:(n=gl(t))?(t=n,Mm):YI)(e,t)}function Nle(e){return function(){this.removeAttribute(e)}}function _le(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Cle(e,t,n){var i,s=n+"",r;return function(){var o=this.getAttribute(e);return o===s?null:o===i?r:r=t(i=o,n)}}function jle(e,t,n){var i,s=n+"",r;return function(){var o=this.getAttributeNS(e.space,e.local);return o===s?null:o===i?r:r=t(i=o,n)}}function Tle(e,t,n){var i,s,r;return function(){var o,c=n(this),d;return c==null?void this.removeAttribute(e):(o=this.getAttribute(e),d=c+"",o===d?null:o===i&&d===s?r:(s=d,r=t(i=o,c)))}}function Ale(e,t,n){var i,s,r;return function(){var o,c=n(this),d;return c==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),d=c+"",o===d?null:o===i&&d===s?r:(s=d,r=t(i=o,c)))}}function Mle(e,t){var n=gg(e),i=n==="transform"?ule:nP;return this.attrTween(e,typeof t=="function"?(n.local?Ale:Tle)(n,i,Fw(this,"attr."+e,t)):t==null?(n.local?_le:Nle)(n):(n.local?jle:Cle)(n,i,t))}function Rle(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Dle(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Ole(e,t){var n,i;function s(){var r=t.apply(this,arguments);return r!==i&&(n=(i=r)&&Dle(e,r)),n}return s._value=t,s}function Lle(e,t){var n,i;function s(){var r=t.apply(this,arguments);return r!==i&&(n=(i=r)&&Rle(e,r)),n}return s._value=t,s}function Ile(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var i=gg(e);return this.tween(n,(i.local?Ole:Lle)(i,t))}function Ple(e,t){return function(){Uw(this,e).delay=+t.apply(this,arguments)}}function zle(e,t){return t=+t,function(){Uw(this,e).delay=t}}function Ble(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Ple:zle)(t,e)):sr(this.node(),t).delay}function Ule(e,t){return function(){Ar(this,e).duration=+t.apply(this,arguments)}}function Fle(e,t){return t=+t,function(){Ar(this,e).duration=t}}function $le(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Ule:Fle)(t,e)):sr(this.node(),t).duration}function qle(e,t){if(typeof t!="function")throw new Error;return function(){Ar(this,e).ease=t}}function Hle(e){var t=this._id;return arguments.length?this.each(qle(t,e)):sr(this.node(),t).ease}function Vle(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ar(this,e).ease=n}}function Kle(e){if(typeof e!="function")throw new Error;return this.each(Vle(this._id,e))}function Gle(e){typeof e!="function"&&(e=DI(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=[],d,f=0;f<o;++f)(d=r[f])&&e.call(d,d.__data__,f,r)&&c.push(d);return new fa(i,this._parents,this._name,this._id)}function Wle(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,i=t.length,s=n.length,r=Math.min(i,s),o=new Array(i),c=0;c<r;++c)for(var d=t[c],f=n[c],m=d.length,p=o[c]=new Array(m),b,y=0;y<m;++y)(b=d[y]||f[y])&&(p[y]=b);for(;c<i;++c)o[c]=t[c];return new fa(o,this._parents,this._name,this._id)}function Yle(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function Xle(e,t,n){var i,s,r=Yle(t)?Uw:Ar;return function(){var o=r(this,e),c=o.on;c!==i&&(s=(i=c).copy()).on(t,n),o.on=s}}function Qle(e,t){var n=this._id;return arguments.length<2?sr(this.node(),n).on.on(e):this.each(Xle(n,e,t))}function Zle(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Jle(){return this.on("end.remove",Zle(this._id))}function ece(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Lw(e));for(var i=this._groups,s=i.length,r=new Array(s),o=0;o<s;++o)for(var c=i[o],d=c.length,f=r[o]=new Array(d),m,p,b=0;b<d;++b)(m=c[b])&&(p=e.call(m,m.__data__,b,c))&&("__data__"in m&&(p.__data__=m.__data__),f[b]=p,bg(f[b],t,n,b,f,sr(m,n)));return new fa(r,this._parents,t,n)}function tce(e){var t=this._name,n=this._id;typeof e!="function"&&(e=RI(e));for(var i=this._groups,s=i.length,r=[],o=[],c=0;c<s;++c)for(var d=i[c],f=d.length,m,p=0;p<f;++p)if(m=d[p]){for(var b=e.call(m,m.__data__,p,d),y,x=sr(m,n),v=0,w=b.length;v<w;++v)(y=b[v])&&bg(y,t,n,v,b,x);r.push(b),o.push(m)}return new fa(r,o,t,n)}var nce=Af.prototype.constructor;function ice(){return new nce(this._groups,this._parents)}function sce(e,t){var n,i,s;return function(){var r=Wc(this,e),o=(this.style.removeProperty(e),Wc(this,e));return r===o?null:r===n&&o===i?s:s=t(n=r,i=o)}}function iP(e){return function(){this.style.removeProperty(e)}}function rce(e,t,n){var i,s=n+"",r;return function(){var o=Wc(this,e);return o===s?null:o===i?r:r=t(i=o,n)}}function ace(e,t,n){var i,s,r;return function(){var o=Wc(this,e),c=n(this),d=c+"";return c==null&&(d=c=(this.style.removeProperty(e),Wc(this,e))),o===d?null:o===i&&d===s?r:(s=d,r=t(i=o,c))}}function oce(e,t){var n,i,s,r="style."+t,o="end."+r,c;return function(){var d=Ar(this,e),f=d.on,m=d.value[r]==null?c||(c=iP(t)):void 0;(f!==n||s!==m)&&(i=(n=f).copy()).on(o,s=m),d.on=i}}function lce(e,t,n){var i=(e+="")=="transform"?cle:nP;return t==null?this.styleTween(e,sce(e,i)).on("end.style."+e,iP(e)):typeof t=="function"?this.styleTween(e,ace(e,i,Fw(this,"style."+e,t))).each(oce(this._id,e)):this.styleTween(e,rce(e,i,t),n).on("end.style."+e,null)}function cce(e,t,n){return function(i){this.style.setProperty(e,t.call(this,i),n)}}function uce(e,t,n){var i,s;function r(){var o=t.apply(this,arguments);return o!==s&&(i=(s=o)&&cce(e,o,n)),i}return r._value=t,r}function dce(e,t,n){var i="style."+(e+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(t==null)return this.tween(i,null);if(typeof t!="function")throw new Error;return this.tween(i,uce(e,t,n??""))}function fce(e){return function(){this.textContent=e}}function hce(e){return function(){var t=e(this);this.textContent=t??""}}function pce(e){return this.tween("text",typeof e=="function"?hce(Fw(this,"text",e)):fce(e==null?"":e+""))}function mce(e){return function(t){this.textContent=e.call(this,t)}}function gce(e){var t,n;function i(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&mce(s)),t}return i._value=e,i}function yce(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,gce(e))}function bce(){for(var e=this._name,t=this._id,n=sP(),i=this._groups,s=i.length,r=0;r<s;++r)for(var o=i[r],c=o.length,d,f=0;f<c;++f)if(d=o[f]){var m=sr(d,t);bg(d,e,n,f,o,{time:m.time+m.delay+m.duration,delay:0,duration:m.duration,ease:m.ease})}return new fa(i,this._parents,e,n)}function xce(){var e,t,n=this,i=n._id,s=n.size();return new Promise(function(r,o){var c={value:o},d={value:function(){--s===0&&r()}};n.each(function(){var f=Ar(this,i),m=f.on;m!==e&&(t=(e=m).copy(),t._.cancel.push(c),t._.interrupt.push(c),t._.end.push(d)),f.on=t}),s===0&&r()})}var vce=0;function fa(e,t,n,i){this._groups=e,this._parents=t,this._name=n,this._id=i}function sP(){return++vce}var Zr=Af.prototype;fa.prototype={constructor:fa,select:ece,selectAll:tce,selectChild:Zr.selectChild,selectChildren:Zr.selectChildren,filter:Gle,merge:Wle,selection:ice,transition:bce,call:Zr.call,nodes:Zr.nodes,node:Zr.node,size:Zr.size,empty:Zr.empty,each:Zr.each,on:Qle,attr:Mle,attrTween:Ile,style:lce,styleTween:dce,text:pce,textTween:yce,remove:Jle,tween:Sle,delay:Ble,duration:$le,ease:Hle,easeVarying:Kle,end:xce,[Symbol.iterator]:Zr[Symbol.iterator]};function wce(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Ece={time:null,delay:0,duration:250,ease:wce};function kce(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function Sce(e){var t,n;e instanceof fa?(t=e._id,e=e._name):(t=sP(),(n=Ece).time=Bw(),e=e==null?null:e+"");for(var i=this._groups,s=i.length,r=0;r<s;++r)for(var o=i[r],c=o.length,d,f=0;f<c;++f)(d=o[f])&&bg(d,e,t,f,o,n||kce(d,t));return new fa(i,this._parents,e,t)}Af.prototype.interrupt=wle;Af.prototype.transition=Sce;const wp=e=>()=>e;function Nce(e,{sourceEvent:t,target:n,transform:i,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:i,enumerable:!0,configurable:!0},_:{value:s}})}function aa(e,t,n){this.k=e,this.x=t,this.y=n}aa.prototype={constructor:aa,scale:function(e){return e===1?this:new aa(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new aa(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 xg=new aa(1,0,0);rP.prototype=aa.prototype;function rP(e){for(;!e.__zoom;)if(!(e=e.parentNode))return xg;return e.__zoom}function Kx(e){e.stopImmediatePropagation()}function pd(e){e.preventDefault(),e.stopImmediatePropagation()}function _ce(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Cce(){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 rT(){return this.__zoom||xg}function jce(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Tce(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ace(e,t,n){var i=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],r=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>i?(i+s)/2:Math.min(0,i)||Math.max(0,s),o>r?(r+o)/2:Math.min(0,r)||Math.max(0,o))}function aP(){var e=_ce,t=Cce,n=Ace,i=jce,s=Tce,r=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],c=250,d=Gp,f=mg("start","zoom","end"),m,p,b,y=500,x=150,v=0,w=10;function k(D){D.property("__zoom",rT).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",P).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",B).on("touchmove.zoom",F).on("touchend.zoom touchcancel.zoom",V).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}k.transform=function(D,I,z,W){var X=D.selection?D.selection():D;X.property("__zoom",rT),D!==X?T(D,I,z,W):X.interrupt().each(function(){A(this,arguments).event(W).start().zoom(null,typeof I=="function"?I.apply(this,arguments):I).end()})},k.scaleBy=function(D,I,z,W){k.scaleTo(D,function(){var X=this.__zoom.k,G=typeof I=="function"?I.apply(this,arguments):I;return X*G},z,W)},k.scaleTo=function(D,I,z,W){k.transform(D,function(){var X=t.apply(this,arguments),G=this.__zoom,U=z==null?j(X):typeof z=="function"?z.apply(this,arguments):z,q=G.invert(U),Y=typeof I=="function"?I.apply(this,arguments):I;return n(S(C(G,Y),U,q),X,o)},z,W)},k.translateBy=function(D,I,z,W){k.transform(D,function(){return n(this.__zoom.translate(typeof I=="function"?I.apply(this,arguments):I,typeof z=="function"?z.apply(this,arguments):z),t.apply(this,arguments),o)},null,W)},k.translateTo=function(D,I,z,W,X){k.transform(D,function(){var G=t.apply(this,arguments),U=this.__zoom,q=W==null?j(G):typeof W=="function"?W.apply(this,arguments):W;return n(xg.translate(q[0],q[1]).scale(U.k).translate(typeof I=="function"?-I.apply(this,arguments):-I,typeof z=="function"?-z.apply(this,arguments):-z),G,o)},W,X)};function C(D,I){return I=Math.max(r[0],Math.min(r[1],I)),I===D.k?D:new aa(I,D.x,D.y)}function S(D,I,z){var W=I[0]-z[0]*D.k,X=I[1]-z[1]*D.k;return W===D.x&&X===D.y?D:new aa(D.k,W,X)}function j(D){return[(+D[0][0]+ +D[1][0])/2,(+D[0][1]+ +D[1][1])/2]}function T(D,I,z,W){D.on("start.zoom",function(){A(this,arguments).event(W).start()}).on("interrupt.zoom end.zoom",function(){A(this,arguments).event(W).end()}).tween("zoom",function(){var X=this,G=arguments,U=A(X,G).event(W),q=t.apply(X,G),Y=z==null?j(q):typeof z=="function"?z.apply(X,G):z,$=Math.max(q[1][0]-q[0][0],q[1][1]-q[0][1]),ie=X.__zoom,be=typeof I=="function"?I.apply(X,G):I,ce=d(ie.invert(Y).concat($/ie.k),be.invert(Y).concat($/be.k));return function(_e){if(_e===1)_e=be;else{var le=ce(_e),pe=$/le[2];_e=new aa(pe,Y[0]-le[0]*pe,Y[1]-le[1]*pe)}U.zoom(null,_e)}})}function A(D,I,z){return!z&&D.__zooming||new M(D,I)}function M(D,I){this.that=D,this.args=I,this.active=0,this.sourceEvent=null,this.extent=t.apply(D,I),this.taps=0}M.prototype={event:function(D){return D&&(this.sourceEvent=D),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(D,I){return this.mouse&&D!=="mouse"&&(this.mouse[1]=I.invert(this.mouse[0])),this.touch0&&D!=="touch"&&(this.touch0[1]=I.invert(this.touch0[0])),this.touch1&&D!=="touch"&&(this.touch1[1]=I.invert(this.touch1[0])),this.that.__zoom=I,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(D){var I=ss(this.that).datum();f.call(D,this.that,new Nce(D,{sourceEvent:this.sourceEvent,target:k,transform:this.that.__zoom,dispatch:f}),I)}};function R(D,...I){if(!e.apply(this,arguments))return;var z=A(this,I).event(D),W=this.__zoom,X=Math.max(r[0],Math.min(r[1],W.k*Math.pow(2,i.apply(this,arguments)))),G=Gs(D);if(z.wheel)(z.mouse[0][0]!==G[0]||z.mouse[0][1]!==G[1])&&(z.mouse[1]=W.invert(z.mouse[0]=G)),clearTimeout(z.wheel);else{if(W.k===X)return;z.mouse=[G,W.invert(G)],Xp(this),z.start()}pd(D),z.wheel=setTimeout(U,x),z.zoom("mouse",n(S(C(W,X),z.mouse[0],z.mouse[1]),z.extent,o));function U(){z.wheel=null,z.end()}}function P(D,...I){if(b||!e.apply(this,arguments))return;var z=D.currentTarget,W=A(this,I,!0).event(D),X=ss(D.view).on("mousemove.zoom",Y,!0).on("mouseup.zoom",$,!0),G=Gs(D,z),U=D.clientX,q=D.clientY;qI(D.view),Kx(D),W.mouse=[G,this.__zoom.invert(G)],Xp(this),W.start();function Y(ie){if(pd(ie),!W.moved){var be=ie.clientX-U,ce=ie.clientY-q;W.moved=be*be+ce*ce>v}W.event(ie).zoom("mouse",n(S(W.that.__zoom,W.mouse[0]=Gs(ie,z),W.mouse[1]),W.extent,o))}function $(ie){X.on("mousemove.zoom mouseup.zoom",null),HI(ie.view,W.moved),pd(ie),W.event(ie).end()}}function O(D,...I){if(e.apply(this,arguments)){var z=this.__zoom,W=Gs(D.changedTouches?D.changedTouches[0]:D,this),X=z.invert(W),G=z.k*(D.shiftKey?.5:2),U=n(S(C(z,G),W,X),t.apply(this,I),o);pd(D),c>0?ss(this).transition().duration(c).call(T,U,W,D):ss(this).call(k.transform,U,W,D)}}function B(D,...I){if(e.apply(this,arguments)){var z=D.touches,W=z.length,X=A(this,I,D.changedTouches.length===W).event(D),G,U,q,Y;for(Kx(D),U=0;U<W;++U)q=z[U],Y=Gs(q,this),Y=[Y,this.__zoom.invert(Y),q.identifier],X.touch0?!X.touch1&&X.touch0[2]!==Y[2]&&(X.touch1=Y,X.taps=0):(X.touch0=Y,G=!0,X.taps=1+!!m);m&&(m=clearTimeout(m)),G&&(X.taps<2&&(p=Y[0],m=setTimeout(function(){m=null},y)),Xp(this),X.start())}}function F(D,...I){if(this.__zooming){var z=A(this,I).event(D),W=D.changedTouches,X=W.length,G,U,q,Y;for(pd(D),G=0;G<X;++G)U=W[G],q=Gs(U,this),z.touch0&&z.touch0[2]===U.identifier?z.touch0[0]=q:z.touch1&&z.touch1[2]===U.identifier&&(z.touch1[0]=q);if(U=z.that.__zoom,z.touch1){var $=z.touch0[0],ie=z.touch0[1],be=z.touch1[0],ce=z.touch1[1],_e=(_e=be[0]-$[0])*_e+(_e=be[1]-$[1])*_e,le=(le=ce[0]-ie[0])*le+(le=ce[1]-ie[1])*le;U=C(U,Math.sqrt(_e/le)),q=[($[0]+be[0])/2,($[1]+be[1])/2],Y=[(ie[0]+ce[0])/2,(ie[1]+ce[1])/2]}else if(z.touch0)q=z.touch0[0],Y=z.touch0[1];else return;z.zoom("touch",n(S(U,q,Y),z.extent,o))}}function V(D,...I){if(this.__zooming){var z=A(this,I).event(D),W=D.changedTouches,X=W.length,G,U;for(Kx(D),b&&clearTimeout(b),b=setTimeout(function(){b=null},y),G=0;G<X;++G)U=W[G],z.touch0&&z.touch0[2]===U.identifier?delete z.touch0:z.touch1&&z.touch1[2]===U.identifier&&delete z.touch1;if(z.touch1&&!z.touch0&&(z.touch0=z.touch1,delete z.touch1),z.touch0)z.touch0[1]=this.__zoom.invert(z.touch0[0]);else if(z.end(),z.taps===2&&(U=Gs(U,this),Math.hypot(p[0]-U[0],p[1]-U[1])<w)){var q=ss(this).on("dblclick.zoom");q&&q.apply(this,arguments)}}}return k.wheelDelta=function(D){return arguments.length?(i=typeof D=="function"?D:wp(+D),k):i},k.filter=function(D){return arguments.length?(e=typeof D=="function"?D:wp(!!D),k):e},k.touchable=function(D){return arguments.length?(s=typeof D=="function"?D:wp(!!D),k):s},k.extent=function(D){return arguments.length?(t=typeof D=="function"?D:wp([[+D[0][0],+D[0][1]],[+D[1][0],+D[1][1]]]),k):t},k.scaleExtent=function(D){return arguments.length?(r[0]=+D[0],r[1]=+D[1],k):[r[0],r[1]]},k.translateExtent=function(D){return arguments.length?(o[0][0]=+D[0][0],o[1][0]=+D[1][0],o[0][1]=+D[0][1],o[1][1]=+D[1][1],k):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},k.constrain=function(D){return arguments.length?(n=D,k):n},k.duration=function(D){return arguments.length?(c=+D,k):c},k.interpolate=function(D){return arguments.length?(d=D,k):d},k.on=function(){var D=f.on.apply(f,arguments);return D===f?k:D},k.clickDistance=function(D){return arguments.length?(v=(D=+D)*D,k):Math.sqrt(v)},k.tapDistance=function(D){return arguments.length?(w=+D,k):w},k}const ls={error001:(e="react")=>`Seems like you have not used ${e==="svelte"?"SvelteFlowProvider":"ReactFlowProvider"} as an ancestor. Help: https://${e}flow.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 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,{id:t,sourceHandle:n,targetHandle:i})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:i}", edge id: ${t}.`,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.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.",error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},ef=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],oP=["Enter"," ","Escape"],lP={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Xc;(function(e){e.Strict="strict",e.Loose="loose"})(Xc||(Xc={}));var ul;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(ul||(ul={}));var tf;(function(e){e.Partial="partial",e.Full="full"})(tf||(tf={}));const cP={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Va;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Va||(Va={}));var Lm;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Lm||(Lm={}));var tt;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(tt||(tt={}));const aT={[tt.Left]:tt.Right,[tt.Right]:tt.Left,[tt.Top]:tt.Bottom,[tt.Bottom]:tt.Top};function uP(e){return e===null?null:e?"valid":"invalid"}const dP=e=>"id"in e&&"source"in e&&"target"in e,Mce=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),$w=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),Rf=(e,t=[0,0])=>{const{width:n,height:i}=pa(e),s=e.origin??t,r=n*s[0],o=i*s[1];return{x:e.position.x-r,y:e.position.y-o}},Rce=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((i,s)=>{const r=typeof s=="string";let o=!t.nodeLookup&&!r?s:void 0;t.nodeLookup&&(o=r?t.nodeLookup.get(s):$w(s)?s:t.nodeLookup.get(s.id));const c=o?Im(o,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return vg(i,c)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return wg(n)},Df=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},i=!1;return e.forEach(s=>{(t.filter===void 0||t.filter(s))&&(n=vg(n,Im(s)),i=!0)}),i?wg(n):{x:0,y:0,width:0,height:0}},qw=(e,t,[n,i,s]=[0,0,1],r=!1,o=!1)=>{const c=(t.x-n)/s,d=(t.y-i)/s,f=t.width/s,m=t.height/s,p=[];for(const b of e.values()){const{measured:y,selectable:x=!0,hidden:v=!1}=b;if(o&&!x||v)continue;const w=y.width??b.width??b.initialWidth??0,k=y.height??b.height??b.initialHeight??0,{x:C,y:S}=b.internals.positionAbsolute,j=mP(c,d,f,m,C,S,w,k),T=w*k,A=r&&j>0;(!b.internals.handleBounds||A||j>=T||b.dragging)&&p.push(b)}return p},Dce=(e,t)=>{const n=new Set;return e.forEach(i=>{n.add(i.id)}),t.filter(i=>n.has(i.source)||n.has(i.target))};function Oce(e,t){const n=new Map,i=t!=null&&t.nodes?new Set(t.nodes.map(s=>s.id)):null;return e.forEach(s=>{s.measured.width&&s.measured.height&&((t==null?void 0:t.includeHiddenNodes)||!s.hidden)&&(!i||i.has(s.id))&&n.set(s.id,s)}),n}async function Lce({nodes:e,width:t,height:n,panZoom:i,minZoom:s,maxZoom:r},o){if(e.size===0)return!0;const c=Oce(e,o),d=Df(c),f=Vw(d,t,n,(o==null?void 0:o.minZoom)??s,(o==null?void 0:o.maxZoom)??r,(o==null?void 0:o.padding)??.1);return await i.setViewport(f,{duration:o==null?void 0:o.duration,ease:o==null?void 0:o.ease,interpolate:o==null?void 0:o.interpolate}),!0}function fP({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:i=[0,0],nodeExtent:s,onError:r}){const o=n.get(e),c=o.parentId?n.get(o.parentId):void 0,{x:d,y:f}=c?c.internals.positionAbsolute:{x:0,y:0},m=o.origin??i;let p=o.extent||s;if(o.extent==="parent"&&!o.expandParent)if(!c)r==null||r("005",ls.error005());else{const y=c.measured.width,x=c.measured.height;y&&x&&(p=[[d,f],[d+y,f+x]])}else c&&xl(o.extent)&&(p=[[o.extent[0][0]+d,o.extent[0][1]+f],[o.extent[1][0]+d,o.extent[1][1]+f]]);const b=xl(p)?bl(t,p,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&(r==null||r("015",ls.error015())),{position:{x:b.x-d+(o.measured.width??0)*m[0],y:b.y-f+(o.measured.height??0)*m[1]},positionAbsolute:b}}async function Ice({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:i,onBeforeDelete:s}){const r=new Set(e.map(b=>b.id)),o=[];for(const b of n){if(b.deletable===!1)continue;const y=r.has(b.id),x=!y&&b.parentId&&o.find(v=>v.id===b.parentId);(y||x)&&o.push(b)}const c=new Set(t.map(b=>b.id)),d=i.filter(b=>b.deletable!==!1),m=Dce(o,d);for(const b of d)c.has(b.id)&&!m.find(x=>x.id===b.id)&&m.push(b);if(!s)return{edges:m,nodes:o};const p=await s({nodes:o,edges:m});return typeof p=="boolean"?p?{edges:m,nodes:o}:{edges:[],nodes:[]}:p}const Qc=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),bl=(e={x:0,y:0},t,n)=>({x:Qc(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:Qc(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function hP(e,t,n){const{width:i,height:s}=pa(n),{x:r,y:o}=n.internals.positionAbsolute;return bl(e,[[r,o],[r+i,o+s]],t)}const oT=(e,t,n)=>e<t?Qc(Math.abs(e-t),1,t)/t:e>n?-Qc(Math.abs(e-n),1,t)/t:0,Hw=(e,t,n=15,i=40)=>{const s=oT(e.x,i,t.width-i)*n,r=oT(e.y,i,t.height-i)*n;return[s,r]},vg=(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)}),F0=({x:e,y:t,width:n,height:i})=>({x:e,y:t,x2:e+n,y2:t+i}),wg=({x:e,y:t,x2:n,y2:i})=>({x:e,y:t,width:n-e,height:i-t}),nf=(e,t=[0,0])=>{var s,r;const{x:n,y:i}=$w(e)?e.internals.positionAbsolute:Rf(e,t);return{x:n,y:i,width:((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0,height:((r=e.measured)==null?void 0:r.height)??e.height??e.initialHeight??0}},Im=(e,t=[0,0])=>{var s,r;const{x:n,y:i}=$w(e)?e.internals.positionAbsolute:Rf(e,t);return{x:n,y:i,x2:n+(((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0),y2:i+(((r=e.measured)==null?void 0:r.height)??e.height??e.initialHeight??0)}},pP=(e,t)=>wg(vg(F0(e),F0(t))),mP=(e,t,n,i,s,r,o,c)=>{const d=Math.max(0,Math.min(e+n,s+o)-Math.max(e,s)),f=Math.max(0,Math.min(t+i,r+c)-Math.max(t,r));return Math.ceil(d*f)},Pm=(e,t)=>mP(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),lT=e=>Xs(e.width)&&Xs(e.height)&&Xs(e.x)&&Xs(e.y),Xs=e=>!isNaN(e)&&isFinite(e),gP=(e,t)=>(n,i)=>{},Of=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Lf=({x:e,y:t},[n,i,s],r=!1,o=[1,1])=>{const c={x:(e-n)/s,y:(t-i)/s};return r?Of(c,o):c},Zc=({x:e,y:t},[n,i,s])=>({x:e*s+n,y:t*s+i});function lc(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function Pce(e,t,n){if(typeof e=="string"||typeof e=="number"){const i=lc(e,n),s=lc(e,t);return{top:i,right:s,bottom:i,left:s,x:s*2,y:i*2}}if(typeof e=="object"){const i=lc(e.top??e.y??0,n),s=lc(e.bottom??e.y??0,n),r=lc(e.left??e.x??0,t),o=lc(e.right??e.x??0,t);return{top:i,right:o,bottom:s,left:r,x:r+o,y:i+s}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function zce(e,t,n,i,s,r){const{x:o,y:c}=Zc(e,[t,n,i]),{x:d,y:f}=Zc({x:e.x+e.width,y:e.y+e.height},[t,n,i]),m=s-d,p=r-f;return{left:Math.floor(o),top:Math.floor(c),right:Math.floor(m),bottom:Math.floor(p)}}const Vw=(e,t,n,i,s,r)=>{const o=Pce(r,t,n),c=(t-o.x)/e.width,d=(n-o.y)/e.height,f=Math.min(c,d),m=Qc(f,i,s),p=e.x+e.width/2,b=e.y+e.height/2,y=t/2-p*m,x=n/2-b*m,v=zce(e,y,x,m,t,n),w={left:Math.min(v.left-o.left,0),top:Math.min(v.top-o.top,0),right:Math.min(v.right-o.right,0),bottom:Math.min(v.bottom-o.bottom,0)};return{x:y-w.left+w.right,y:x-w.top+w.bottom,zoom:m}},sf=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function xl(e){return e!=null&&e!=="parent"}function pa(e){var t,n;return{width:((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth??0,height:((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight??0}}function yP(e){var t,n;return(((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth)!==void 0&&(((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight)!==void 0}function bP(e,t={width:0,height:0},n,i,s){const r={...e},o=i.get(n);if(o){const c=o.origin||s;r.x+=o.internals.positionAbsolute.x-(t.width??0)*c[0],r.y+=o.internals.positionAbsolute.y-(t.height??0)*c[1]}return r}function cT(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function Bce(){let e,t;return{promise:new Promise((i,s)=>{e=i,t=s}),resolve:e,reject:t}}function Uce(e){return{...lP,...e||{}}}function Od(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:i,containerBounds:s}){const{x:r,y:o}=Qs(e),c=Lf({x:r-((s==null?void 0:s.left)??0),y:o-((s==null?void 0:s.top)??0)},i),{x:d,y:f}=n?Of(c,t):c;return{xSnapped:d,ySnapped:f,...c}}const Kw=e=>({width:e.offsetWidth,height:e.offsetHeight}),xP=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},Fce=["INPUT","SELECT","TEXTAREA"];function vP(e){var i,s;const t=((s=(i=e.composedPath)==null?void 0:i.call(e))==null?void 0:s[0])||e.target;return(t==null?void 0:t.nodeType)!==1?!1:Fce.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const wP=e=>"clientX"in e,Qs=(e,t)=>{var r,o;const n=wP(e),i=n?e.clientX:(r=e.touches)==null?void 0:r[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:i-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},uT=(e,t,n,i,s)=>{const r=t.querySelectorAll(`.${e}`);return!r||!r.length?null:Array.from(r).map(o=>{const c=o.getBoundingClientRect();return{id:o.getAttribute("data-handleid"),type:e,nodeId:s,position:o.getAttribute("data-handlepos"),x:(c.left-n.left)/i,y:(c.top-n.top)/i,...Kw(o)}})};function EP({sourceX:e,sourceY:t,targetX:n,targetY:i,sourceControlX:s,sourceControlY:r,targetControlX:o,targetControlY:c}){const d=e*.125+s*.375+o*.375+n*.125,f=t*.125+r*.375+c*.375+i*.125,m=Math.abs(d-e),p=Math.abs(f-t);return[d,f,m,p]}function Ep(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function dT({pos:e,x1:t,y1:n,x2:i,y2:s,c:r}){switch(e){case tt.Left:return[t-Ep(t-i,r),n];case tt.Right:return[t+Ep(i-t,r),n];case tt.Top:return[t,n-Ep(n-s,r)];case tt.Bottom:return[t,n+Ep(s-n,r)]}}function kP({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:s,targetPosition:r=tt.Top,curvature:o=.25}){const[c,d]=dT({pos:n,x1:e,y1:t,x2:i,y2:s,c:o}),[f,m]=dT({pos:r,x1:i,y1:s,x2:e,y2:t,c:o}),[p,b,y,x]=EP({sourceX:e,sourceY:t,targetX:i,targetY:s,sourceControlX:c,sourceControlY:d,targetControlX:f,targetControlY:m});return[`M${e},${t} C${c},${d} ${f},${m} ${i},${s}`,p,b,y,x]}function SP({sourceX:e,sourceY:t,targetX:n,targetY:i}){const s=Math.abs(n-e)/2,r=n<e?n+s:n-s,o=Math.abs(i-t)/2,c=i<t?i+o:i-o;return[r,c,s,o]}function $ce({sourceNode:e,targetNode:t,selected:n=!1,zIndex:i=0,elevateOnSelect:s=!1,zIndexMode:r="basic"}){if(r==="manual")return i;const o=s&&n?i+1e3:i,c=Math.max(e.parentId||s&&e.selected?e.internals.z:0,t.parentId||s&&t.selected?t.internals.z:0);return o+c}function qce({sourceNode:e,targetNode:t,width:n,height:i,transform:s}){const r=vg(Im(e),Im(t));r.x===r.x2&&(r.x2+=1),r.y===r.y2&&(r.y2+=1);const o={x:-s[0]/s[2],y:-s[1]/s[2],width:n/s[2],height:i/s[2]};return Pm(o,wg(r))>0}const NP=({source:e,sourceHandle:t,target:n,targetHandle:i})=>`xy-edge__${e}${t||""}-${n}${i||""}`,Hce=(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)),Vce=(e,t,n={})=>{var r;if(!e.source||!e.target)return(r=n.onError)==null||r.call(n,"006",ls.error006()),t;const i=n.getEdgeId||NP;let s;return dP(e)?s={...e}:s={...e,id:i(e)},Hce(s,t)?t:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,t.concat(s))},Kce=(e,t,n,i={shouldReplaceId:!0})=>{var f,m;const{id:s,...r}=e;if(!t.source||!t.target)return(f=i.onError)==null||f.call(i,"006",ls.error006()),n;if(!n.find(p=>p.id===e.id))return(m=i.onError)==null||m.call(i,"007",ls.error007(s)),n;const c=i.getEdgeId||NP,d={...r,id:i.shouldReplaceId?c(t):s,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle};return n.filter(p=>p.id!==s).concat(d)};function _P({sourceX:e,sourceY:t,targetX:n,targetY:i}){const[s,r,o,c]=SP({sourceX:e,sourceY:t,targetX:n,targetY:i});return[`M ${e},${t}L ${n},${i}`,s,r,o,c]}const fT={[tt.Left]:{x:-1,y:0},[tt.Right]:{x:1,y:0},[tt.Top]:{x:0,y:-1},[tt.Bottom]:{x:0,y:1}},Gce=({source:e,sourcePosition:t=tt.Bottom,target:n})=>t===tt.Left||t===tt.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},hT=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function Wce({source:e,sourcePosition:t=tt.Bottom,target:n,targetPosition:i=tt.Top,center:s,offset:r,stepPosition:o}){const c=fT[t],d=fT[i],f={x:e.x+c.x*r,y:e.y+c.y*r},m={x:n.x+d.x*r,y:n.y+d.y*r},p=Gce({source:f,sourcePosition:t,target:m}),b=p.x!==0?"x":"y",y=p[b];let x=[],v,w;const k={x:0,y:0},C={x:0,y:0},[,,S,j]=SP({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(c[b]*d[b]===-1){b==="x"?(v=s.x??f.x+(m.x-f.x)*o,w=s.y??(f.y+m.y)/2):(v=s.x??(f.x+m.x)/2,w=s.y??f.y+(m.y-f.y)*o);const R=[{x:v,y:f.y},{x:v,y:m.y}],P=[{x:f.x,y:w},{x:m.x,y:w}];c[b]===y?x=b==="x"?R:P:x=b==="x"?P:R}else{const R=[{x:f.x,y:m.y}],P=[{x:m.x,y:f.y}];if(b==="x"?x=c.x===y?P:R:x=c.y===y?R:P,t===i){const D=Math.abs(e[b]-n[b]);if(D<=r){const I=Math.min(r-1,r-D);c[b]===y?k[b]=(f[b]>e[b]?-1:1)*I:C[b]=(m[b]>n[b]?-1:1)*I}}if(t!==i){const D=b==="x"?"y":"x",I=c[b]===d[D],z=f[D]>m[D],W=f[D]<m[D];(c[b]===1&&(!I&&z||I&&W)||c[b]!==1&&(!I&&W||I&&z))&&(x=b==="x"?R:P)}const O={x:f.x+k.x,y:f.y+k.y},B={x:m.x+C.x,y:m.y+C.y},F=Math.max(Math.abs(O.x-x[0].x),Math.abs(B.x-x[0].x)),V=Math.max(Math.abs(O.y-x[0].y),Math.abs(B.y-x[0].y));F>=V?(v=(O.x+B.x)/2,w=x[0].y):(v=x[0].x,w=(O.y+B.y)/2)}const T={x:f.x+k.x,y:f.y+k.y},A={x:m.x+C.x,y:m.y+C.y};return[[e,...T.x!==x[0].x||T.y!==x[0].y?[T]:[],...x,...A.x!==x[x.length-1].x||A.y!==x[x.length-1].y?[A]:[],n],v,w,S,j]}function Yce(e,t,n,i){const s=Math.min(hT(e,t)/2,hT(t,n)/2,i),{x:r,y:o}=t;if(e.x===r&&r===n.x||e.y===o&&o===n.y)return`L${r} ${o}`;if(e.y===o){const f=e.x<n.x?-1:1,m=e.y<n.y?1:-1;return`L ${r+s*f},${o}Q ${r},${o} ${r},${o+s*m}`}const c=e.x<n.x?1:-1,d=e.y<n.y?-1:1;return`L ${r},${o+s*d}Q ${r},${o} ${r+s*c},${o}`}function $0({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:s,targetPosition:r=tt.Top,borderRadius:o=5,centerX:c,centerY:d,offset:f=20,stepPosition:m=.5}){const[p,b,y,x,v]=Wce({source:{x:e,y:t},sourcePosition:n,target:{x:i,y:s},targetPosition:r,center:{x:c,y:d},offset:f,stepPosition:m});let w=`M${p[0].x} ${p[0].y}`;for(let k=1;k<p.length-1;k++)w+=Yce(p[k-1],p[k],p[k+1],o);return w+=`L${p[p.length-1].x} ${p[p.length-1].y}`,[w,b,y,x,v]}function pT(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Xce(e){var p;const{sourceNode:t,targetNode:n}=e;if(!pT(t)||!pT(n))return null;const i=t.internals.handleBounds||mT(t.handles),s=n.internals.handleBounds||mT(n.handles),r=gT((i==null?void 0:i.source)??[],e.sourceHandle),o=gT(e.connectionMode===Xc.Strict?(s==null?void 0:s.target)??[]:((s==null?void 0:s.target)??[]).concat((s==null?void 0:s.source)??[]),e.targetHandle);if(!r||!o)return(p=e.onError)==null||p.call(e,"008",ls.error008(r?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const c=(r==null?void 0:r.position)||tt.Bottom,d=(o==null?void 0:o.position)||tt.Top,f=vl(t,r,c),m=vl(n,o,d);return{sourceX:f.x,sourceY:f.y,targetX:m.x,targetY:m.y,sourcePosition:c,targetPosition:d}}function mT(e){if(!e)return null;const t=[],n=[];for(const i of e)i.width=i.width??1,i.height=i.height??1,i.type==="source"?t.push(i):i.type==="target"&&n.push(i);return{source:t,target:n}}function vl(e,t,n=tt.Left,i=!1){const s=((t==null?void 0:t.x)??0)+e.internals.positionAbsolute.x,r=((t==null?void 0:t.y)??0)+e.internals.positionAbsolute.y,{width:o,height:c}=t??pa(e);if(i)return{x:s+o/2,y:r+c/2};switch((t==null?void 0:t.position)??n){case tt.Top:return{x:s+o/2,y:r};case tt.Right:return{x:s+o,y:r+c/2};case tt.Bottom:return{x:s+o/2,y:r+c};case tt.Left:return{x:s,y:r+c/2}}}function gT(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function q0(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(i=>`${i}=${e[i]}`).join("&")}`:""}function Qce(e,{id:t,defaultColor:n,defaultMarkerStart:i,defaultMarkerEnd:s}){const r=new Set;return e.reduce((o,c)=>([c.markerStart||i,c.markerEnd||s].forEach(d=>{if(d&&typeof d=="object"){const f=q0(d,t);r.has(f)||(o.push({id:f,color:d.color||n,...d}),r.add(f))}}),o),[]).sort((o,c)=>o.id.localeCompare(c.id))}const CP=1e3,Zce=10,Gw={nodeOrigin:[0,0],nodeExtent:ef,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Jce={...Gw,checkEquality:!0};function Ww(e,t){const n={...e};for(const i in t)t[i]!==void 0&&(n[i]=t[i]);return n}function eue(e,t,n){const i=Ww(Gw,n);for(const s of e.values())if(s.parentId)Xw(s,e,t,i);else{const r=Rf(s,i.nodeOrigin),o=xl(s.extent)?s.extent:i.nodeExtent,c=bl(r,o,pa(s));s.internals.positionAbsolute=c}}function tue(e,t){if(!e.handles)return e.measured?t==null?void 0:t.internals.handleBounds:void 0;const n=[],i=[];for(const s of e.handles){const r={id:s.id,width:s.width??1,height:s.height??1,nodeId:e.id,x:s.x,y:s.y,position:s.position,type:s.type};s.type==="source"?n.push(r):s.type==="target"&&i.push(r)}return{source:n,target:i}}function Yw(e){return e==="manual"}function H0(e,t,n,i={}){var m,p;const s=Ww(Jce,i),r={i:0},o=new Map(t),c=s!=null&&s.elevateNodesOnSelect&&!Yw(s.zIndexMode)?CP:0;let d=e.length>0,f=!1;t.clear(),n.clear();for(const b of e){let y=o.get(b.id);if(s.checkEquality&&b===(y==null?void 0:y.internals.userNode))t.set(b.id,y);else{const x=Rf(b,s.nodeOrigin),v=xl(b.extent)?b.extent:s.nodeExtent,w=bl(x,v,pa(b));y={...s.defaults,...b,measured:{width:(m=b.measured)==null?void 0:m.width,height:(p=b.measured)==null?void 0:p.height},internals:{positionAbsolute:w,handleBounds:tue(b,y),z:jP(b,c,s.zIndexMode),userNode:b}},t.set(b.id,y)}(y.measured===void 0||y.measured.width===void 0||y.measured.height===void 0)&&!y.hidden&&(d=!1),b.parentId&&Xw(y,t,n,i,r),f||(f=b.selected??!1)}return{nodesInitialized:d,hasSelectedNodes:f}}function nue(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function Xw(e,t,n,i,s){const{elevateNodesOnSelect:r,nodeOrigin:o,nodeExtent:c,zIndexMode:d}=Ww(Gw,i),f=e.parentId,m=t.get(f);if(!m){console.warn(`Parent node ${f} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}nue(e,n),s&&!m.parentId&&m.internals.rootParentIndex===void 0&&d==="auto"&&(m.internals.rootParentIndex=++s.i,m.internals.z=m.internals.z+s.i*Zce),s&&m.internals.rootParentIndex!==void 0&&(s.i=m.internals.rootParentIndex);const p=r&&!Yw(d)?CP:0,{x:b,y,z:x}=iue(e,m,o,c,p,d),{positionAbsolute:v}=e.internals,w=b!==v.x||y!==v.y;(w||x!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:w?{x:b,y}:v,z:x}})}function jP(e,t,n){const i=Xs(e.zIndex)?e.zIndex:0;return Yw(n)?i:i+(e.selected?t:0)}function iue(e,t,n,i,s,r){const{x:o,y:c}=t.internals.positionAbsolute,d=pa(e),f=Rf(e,n),m=xl(e.extent)?bl(f,e.extent,d):f;let p=bl({x:o+m.x,y:c+m.y},i,d);e.extent==="parent"&&(p=hP(p,d,t));const b=jP(e,s,r),y=t.internals.z??0;return{x:p.x,y:p.y,z:y>=b?y+1:b}}function Qw(e,t,n,i=[0,0]){var o;const s=[],r=new Map;for(const c of e){const d=t.get(c.parentId);if(!d)continue;const f=((o=r.get(c.parentId))==null?void 0:o.expandedRect)??nf(d),m=pP(f,c.rect);r.set(c.parentId,{expandedRect:m,parent:d})}return r.size>0&&r.forEach(({expandedRect:c,parent:d},f)=>{var S;const m=d.internals.positionAbsolute,p=pa(d),b=d.origin??i,y=c.x<m.x?Math.round(Math.abs(m.x-c.x)):0,x=c.y<m.y?Math.round(Math.abs(m.y-c.y)):0,v=Math.max(p.width,Math.round(c.width)),w=Math.max(p.height,Math.round(c.height)),k=(v-p.width)*b[0],C=(w-p.height)*b[1];(y>0||x>0||k||C)&&(s.push({id:f,type:"position",position:{x:d.position.x-y+k,y:d.position.y-x+C}}),(S=n.get(f))==null||S.forEach(j=>{e.some(T=>T.id===j.id)||s.push({id:j.id,type:"position",position:{x:j.position.x+y,y:j.position.y+x}})})),(p.width<c.width||p.height<c.height||y||x)&&s.push({id:f,type:"dimensions",setAttributes:!0,dimensions:{width:v+(y?b[0]*y-k:0),height:w+(x?b[1]*x-C:0)}})}),s}function sue(e,t,n,i,s,r,o){const c=i==null?void 0:i.querySelector(".xyflow__viewport");let d=!1;if(!c)return{changes:[],updatedInternals:d};const f=[],m=window.getComputedStyle(c),{m22:p}=new window.DOMMatrixReadOnly(m.transform),b=[];for(const y of e.values()){const x=t.get(y.id);if(!x)continue;if(x.hidden){t.set(x.id,{...x,internals:{...x.internals,handleBounds:void 0}}),d=!0;continue}const v=Kw(y.nodeElement),w=x.measured.width!==v.width||x.measured.height!==v.height;if(!!(v.width&&v.height&&(w||!x.internals.handleBounds||y.force))){const C=y.nodeElement.getBoundingClientRect(),S=xl(x.extent)?x.extent:r;let{positionAbsolute:j}=x.internals;x.parentId&&x.extent==="parent"?j=hP(j,v,t.get(x.parentId)):S&&(j=bl(j,S,v));const T={...x,measured:v,internals:{...x.internals,positionAbsolute:j,handleBounds:{source:uT("source",y.nodeElement,C,p,x.id),target:uT("target",y.nodeElement,C,p,x.id)}}};t.set(x.id,T),x.parentId&&Xw(T,t,n,{nodeOrigin:s,zIndexMode:o}),d=!0,w&&(f.push({id:x.id,type:"dimensions",dimensions:v}),x.expandParent&&x.parentId&&b.push({id:x.id,parentId:x.parentId,rect:nf(T,s)}))}}if(b.length>0){const y=Qw(b,t,n,s);f.push(...y)}return{changes:f,updatedInternals:d}}async function rue({delta:e,panZoom:t,transform:n,translateExtent:i,width:s,height:r}){if(!t||!e.x&&!e.y)return!1;const o=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[s,r]],i);return!!o&&(o.x!==n[0]||o.y!==n[1]||o.k!==n[2])}function yT(e,t,n,i,s,r){let o=s;const c=i.get(o)||new Map;i.set(o,c.set(n,t)),o=`${s}-${e}`;const d=i.get(o)||new Map;if(i.set(o,d.set(n,t)),r){o=`${s}-${e}-${r}`;const f=i.get(o)||new Map;i.set(o,f.set(n,t))}}function TP(e,t,n){e.clear(),t.clear();for(const i of n){const{source:s,target:r,sourceHandle:o=null,targetHandle:c=null}=i,d={edgeId:i.id,source:s,target:r,sourceHandle:o,targetHandle:c},f=`${s}-${o}--${r}-${c}`,m=`${r}-${c}--${s}-${o}`;yT("source",d,m,e,s,o),yT("target",d,f,e,r,c),t.set(i.id,i)}}function AP(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:AP(n,t):!1}function bT(e,t,n){var s;let i=e;do{if((s=i==null?void 0:i.matches)!=null&&s.call(i,t))return!0;if(i===n)return!1;i=i==null?void 0:i.parentElement}while(i);return!1}function aue(e,t,n,i){const s=new Map;for(const[r,o]of e)if((o.selected||o.id===i)&&(!o.parentId||!AP(o,e))&&(o.draggable||t&&typeof o.draggable>"u")){const c=e.get(r);c&&s.set(r,{id:r,position:c.position||{x:0,y:0},distance:{x:n.x-c.internals.positionAbsolute.x,y:n.y-c.internals.positionAbsolute.y},extent:c.extent,parentId:c.parentId,origin:c.origin,expandParent:c.expandParent,internals:{positionAbsolute:c.internals.positionAbsolute||{x:0,y:0}},measured:{width:c.measured.width??0,height:c.measured.height??0}})}return s}function Gx({nodeId:e,dragItems:t,nodeLookup:n,dragging:i=!0}){var o,c,d;const s=[];for(const[f,m]of t){const p=(o=n.get(f))==null?void 0:o.internals.userNode;p&&s.push({...p,position:m.position,dragging:i})}if(!e)return[s[0],s];const r=(c=n.get(e))==null?void 0:c.internals.userNode;return[r?{...r,position:((d=t.get(e))==null?void 0:d.position)||r.position,dragging:i}:s[0],s]}function oue({dragItems:e,snapGrid:t,x:n,y:i}){const s=e.values().next().value;if(!s)return null;const r={x:n-s.distance.x,y:i-s.distance.y},o=Of(r,t);return{x:o.x-r.x,y:o.y-r.y}}function lue({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:i,onDragStop:s}){let r={x:null,y:null},o=0,c=new Map,d=!1,f={x:0,y:0},m=null,p=!1,b=null,y=!1,x=!1,v=null;function w({noDragClassName:C,handleSelector:S,domNode:j,isSelectable:T,nodeId:A,nodeClickDistance:M=0}){b=ss(j);function R({x:F,y:V}){const{nodeLookup:D,nodeExtent:I,snapGrid:z,snapToGrid:W,nodeOrigin:X,onNodeDrag:G,onSelectionDrag:U,onError:q,updateNodePositions:Y}=t();r={x:F,y:V};let $=!1;const ie=c.size>1,be=ie&&I?F0(Df(c)):null,ce=ie&&W?oue({dragItems:c,snapGrid:z,x:F,y:V}):null;for(const[_e,le]of c){if(!D.has(_e))continue;let pe={x:F-le.distance.x,y:V-le.distance.y};W&&(pe=ce?{x:Math.round(pe.x+ce.x),y:Math.round(pe.y+ce.y)}:Of(pe,z));let Te=null;if(ie&&I&&!le.extent&&be){const{positionAbsolute:xe}=le.internals,fe=xe.x-be.x+I[0][0],te=xe.x+le.measured.width-be.x2+I[1][0],we=xe.y-be.y+I[0][1],Fe=xe.y+le.measured.height-be.y2+I[1][1];Te=[[fe,we],[te,Fe]]}const{position:ne,positionAbsolute:oe}=fP({nodeId:_e,nextPosition:pe,nodeLookup:D,nodeExtent:Te||I,nodeOrigin:X,onError:q});$=$||le.position.x!==ne.x||le.position.y!==ne.y,le.position=ne,le.internals.positionAbsolute=oe}if(x=x||$,!!$&&(Y(c,!0),v&&(i||G||!A&&U))){const[_e,le]=Gx({nodeId:A,dragItems:c,nodeLookup:D});i==null||i(v,c,_e,le),G==null||G(v,_e,le),A||U==null||U(v,le)}}async function P(){if(!m)return;const{transform:F,panBy:V,autoPanSpeed:D,autoPanOnNodeDrag:I}=t();if(!I){d=!1,cancelAnimationFrame(o);return}const[z,W]=Hw(f,m,D);(z!==0||W!==0)&&(r.x=(r.x??0)-z/F[2],r.y=(r.y??0)-W/F[2],await V({x:z,y:W})&&R(r)),o=requestAnimationFrame(P)}function O(F){var ie;const{nodeLookup:V,multiSelectionActive:D,nodesDraggable:I,transform:z,snapGrid:W,snapToGrid:X,selectNodesOnDrag:G,onNodeDragStart:U,onSelectionDragStart:q,unselectNodesAndEdges:Y}=t();p=!0,(!G||!T)&&!D&&A&&((ie=V.get(A))!=null&&ie.selected||Y()),T&&G&&A&&(e==null||e(A));const $=Od(F.sourceEvent,{transform:z,snapGrid:W,snapToGrid:X,containerBounds:m});if(r=$,c=aue(V,I,$,A),c.size>0&&(n||U||!A&&q)){const[be,ce]=Gx({nodeId:A,dragItems:c,nodeLookup:V});n==null||n(F.sourceEvent,c,be,ce),U==null||U(F.sourceEvent,be,ce),A||q==null||q(F.sourceEvent,ce)}}const B=VI().clickDistance(M).on("start",F=>{const{domNode:V,nodeDragThreshold:D,transform:I,snapGrid:z,snapToGrid:W}=t();m=(V==null?void 0:V.getBoundingClientRect())||null,y=!1,x=!1,v=F.sourceEvent,D===0&&O(F),r=Od(F.sourceEvent,{transform:I,snapGrid:z,snapToGrid:W,containerBounds:m}),f=Qs(F.sourceEvent,m)}).on("drag",F=>{const{autoPanOnNodeDrag:V,transform:D,snapGrid:I,snapToGrid:z,nodeDragThreshold:W,nodeLookup:X}=t(),G=Od(F.sourceEvent,{transform:D,snapGrid:I,snapToGrid:z,containerBounds:m});if(v=F.sourceEvent,(F.sourceEvent.type==="touchmove"&&F.sourceEvent.touches.length>1||A&&!X.has(A))&&(y=!0),!y){if(!d&&V&&p&&(d=!0,P()),!p){const U=Qs(F.sourceEvent,m),q=U.x-f.x,Y=U.y-f.y;Math.sqrt(q*q+Y*Y)>W&&O(F)}(r.x!==G.xSnapped||r.y!==G.ySnapped)&&c&&p&&(f=Qs(F.sourceEvent,m),R(G))}}).on("end",F=>{if(!p||y){y&&c.size>0&&t().updateNodePositions(c,!1);return}if(d=!1,p=!1,cancelAnimationFrame(o),c.size>0){const{nodeLookup:V,updateNodePositions:D,onNodeDragStop:I,onSelectionDragStop:z}=t();if(x&&(D(c,!1),x=!1),s||I||!A&&z){const[W,X]=Gx({nodeId:A,dragItems:c,nodeLookup:V,dragging:!1});s==null||s(F.sourceEvent,c,W,X),I==null||I(F.sourceEvent,W,X),A||z==null||z(F.sourceEvent,X)}}}).filter(F=>{const V=F.target;return!F.button&&(!C||!bT(V,`.${C}`,j))&&(!S||bT(V,S,j))});b.call(B)}function k(){b==null||b.on(".drag",null)}return{update:w,destroy:k}}function cue(e,t,n){const i=[],s={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const r of t.values())Pm(s,nf(r))>0&&i.push(r);return i}const uue=250;function due(e,t,n,i){var c,d;let s=[],r=1/0;const o=cue(e,n,t+uue);for(const f of o){const m=[...((c=f.internals.handleBounds)==null?void 0:c.source)??[],...((d=f.internals.handleBounds)==null?void 0:d.target)??[]];for(const p of m){if(i.nodeId===p.nodeId&&i.type===p.type&&i.id===p.id)continue;const{x:b,y}=vl(f,p,p.position,!0),x=Math.sqrt(Math.pow(b-e.x,2)+Math.pow(y-e.y,2));x>t||(x<r?(s=[{...p,x:b,y}],r=x):x===r&&s.push({...p,x:b,y}))}}if(!s.length)return null;if(s.length>1){const f=i.type==="source"?"target":"source";return s.find(m=>m.type===f)??s[0]}return s[0]}function MP(e,t,n,i,s,r=!1){var f,m,p;const o=i.get(e);if(!o)return null;const c=s==="strict"?(f=o.internals.handleBounds)==null?void 0:f[t]:[...((m=o.internals.handleBounds)==null?void 0:m.source)??[],...((p=o.internals.handleBounds)==null?void 0:p.target)??[]],d=(n?c==null?void 0:c.find(b=>b.id===n):c==null?void 0:c[0])??null;return d&&r?{...d,...vl(o,d,d.position,!0)}:d}function RP(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function fue(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const DP=()=>!0;function hue(e,{connectionMode:t,connectionRadius:n,handleId:i,nodeId:s,edgeUpdaterType:r,isTarget:o,domNode:c,nodeLookup:d,lib:f,autoPanOnConnect:m,flowId:p,panBy:b,cancelConnection:y,onConnectStart:x,onConnect:v,onConnectEnd:w,isValidConnection:k=DP,onReconnectEnd:C,updateConnection:S,getTransform:j,getFromHandle:T,autoPanSpeed:A,dragThreshold:M=1,handleDomNode:R}){const P=xP(e.target);let O=0,B;const{x:F,y:V}=Qs(e),D=RP(r,R),I=c==null?void 0:c.getBoundingClientRect();let z=!1;if(!I||!D)return;const W=MP(s,D,i,d,t);if(!W)return;let X=Qs(e,I),G=!1,U=null,q=!1,Y=null;function $(){if(!m||!I)return;const[ne,oe]=Hw(X,I,A);b({x:ne,y:oe}),O=requestAnimationFrame($)}const ie={...W,nodeId:s,type:D,position:W.position},be=d.get(s);let _e={inProgress:!0,isValid:null,from:vl(be,ie,tt.Left,!0),fromHandle:ie,fromPosition:ie.position,fromNode:be,to:X,toHandle:null,toPosition:aT[ie.position],toNode:null,pointer:X};function le(){z=!0,S(_e),x==null||x(e,{nodeId:s,handleId:i,handleType:D})}M===0&&le();function pe(ne){if(!z){const{x:Fe,y:Le}=Qs(ne),pt=Fe-F,nt=Le-V;if(!(pt*pt+nt*nt>M*M))return;le()}if(!T()||!ie){Te(ne);return}const oe=j();X=Qs(ne,I),B=due(Lf(X,oe,!1,[1,1]),n,d,ie),G||($(),G=!0);const xe=OP(ne,{handle:B,connectionMode:t,fromNodeId:s,fromHandleId:i,fromType:o?"target":"source",isValidConnection:k,doc:P,lib:f,flowId:p,nodeLookup:d});Y=xe.handleDomNode,U=xe.connection,q=fue(!!B,xe.isValid);const fe=d.get(s),te=fe?vl(fe,ie,tt.Left,!0):_e.from,we={..._e,from:te,isValid:q,to:xe.toHandle&&q?Zc({x:xe.toHandle.x,y:xe.toHandle.y},oe):X,toHandle:xe.toHandle,toPosition:q&&xe.toHandle?xe.toHandle.position:aT[ie.position],toNode:xe.toHandle?d.get(xe.toHandle.nodeId):null,pointer:X};S(we),_e=we}function Te(ne){if(!("touches"in ne&&ne.touches.length>0)){if(z){(B||Y)&&U&&q&&(v==null||v(U));const{inProgress:oe,...xe}=_e,fe={...xe,toPosition:_e.toHandle?_e.toPosition:null};w==null||w(ne,fe),r&&(C==null||C(ne,fe))}y(),cancelAnimationFrame(O),G=!1,q=!1,U=null,Y=null,P.removeEventListener("mousemove",pe),P.removeEventListener("mouseup",Te),P.removeEventListener("touchmove",pe),P.removeEventListener("touchend",Te)}}P.addEventListener("mousemove",pe),P.addEventListener("mouseup",Te),P.addEventListener("touchmove",pe),P.addEventListener("touchend",Te)}function OP(e,{handle:t,connectionMode:n,fromNodeId:i,fromHandleId:s,fromType:r,doc:o,lib:c,flowId:d,isValidConnection:f=DP,nodeLookup:m}){const p=r==="target",b=t?o.querySelector(`.${c}-flow__handle[data-id="${d}-${t==null?void 0:t.nodeId}-${t==null?void 0:t.id}-${t==null?void 0:t.type}"]`):null,{x:y,y:x}=Qs(e),v=o.elementFromPoint(y,x),w=v!=null&&v.classList.contains(`${c}-flow__handle`)?v:b,k={handleDomNode:w,isValid:!1,connection:null,toHandle:null};if(w){const C=RP(void 0,w),S=w.getAttribute("data-nodeid"),j=w.getAttribute("data-handleid"),T=w.classList.contains("connectable"),A=w.classList.contains("connectableend");if(!S||!C)return k;const M={source:p?S:i,sourceHandle:p?j:s,target:p?i:S,targetHandle:p?s:j};k.connection=M;const P=T&&A&&(n===Xc.Strict?p&&C==="source"||!p&&C==="target":S!==i||j!==s);k.isValid=P&&f(M),k.toHandle=MP(S,C,j,m,n,!0)}return k}const V0={onPointerDown:hue,isValid:OP};function pue({domNode:e,panZoom:t,getTransform:n,getViewScale:i}){const s=ss(e);function r({translateExtent:c,width:d,height:f,zoomStep:m=1,pannable:p=!0,zoomable:b=!0,inversePan:y=!1}){const x=S=>{if(S.sourceEvent.type!=="wheel"||!t)return;const j=n(),T=S.sourceEvent.ctrlKey&&sf()?10:1,A=-S.sourceEvent.deltaY*(S.sourceEvent.deltaMode===1?.05:S.sourceEvent.deltaMode?1:.002)*m,M=j[2]*Math.pow(2,A*T);t.scaleTo(M)};let v=[0,0];const w=S=>{(S.sourceEvent.type==="mousedown"||S.sourceEvent.type==="touchstart")&&(v=[S.sourceEvent.clientX??S.sourceEvent.touches[0].clientX,S.sourceEvent.clientY??S.sourceEvent.touches[0].clientY])},k=S=>{const j=n();if(S.sourceEvent.type!=="mousemove"&&S.sourceEvent.type!=="touchmove"||!t)return;const T=[S.sourceEvent.clientX??S.sourceEvent.touches[0].clientX,S.sourceEvent.clientY??S.sourceEvent.touches[0].clientY],A=[T[0]-v[0],T[1]-v[1]];v=T;const M=i()*Math.max(j[2],Math.log(j[2]))*(y?-1:1),R={x:j[0]-A[0]*M,y:j[1]-A[1]*M},P=[[0,0],[d,f]];t.setViewportConstrained({x:R.x,y:R.y,zoom:j[2]},P,c)},C=aP().on("start",w).on("zoom",p?k:null).on("zoom.wheel",b?x:null);s.call(C,{})}function o(){s.on("zoom",null)}return{update:r,destroy:o,pointer:Gs}}const Eg=e=>({x:e.x,y:e.y,zoom:e.k}),Wx=({x:e,y:t,zoom:n})=>xg.translate(e,t).scale(n),vc=(e,t)=>e.target.closest(`.${t}`),LP=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),mue=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Yx=(e,t=0,n=mue,i=()=>{})=>{const s=typeof t=="number"&&t>0;return s||i(),s?e.transition().duration(t).ease(n).on("end",i):e},IP=e=>{const t=e.ctrlKey&&sf()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function gue({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:i,panOnScrollMode:s,panOnScrollSpeed:r,zoomOnPinch:o,onPanZoomStart:c,onPanZoom:d,onPanZoomEnd:f}){return m=>{if(vc(m,t))return m.ctrlKey&&m.preventDefault(),!1;m.preventDefault(),m.stopImmediatePropagation();const p=n.property("__zoom").k||1;if(m.ctrlKey&&o){const w=Gs(m),k=IP(m),C=p*Math.pow(2,k);i.scaleTo(n,C,w,m);return}const b=m.deltaMode===1?20:1;let y=s===ul.Vertical?0:m.deltaX*b,x=s===ul.Horizontal?0:m.deltaY*b;!sf()&&m.shiftKey&&s!==ul.Vertical&&(y=m.deltaY*b,x=0),i.translateBy(n,-(y/p)*r,-(x/p)*r,{internal:!0});const v=Eg(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(d==null||d(m,v),e.panScrollTimeout=setTimeout(()=>{f==null||f(m,v),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,c==null||c(m,v))}}function yue({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(i,s){const r=i.type==="wheel",o=!t&&r&&!i.ctrlKey,c=vc(i,e);if(i.ctrlKey&&r&&c&&i.preventDefault(),o||c)return null;i.preventDefault(),n.call(this,i,s)}}function bue({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return i=>{var r,o,c;if((r=i.sourceEvent)!=null&&r.internal)return;const s=Eg(i.transform);e.mouseButton=((o=i.sourceEvent)==null?void 0:o.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=s,((c=i.sourceEvent)==null?void 0:c.type)==="mousedown"&&t(!0),n&&(n==null||n(i.sourceEvent,s))}}function xue({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:i,onPanZoom:s}){return r=>{var o,c;e.usedRightMouseButton=!!(n&&LP(t,e.mouseButton??0)),(o=r.sourceEvent)!=null&&o.sync||i([r.transform.x,r.transform.y,r.transform.k]),s&&!((c=r.sourceEvent)!=null&&c.internal)&&(s==null||s(r.sourceEvent,Eg(r.transform)))}}function vue({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:i,onPanZoomEnd:s,onPaneContextMenu:r}){return o=>{var c;if(!((c=o.sourceEvent)!=null&&c.internal)&&(e.isZoomingOrPanning=!1,r&&LP(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&r(o.sourceEvent),e.usedRightMouseButton=!1,i(!1),s)){const d=Eg(o.transform);e.prevViewport=d,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s==null||s(o.sourceEvent,d)},n?150:0)}}}function wue({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:i,panOnScroll:s,zoomOnDoubleClick:r,userSelectionActive:o,noWheelClassName:c,noPanClassName:d,lib:f,connectionInProgress:m}){return p=>{var w;const b=e||t,y=n&&p.ctrlKey,x=p.type==="wheel";if(p.button===1&&p.type==="mousedown"&&(vc(p,`${f}-flow__node`)||vc(p,`${f}-flow__edge`)))return!0;if(!i&&!b&&!s&&!r&&!n||o||m&&!x||vc(p,c)&&x||vc(p,d)&&(!x||s&&x&&!e)||!n&&p.ctrlKey&&x)return!1;if(!n&&p.type==="touchstart"&&((w=p.touches)==null?void 0:w.length)>1)return p.preventDefault(),!1;if(!b&&!s&&!y&&x||!i&&(p.type==="mousedown"||p.type==="touchstart")||Array.isArray(i)&&!i.includes(p.button)&&p.type==="mousedown")return!1;const v=Array.isArray(i)&&i.includes(p.button)||!p.button||p.button<=1;return(!p.ctrlKey||x)&&v}}function Eue({domNode:e,minZoom:t,maxZoom:n,translateExtent:i,viewport:s,onPanZoom:r,onPanZoomStart:o,onPanZoomEnd:c,onDraggingChange:d}){const f={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},m=e.getBoundingClientRect(),p=aP().scaleExtent([t,n]).translateExtent(i),b=ss(e).call(p);C({x:s.x,y:s.y,zoom:Qc(s.zoom,t,n)},[[0,0],[m.width,m.height]],i);const y=b.on("wheel.zoom"),x=b.on("dblclick.zoom");p.wheelDelta(IP);async function v(B,F){return b?new Promise(V=>{p==null||p.interpolate((F==null?void 0:F.interpolate)==="linear"?Dd:Gp).transform(Yx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}function w({noWheelClassName:B,noPanClassName:F,onPaneContextMenu:V,userSelectionActive:D,panOnScroll:I,panOnDrag:z,panOnScrollMode:W,panOnScrollSpeed:X,preventScrolling:G,zoomOnPinch:U,zoomOnScroll:q,zoomOnDoubleClick:Y,zoomActivationKeyPressed:$,lib:ie,onTransformChange:be,connectionInProgress:ce,paneClickDistance:_e,selectionOnDrag:le}){D&&!f.isZoomingOrPanning&&k();const pe=I&&!$&&!D;p.clickDistance(le?1/0:!Xs(_e)||_e<0?0:_e);const Te=pe?gue({zoomPanValues:f,noWheelClassName:B,d3Selection:b,d3Zoom:p,panOnScrollMode:W,panOnScrollSpeed:X,zoomOnPinch:U,onPanZoomStart:o,onPanZoom:r,onPanZoomEnd:c}):yue({noWheelClassName:B,preventScrolling:G,d3ZoomHandler:y});b.on("wheel.zoom",Te,{passive:!1});const ne=bue({zoomPanValues:f,onDraggingChange:d,onPanZoomStart:o});p.on("start",ne);const oe=xue({zoomPanValues:f,panOnDrag:z,onPaneContextMenu:!!V,onPanZoom:r,onTransformChange:be});p.on("zoom",oe);const xe=vue({zoomPanValues:f,panOnDrag:z,panOnScroll:I,onPaneContextMenu:V,onPanZoomEnd:c,onDraggingChange:d});p.on("end",xe);const fe=wue({zoomActivationKeyPressed:$,panOnDrag:z,zoomOnScroll:q,panOnScroll:I,zoomOnDoubleClick:Y,zoomOnPinch:U,userSelectionActive:D,noPanClassName:F,noWheelClassName:B,lib:ie,connectionInProgress:ce});p.filter(fe),Y?b.on("dblclick.zoom",x):b.on("dblclick.zoom",null)}function k(){p.on("zoom",null)}async function C(B,F,V){const D=Wx(B),I=p==null?void 0:p.constrain()(D,F,V);return I&&await v(I),I}async function S(B,F){const V=Wx(B);return await v(V,F),V}function j(B){if(b){const F=Wx(B),V=b.property("__zoom");(V.k!==B.zoom||V.x!==B.x||V.y!==B.y)&&(p==null||p.transform(b,F,null,{sync:!0}))}}function T(){const B=b?rP(b.node()):{x:0,y:0,k:1};return{x:B.x,y:B.y,zoom:B.k}}async function A(B,F){return b?new Promise(V=>{p==null||p.interpolate((F==null?void 0:F.interpolate)==="linear"?Dd:Gp).scaleTo(Yx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}async function M(B,F){return b?new Promise(V=>{p==null||p.interpolate((F==null?void 0:F.interpolate)==="linear"?Dd:Gp).scaleBy(Yx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}function R(B){p==null||p.scaleExtent(B)}function P(B){p==null||p.translateExtent(B)}function O(B){const F=!Xs(B)||B<0?0:B;p==null||p.clickDistance(F)}return{update:w,destroy:k,setViewport:S,setViewportConstrained:C,getViewport:T,scaleTo:A,scaleBy:M,setScaleExtent:R,setTranslateExtent:P,syncViewport:j,setClickDistance:O}}var Jc;(function(e){e.Line="line",e.Handle="handle"})(Jc||(Jc={}));function kue({width:e,prevWidth:t,height:n,prevHeight:i,affectsX:s,affectsY:r}){const o=e-t,c=n-i,d=[o>0?1:o<0?-1:0,c>0?1:c<0?-1:0];return o&&s&&(d[0]=d[0]*-1),c&&r&&(d[1]=d[1]*-1),d}function xT(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),i=e.includes("left"),s=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:i,affectsY:s}}function Ua(e,t){return Math.max(0,t-e)}function Fa(e,t){return Math.max(0,e-t)}function kp(e,t,n){return Math.max(0,t-e,e-n)}function vT(e,t){return e?!t:t}function Sue(e,t,n,i,s,r,o,c){let{affectsX:d,affectsY:f}=t;const{isHorizontal:m,isVertical:p}=t,b=m&&p,{xSnapped:y,ySnapped:x}=n,{minWidth:v,maxWidth:w,minHeight:k,maxHeight:C}=i,{x:S,y:j,width:T,height:A,aspectRatio:M}=e;let R=Math.floor(m?y-e.pointerX:0),P=Math.floor(p?x-e.pointerY:0);const O=T+(d?-R:R),B=A+(f?-P:P),F=-r[0]*T,V=-r[1]*A;let D=kp(O,v,w),I=kp(B,k,C);if(o){let X=0,G=0;d&&R<0?X=Ua(S+R+F,o[0][0]):!d&&R>0&&(X=Fa(S+O+F,o[1][0])),f&&P<0?G=Ua(j+P+V,o[0][1]):!f&&P>0&&(G=Fa(j+B+V,o[1][1])),D=Math.max(D,X),I=Math.max(I,G)}if(c){let X=0,G=0;d&&R>0?X=Fa(S+R,c[0][0]):!d&&R<0&&(X=Ua(S+O,c[1][0])),f&&P>0?G=Fa(j+P,c[0][1]):!f&&P<0&&(G=Ua(j+B,c[1][1])),D=Math.max(D,X),I=Math.max(I,G)}if(s){if(m){const X=kp(O/M,k,C)*M;if(D=Math.max(D,X),o){let G=0;!d&&!f||d&&!f&&b?G=Fa(j+V+O/M,o[1][1])*M:G=Ua(j+V+(d?R:-R)/M,o[0][1])*M,D=Math.max(D,G)}if(c){let G=0;!d&&!f||d&&!f&&b?G=Ua(j+O/M,c[1][1])*M:G=Fa(j+(d?R:-R)/M,c[0][1])*M,D=Math.max(D,G)}}if(p){const X=kp(B*M,v,w)/M;if(I=Math.max(I,X),o){let G=0;!d&&!f||f&&!d&&b?G=Fa(S+B*M+F,o[1][0])/M:G=Ua(S+(f?P:-P)*M+F,o[0][0])/M,I=Math.max(I,G)}if(c){let G=0;!d&&!f||f&&!d&&b?G=Ua(S+B*M,c[1][0])/M:G=Fa(S+(f?P:-P)*M,c[0][0])/M,I=Math.max(I,G)}}}P=P+(P<0?I:-I),R=R+(R<0?D:-D),s&&(b?O>B*M?P=(vT(d,f)?-R:R)/M:R=(vT(d,f)?-P:P)*M:m?(P=R/M,f=d):(R=P*M,d=f));const z=d?S+R:S,W=f?j+P:j;return{width:T+(d?-R:R),height:A+(f?-P:P),x:r[0]*R*(d?-1:1)+z,y:r[1]*P*(f?-1:1)+W}}const PP={width:0,height:0,x:0,y:0},Nue={...PP,pointerX:0,pointerY:0,aspectRatio:1};function _ue(e,t,n){const i=t.position.x+e.position.x,s=t.position.y+e.position.y,r=e.measured.width??0,o=e.measured.height??0,c=n[0]*r,d=n[1]*o;return[[i-c,s-d],[i+r-c,s+o-d]]}function Cue({domNode:e,nodeId:t,getStoreItems:n,onChange:i,onEnd:s}){const r=ss(e);let o={controlDirection:xT("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function c({controlPosition:f,boundaries:m,keepAspectRatio:p,resizeDirection:b,onResizeStart:y,onResize:x,onResizeEnd:v,shouldResize:w}){let k={...PP},C={...Nue};o={boundaries:m,resizeDirection:b,keepAspectRatio:p,controlDirection:xT(f)};let S,j=null,T=[],A,M,R,P=!1;const O=VI().on("start",B=>{const{nodeLookup:F,transform:V,snapGrid:D,snapToGrid:I,nodeOrigin:z,paneDomNode:W}=n();if(S=F.get(t),!S)return;j=(W==null?void 0:W.getBoundingClientRect())??null;const{xSnapped:X,ySnapped:G}=Od(B.sourceEvent,{transform:V,snapGrid:D,snapToGrid:I,containerBounds:j});k={width:S.measured.width??0,height:S.measured.height??0,x:S.position.x??0,y:S.position.y??0},C={...k,pointerX:X,pointerY:G,aspectRatio:k.width/k.height},A=void 0,M=xl(S.extent)?S.extent:void 0,S.parentId&&(S.extent==="parent"||S.expandParent)&&(A=F.get(S.parentId)),A&&S.extent==="parent"&&(M=[[0,0],[A.measured.width,A.measured.height]]),T=[],R=void 0;for(const[U,q]of F)if(q.parentId===t&&(T.push({id:U,position:{...q.position},extent:q.extent}),q.extent==="parent"||q.expandParent)){const Y=_ue(q,S,q.origin??z);R?R=[[Math.min(Y[0][0],R[0][0]),Math.min(Y[0][1],R[0][1])],[Math.max(Y[1][0],R[1][0]),Math.max(Y[1][1],R[1][1])]]:R=Y}y==null||y(B,{...k})}).on("drag",B=>{const{transform:F,snapGrid:V,snapToGrid:D,nodeOrigin:I}=n(),z=Od(B.sourceEvent,{transform:F,snapGrid:V,snapToGrid:D,containerBounds:j}),W=[];if(!S)return;const{x:X,y:G,width:U,height:q}=k,Y={},$=S.origin??I,{width:ie,height:be,x:ce,y:_e}=Sue(C,o.controlDirection,z,o.boundaries,o.keepAspectRatio,$,M,R),le=ie!==U,pe=be!==q,Te=ce!==X&&le,ne=_e!==G&&pe;if(!Te&&!ne&&!le&&!pe)return;if((Te||ne||$[0]===1||$[1]===1)&&(Y.x=Te?ce:k.x,Y.y=ne?_e:k.y,k.x=Y.x,k.y=Y.y,T.length>0)){const te=ce-X,we=_e-G;for(const Fe of T)Fe.position={x:Fe.position.x-te+$[0]*(ie-U),y:Fe.position.y-we+$[1]*(be-q)},W.push(Fe)}if((le||pe)&&(Y.width=le&&(!o.resizeDirection||o.resizeDirection==="horizontal")?ie:k.width,Y.height=pe&&(!o.resizeDirection||o.resizeDirection==="vertical")?be:k.height,k.width=Y.width,k.height=Y.height),A&&S.expandParent){const te=$[0]*(Y.width??0);Y.x&&Y.x<te&&(k.x=te,C.x=C.x-(Y.x-te));const we=$[1]*(Y.height??0);Y.y&&Y.y<we&&(k.y=we,C.y=C.y-(Y.y-we))}const oe=kue({width:k.width,prevWidth:U,height:k.height,prevHeight:q,affectsX:o.controlDirection.affectsX,affectsY:o.controlDirection.affectsY}),xe={...k,direction:oe};(w==null?void 0:w(B,xe))!==!1&&(P=!0,x==null||x(B,xe),i(Y,W))}).on("end",B=>{P&&(v==null||v(B,{...k}),s==null||s({...k}),P=!1)});r.call(O)}function d(){r.on(".drag",null)}return{update:c,destroy:d}}var Xx={exports:{}},Qx={},Zx={exports:{}},Jx={};/**
843
+ `).map(B=>B.trim()).filter(Boolean))})]},p)}const k=((A=y.meta)==null?void 0:A.role)==="secret";return u.jsxs("label",{className:"flex flex-col gap-1",children:[v,w,u.jsx("input",{className:"nb-input text-sm",type:k?"password":y.type==="number"?"number":"text",value:x==null?"":String(x),...y.type==="number"?{min:(M=y.meta)==null?void 0:M.min,max:(R=y.meta)==null?void 0:R.max}:{},onChange:P=>m(p,y.type==="number"?Number(P.target.value):P.target.value)})]},p)})})}function Vp(e){if(e instanceof wM&&e.detail&&typeof e.detail=="object"){const t=e.detail;if(t.error)return{error:t.error,kind:t.kind??"unknown",detail:t.detail}}return{error:e instanceof Error?e.message:String(e),kind:"unknown"}}const zj={network:"装不上是网络问题 —— 检查代理或 registry 后重试。",auth:"registry 要凭据 —— 配好 npm 认证再试。","not-found":"这个名字或版本在 registry 上不存在。","not-plugin":"它装上了,但不是 Cordis 插件(没有 apply 导出)。装配档没有被改。",apply:"插件自己的代码抛了 —— 这是插件作者的问题。",conflict:"和已有的插件撞了(同名 id,或它提供的服务已经被别人占了)。"};function Bj({fail:e,title:t}){const[n,i]=_.useState(!1);return u.jsx("div",{className:"nb-card !border-[var(--color-danger)] text-sm",children:u.jsxs("div",{className:"flex items-start gap-2",children:[u.jsx(dF,{size:16,className:"mt-0.5 shrink-0 text-[var(--color-danger)]"}),u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsxs("p",{className:"font-medium",children:[t,":",e.error]}),u.jsxs("p",{className:"mt-1 text-[var(--color-text-muted)]",children:[u.jsx("code",{className:"text-xs",children:e.kind}),zj[e.kind]?` · ${zj[e.kind]}`:""]}),e.detail?u.jsxs(u.Fragment,{children:[u.jsx("button",{type:"button",className:"mt-2 text-xs underline text-[var(--color-text-muted)]",onClick:()=>i(s=>!s),children:n?"收起原文":"展开原文"}),n?u.jsx("pre",{className:"mt-2 max-h-64 overflow-auto whitespace-pre-wrap rounded bg-black/20 p-2 text-xs",children:e.detail}):null]}):null]})]})})}const gre=[{key:"user",title:"已装扩展",hint:"你自己装的插件。"},{key:"backend",title:"可换后端",hint:"换一行 name 就换掉实现;消费方一行不改。"},{key:"builtin",title:"内建能力包",hint:"把内建实现注册进对应的注册表。停用 = 那一类内建全部让路(比如让第三方生图适配器独占)。"},{key:"registry",title:"注册表(插座)",hint:"别人往里注册东西的挂载点,本身不需要配置。停用会让插在上面的一起失效。"}],yre=new Set(["tools","agents","repo","capabilities","media","im"]);function bre(e){return e.layer==="user"?"user":yre.has(e.key)?"registry":e.key.endsWith("-builtin")||e.key.startsWith("capabilities-")?"builtin":"backend"}function xre(e,t){return!!(t!=null&&t(e))||e.schema!==null}function vre({panelFor:e}){const t=Xt(),[n,i]=_.useState(""),[s,r]=_.useState(null),[o,c]=_.useState(null),[d,f]=_.useState(null),{data:m=[],isLoading:p}=Je({queryKey:["plugins"],queryFn:CI}),b=d?m.find(C=>C.key===d)??null:null,y=C=>{r(null),c(C??null),t.invalidateQueries({queryKey:["plugins"]})},x=At({mutationFn:()=>nre(n.trim()),onSuccess:C=>{i(""),y(C.warning)},onError:C=>r({title:"安装失败",fail:Vp(C)})}),v=At({mutationFn:({key:C,disabled:S})=>ire(C,S),onSuccess:C=>y(C.warning),onError:C=>r({title:"启停失败",fail:Vp(C)})}),w=At({mutationFn:C=>sre(C),onSuccess:C=>y(C.warning),onError:C=>r({title:"卸载失败",fail:Vp(C)})}),k=x.isPending||v.isPending||w.isPending;return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"nb-card",children:[u.jsx("label",{htmlFor:"plugin-spec",className:"text-sm font-medium",children:"装一个插件"}),u.jsxs("p",{className:"mt-1 text-xs text-[var(--color-text-muted)]",children:["填 npm 包名(可带 ",u.jsx("code",{children:"@版本"}),")或本地路径。装完**当场生效**,不用重启。"]}),u.jsxs("div",{className:"mt-3 flex gap-2",children:[u.jsx("input",{id:"plugin-spec",value:n,onChange:C=>i(C.target.value),placeholder:"@scope/coral-plugin-xxx",className:"nb-input flex-1 text-sm",disabled:k}),u.jsxs("button",{type:"button",onClick:()=>x.mutate(),disabled:k||!n.trim(),className:"nb-btn nb-btn-primary",children:[x.isPending?u.jsx(ht,{size:16,className:"animate-spin"}):u.jsx(Bn,{size:16}),"安装"]})]})]}),s?u.jsx(Bj,{fail:s.fail,title:s.title}):null,o?u.jsx(Bj,{fail:o,title:"操作完成,但有一件事没做成"}):null,p?u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:"读取中…"}):gre.map(C=>{const S=m.filter(j=>bre(j)===C.key);return S.length===0?null:u.jsxs("section",{className:"flex flex-col gap-3",children:[u.jsxs("header",{children:[u.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-base font-bold",children:C.title}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:C.hint})]}),u.jsx("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:S.map(j=>u.jsx(Ere,{row:j,busy:k,hasConfig:xre(j,e),onConfig:()=>f(j.key),onToggle:()=>v.mutate({key:j.key,disabled:!j.disabled}),onRemove:()=>w.mutate(j.key)},j.key))})]},C.key)}),b?u.jsx(Ow,{onClose:()=>f(null),children:u.jsxs("div",{className:"nb-card flex max-h-[88vh] w-full max-w-[min(1040px,94vw)] flex-col overflow-hidden !p-0",children:[u.jsxs("header",{className:"flex shrink-0 items-center justify-between gap-4 border-b border-[var(--color-border-light)] px-5 py-3",children:[u.jsx("h2",{className:"min-w-0 truncate font-[family-name:var(--font-heading)] text-base font-bold",children:b.key}),u.jsx("button",{type:"button",onClick:()=>f(null),"aria-label":"关闭",title:"关闭",className:"nb-btn shrink-0 !px-2 !py-1",children:u.jsx(vn,{size:14,strokeWidth:2.5})})]}),u.jsxs("div",{className:"flex flex-col divide-y divide-[var(--color-border-light)] overflow-y-auto",children:[(()=>{const C=(e==null?void 0:e(b))??(b.schema!==null?u.jsx(kre,{row:b,onSaved:S=>{f(null),y(S)},onFail:r}):null);return C?u.jsx("div",{className:"px-5 py-4",children:C}):null})(),u.jsx("div",{className:"px-5 py-4",children:u.jsx(wre,{row:b})})]})]})}):null]})}function wre({row:e}){const t=jI(e.key),n=[["包",e.pkg??e.name],["版本",e.version??"—"],["来源",e.layer==="factory"?"内建(随包出厂,只能停用)":"你装的"],["分类",e.category??"—"],["状态",e.disabled?"已停用":e.mounted?"运行中":"未挂上(装配档里有,但没启动起来)"],...e.essential?[["内核依赖",`停不掉 —— ${e.essential}`]]:[],["界面",e.clientFormat===null?"没有浏览器半区":e.clientFormat==="dsh"?"dsh 格式,没有装(需要移植)":t.ok===!1?`没加载起来:${t.error}`:`已加载 · 贡献了 ${t.slots} 个界面块`]];return u.jsxs("section",{className:"flex flex-col gap-2",children:[u.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-base font-bold",children:"插件信息"}),u.jsx("p",{className:"text-sm leading-5 text-[var(--color-text-muted)]",children:e.description||"(这个插件没写简介)"}),u.jsx("dl",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-xs",children:n.map(([i,s])=>u.jsxs(_.Fragment,{children:[u.jsx("dt",{className:"text-[var(--color-text-subtle)]",children:i}),u.jsx("dd",{className:"break-all font-[family-name:var(--font-mono)]",children:s})]},i))}),e.schema===null?u.jsx("p",{className:"text-xs text-[var(--color-text-subtle)]",children:"这个插件没有声明可配置项 —— 只能开关。"}):null]})}function Ere({row:e,busy:t,hasConfig:n,onConfig:i,onToggle:s,onRemove:r}){const o=jI(e.key),c=e.disabled?{text:"已停用",cls:"bg-[var(--color-text-muted)]/15 text-[var(--color-text-muted)]"}:e.mounted?{text:"运行中",cls:"bg-[var(--color-success)]/20 text-[var(--color-success)]"}:{text:"未挂上",cls:"bg-[var(--color-danger)]/20 text-[var(--color-danger)]"};return u.jsxs("article",{className:"nb-card nb-card-interactive relative flex flex-col gap-3",children:[u.jsx("button",{type:"button",onClick:i,"aria-label":`${n?"配置":"查看"} ${e.key}`,className:"absolute inset-0 cursor-pointer rounded-[inherit] border-0 bg-transparent"}),u.jsxs("div",{className:"flex items-start justify-between gap-2",children:[u.jsx("h3",{className:"min-w-0 flex-1 overflow-hidden break-all font-[family-name:var(--font-heading)] text-base font-bold",children:e.key}),u.jsx("span",{className:`nb-badge shrink-0 text-[10px] ${c.cls}`,title:e.disabled?"人主动停用的":e.mounted?"这个进程里正挂着":"装配档里有它,但没挂起来 —— 多半是它启动时抛了",children:c.text})]}),u.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.category?u.jsx("span",{className:"nb-badge text-[10px]",children:e.category}):null,e.essential?u.jsx("span",{className:"nb-badge text-[10px] opacity-70",title:e.essential,children:"内核依赖"}):null,u.jsx("span",{className:"nb-badge text-[10px] opacity-70",children:e.layer==="factory"?"内建":"已装"})]}),u.jsx("p",{className:"line-clamp-3 text-sm leading-5 text-[var(--color-text-muted)]",children:e.description||"(无简介)"}),e.clientFormat==="dsh"?u.jsxs("div",{className:"rounded-md border border-[var(--color-border-light)] bg-[var(--color-bg-soft)] px-2 py-1.5",children:[u.jsx("p",{className:"text-[11px] font-bold",children:"界面部分是 dsh 格式,没有装"}),u.jsxs("p",{className:"mt-0.5 text-[10px] text-[var(--color-text-muted)]",children:["它调 ",u.jsx("code",{children:"__ModuleLoader__"})," 并用 dsh 的槽名,需要移植。",u.jsx("b",{children:"工具/宿主部分不受影响。"})]})]}):o.ok===!1?u.jsxs("div",{className:"rounded-md border border-[var(--color-danger)] bg-[var(--color-danger)]/10 px-2 py-1.5",children:[u.jsx("p",{className:"text-[11px] font-bold",children:"界面部分没加载起来"}),u.jsx("p",{className:"mt-0.5 break-words text-[10px] text-[var(--color-text-muted)]",children:o.error})]}):o.slots>0?u.jsxs("p",{className:"text-[11px] text-[var(--color-text-muted)]",children:["贡献了 ",o.slots," 个界面块"]}):null,e.takeovers.length>0?u.jsxs("div",{className:"rounded-md border border-[var(--color-warning,#c90)] bg-[var(--color-warning,#c90)]/10 px-2 py-1.5",children:[u.jsxs("p",{className:"text-[11px] font-bold",children:["接管了 ",e.takeovers.length," 条宿主路由"]}),u.jsx("ul",{className:"mt-0.5 font-[family-name:var(--font-mono)] text-[10px] text-[var(--color-text-muted)]",children:e.takeovers.map(d=>u.jsx("li",{className:"truncate",children:d.kind==="prefix"?`${d.path}/*`:d.path},`${d.kind}:${d.path}`))})]}):null,u.jsxs("div",{className:"flex items-center justify-between gap-2 border-t border-[var(--color-border-light)] pt-2",children:[u.jsxs("span",{className:"min-w-0 flex-1 truncate font-[family-name:var(--font-mono)] text-[11px] text-[var(--color-text-subtle)]",title:e.pkg??e.name,children:[e.pkg??e.name,e.version?` · ${e.version}`:""]}),u.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n?u.jsx(Q6,{size:13,strokeWidth:2.5,"aria-hidden":!0,className:"text-[var(--color-text-subtle)]"}):null,u.jsx("button",{type:"button",className:"nb-btn relative z-10 !px-2 !py-1",onClick:s,disabled:t||!e.disabled&&e.essential!==null,"aria-label":e.disabled?`启用 ${e.key}`:`停用 ${e.key}`,title:!e.disabled&&e.essential?`内核直接依赖它,停不掉:${e.essential}。要换实现请改装配档那一行的 name。`:e.disabled?"启用":"停用",children:u.jsx(I6,{size:13,strokeWidth:2.5})}),u.jsx("button",{type:"button",className:"nb-btn relative z-10 !px-2 !py-1",onClick:r,disabled:t||e.layer==="factory","aria-label":`卸载 ${e.key}`,title:e.layer==="factory"?"内建插件不能卸载,只能停用":"卸载",children:u.jsx(us,{size:13,strokeWidth:2.5})})]})]})]})}function kre({row:e,onSaved:t,onFail:n}){const[i,s]=_.useState(()=>e.config&&typeof e.config=="object"?{...e.config}:{}),r=At({mutationFn:()=>rre(e.key,i),onSuccess:o=>t(o.warning),onError:o=>n({title:"保存配置失败",fail:Vp(o)})});return u.jsxs("section",{className:"flex flex-col gap-4",children:[u.jsxs("header",{className:"flex items-start justify-between gap-3",children:[u.jsx("div",{className:"min-w-0",children:u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:e.description||"(无简介)"})}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-primary shrink-0",disabled:r.isPending,onClick:()=>r.mutate(),"aria-label":`保存 ${e.key} 的配置`,children:[r.isPending?u.jsx(ht,{size:14,className:"animate-spin"}):u.jsx(cs,{size:14,strokeWidth:2.5}),"保存"]})]}),u.jsx(mre,{schema:e.schema,value:i,onChange:s}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"保存后**当场重挂**这个插件 —— 配置只在挂载那一刻读一次,不重挂等于没改。"})]})}async function Sre(){return(await wt("/api/channels")).data??{console:{},adapters:[]}}async function Nre(e){return(await bf("/api/channels",e)).data}function _re(e){return wt(`/api/media-providers?capability=${encodeURIComponent(e)}`)}async function Cre(e){const t=await fetch("/api/media-providers",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`${t.status}: ${await t.text()}`);return t.json()}function jre(e){return m1(`/api/media-providers/${encodeURIComponent(e)}`)}async function Tre(e,t){const n=await fetch(`/api/media-providers/default/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`${n.status}: ${await n.text()}`);return n.json()}const M0={image:"图片",video:"视频",music:"音乐",voice:"语音","3d":"3D",embedding:"向量(Embedding)",rerank:"重排(Rerank)"},Are={image:["codex","openai","volcengine","minimax","tripo","agnes","bailian","openrouter"],video:["volcengine"],music:["minimax"],voice:["doubao"],"3d":["tripo"],embedding:["openai-compatible"],rerank:["openai-compatible"]},TI={codex:"",openai:"https://api.openai.com/v1",tripo:"https://openapi.tripo3d.ai",volcengine:"https://ark.cn-beijing.volces.com/api/v3",minimax:"https://api.minimaxi.com",doubao:"https://openspeech.bytedance.com",agnes:"https://apihub.agnes-ai.com",bailian:"https://dashscope.aliyuncs.com",openrouter:"https://openrouter.ai/api/v1","openai-compatible":""},Mre=new Set(["codex"]);function Rre({capability:e}){var w,k,C;const t=Xt(),{alert:n,confirm:i}=Un(),s=Je({queryKey:["media-providers",e],queryFn:()=>_re(e)}),[r,o]=_.useState(null),c=Are[e]??[],d=((w=s.data)==null?void 0:w.providers)??[],f=(C=(k=s.data)==null?void 0:k.defaults)==null?void 0:C[e],m=At({mutationFn:S=>Cre(S),onSuccess:()=>{o(null),t.invalidateQueries({queryKey:["media-providers",e]})},onError:S=>void n({title:"保存失败",body:S instanceof Error?S.message:String(S)})}),p=At({mutationFn:S=>jre(S),onSuccess:()=>void t.invalidateQueries({queryKey:["media-providers",e]}),onError:S=>void n({title:"删除失败",body:S instanceof Error?S.message:String(S)})}),b=At({mutationFn:S=>Tre(e,S),onSuccess:()=>void t.invalidateQueries({queryKey:["media-providers",e]}),onError:S=>void n({title:"设默认失败",body:S instanceof Error?S.message:String(S)})}),y=(S,j)=>(f==null?void 0:f.providerId)===S&&(f==null?void 0:f.model)===j,x=()=>o({isNew:!0,entry:{id:"",name:"",capability:e,adapter:c[0]??"",baseUrl:c[0]?TI[c[0]]??"":"",apiKey:"",models:[]}}),v=S=>o({isNew:!1,entry:{id:S.id,name:S.name,capability:e,adapter:S.adapter,baseUrl:S.baseUrl,apiKey:"",models:S.models}});return u.jsxs("section",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[u.jsxs("div",{children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:[M0[e],"供应商"]}),u.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["增删该能力的第三方生成端点(adapter + Base URL + key + models)。**点模型标签设为该能力默认**;✓ = 当前默认。",f?u.jsxs(u.Fragment,{children:[" ","当前默认:",u.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:f.providerId}),f.model?u.jsxs(u.Fragment,{children:[" · ",u.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:f.model})]}):null]}):" 当前默认:未设置"]})]}),u.jsxs("button",{className:"nb-btn nb-btn-primary shrink-0",style:{padding:"8px 16px"},type:"button",onClick:x,"aria-label":`添加${M0[e]}供应商`,children:[u.jsx(Bn,{size:14,strokeWidth:3})," 添加供应商"]})]}),u.jsxs("div",{className:"flex flex-col gap-2 mt-4",children:[s.isLoading&&u.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[u.jsx(ht,{size:14,strokeWidth:3,className:"animate-spin"})," 加载中…"]}),!s.isLoading&&d.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无供应商)"}),d.map(S=>u.jsxs("div",{className:"rounded-lg px-3 py-2 border-2 border-[var(--color-text)]",children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:S.id}),u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",S.name]}),u.jsx("span",{className:"ml-2 text-[10px] font-bold px-2 py-0.5 rounded-md border-2 border-[var(--color-text)] bg-[var(--color-accent-yellow)]",children:S.adapter}),u.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[S.baseUrl," · key ",S.keyMasked||"未设置"]})]}),u.jsxs("div",{className:"flex gap-1 shrink-0",children:[u.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>v(S),"aria-label":`编辑 ${S.id}`,children:u.jsx(d1,{size:12,strokeWidth:3})}),u.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await i({title:"删除供应商",body:`删除 ${S.id}?`,danger:!0})&&p.mutate(S.id)},"aria-label":`删除 ${S.id}`,children:u.jsx(us,{size:12,strokeWidth:3})})]})]}),S.models.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:S.models.map(j=>{const T=y(S.id,j);return u.jsxs("button",{type:"button",onClick:()=>b.mutate({providerId:S.id,model:j}),disabled:b.isPending,"aria-pressed":T,className:["nb-btn px-2 py-0.5 text-xs font-[family-name:var(--font-mono)]",T?"nb-btn-mint":""].join(" "),title:T?"当前默认":"设为该能力默认",children:[j,T?" ✓":""]},j)})})]},S.id))]}),r&&u.jsx(Ow,{onClose:()=>o(null),children:u.jsx(Ore,{state:r,adapters:c,onChange:S=>o({...r,entry:S}),onCancel:()=>o(null),onSave:S=>m.mutate(S),saving:m.isPending})})]})}function Dre(e,t){const n=[...e];for(const i of t.split(/[,,\n\r]+/)){const s=i.trim();s&&!n.includes(s)&&n.push(s)}return n}function Ore({state:e,adapters:t,onChange:n,onCancel:i,onSave:s,saving:r}){const o=e.entry,[c,d]=_.useState(""),f=y=>n({...o,...y}),m=Mre.has(o.adapter),p=/^[a-zA-Z0-9_-]+$/.test(o.id)&&!!o.name.trim()&&!!o.adapter.trim()&&(m||!!o.baseUrl.trim()),b=y=>{f({adapter:y,baseUrl:TI[y]??""})};return u.jsxs("div",{className:"border-[3px] border-[var(--color-text)] rounded-2xl p-6 bg-[var(--color-bg-cream)] shadow-[6px_6px_0_var(--color-text)] flex flex-col gap-4 w-[min(92vw,640px)] max-h-[88vh] overflow-y-auto",children:[u.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增供应商":`编辑 ${o.id}`,u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:[" (",M0[o.capability],")"]})]}),u.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:o.id,disabled:!e.isNew,onChange:y=>f({id:y.target.value}),placeholder:"如 my-tripo",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",u.jsx("input",{className:"nb-input",value:o.name,onChange:y=>f({name:y.target.value}),placeholder:"显示名"})]})]}),u.jsxs("div",{className:"flex flex-col gap-1 text-sm font-bold",children:["adapter",u.jsx(Nc,{value:o.adapter,onChange:b,ariaLabel:"adapter",options:t.map(y=>({value:y,label:y}))})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",m&&"(订阅无需,可留空)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:o.baseUrl,onChange:y=>f({baseUrl:y.target.value}),placeholder:m?"订阅走本地凭据,无需填":"https://api.example.com",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",m?"(订阅无需)":!e.isNew&&"(留空=保留)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:o.apiKey??"",onChange:y=>f({apiKey:y.target.value}),placeholder:m?"订阅无需":e.isNew?"sk-...":"留空保留",spellCheck:!1})]}),u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("label",{htmlFor:"provider-models",className:"text-sm font-bold",children:"Models"}),u.jsx(AI,{models:o.models,draft:c,onModelsChange:y=>f({models:y}),onDraftChange:d}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"输入模型名,按 Enter 或逗号添加"})]}),u.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[u.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:i,children:"取消"}),u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!p||r,onClick:()=>s({...o,models:Dre(o.models,c)}),children:[r?u.jsx(ht,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(cs,{size:14,strokeWidth:3})," 保存"]})]})]})}async function Lre(){return(await wt("/api/mcp-tools")).tools}const Ire=[{key:"plugin",labelKey:"plugins.tab.plugin"},{key:"model",labelKey:"plugins.tab.model"},{key:"tool",labelKey:"plugins.tab.tool"}];function Pre(e){return lte("plugin.config",{pluginKey:e.key})?u.jsx(mw,{name:"plugin.config",props:{pluginKey:e.key}}):null}function zre(){const e=Ye(),[t,n]=_.useState("plugin");return u.jsxs("div",{className:"flex flex-col gap-6 w-full",children:[u.jsxs("header",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("plugins.h1")}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:e("plugins.desc")})]}),u.jsx(uu,{ariaLabel:e("plugins.h1"),className:"",value:t,onChange:n,options:Ire.map(i=>({value:i.key,label:e(i.labelKey)}))}),u.jsx("div",{role:"tabpanel",children:t==="plugin"?u.jsx(vre,{panelFor:Pre}):t==="model"?u.jsx($re,{}):u.jsx(Qre,{})})]})}function Bre(){var x,v,w;const e=Ye(),t=Xt(),{alert:n}=Un(),i=Je({queryKey:["system-memory"],queryFn:FF}),[s,r]=_.useState(null),[o,c]=_.useState(null);_.useEffect(()=>{i.data&&s===null&&(r(i.data.provider),c(i.data.url))},[i.data,s]);const d=s??((x=i.data)==null?void 0:x.provider)??"agentmemory",f=o??((v=i.data)==null?void 0:v.url)??"",m=i.data!=null&&(d!==i.data.provider||d==="custom"&&f!==i.data.url),p=k=>{const C=`system.memory.opt.${k}`;return e(C)},b=At({mutationFn:()=>$F(d,d==="custom"?f:""),onSuccess:()=>{t.invalidateQueries({queryKey:["system-memory"]}),t.invalidateQueries({queryKey:["system-env"]})},onError:k=>{n({title:e("system.memory.error"),body:k instanceof Error?k.message:String(k)})}}),y=((w=i.data)==null?void 0:w.options)??["none","builtin","agentmemory","custom"];return u.jsxs("section",{children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:e("system.memory.title")}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-3",children:e("system.memory.desc")}),u.jsxs("div",{className:"flex flex-col gap-3 max-w-md",children:[u.jsxs("div",{className:"flex flex-col gap-1 text-sm",children:[u.jsx("span",{className:"font-bold",children:e("system.memory.provider")}),u.jsx(Nc,{value:d,onChange:r,ariaLabel:e("system.memory.provider"),options:y.map(k=>({value:k,label:p(k)}))})]}),d==="custom"&&u.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[u.jsx("span",{className:"font-bold",children:e("system.memory.url")}),u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",type:"text",value:f,onChange:k=>c(k.target.value),placeholder:e("system.memory.url.placeholder"),spellCheck:!1,"aria-label":e("system.memory.url")})]}),u.jsx("div",{className:"flex justify-end",children:u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px",fontSize:12},onClick:()=>b.mutate(),disabled:!m||b.isPending,type:"button","aria-label":e("system.memory.save.aria"),children:[b.isPending?u.jsx(ht,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(cs,{size:12,strokeWidth:3}),b.isSuccess&&!m?e("system.memory.saved"):e("system.memory.save")]})})]})]})}const Ure=[{key:"llm",label:"sps agent"},{key:"image",label:"图片"},{key:"video",label:"视频"},{key:"music",label:"音乐"},{key:"voice",label:"语音"},{key:"3d",label:"3D"},{key:"embedding",label:"Embedding"},{key:"rerank",label:"Rerank"}];function Fre(){const e=Ye(),t=Xt(),n=_.useRef(null),[i,s]=_.useState(!1),r=async()=>{s(!0);try{const c=await wt("/api/model-config/export"),d=new Blob([JSON.stringify(c,null,2)],{type:"application/json"}),f=document.createElement("a");f.href=URL.createObjectURL(d),f.download=`sps-model-config-${new Date().toISOString().slice(0,10)}.json`,f.click(),URL.revokeObjectURL(f.href)}catch(c){window.alert(`${e("plugins.model.export.failed")}: ${c instanceof Error?c.message:String(c)}`)}finally{s(!1)}},o=async c=>{s(!0);try{const d=JSON.parse(await c.text());if(!window.confirm(e("plugins.model.import.confirm")))return;const m=(await jr("/api/model-config/import",d)).summary;window.alert(e("plugins.model.import.done",{llm:String(Number(m.llmAnthropic??0)+Number(m.llmOpenai??0)),media:String(m.media??0),skipped:String(m.skipped??0)})),t.invalidateQueries()}catch(d){window.alert(`${e("plugins.model.import.failed")}: ${d instanceof Error?d.message:String(d)}`)}finally{s(!1),n.current&&(n.current.value="")}};return u.jsxs("div",{className:"flex gap-2 items-center ml-auto",children:[u.jsxs("button",{type:"button",className:"nb-btn",style:{padding:"6px 12px"},disabled:i,onClick:()=>void r(),title:e("plugins.model.export.hint"),children:[u.jsx(sM,{size:14,strokeWidth:2.5})," ",e("plugins.model.export")]}),u.jsxs("button",{type:"button",className:"nb-btn",style:{padding:"6px 12px"},disabled:i,onClick:()=>{var c;return(c=n.current)==null?void 0:c.click()},title:e("plugins.model.import.hint"),children:[u.jsx(h1,{size:14,strokeWidth:2.5})," ",e("plugins.model.import")]}),u.jsx("input",{ref:n,type:"file",accept:"application/json,.json",className:"hidden",onChange:c=>{var f;const d=(f=c.target.files)==null?void 0:f[0];d&&o(d)}})]})}function $re(){const[e,t]=_.useState("llm");return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"flex flex-wrap gap-2 items-center",role:"tablist","aria-label":"模型/资源供应商",children:[Ure.map(n=>{const i=e===n.key;return u.jsx("button",{type:"button",role:"tab","aria-selected":i,onClick:()=>t(n.key),className:["nb-btn",i?"nb-btn-primary":""].join(" "),style:{padding:"6px 14px"},children:n.label},n.key)}),u.jsx(Fre,{})]}),e==="llm"?u.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:["Anthropic 兼容 ",u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"· 含 Claude 订阅"})]}),u.jsx(Uj,{only:"anthropic"})]}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:["OpenAI 兼容 ",u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"· 含 codex 订阅"})]}),u.jsx(Uj,{only:"openai"})]})]}):u.jsx(Rre,{capability:e})]})}function Uj({only:e}={}){var C,S,j;const t=Xt(),{alert:n,confirm:i}=Un(),s=Je({queryKey:["providers"],queryFn:B1}),o=(C=Je({queryKey:["system-agents"],queryFn:g1}).data)==null?void 0:C.agents,[c,d]=_.useState(null),f=At({mutationFn:T=>VY(c.kind,T),onSuccess:()=>{d(null),t.invalidateQueries({queryKey:["providers"]})},onError:T=>void n({title:"保存失败",body:T instanceof Error?T.message:String(T)})}),m=At({mutationFn:T=>KY(T.kind,T.id),onSuccess:()=>void t.invalidateQueries({queryKey:["providers"]}),onError:T=>void n({title:"删除失败",body:T instanceof Error?T.message:String(T)})}),p=At({mutationFn:T=>qF(T),onSuccess:()=>void t.invalidateQueries({queryKey:["system-agents"]}),onError:T=>void n({title:"设默认失败",body:T instanceof Error?T.message:String(T)})}),b=(T,A,M)=>{if(!o)return!1;const R=T==="anthropic"?o.worker:o.reviewer;return(R.providerId||"official")===A&&R.model===M},y=(T,A,M)=>{if(!o)return;let R;if(T==="anthropic"){const P={...o.worker,model:M};A==="official"?delete P.providerId:P.providerId=A,R={...o,worker:P}}else R={...o,reviewer:{...o.reviewer,providerId:A,model:M}};p.mutate(R)},x=[{kind:"anthropic",title:"Anthropic 兼容(worker / claude)",items:((S=s.data)==null?void 0:S.anthropic)??[]},{kind:"openai",title:"OpenAI 兼容(reviewer / openai agent)",items:((j=s.data)==null?void 0:j.openai)??[]}],v=e?x.filter(T=>T.kind===e):x,w=T=>d({kind:T,isNew:!0,entry:{id:"",name:"",baseUrl:"",apiKey:"",models:[]}}),k=(T,A)=>d({kind:T,isNew:!1,entry:{id:A.id,name:A.name,baseUrl:A.baseUrl,apiKey:"",transport:A.transport,models:A.models}});return u.jsxs("section",{className:"nb-card",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:"模型 API 端点"}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-4",children:"本地官方订阅(已登录验证)自动置顶,不可编辑;下方可增删第三方兼容端点。**点模型标签设为默认**(anthropic→worker / openai→监工);✓ = 当前默认。"}),u.jsx("div",{className:["grid grid-cols-1 gap-5",e?"":"lg:grid-cols-2"].join(" "),children:v.map(T=>u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("span",{className:"font-bold text-sm",children:T.title}),u.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:()=>w(T.kind),"aria-label":`添加 ${T.title} 端点`,children:[u.jsx(Bn,{size:12,strokeWidth:3})," 添加"]})]}),T.items.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无端点)"}),T.items.map(A=>u.jsxs("div",{className:["rounded-lg px-3 py-2 border-2",(A.builtin,"border-[var(--color-text)]")].join(" "),children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:A.id}),u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",A.name]}),A.builtin?u.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:["本地订阅",A.detail?` · ${A.detail}`:""," · 已验证可用"]}):u.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[A.baseUrl," · key ",A.hasKey?A.apiKey:"未设置"]})]}),A.builtin?u.jsx("span",{className:"shrink-0 text-[10px] font-bold px-2 py-0.5 rounded-md border-2 border-[var(--color-text)] bg-[var(--color-accent-yellow)]",children:"内置"}):u.jsxs("div",{className:"flex gap-1 shrink-0",children:[u.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>k(T.kind,A),"aria-label":`编辑 ${A.id}`,children:u.jsx(d1,{size:12,strokeWidth:3})}),u.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await i({title:"删除端点",body:`删除 ${A.id}?`,danger:!0})&&m.mutate({kind:T.kind,id:A.id})},"aria-label":`删除 ${A.id}`,children:u.jsx(us,{size:12,strokeWidth:3})})]})]}),A.models.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:A.models.map(M=>{const R=b(T.kind,A.id,M);return u.jsxs("button",{type:"button",onClick:()=>y(T.kind,A.id,M),disabled:p.isPending,"aria-pressed":R,className:["nb-btn px-2 py-0.5 text-xs font-[family-name:var(--font-mono)]",R?"nb-btn-mint":""].join(" "),title:R?"当前默认":"设为默认",children:[M,R?" ✓":""]},M)})})]},A.id))]},T.kind))}),c&&u.jsx(Ow,{onClose:()=>d(null),children:u.jsx(qre,{state:c,onChange:T=>d({...c,entry:T}),onCancel:()=>d(null),onSave:T=>f.mutate(T),saving:f.isPending})})]})}function R0(e,t){const n=[...e];for(const i of t.split(/[,,\n\r]+/)){const s=i.trim();s&&!n.includes(s)&&n.push(s)}return n}function AI({models:e,draft:t,onModelsChange:n,onDraftChange:i}){const s=r=>{n(R0(e,r)),i("")};return u.jsxs("div",{className:"nb-input min-h-[46px] w-full flex flex-wrap gap-1.5 items-center px-2.5 py-2",children:[e.map(r=>u.jsxs("span",{className:"inline-flex max-w-full items-center gap-1.5 rounded-md border border-[var(--color-border-light)] bg-[var(--surface-control)] px-2 py-1 text-xs font-[family-name:var(--font-mono)]",children:[u.jsx("span",{className:"max-w-[480px] truncate",children:r}),u.jsx("button",{type:"button",className:"shrink-0 text-[var(--color-text-muted)] hover:text-[var(--color-text)]",onClick:()=>n(e.filter(o=>o!==r)),"aria-label":`删除模型 ${r}`,children:u.jsx(vn,{size:12,strokeWidth:2.5})})]},r)),u.jsx("input",{id:"provider-models",className:"min-w-[180px] flex-1 bg-transparent px-1 py-0.5 text-sm outline-none font-[family-name:var(--font-mono)]",value:t,onChange:r=>{const o=r.target.value,c=o.split(/[,,\n\r]/);if(c.length===1){i(o);return}const d=c.pop()??"";n(R0(e,c.join(","))),i(d)},onKeyDown:r=>{r.key==="Enter"&&!r.nativeEvent.isComposing?(r.preventDefault(),s(t)):r.key==="Backspace"&&!t&&e.length>0&&n(e.slice(0,-1))},placeholder:e.length>0?"继续添加模型":"输入模型名后按 Enter","aria-label":"Models",spellCheck:!1})]})}function qre({state:e,onChange:t,onCancel:n,onSave:i,saving:s}){const r=e.entry,[o,c]=_.useState(""),d=m=>t({...r,...m}),f=/^[a-zA-Z0-9_-]+$/.test(r.id)&&r.name.trim()&&r.baseUrl.trim();return u.jsxs("div",{className:"border-[3px] border-[var(--color-text)] rounded-2xl p-6 bg-[var(--color-bg-cream)] shadow-[6px_6px_0_var(--color-text)] flex flex-col gap-4 w-[min(92vw,640px)] max-h-[88vh] overflow-y-auto",children:[u.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增端点":`编辑 ${r.id}`,u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:["(",e.kind,")"]})]}),u.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:r.id,disabled:!e.isNew,onChange:m=>d({id:m.target.value}),placeholder:"如 my-openai",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",u.jsx("input",{className:"nb-input",value:r.name,onChange:m=>d({name:m.target.value}),placeholder:"显示名"})]})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:r.baseUrl,onChange:m=>d({baseUrl:m.target.value}),placeholder:"https://api.example.com/v1",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",!e.isNew&&"(留空=保留)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:r.apiKey??"",onChange:m=>d({apiKey:m.target.value}),placeholder:e.isNew?"sk-...":"••••(留空不改)",spellCheck:!1})]}),e.kind==="openai"&&u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["请求方言",u.jsxs("select",{className:"nb-input text-sm",value:r.transport??"chat_completions",onChange:m=>d({transport:m.target.value}),children:[u.jsx("option",{value:"chat_completions",children:"Chat Completions(/v1/chat/completions,默认)"}),u.jsx("option",{value:"responses",children:"Responses(/v1/responses)"})]}),u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"走 codex 订阅的网关端点(如 gpt-*)必须选 Responses,否则上游 400。"})]}),u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("label",{htmlFor:"provider-models",className:"text-sm font-bold",children:"Models"}),u.jsx(AI,{models:r.models,draft:o,onModelsChange:m=>d({models:m}),onDraftChange:c}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"输入模型名,按 Enter 或逗号添加"})]}),u.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[u.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:n,children:"取消"}),u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!f||s,onClick:()=>i({...r,models:R0(r.models,o)}),children:[s?u.jsx(ht,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(cs,{size:14,strokeWidth:3})," 保存"]})]})]})}function Ow({children:e,onClose:t}){return ZA.createPortal(u.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/50 p-4",onClick:t,children:u.jsx("div",{onClick:n=>n.stopPropagation(),children:e})}),document.body)}const Hre=["telegram","dingtalk","matrix","slack","discord","feishu"],Yd={telegram:"Telegram",dingtalk:"钉钉 (Stream)",matrix:"Matrix",slack:"Slack",discord:"Discord",feishu:"飞书 / Lark"},Vre={telegram:[{key:"token",label:"Bot Token(@BotFather)",type:"password",placeholder:"123456:ABC-..."},{key:"allowedChatIds",label:"允许的 Chat ID(白名单,空=全放)",type:"list",placeholder:"逗号/换行分隔"}],dingtalk:[{key:"clientId",label:"Client ID(AppKey)",type:"text"},{key:"clientSecret",label:"Client Secret(AppSecret)",type:"password"},{key:"allowedConversations",label:"允许的会话 ID(白名单,空=全放)",type:"list"}],matrix:[{key:"homeserver",label:"Homeserver URL",type:"text",placeholder:"https://matrix.org"},{key:"accessToken",label:"Access Token",type:"password"},{key:"allowedRooms",label:"允许的 Room ID(白名单,空=全放)",type:"list"}],slack:[{key:"appToken",label:"App Token(xapp-,Socket Mode)",type:"password",placeholder:"xapp-..."},{key:"botToken",label:"Bot Token(xoxb-)",type:"password",placeholder:"xoxb-..."},{key:"allowedChannels",label:"允许的 Channel(白名单,空=全放)",type:"list"}],discord:[{key:"token",label:"Bot Token",type:"password"},{key:"allowedChannels",label:"允许的 Channel ID(白名单,空=全放)",type:"list"}],feishu:[{key:"appId",label:"App ID",type:"text"},{key:"appSecret",label:"App Secret",type:"password"},{key:"verificationToken",label:"Verification Token",type:"text"},{key:"encryptKey",label:"Encrypt Key(设了则事件 AES 解密)",type:"password"},{key:"port",label:"本机监听端口(默认 9800)",type:"number",placeholder:"9800"},{key:"path",label:"监听路径(默认 /feishu)",type:"text",placeholder:"/feishu"},{key:"allowedChats",label:"允许的 chat_id(白名单,空=全放)",type:"list"}]};function Kre(){var x,v,w;const e=Xt(),{alert:t}=Un(),n=Je({queryKey:["channels"],queryFn:Sre}),[i,s]=_.useState(null),[r,o]=_.useState({type:"console"});_.useEffect(()=>{n.data&&!i&&s({console:n.data.console??{},adapters:n.data.adapters??[]})},[n.data,i]);const c=At({mutationFn:()=>Nre(i),onSuccess:k=>{s({console:k.console??{},adapters:k.adapters??[]}),e.invalidateQueries({queryKey:["channels"]})},onError:k=>void t({title:"保存失败",body:k instanceof Error?k.message:String(k)})});if(!i)return u.jsx("section",{children:u.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[u.jsx(ht,{size:14,strokeWidth:3,className:"animate-spin"})," 加载频道配置…"]})});const d=i.adapters??[],f=JSON.stringify(i)!==JSON.stringify({console:((x=n.data)==null?void 0:x.console)??{},adapters:((v=n.data)==null?void 0:v.adapters)??[]}),m=k=>{const C=[...d,{kind:k,enabled:!0}];s({...i,adapters:C}),o({type:"adapter",index:C.length-1})},p=k=>{const C=d.filter((S,j)=>j!==k);s({...i,adapters:C}),o({type:"console"})},b=(k,C)=>{const S=d.map((j,T)=>T===k?{...j,...C}:j);s({...i,adapters:S})},y=k=>s({...i,console:{...i.console,...k}});return u.jsxs("section",{children:[u.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[u.jsxs("div",{children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:"频道(IM 网关)"}),u.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["接入 Telegram / 钉钉 / 飞书 / Slack / Discord / Matrix。左侧选频道,右侧改设置。保存后 ",u.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:"sps im"})," 重启生效。"]})]}),u.jsxs("button",{className:"nb-btn nb-btn-primary shrink-0",style:{padding:"8px 16px"},type:"button",disabled:!f||c.isPending,onClick:()=>c.mutate(),"aria-label":"保存频道配置",children:[c.isPending?u.jsx(ht,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(cs,{size:14,strokeWidth:3})," 保存"]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[220px_1fr] gap-5 mt-4",children:[u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"rounded-2xl border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] p-2 flex flex-col gap-1",children:[u.jsx(Fj,{label:"console 桥接",sub:((w=i.console)==null?void 0:w.url)||"未配置",active:r.type==="console",onClick:()=>o({type:"console"})}),u.jsx("div",{className:"h-px bg-[var(--color-text)] opacity-15 my-0.5"}),d.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] px-2 py-1",children:"(无频道)"}),d.map((k,C)=>u.jsx(Fj,{label:Yd[k.kind]??k.kind,sub:k.enabled===!1?"已停用":"启用",active:r.type==="adapter"&&r.index===C,onClick:()=>o({type:"adapter",index:C})},C))]}),u.jsx(Gre,{onAdd:m})]}),u.jsx("div",{className:"border-2 bg-surface-input border-[var(--color-text)] rounded-xl p-4 bg-[var(--color-bg-cream)]",children:(()=>{if(r.type!=="adapter")return u.jsx($j,{console:i.console??{},onChange:y});const k=d[r.index];if(!k)return u.jsx($j,{console:i.console??{},onChange:y});const C=r.index;return u.jsx(Wre,{adapter:k,onChange:S=>b(C,S),onRemove:()=>p(C)})})()})]})]})}function Gre({onAdd:e}){const[t,n]=_.useState(!1),i=_.useRef(null),s=_.useRef(null);return _.useEffect(()=>{const r=o=>{var c;(c=i.current)!=null&&c.contains(o.target)||n(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[]),u.jsxs("div",{className:"relative",ref:i,children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-primary w-full justify-center",onClick:()=>n(r=>!r),"aria-expanded":t,"aria-label":"添加频道",children:[u.jsx(Bn,{size:13,strokeWidth:3})," 添加频道",u.jsx(uo,{size:13,strokeWidth:2.5,className:["transition-transform",t?"rotate-180":""].join(" ")})]}),t&&u.jsx("div",{className:"mt-2 min-w-full nb-card p-1 overflow-hidden bg-[var(--surface-menu)]",children:u.jsx("div",{ref:s,className:"max-h-[50vh] overflow-y-auto",children:Hre.map((r,o)=>u.jsx(cu,{index:o,root:s,delay:.02,children:u.jsxs("button",{type:"button",className:"dimension-menu-item w-full text-left px-4 py-2 text-sm font-semibold flex items-center gap-2",onClick:()=>{e(r),n(!1)},"aria-label":`添加 ${Yd[r]} 频道`,children:[u.jsx(Bn,{size:12,strokeWidth:3,className:"shrink-0"})," ",Yd[r]]})},r))})})]})}function Fj({label:e,sub:t,active:n,onClick:i}){return u.jsxs("button",{type:"button",onClick:i,"aria-pressed":n,className:["dimension-menu-item flex-col items-start gap-0.5 px-3 py-2 text-left",n?"dimension-menu-item-active":""].join(" "),children:[u.jsx("div",{className:"font-bold text-sm",children:e}),u.jsx("div",{className:"text-xs text-[var(--color-text-muted)] truncate w-full font-[family-name:var(--font-mono)]",children:t})]})}function $j({console:e,onChange:t}){return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{children:[u.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"console 桥接"}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:"IM 纯文本消息桥接到项目 agent 对话。设了 URL 才启用桥接;token 为 console 鉴权令牌。"})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console URL",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:e.url??"",onChange:n=>t({url:n.target.value}),placeholder:"http://localhost:4321",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console Token(SPS_CONSOLE_TOKEN)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:e.token??"",onChange:n=>t({token:n.target.value}),placeholder:"鉴权令牌(可空)",spellCheck:!1})]}),u.jsxs("div",{className:"flex flex-col gap-1 text-sm font-bold",children:["对话后端",u.jsx(Nc,{value:e.agentKind??"claude",onChange:n=>t({agentKind:n}),ariaLabel:"对话后端",options:[{value:"claude",label:"claude"},{value:"openai",label:"openai"}]})]})]})}function Wre({adapter:e,onChange:t,onRemove:n}){const{confirm:i}=Un(),s=Vre[e.kind]??[],r=e.enabled!==!1;return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"flex items-start justify-between gap-2",children:[u.jsxs("div",{children:[u.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:Yd[e.kind]??e.kind}),u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-[family-name:var(--font-mono)]",children:[" · ",e.kind]})]}),u.jsxs("button",{className:"nb-btn nb-btn-danger shrink-0",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:async()=>{await i({title:"删除频道",body:`删除 ${Yd[e.kind]??e.kind} 频道?`,danger:!0})&&n()},"aria-label":"删除频道",children:[u.jsx(us,{size:12,strokeWidth:3})," 删除"]})]}),u.jsxs("label",{className:"flex items-center gap-2 text-sm font-bold",children:[u.jsx("input",{type:"checkbox",checked:r,onChange:o=>t({enabled:o.target.checked})}),"启用此频道"]}),s.map(o=>u.jsx(Yre,{spec:o,value:e[o.key],onChange:c=>t({[o.key]:c})},o.key))]})}function Yre({spec:e,value:t,onChange:n}){if(e.type==="list"){const i=Array.isArray(t)?t.map(String):[];return u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,u.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",rows:2,value:i.join(", "),onChange:s=>{const r=s.target.value.split(/[,\n]/).map(o=>o.trim()).filter(Boolean);n(r.length?r:void 0)},placeholder:e.placeholder,spellCheck:!1})]})}return u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:e.type==="password"?"password":"text",value:t==null?"":String(t),onChange:i=>{const s=i.target.value;e.type==="number"?n(s.trim()===""?void 0:Number(s)):n(s===""?void 0:s)},placeholder:e.placeholder,spellCheck:!1})]})}const Xre=["skill","asset","project","interaction","memory","agent","other"];function Qre(){const e=Ye(),t=Je({queryKey:["mcp-tools"],queryFn:Lre});if(t.isLoading)return u.jsx("section",{className:"nb-card",children:u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("plugins.tool.loading")})});if(t.isError)return u.jsx("section",{className:"nb-card",children:u.jsxs("p",{className:"text-sm text-[var(--color-crashed)]",children:[e("plugins.tool.failed"),":",t.error instanceof Error?t.error.message:String(t.error)]})});const n=t.data??[],i=Xre.map(s=>({key:s,items:n.filter(r=>r.group===s)})).filter(s=>s.items.length>0);return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx("section",{className:"nb-card",children:u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("plugins.tool.desc",{count:String(n.length)})})}),i.map(s=>u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:[e(`plugins.tool.group.${s.key}`),u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)] ml-2",children:s.items.length})]}),u.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:s.items.map(r=>u.jsxs("section",{className:"nb-card flex flex-col gap-2",children:[u.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-sm font-bold",children:r.name}),!r.viaMcpOnOpenai&&u.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded-lg border-2 border-[var(--color-text)] bg-[var(--color-secondary)]",children:e("plugins.tool.nativeOnOpenai")})]}),u.jsx("p",{className:"text-sm leading-5",children:r.description}),r.params.length>0&&u.jsx("ul",{className:"flex flex-col gap-1 m-0 p-0 list-none",children:r.params.map(o=>u.jsxs("li",{className:"text-xs text-[var(--color-text-muted)] leading-4",children:[u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[var(--color-text)]",children:o.name}),u.jsx("span",{className:"ml-1",children:o.type}),o.required&&u.jsx("span",{className:"ml-1 font-bold",children:e("plugins.tool.required")}),o.description&&u.jsxs("span",{className:"ml-1",children:["— ",o.description]})]},o.name))}),u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[11px] text-[var(--color-text-subtle)]",children:r.qualifiedName})]},r.name))})]},s.key))]})}function Wn(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,i;n<e.length;n++)(i=Wn(e[n]))!==""&&(t+=(t&&" ")+i);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var Zre={value:()=>{}};function mg(){for(var e=0,t=arguments.length,n={},i;e<t;++e){if(!(i=arguments[e]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new Kp(n)}function Kp(e){this._=e}function Jre(e,t){return e.trim().split(/^|\s+/).map(function(n){var i="",s=n.indexOf(".");if(s>=0&&(i=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}Kp.prototype=mg.prototype={constructor:Kp,on:function(e,t){var n=this._,i=Jre(e+"",n),s,r=-1,o=i.length;if(arguments.length<2){for(;++r<o;)if((s=(e=i[r]).type)&&(s=eae(n[s],e.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++r<o;)if(s=(e=i[r]).type)n[s]=qj(n[s],e.name,t);else if(t==null)for(s in n)n[s]=qj(n[s],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new Kp(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),i=0,s,r;i<s;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(r=this._[e],i=0,s=r.length;i<s;++i)r[i].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],s=0,r=i.length;s<r;++s)i[s].value.apply(t,n)}};function eae(e,t){for(var n=0,i=e.length,s;n<i;++n)if((s=e[n]).name===t)return s.value}function qj(e,t,n){for(var i=0,s=e.length;i<s;++i)if(e[i].name===t){e[i]=Zre,e=e.slice(0,i).concat(e.slice(i+1));break}return n!=null&&e.push({name:t,value:n}),e}var D0="http://www.w3.org/1999/xhtml";const Hj={svg:"http://www.w3.org/2000/svg",xhtml:D0,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function gg(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Hj.hasOwnProperty(t)?{space:Hj[t],local:e}:e}function tae(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===D0&&t.documentElement.namespaceURI===D0?t.createElement(e):t.createElementNS(n,e)}}function nae(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function MI(e){var t=gg(e);return(t.local?nae:tae)(t)}function iae(){}function Lw(e){return e==null?iae:function(){return this.querySelector(e)}}function sae(e){typeof e!="function"&&(e=Lw(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=new Array(o),d,f,m=0;m<o;++m)(d=r[m])&&(f=e.call(d,d.__data__,m,r))&&("__data__"in d&&(f.__data__=d.__data__),c[m]=f);return new os(i,this._parents)}function rae(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function aae(){return[]}function RI(e){return e==null?aae:function(){return this.querySelectorAll(e)}}function oae(e){return function(){return rae(e.apply(this,arguments))}}function lae(e){typeof e=="function"?e=oae(e):e=RI(e);for(var t=this._groups,n=t.length,i=[],s=[],r=0;r<n;++r)for(var o=t[r],c=o.length,d,f=0;f<c;++f)(d=o[f])&&(i.push(e.call(d,d.__data__,f,o)),s.push(d));return new os(i,s)}function DI(e){return function(){return this.matches(e)}}function OI(e){return function(t){return t.matches(e)}}var cae=Array.prototype.find;function uae(e){return function(){return cae.call(this.children,e)}}function dae(){return this.firstElementChild}function fae(e){return this.select(e==null?dae:uae(typeof e=="function"?e:OI(e)))}var hae=Array.prototype.filter;function pae(){return Array.from(this.children)}function mae(e){return function(){return hae.call(this.children,e)}}function gae(e){return this.selectAll(e==null?pae:mae(typeof e=="function"?e:OI(e)))}function yae(e){typeof e!="function"&&(e=DI(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=[],d,f=0;f<o;++f)(d=r[f])&&e.call(d,d.__data__,f,r)&&c.push(d);return new os(i,this._parents)}function LI(e){return new Array(e.length)}function bae(){return new os(this._enter||this._groups.map(LI),this._parents)}function jm(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}jm.prototype={constructor:jm,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function xae(e){return function(){return e}}function vae(e,t,n,i,s,r){for(var o=0,c,d=t.length,f=r.length;o<f;++o)(c=t[o])?(c.__data__=r[o],i[o]=c):n[o]=new jm(e,r[o]);for(;o<d;++o)(c=t[o])&&(s[o]=c)}function wae(e,t,n,i,s,r,o){var c,d,f=new Map,m=t.length,p=r.length,b=new Array(m),y;for(c=0;c<m;++c)(d=t[c])&&(b[c]=y=o.call(d,d.__data__,c,t)+"",f.has(y)?s[c]=d:f.set(y,d));for(c=0;c<p;++c)y=o.call(e,r[c],c,r)+"",(d=f.get(y))?(i[c]=d,d.__data__=r[c],f.delete(y)):n[c]=new jm(e,r[c]);for(c=0;c<m;++c)(d=t[c])&&f.get(b[c])===d&&(s[c]=d)}function Eae(e){return e.__data__}function kae(e,t){if(!arguments.length)return Array.from(this,Eae);var n=t?wae:vae,i=this._parents,s=this._groups;typeof e!="function"&&(e=xae(e));for(var r=s.length,o=new Array(r),c=new Array(r),d=new Array(r),f=0;f<r;++f){var m=i[f],p=s[f],b=p.length,y=Sae(e.call(m,m&&m.__data__,f,i)),x=y.length,v=c[f]=new Array(x),w=o[f]=new Array(x),k=d[f]=new Array(b);n(m,p,v,w,k,y,t);for(var C=0,S=0,j,T;C<x;++C)if(j=v[C]){for(C>=S&&(S=C+1);!(T=w[S])&&++S<x;);j._next=T||null}}return o=new os(o,i),o._enter=c,o._exit=d,o}function Sae(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Nae(){return new os(this._exit||this._groups.map(LI),this._parents)}function _ae(e,t,n){var i=this.enter(),s=this,r=this.exit();return typeof e=="function"?(i=e(i),i&&(i=i.selection())):i=i.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?r.remove():n(r),i&&s?i.merge(s).order():s}function Cae(e){for(var t=e.selection?e.selection():e,n=this._groups,i=t._groups,s=n.length,r=i.length,o=Math.min(s,r),c=new Array(s),d=0;d<o;++d)for(var f=n[d],m=i[d],p=f.length,b=c[d]=new Array(p),y,x=0;x<p;++x)(y=f[x]||m[x])&&(b[x]=y);for(;d<s;++d)c[d]=n[d];return new os(c,this._parents)}function jae(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var i=e[t],s=i.length-1,r=i[s],o;--s>=0;)(o=i[s])&&(r&&o.compareDocumentPosition(r)^4&&r.parentNode.insertBefore(o,r),r=o);return this}function Tae(e){e||(e=Aae);function t(p,b){return p&&b?e(p.__data__,b.__data__):!p-!b}for(var n=this._groups,i=n.length,s=new Array(i),r=0;r<i;++r){for(var o=n[r],c=o.length,d=s[r]=new Array(c),f,m=0;m<c;++m)(f=o[m])&&(d[m]=f);d.sort(t)}return new os(s,this._parents).order()}function Aae(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Mae(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Rae(){return Array.from(this)}function Dae(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],s=0,r=i.length;s<r;++s){var o=i[s];if(o)return o}return null}function Oae(){let e=0;for(const t of this)++e;return e}function Lae(){return!this.node()}function Iae(e){for(var t=this._groups,n=0,i=t.length;n<i;++n)for(var s=t[n],r=0,o=s.length,c;r<o;++r)(c=s[r])&&e.call(c,c.__data__,r,s);return this}function Pae(e){return function(){this.removeAttribute(e)}}function zae(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Bae(e,t){return function(){this.setAttribute(e,t)}}function Uae(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Fae(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function $ae(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function qae(e,t){var n=gg(e);if(arguments.length<2){var i=this.node();return n.local?i.getAttributeNS(n.space,n.local):i.getAttribute(n)}return this.each((t==null?n.local?zae:Pae:typeof t=="function"?n.local?$ae:Fae:n.local?Uae:Bae)(n,t))}function II(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Hae(e){return function(){this.style.removeProperty(e)}}function Vae(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Kae(e,t,n){return function(){var i=t.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,n)}}function Gae(e,t,n){return arguments.length>1?this.each((t==null?Hae:typeof t=="function"?Kae:Vae)(e,t,n??"")):Wc(this.node(),e)}function Wc(e,t){return e.style.getPropertyValue(t)||II(e).getComputedStyle(e,null).getPropertyValue(t)}function Wae(e){return function(){delete this[e]}}function Yae(e,t){return function(){this[e]=t}}function Xae(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Qae(e,t){return arguments.length>1?this.each((t==null?Wae:typeof t=="function"?Xae:Yae)(e,t)):this.node()[e]}function PI(e){return e.trim().split(/^|\s+/)}function Iw(e){return e.classList||new zI(e)}function zI(e){this._node=e,this._names=PI(e.getAttribute("class")||"")}zI.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 BI(e,t){for(var n=Iw(e),i=-1,s=t.length;++i<s;)n.add(t[i])}function UI(e,t){for(var n=Iw(e),i=-1,s=t.length;++i<s;)n.remove(t[i])}function Zae(e){return function(){BI(this,e)}}function Jae(e){return function(){UI(this,e)}}function eoe(e,t){return function(){(t.apply(this,arguments)?BI:UI)(this,e)}}function toe(e,t){var n=PI(e+"");if(arguments.length<2){for(var i=Iw(this.node()),s=-1,r=n.length;++s<r;)if(!i.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?eoe:t?Zae:Jae)(n,t))}function noe(){this.textContent=""}function ioe(e){return function(){this.textContent=e}}function soe(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function roe(e){return arguments.length?this.each(e==null?noe:(typeof e=="function"?soe:ioe)(e)):this.node().textContent}function aoe(){this.innerHTML=""}function ooe(e){return function(){this.innerHTML=e}}function loe(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function coe(e){return arguments.length?this.each(e==null?aoe:(typeof e=="function"?loe:ooe)(e)):this.node().innerHTML}function uoe(){this.nextSibling&&this.parentNode.appendChild(this)}function doe(){return this.each(uoe)}function foe(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function hoe(){return this.each(foe)}function poe(e){var t=typeof e=="function"?e:MI(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function moe(){return null}function goe(e,t){var n=typeof e=="function"?e:MI(e),i=t==null?moe:typeof t=="function"?t:Lw(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})}function yoe(){var e=this.parentNode;e&&e.removeChild(this)}function boe(){return this.each(yoe)}function xoe(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function voe(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function woe(e){return this.select(e?voe:xoe)}function Eoe(e){return arguments.length?this.property("__data__",e):this.node().__data__}function koe(e){return function(t){e.call(this,t,this.__data__)}}function Soe(e){return e.trim().split(/^|\s+/).map(function(t){var n="",i=t.indexOf(".");return i>=0&&(n=t.slice(i+1),t=t.slice(0,i)),{type:t,name:n}})}function Noe(e){return function(){var t=this.__on;if(t){for(var n=0,i=-1,s=t.length,r;n<s;++n)r=t[n],(!e.type||r.type===e.type)&&r.name===e.name?this.removeEventListener(r.type,r.listener,r.options):t[++i]=r;++i?t.length=i:delete this.__on}}}function _oe(e,t,n){return function(){var i=this.__on,s,r=koe(t);if(i){for(var o=0,c=i.length;o<c;++o)if((s=i[o]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=r,s.options=n),s.value=t;return}}this.addEventListener(e.type,r,n),s={type:e.type,name:e.name,value:t,listener:r,options:n},i?i.push(s):this.__on=[s]}}function Coe(e,t,n){var i=Soe(e+""),s,r=i.length,o;if(arguments.length<2){var c=this.node().__on;if(c){for(var d=0,f=c.length,m;d<f;++d)for(s=0,m=c[d];s<r;++s)if((o=i[s]).type===m.type&&o.name===m.name)return m.value}return}for(c=t?_oe:Noe,s=0;s<r;++s)this.each(c(i[s],t,n));return this}function FI(e,t,n){var i=II(e),s=i.CustomEvent;typeof s=="function"?s=new s(t,n):(s=i.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function joe(e,t){return function(){return FI(this,e,t)}}function Toe(e,t){return function(){return FI(this,e,t.apply(this,arguments))}}function Aoe(e,t){return this.each((typeof t=="function"?Toe:joe)(e,t))}function*Moe(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],s=0,r=i.length,o;s<r;++s)(o=i[s])&&(yield o)}var $I=[null];function os(e,t){this._groups=e,this._parents=t}function Af(){return new os([[document.documentElement]],$I)}function Roe(){return this}os.prototype=Af.prototype={constructor:os,select:sae,selectAll:lae,selectChild:fae,selectChildren:gae,filter:yae,data:kae,enter:bae,exit:Nae,join:_ae,merge:Cae,selection:Roe,order:jae,sort:Tae,call:Mae,nodes:Rae,node:Dae,size:Oae,empty:Lae,each:Iae,attr:qae,style:Gae,property:Qae,classed:toe,text:roe,html:coe,raise:doe,lower:hoe,append:poe,insert:goe,remove:boe,clone:woe,datum:Eoe,on:Coe,dispatch:Aoe,[Symbol.iterator]:Moe};function ss(e){return typeof e=="string"?new os([[document.querySelector(e)]],[document.documentElement]):new os([[e]],$I)}function Doe(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Gs(e,t){if(e=Doe(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var i=n.createSVGPoint();return i.x=e.clientX,i.y=e.clientY,i=i.matrixTransform(t.getScreenCTM().inverse()),[i.x,i.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[e.clientX-s.left-t.clientLeft,e.clientY-s.top-t.clientTop]}}return[e.pageX,e.pageY]}const Ooe={passive:!1},Xd={capture:!0,passive:!1};function qx(e){e.stopImmediatePropagation()}function Cc(e){e.preventDefault(),e.stopImmediatePropagation()}function qI(e){var t=e.document.documentElement,n=ss(e).on("dragstart.drag",Cc,Xd);"onselectstart"in t?n.on("selectstart.drag",Cc,Xd):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function HI(e,t){var n=e.document.documentElement,i=ss(e).on("dragstart.drag",null);t&&(i.on("click.drag",Cc,Xd),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in n?i.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const yp=e=>()=>e;function O0(e,{sourceEvent:t,subject:n,target:i,identifier:s,active:r,x:o,y:c,dx:d,dy:f,dispatch:m}){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:i,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:r,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:c,enumerable:!0,configurable:!0},dx:{value:d,enumerable:!0,configurable:!0},dy:{value:f,enumerable:!0,configurable:!0},_:{value:m}})}O0.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Loe(e){return!e.ctrlKey&&!e.button}function Ioe(){return this.parentNode}function Poe(e,t){return t??{x:e.x,y:e.y}}function zoe(){return navigator.maxTouchPoints||"ontouchstart"in this}function VI(){var e=Loe,t=Ioe,n=Poe,i=zoe,s={},r=mg("start","drag","end"),o=0,c,d,f,m,p=0;function b(j){j.on("mousedown.drag",y).filter(i).on("touchstart.drag",w).on("touchmove.drag",k,Ooe).on("touchend.drag touchcancel.drag",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function y(j,T){if(!(m||!e.call(this,j,T))){var A=S(this,t.call(this,j,T),j,T,"mouse");A&&(ss(j.view).on("mousemove.drag",x,Xd).on("mouseup.drag",v,Xd),qI(j.view),qx(j),f=!1,c=j.clientX,d=j.clientY,A("start",j))}}function x(j){if(Cc(j),!f){var T=j.clientX-c,A=j.clientY-d;f=T*T+A*A>p}s.mouse("drag",j)}function v(j){ss(j.view).on("mousemove.drag mouseup.drag",null),HI(j.view,f),Cc(j),s.mouse("end",j)}function w(j,T){if(e.call(this,j,T)){var A=j.changedTouches,M=t.call(this,j,T),R=A.length,P,O;for(P=0;P<R;++P)(O=S(this,M,j,T,A[P].identifier,A[P]))&&(qx(j),O("start",j,A[P]))}}function k(j){var T=j.changedTouches,A=T.length,M,R;for(M=0;M<A;++M)(R=s[T[M].identifier])&&(Cc(j),R("drag",j,T[M]))}function C(j){var T=j.changedTouches,A=T.length,M,R;for(m&&clearTimeout(m),m=setTimeout(function(){m=null},500),M=0;M<A;++M)(R=s[T[M].identifier])&&(qx(j),R("end",j,T[M]))}function S(j,T,A,M,R,P){var O=r.copy(),B=Gs(P||A,T),F,V,D;if((D=n.call(j,new O0("beforestart",{sourceEvent:A,target:b,identifier:R,active:o,x:B[0],y:B[1],dx:0,dy:0,dispatch:O}),M))!=null)return F=D.x-B[0]||0,V=D.y-B[1]||0,function I(z,W,X){var G=B,U;switch(z){case"start":s[R]=I,U=o++;break;case"end":delete s[R],--o;case"drag":B=Gs(X||W,T),U=o;break}O.call(z,j,new O0(z,{sourceEvent:W,subject:D,target:b,identifier:R,active:U,x:B[0]+F,y:B[1]+V,dx:B[0]-G[0],dy:B[1]-G[1],dispatch:O}),M)}}return b.filter=function(j){return arguments.length?(e=typeof j=="function"?j:yp(!!j),b):e},b.container=function(j){return arguments.length?(t=typeof j=="function"?j:yp(j),b):t},b.subject=function(j){return arguments.length?(n=typeof j=="function"?j:yp(j),b):n},b.touchable=function(j){return arguments.length?(i=typeof j=="function"?j:yp(!!j),b):i},b.on=function(){var j=r.on.apply(r,arguments);return j===r?b:j},b.clickDistance=function(j){return arguments.length?(p=(j=+j)*j,b):Math.sqrt(p)},b}function Pw(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function KI(e,t){var n=Object.create(e.prototype);for(var i in t)n[i]=t[i];return n}function Mf(){}var Qd=.7,Tm=1/Qd,jc="\\s*([+-]?\\d+)\\s*",Zd="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Sr="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Boe=/^#([0-9a-f]{3,8})$/,Uoe=new RegExp(`^rgb\\(${jc},${jc},${jc}\\)$`),Foe=new RegExp(`^rgb\\(${Sr},${Sr},${Sr}\\)$`),$oe=new RegExp(`^rgba\\(${jc},${jc},${jc},${Zd}\\)$`),qoe=new RegExp(`^rgba\\(${Sr},${Sr},${Sr},${Zd}\\)$`),Hoe=new RegExp(`^hsl\\(${Zd},${Sr},${Sr}\\)$`),Voe=new RegExp(`^hsla\\(${Zd},${Sr},${Sr},${Zd}\\)$`),Vj={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Pw(Mf,gl,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Kj,formatHex:Kj,formatHex8:Koe,formatHsl:Goe,formatRgb:Gj,toString:Gj});function Kj(){return this.rgb().formatHex()}function Koe(){return this.rgb().formatHex8()}function Goe(){return GI(this).formatHsl()}function Gj(){return this.rgb().formatRgb()}function gl(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=Boe.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Wj(t):n===3?new Hi(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?bp(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?bp(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=Uoe.exec(e))?new Hi(t[1],t[2],t[3],1):(t=Foe.exec(e))?new Hi(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=$oe.exec(e))?bp(t[1],t[2],t[3],t[4]):(t=qoe.exec(e))?bp(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Hoe.exec(e))?Qj(t[1],t[2]/100,t[3]/100,1):(t=Voe.exec(e))?Qj(t[1],t[2]/100,t[3]/100,t[4]):Vj.hasOwnProperty(e)?Wj(Vj[e]):e==="transparent"?new Hi(NaN,NaN,NaN,0):null}function Wj(e){return new Hi(e>>16&255,e>>8&255,e&255,1)}function bp(e,t,n,i){return i<=0&&(e=t=n=NaN),new Hi(e,t,n,i)}function Woe(e){return e instanceof Mf||(e=gl(e)),e?(e=e.rgb(),new Hi(e.r,e.g,e.b,e.opacity)):new Hi}function L0(e,t,n,i){return arguments.length===1?Woe(e):new Hi(e,t,n,i??1)}function Hi(e,t,n,i){this.r=+e,this.g=+t,this.b=+n,this.opacity=+i}Pw(Hi,L0,KI(Mf,{brighter(e){return e=e==null?Tm:Math.pow(Tm,e),new Hi(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Qd:Math.pow(Qd,e),new Hi(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Hi(cl(this.r),cl(this.g),cl(this.b),Am(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:Yj,formatHex:Yj,formatHex8:Yoe,formatRgb:Xj,toString:Xj}));function Yj(){return`#${Yo(this.r)}${Yo(this.g)}${Yo(this.b)}`}function Yoe(){return`#${Yo(this.r)}${Yo(this.g)}${Yo(this.b)}${Yo((isNaN(this.opacity)?1:this.opacity)*255)}`}function Xj(){const e=Am(this.opacity);return`${e===1?"rgb(":"rgba("}${cl(this.r)}, ${cl(this.g)}, ${cl(this.b)}${e===1?")":`, ${e})`}`}function Am(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function cl(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Yo(e){return e=cl(e),(e<16?"0":"")+e.toString(16)}function Qj(e,t,n,i){return i<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ws(e,t,n,i)}function GI(e){if(e instanceof Ws)return new Ws(e.h,e.s,e.l,e.opacity);if(e instanceof Mf||(e=gl(e)),!e)return new Ws;if(e instanceof Ws)return e;e=e.rgb();var t=e.r/255,n=e.g/255,i=e.b/255,s=Math.min(t,n,i),r=Math.max(t,n,i),o=NaN,c=r-s,d=(r+s)/2;return c?(t===r?o=(n-i)/c+(n<i)*6:n===r?o=(i-t)/c+2:o=(t-n)/c+4,c/=d<.5?r+s:2-r-s,o*=60):c=d>0&&d<1?0:o,new Ws(o,c,d,e.opacity)}function Xoe(e,t,n,i){return arguments.length===1?GI(e):new Ws(e,t,n,i??1)}function Ws(e,t,n,i){this.h=+e,this.s=+t,this.l=+n,this.opacity=+i}Pw(Ws,Xoe,KI(Mf,{brighter(e){return e=e==null?Tm:Math.pow(Tm,e),new Ws(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Qd:Math.pow(Qd,e),new Ws(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,i=n+(n<.5?n:1-n)*t,s=2*n-i;return new Hi(Hx(e>=240?e-240:e+120,s,i),Hx(e,s,i),Hx(e<120?e+240:e-120,s,i),this.opacity)},clamp(){return new Ws(Zj(this.h),xp(this.s),xp(this.l),Am(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=Am(this.opacity);return`${e===1?"hsl(":"hsla("}${Zj(this.h)}, ${xp(this.s)*100}%, ${xp(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Zj(e){return e=(e||0)%360,e<0?e+360:e}function xp(e){return Math.max(0,Math.min(1,e||0))}function Hx(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 zw=e=>()=>e;function Qoe(e,t){return function(n){return e+n*t}}function Zoe(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(i){return Math.pow(e+i*t,n)}}function Joe(e){return(e=+e)==1?WI:function(t,n){return n-t?Zoe(t,n,e):zw(isNaN(t)?n:t)}}function WI(e,t){var n=t-e;return n?Qoe(e,n):zw(isNaN(e)?t:e)}const Mm=(function e(t){var n=Joe(t);function i(s,r){var o=n((s=L0(s)).r,(r=L0(r)).r),c=n(s.g,r.g),d=n(s.b,r.b),f=WI(s.opacity,r.opacity);return function(m){return s.r=o(m),s.g=c(m),s.b=d(m),s.opacity=f(m),s+""}}return i.gamma=e,i})(1);function ele(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,i=t.slice(),s;return function(r){for(s=0;s<n;++s)i[s]=e[s]*(1-r)+t[s]*r;return i}}function tle(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function nle(e,t){var n=t?t.length:0,i=e?Math.min(n,e.length):0,s=new Array(i),r=new Array(n),o;for(o=0;o<i;++o)s[o]=Dd(e[o],t[o]);for(;o<n;++o)r[o]=t[o];return function(c){for(o=0;o<i;++o)r[o]=s[o](c);return r}}function ile(e,t){var n=new Date;return e=+e,t=+t,function(i){return n.setTime(e*(1-i)+t*i),n}}function wr(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function sle(e,t){var n={},i={},s;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(s in t)s in e?n[s]=Dd(e[s],t[s]):i[s]=t[s];return function(r){for(s in n)i[s]=n[s](r);return i}}var I0=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Vx=new RegExp(I0.source,"g");function rle(e){return function(){return e}}function ale(e){return function(t){return e(t)+""}}function YI(e,t){var n=I0.lastIndex=Vx.lastIndex=0,i,s,r,o=-1,c=[],d=[];for(e=e+"",t=t+"";(i=I0.exec(e))&&(s=Vx.exec(t));)(r=s.index)>n&&(r=t.slice(n,r),c[o]?c[o]+=r:c[++o]=r),(i=i[0])===(s=s[0])?c[o]?c[o]+=s:c[++o]=s:(c[++o]=null,d.push({i:o,x:wr(i,s)})),n=Vx.lastIndex;return n<t.length&&(r=t.slice(n),c[o]?c[o]+=r:c[++o]=r),c.length<2?d[0]?ale(d[0].x):rle(t):(t=d.length,function(f){for(var m=0,p;m<t;++m)c[(p=d[m]).i]=p.x(f);return c.join("")})}function Dd(e,t){var n=typeof t,i;return t==null||n==="boolean"?zw(t):(n==="number"?wr:n==="string"?(i=gl(t))?(t=i,Mm):YI:t instanceof gl?Mm:t instanceof Date?ile:tle(t)?ele:Array.isArray(t)?nle:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?sle:wr)(e,t)}var Jj=180/Math.PI,P0={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function XI(e,t,n,i,s,r){var o,c,d;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(d=e*n+t*i)&&(n-=e*d,i-=t*d),(c=Math.sqrt(n*n+i*i))&&(n/=c,i/=c,d/=c),e*i<t*n&&(e=-e,t=-t,d=-d,o=-o),{translateX:s,translateY:r,rotate:Math.atan2(t,e)*Jj,skewX:Math.atan(d)*Jj,scaleX:o,scaleY:c}}var vp;function ole(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?P0:XI(t.a,t.b,t.c,t.d,t.e,t.f)}function lle(e){return e==null||(vp||(vp=document.createElementNS("http://www.w3.org/2000/svg","g")),vp.setAttribute("transform",e),!(e=vp.transform.baseVal.consolidate()))?P0:(e=e.matrix,XI(e.a,e.b,e.c,e.d,e.e,e.f))}function QI(e,t,n,i){function s(f){return f.length?f.pop()+" ":""}function r(f,m,p,b,y,x){if(f!==p||m!==b){var v=y.push("translate(",null,t,null,n);x.push({i:v-4,x:wr(f,p)},{i:v-2,x:wr(m,b)})}else(p||b)&&y.push("translate("+p+t+b+n)}function o(f,m,p,b){f!==m?(f-m>180?m+=360:m-f>180&&(f+=360),b.push({i:p.push(s(p)+"rotate(",null,i)-2,x:wr(f,m)})):m&&p.push(s(p)+"rotate("+m+i)}function c(f,m,p,b){f!==m?b.push({i:p.push(s(p)+"skewX(",null,i)-2,x:wr(f,m)}):m&&p.push(s(p)+"skewX("+m+i)}function d(f,m,p,b,y,x){if(f!==p||m!==b){var v=y.push(s(y)+"scale(",null,",",null,")");x.push({i:v-4,x:wr(f,p)},{i:v-2,x:wr(m,b)})}else(p!==1||b!==1)&&y.push(s(y)+"scale("+p+","+b+")")}return function(f,m){var p=[],b=[];return f=e(f),m=e(m),r(f.translateX,f.translateY,m.translateX,m.translateY,p,b),o(f.rotate,m.rotate,p,b),c(f.skewX,m.skewX,p,b),d(f.scaleX,f.scaleY,m.scaleX,m.scaleY,p,b),f=m=null,function(y){for(var x=-1,v=b.length,w;++x<v;)p[(w=b[x]).i]=w.x(y);return p.join("")}}}var cle=QI(ole,"px, ","px)","deg)"),ule=QI(lle,", ",")",")"),dle=1e-12;function eT(e){return((e=Math.exp(e))+1/e)/2}function fle(e){return((e=Math.exp(e))-1/e)/2}function hle(e){return((e=Math.exp(2*e))-1)/(e+1)}const Gp=(function e(t,n,i){function s(r,o){var c=r[0],d=r[1],f=r[2],m=o[0],p=o[1],b=o[2],y=m-c,x=p-d,v=y*y+x*x,w,k;if(v<dle)k=Math.log(b/f)/t,w=function(M){return[c+M*y,d+M*x,f*Math.exp(t*M*k)]};else{var C=Math.sqrt(v),S=(b*b-f*f+i*v)/(2*f*n*C),j=(b*b-f*f-i*v)/(2*b*n*C),T=Math.log(Math.sqrt(S*S+1)-S),A=Math.log(Math.sqrt(j*j+1)-j);k=(A-T)/t,w=function(M){var R=M*k,P=eT(T),O=f/(n*C)*(P*hle(t*R+T)-fle(T));return[c+O*y,d+O*x,f*P/eT(t*R+T)]}}return w.duration=k*1e3*t/Math.SQRT2,w}return s.rho=function(r){var o=Math.max(.001,+r),c=o*o,d=c*c;return e(o,c,d)},s})(Math.SQRT2,2,4);var Yc=0,wd=0,hd=0,ZI=1e3,Rm,Ed,Dm=0,yl=0,yg=0,Jd=typeof performance=="object"&&performance.now?performance:Date,JI=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Bw(){return yl||(JI(ple),yl=Jd.now()+yg)}function ple(){yl=0}function Om(){this._call=this._time=this._next=null}Om.prototype=eP.prototype={constructor:Om,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Bw():+n)+(t==null?0:+t),!this._next&&Ed!==this&&(Ed?Ed._next=this:Rm=this,Ed=this),this._call=e,this._time=n,z0()},stop:function(){this._call&&(this._call=null,this._time=1/0,z0())}};function eP(e,t,n){var i=new Om;return i.restart(e,t,n),i}function mle(){Bw(),++Yc;for(var e=Rm,t;e;)(t=yl-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Yc}function tT(){yl=(Dm=Jd.now())+yg,Yc=wd=0;try{mle()}finally{Yc=0,yle(),yl=0}}function gle(){var e=Jd.now(),t=e-Dm;t>ZI&&(yg-=t,Dm=e)}function yle(){for(var e,t=Rm,n,i=1/0;t;)t._call?(i>t._time&&(i=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Rm=n);Ed=e,z0(i)}function z0(e){if(!Yc){wd&&(wd=clearTimeout(wd));var t=e-yl;t>24?(e<1/0&&(wd=setTimeout(tT,e-Jd.now()-yg)),hd&&(hd=clearInterval(hd))):(hd||(Dm=Jd.now(),hd=setInterval(gle,ZI)),Yc=1,JI(tT))}}function nT(e,t,n){var i=new Om;return t=t==null?0:+t,i.restart(s=>{i.stop(),e(s+t)},t,n),i}var ble=mg("start","end","cancel","interrupt"),xle=[],tP=0,iT=1,B0=2,Wp=3,sT=4,U0=5,Yp=6;function bg(e,t,n,i,s,r){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;vle(e,n,{name:t,index:i,group:s,on:ble,tween:xle,time:r.time,delay:r.delay,duration:r.duration,ease:r.ease,timer:null,state:tP})}function Uw(e,t){var n=sr(e,t);if(n.state>tP)throw new Error("too late; already scheduled");return n}function Ar(e,t){var n=sr(e,t);if(n.state>Wp)throw new Error("too late; already running");return n}function sr(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function vle(e,t,n){var i=e.__transition,s;i[t]=n,n.timer=eP(r,0,n.time);function r(f){n.state=iT,n.timer.restart(o,n.delay,n.time),n.delay<=f&&o(f-n.delay)}function o(f){var m,p,b,y;if(n.state!==iT)return d();for(m in i)if(y=i[m],y.name===n.name){if(y.state===Wp)return nT(o);y.state===sT?(y.state=Yp,y.timer.stop(),y.on.call("interrupt",e,e.__data__,y.index,y.group),delete i[m]):+m<t&&(y.state=Yp,y.timer.stop(),y.on.call("cancel",e,e.__data__,y.index,y.group),delete i[m])}if(nT(function(){n.state===Wp&&(n.state=sT,n.timer.restart(c,n.delay,n.time),c(f))}),n.state=B0,n.on.call("start",e,e.__data__,n.index,n.group),n.state===B0){for(n.state=Wp,s=new Array(b=n.tween.length),m=0,p=-1;m<b;++m)(y=n.tween[m].value.call(e,e.__data__,n.index,n.group))&&(s[++p]=y);s.length=p+1}}function c(f){for(var m=f<n.duration?n.ease.call(null,f/n.duration):(n.timer.restart(d),n.state=U0,1),p=-1,b=s.length;++p<b;)s[p].call(e,m);n.state===U0&&(n.on.call("end",e,e.__data__,n.index,n.group),d())}function d(){n.state=Yp,n.timer.stop(),delete i[t];for(var f in i)return;delete e.__transition}}function Xp(e,t){var n=e.__transition,i,s,r=!0,o;if(n){t=t==null?null:t+"";for(o in n){if((i=n[o]).name!==t){r=!1;continue}s=i.state>B0&&i.state<U0,i.state=Yp,i.timer.stop(),i.on.call(s?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete n[o]}r&&delete e.__transition}}function wle(e){return this.each(function(){Xp(this,e)})}function Ele(e,t){var n,i;return function(){var s=Ar(this,e),r=s.tween;if(r!==n){i=n=r;for(var o=0,c=i.length;o<c;++o)if(i[o].name===t){i=i.slice(),i.splice(o,1);break}}s.tween=i}}function kle(e,t,n){var i,s;if(typeof n!="function")throw new Error;return function(){var r=Ar(this,e),o=r.tween;if(o!==i){s=(i=o).slice();for(var c={name:t,value:n},d=0,f=s.length;d<f;++d)if(s[d].name===t){s[d]=c;break}d===f&&s.push(c)}r.tween=s}}function Sle(e,t){var n=this._id;if(e+="",arguments.length<2){for(var i=sr(this.node(),n).tween,s=0,r=i.length,o;s<r;++s)if((o=i[s]).name===e)return o.value;return null}return this.each((t==null?Ele:kle)(n,e,t))}function Fw(e,t,n){var i=e._id;return e.each(function(){var s=Ar(this,i);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return sr(s,i).value[t]}}function nP(e,t){var n;return(typeof t=="number"?wr:t instanceof gl?Mm:(n=gl(t))?(t=n,Mm):YI)(e,t)}function Nle(e){return function(){this.removeAttribute(e)}}function _le(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Cle(e,t,n){var i,s=n+"",r;return function(){var o=this.getAttribute(e);return o===s?null:o===i?r:r=t(i=o,n)}}function jle(e,t,n){var i,s=n+"",r;return function(){var o=this.getAttributeNS(e.space,e.local);return o===s?null:o===i?r:r=t(i=o,n)}}function Tle(e,t,n){var i,s,r;return function(){var o,c=n(this),d;return c==null?void this.removeAttribute(e):(o=this.getAttribute(e),d=c+"",o===d?null:o===i&&d===s?r:(s=d,r=t(i=o,c)))}}function Ale(e,t,n){var i,s,r;return function(){var o,c=n(this),d;return c==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),d=c+"",o===d?null:o===i&&d===s?r:(s=d,r=t(i=o,c)))}}function Mle(e,t){var n=gg(e),i=n==="transform"?ule:nP;return this.attrTween(e,typeof t=="function"?(n.local?Ale:Tle)(n,i,Fw(this,"attr."+e,t)):t==null?(n.local?_le:Nle)(n):(n.local?jle:Cle)(n,i,t))}function Rle(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Dle(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Ole(e,t){var n,i;function s(){var r=t.apply(this,arguments);return r!==i&&(n=(i=r)&&Dle(e,r)),n}return s._value=t,s}function Lle(e,t){var n,i;function s(){var r=t.apply(this,arguments);return r!==i&&(n=(i=r)&&Rle(e,r)),n}return s._value=t,s}function Ile(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var i=gg(e);return this.tween(n,(i.local?Ole:Lle)(i,t))}function Ple(e,t){return function(){Uw(this,e).delay=+t.apply(this,arguments)}}function zle(e,t){return t=+t,function(){Uw(this,e).delay=t}}function Ble(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Ple:zle)(t,e)):sr(this.node(),t).delay}function Ule(e,t){return function(){Ar(this,e).duration=+t.apply(this,arguments)}}function Fle(e,t){return t=+t,function(){Ar(this,e).duration=t}}function $le(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Ule:Fle)(t,e)):sr(this.node(),t).duration}function qle(e,t){if(typeof t!="function")throw new Error;return function(){Ar(this,e).ease=t}}function Hle(e){var t=this._id;return arguments.length?this.each(qle(t,e)):sr(this.node(),t).ease}function Vle(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ar(this,e).ease=n}}function Kle(e){if(typeof e!="function")throw new Error;return this.each(Vle(this._id,e))}function Gle(e){typeof e!="function"&&(e=DI(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=[],d,f=0;f<o;++f)(d=r[f])&&e.call(d,d.__data__,f,r)&&c.push(d);return new fa(i,this._parents,this._name,this._id)}function Wle(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,i=t.length,s=n.length,r=Math.min(i,s),o=new Array(i),c=0;c<r;++c)for(var d=t[c],f=n[c],m=d.length,p=o[c]=new Array(m),b,y=0;y<m;++y)(b=d[y]||f[y])&&(p[y]=b);for(;c<i;++c)o[c]=t[c];return new fa(o,this._parents,this._name,this._id)}function Yle(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function Xle(e,t,n){var i,s,r=Yle(t)?Uw:Ar;return function(){var o=r(this,e),c=o.on;c!==i&&(s=(i=c).copy()).on(t,n),o.on=s}}function Qle(e,t){var n=this._id;return arguments.length<2?sr(this.node(),n).on.on(e):this.each(Xle(n,e,t))}function Zle(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Jle(){return this.on("end.remove",Zle(this._id))}function ece(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Lw(e));for(var i=this._groups,s=i.length,r=new Array(s),o=0;o<s;++o)for(var c=i[o],d=c.length,f=r[o]=new Array(d),m,p,b=0;b<d;++b)(m=c[b])&&(p=e.call(m,m.__data__,b,c))&&("__data__"in m&&(p.__data__=m.__data__),f[b]=p,bg(f[b],t,n,b,f,sr(m,n)));return new fa(r,this._parents,t,n)}function tce(e){var t=this._name,n=this._id;typeof e!="function"&&(e=RI(e));for(var i=this._groups,s=i.length,r=[],o=[],c=0;c<s;++c)for(var d=i[c],f=d.length,m,p=0;p<f;++p)if(m=d[p]){for(var b=e.call(m,m.__data__,p,d),y,x=sr(m,n),v=0,w=b.length;v<w;++v)(y=b[v])&&bg(y,t,n,v,b,x);r.push(b),o.push(m)}return new fa(r,o,t,n)}var nce=Af.prototype.constructor;function ice(){return new nce(this._groups,this._parents)}function sce(e,t){var n,i,s;return function(){var r=Wc(this,e),o=(this.style.removeProperty(e),Wc(this,e));return r===o?null:r===n&&o===i?s:s=t(n=r,i=o)}}function iP(e){return function(){this.style.removeProperty(e)}}function rce(e,t,n){var i,s=n+"",r;return function(){var o=Wc(this,e);return o===s?null:o===i?r:r=t(i=o,n)}}function ace(e,t,n){var i,s,r;return function(){var o=Wc(this,e),c=n(this),d=c+"";return c==null&&(d=c=(this.style.removeProperty(e),Wc(this,e))),o===d?null:o===i&&d===s?r:(s=d,r=t(i=o,c))}}function oce(e,t){var n,i,s,r="style."+t,o="end."+r,c;return function(){var d=Ar(this,e),f=d.on,m=d.value[r]==null?c||(c=iP(t)):void 0;(f!==n||s!==m)&&(i=(n=f).copy()).on(o,s=m),d.on=i}}function lce(e,t,n){var i=(e+="")=="transform"?cle:nP;return t==null?this.styleTween(e,sce(e,i)).on("end.style."+e,iP(e)):typeof t=="function"?this.styleTween(e,ace(e,i,Fw(this,"style."+e,t))).each(oce(this._id,e)):this.styleTween(e,rce(e,i,t),n).on("end.style."+e,null)}function cce(e,t,n){return function(i){this.style.setProperty(e,t.call(this,i),n)}}function uce(e,t,n){var i,s;function r(){var o=t.apply(this,arguments);return o!==s&&(i=(s=o)&&cce(e,o,n)),i}return r._value=t,r}function dce(e,t,n){var i="style."+(e+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(t==null)return this.tween(i,null);if(typeof t!="function")throw new Error;return this.tween(i,uce(e,t,n??""))}function fce(e){return function(){this.textContent=e}}function hce(e){return function(){var t=e(this);this.textContent=t??""}}function pce(e){return this.tween("text",typeof e=="function"?hce(Fw(this,"text",e)):fce(e==null?"":e+""))}function mce(e){return function(t){this.textContent=e.call(this,t)}}function gce(e){var t,n;function i(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&mce(s)),t}return i._value=e,i}function yce(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,gce(e))}function bce(){for(var e=this._name,t=this._id,n=sP(),i=this._groups,s=i.length,r=0;r<s;++r)for(var o=i[r],c=o.length,d,f=0;f<c;++f)if(d=o[f]){var m=sr(d,t);bg(d,e,n,f,o,{time:m.time+m.delay+m.duration,delay:0,duration:m.duration,ease:m.ease})}return new fa(i,this._parents,e,n)}function xce(){var e,t,n=this,i=n._id,s=n.size();return new Promise(function(r,o){var c={value:o},d={value:function(){--s===0&&r()}};n.each(function(){var f=Ar(this,i),m=f.on;m!==e&&(t=(e=m).copy(),t._.cancel.push(c),t._.interrupt.push(c),t._.end.push(d)),f.on=t}),s===0&&r()})}var vce=0;function fa(e,t,n,i){this._groups=e,this._parents=t,this._name=n,this._id=i}function sP(){return++vce}var Zr=Af.prototype;fa.prototype={constructor:fa,select:ece,selectAll:tce,selectChild:Zr.selectChild,selectChildren:Zr.selectChildren,filter:Gle,merge:Wle,selection:ice,transition:bce,call:Zr.call,nodes:Zr.nodes,node:Zr.node,size:Zr.size,empty:Zr.empty,each:Zr.each,on:Qle,attr:Mle,attrTween:Ile,style:lce,styleTween:dce,text:pce,textTween:yce,remove:Jle,tween:Sle,delay:Ble,duration:$le,ease:Hle,easeVarying:Kle,end:xce,[Symbol.iterator]:Zr[Symbol.iterator]};function wce(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Ece={time:null,delay:0,duration:250,ease:wce};function kce(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function Sce(e){var t,n;e instanceof fa?(t=e._id,e=e._name):(t=sP(),(n=Ece).time=Bw(),e=e==null?null:e+"");for(var i=this._groups,s=i.length,r=0;r<s;++r)for(var o=i[r],c=o.length,d,f=0;f<c;++f)(d=o[f])&&bg(d,e,t,f,o,n||kce(d,t));return new fa(i,this._parents,e,t)}Af.prototype.interrupt=wle;Af.prototype.transition=Sce;const wp=e=>()=>e;function Nce(e,{sourceEvent:t,target:n,transform:i,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:i,enumerable:!0,configurable:!0},_:{value:s}})}function aa(e,t,n){this.k=e,this.x=t,this.y=n}aa.prototype={constructor:aa,scale:function(e){return e===1?this:new aa(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new aa(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 xg=new aa(1,0,0);rP.prototype=aa.prototype;function rP(e){for(;!e.__zoom;)if(!(e=e.parentNode))return xg;return e.__zoom}function Kx(e){e.stopImmediatePropagation()}function pd(e){e.preventDefault(),e.stopImmediatePropagation()}function _ce(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Cce(){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 rT(){return this.__zoom||xg}function jce(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Tce(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ace(e,t,n){var i=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],r=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>i?(i+s)/2:Math.min(0,i)||Math.max(0,s),o>r?(r+o)/2:Math.min(0,r)||Math.max(0,o))}function aP(){var e=_ce,t=Cce,n=Ace,i=jce,s=Tce,r=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],c=250,d=Gp,f=mg("start","zoom","end"),m,p,b,y=500,x=150,v=0,w=10;function k(D){D.property("__zoom",rT).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",P).on("dblclick.zoom",O).filter(s).on("touchstart.zoom",B).on("touchmove.zoom",F).on("touchend.zoom touchcancel.zoom",V).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}k.transform=function(D,I,z,W){var X=D.selection?D.selection():D;X.property("__zoom",rT),D!==X?T(D,I,z,W):X.interrupt().each(function(){A(this,arguments).event(W).start().zoom(null,typeof I=="function"?I.apply(this,arguments):I).end()})},k.scaleBy=function(D,I,z,W){k.scaleTo(D,function(){var X=this.__zoom.k,G=typeof I=="function"?I.apply(this,arguments):I;return X*G},z,W)},k.scaleTo=function(D,I,z,W){k.transform(D,function(){var X=t.apply(this,arguments),G=this.__zoom,U=z==null?j(X):typeof z=="function"?z.apply(this,arguments):z,q=G.invert(U),Y=typeof I=="function"?I.apply(this,arguments):I;return n(S(C(G,Y),U,q),X,o)},z,W)},k.translateBy=function(D,I,z,W){k.transform(D,function(){return n(this.__zoom.translate(typeof I=="function"?I.apply(this,arguments):I,typeof z=="function"?z.apply(this,arguments):z),t.apply(this,arguments),o)},null,W)},k.translateTo=function(D,I,z,W,X){k.transform(D,function(){var G=t.apply(this,arguments),U=this.__zoom,q=W==null?j(G):typeof W=="function"?W.apply(this,arguments):W;return n(xg.translate(q[0],q[1]).scale(U.k).translate(typeof I=="function"?-I.apply(this,arguments):-I,typeof z=="function"?-z.apply(this,arguments):-z),G,o)},W,X)};function C(D,I){return I=Math.max(r[0],Math.min(r[1],I)),I===D.k?D:new aa(I,D.x,D.y)}function S(D,I,z){var W=I[0]-z[0]*D.k,X=I[1]-z[1]*D.k;return W===D.x&&X===D.y?D:new aa(D.k,W,X)}function j(D){return[(+D[0][0]+ +D[1][0])/2,(+D[0][1]+ +D[1][1])/2]}function T(D,I,z,W){D.on("start.zoom",function(){A(this,arguments).event(W).start()}).on("interrupt.zoom end.zoom",function(){A(this,arguments).event(W).end()}).tween("zoom",function(){var X=this,G=arguments,U=A(X,G).event(W),q=t.apply(X,G),Y=z==null?j(q):typeof z=="function"?z.apply(X,G):z,$=Math.max(q[1][0]-q[0][0],q[1][1]-q[0][1]),ie=X.__zoom,be=typeof I=="function"?I.apply(X,G):I,ce=d(ie.invert(Y).concat($/ie.k),be.invert(Y).concat($/be.k));return function(_e){if(_e===1)_e=be;else{var le=ce(_e),pe=$/le[2];_e=new aa(pe,Y[0]-le[0]*pe,Y[1]-le[1]*pe)}U.zoom(null,_e)}})}function A(D,I,z){return!z&&D.__zooming||new M(D,I)}function M(D,I){this.that=D,this.args=I,this.active=0,this.sourceEvent=null,this.extent=t.apply(D,I),this.taps=0}M.prototype={event:function(D){return D&&(this.sourceEvent=D),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(D,I){return this.mouse&&D!=="mouse"&&(this.mouse[1]=I.invert(this.mouse[0])),this.touch0&&D!=="touch"&&(this.touch0[1]=I.invert(this.touch0[0])),this.touch1&&D!=="touch"&&(this.touch1[1]=I.invert(this.touch1[0])),this.that.__zoom=I,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(D){var I=ss(this.that).datum();f.call(D,this.that,new Nce(D,{sourceEvent:this.sourceEvent,target:k,transform:this.that.__zoom,dispatch:f}),I)}};function R(D,...I){if(!e.apply(this,arguments))return;var z=A(this,I).event(D),W=this.__zoom,X=Math.max(r[0],Math.min(r[1],W.k*Math.pow(2,i.apply(this,arguments)))),G=Gs(D);if(z.wheel)(z.mouse[0][0]!==G[0]||z.mouse[0][1]!==G[1])&&(z.mouse[1]=W.invert(z.mouse[0]=G)),clearTimeout(z.wheel);else{if(W.k===X)return;z.mouse=[G,W.invert(G)],Xp(this),z.start()}pd(D),z.wheel=setTimeout(U,x),z.zoom("mouse",n(S(C(W,X),z.mouse[0],z.mouse[1]),z.extent,o));function U(){z.wheel=null,z.end()}}function P(D,...I){if(b||!e.apply(this,arguments))return;var z=D.currentTarget,W=A(this,I,!0).event(D),X=ss(D.view).on("mousemove.zoom",Y,!0).on("mouseup.zoom",$,!0),G=Gs(D,z),U=D.clientX,q=D.clientY;qI(D.view),Kx(D),W.mouse=[G,this.__zoom.invert(G)],Xp(this),W.start();function Y(ie){if(pd(ie),!W.moved){var be=ie.clientX-U,ce=ie.clientY-q;W.moved=be*be+ce*ce>v}W.event(ie).zoom("mouse",n(S(W.that.__zoom,W.mouse[0]=Gs(ie,z),W.mouse[1]),W.extent,o))}function $(ie){X.on("mousemove.zoom mouseup.zoom",null),HI(ie.view,W.moved),pd(ie),W.event(ie).end()}}function O(D,...I){if(e.apply(this,arguments)){var z=this.__zoom,W=Gs(D.changedTouches?D.changedTouches[0]:D,this),X=z.invert(W),G=z.k*(D.shiftKey?.5:2),U=n(S(C(z,G),W,X),t.apply(this,I),o);pd(D),c>0?ss(this).transition().duration(c).call(T,U,W,D):ss(this).call(k.transform,U,W,D)}}function B(D,...I){if(e.apply(this,arguments)){var z=D.touches,W=z.length,X=A(this,I,D.changedTouches.length===W).event(D),G,U,q,Y;for(Kx(D),U=0;U<W;++U)q=z[U],Y=Gs(q,this),Y=[Y,this.__zoom.invert(Y),q.identifier],X.touch0?!X.touch1&&X.touch0[2]!==Y[2]&&(X.touch1=Y,X.taps=0):(X.touch0=Y,G=!0,X.taps=1+!!m);m&&(m=clearTimeout(m)),G&&(X.taps<2&&(p=Y[0],m=setTimeout(function(){m=null},y)),Xp(this),X.start())}}function F(D,...I){if(this.__zooming){var z=A(this,I).event(D),W=D.changedTouches,X=W.length,G,U,q,Y;for(pd(D),G=0;G<X;++G)U=W[G],q=Gs(U,this),z.touch0&&z.touch0[2]===U.identifier?z.touch0[0]=q:z.touch1&&z.touch1[2]===U.identifier&&(z.touch1[0]=q);if(U=z.that.__zoom,z.touch1){var $=z.touch0[0],ie=z.touch0[1],be=z.touch1[0],ce=z.touch1[1],_e=(_e=be[0]-$[0])*_e+(_e=be[1]-$[1])*_e,le=(le=ce[0]-ie[0])*le+(le=ce[1]-ie[1])*le;U=C(U,Math.sqrt(_e/le)),q=[($[0]+be[0])/2,($[1]+be[1])/2],Y=[(ie[0]+ce[0])/2,(ie[1]+ce[1])/2]}else if(z.touch0)q=z.touch0[0],Y=z.touch0[1];else return;z.zoom("touch",n(S(U,q,Y),z.extent,o))}}function V(D,...I){if(this.__zooming){var z=A(this,I).event(D),W=D.changedTouches,X=W.length,G,U;for(Kx(D),b&&clearTimeout(b),b=setTimeout(function(){b=null},y),G=0;G<X;++G)U=W[G],z.touch0&&z.touch0[2]===U.identifier?delete z.touch0:z.touch1&&z.touch1[2]===U.identifier&&delete z.touch1;if(z.touch1&&!z.touch0&&(z.touch0=z.touch1,delete z.touch1),z.touch0)z.touch0[1]=this.__zoom.invert(z.touch0[0]);else if(z.end(),z.taps===2&&(U=Gs(U,this),Math.hypot(p[0]-U[0],p[1]-U[1])<w)){var q=ss(this).on("dblclick.zoom");q&&q.apply(this,arguments)}}}return k.wheelDelta=function(D){return arguments.length?(i=typeof D=="function"?D:wp(+D),k):i},k.filter=function(D){return arguments.length?(e=typeof D=="function"?D:wp(!!D),k):e},k.touchable=function(D){return arguments.length?(s=typeof D=="function"?D:wp(!!D),k):s},k.extent=function(D){return arguments.length?(t=typeof D=="function"?D:wp([[+D[0][0],+D[0][1]],[+D[1][0],+D[1][1]]]),k):t},k.scaleExtent=function(D){return arguments.length?(r[0]=+D[0],r[1]=+D[1],k):[r[0],r[1]]},k.translateExtent=function(D){return arguments.length?(o[0][0]=+D[0][0],o[1][0]=+D[1][0],o[0][1]=+D[0][1],o[1][1]=+D[1][1],k):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},k.constrain=function(D){return arguments.length?(n=D,k):n},k.duration=function(D){return arguments.length?(c=+D,k):c},k.interpolate=function(D){return arguments.length?(d=D,k):d},k.on=function(){var D=f.on.apply(f,arguments);return D===f?k:D},k.clickDistance=function(D){return arguments.length?(v=(D=+D)*D,k):Math.sqrt(v)},k.tapDistance=function(D){return arguments.length?(w=+D,k):w},k}const ls={error001:(e="react")=>`Seems like you have not used ${e==="svelte"?"SvelteFlowProvider":"ReactFlowProvider"} as an ancestor. Help: https://${e}flow.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 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,{id:t,sourceHandle:n,targetHandle:i})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:i}", edge id: ${t}.`,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.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.",error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},ef=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],oP=["Enter"," ","Escape"],lP={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Xc;(function(e){e.Strict="strict",e.Loose="loose"})(Xc||(Xc={}));var ul;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(ul||(ul={}));var tf;(function(e){e.Partial="partial",e.Full="full"})(tf||(tf={}));const cP={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Va;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Va||(Va={}));var Lm;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Lm||(Lm={}));var tt;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(tt||(tt={}));const aT={[tt.Left]:tt.Right,[tt.Right]:tt.Left,[tt.Top]:tt.Bottom,[tt.Bottom]:tt.Top};function uP(e){return e===null?null:e?"valid":"invalid"}const dP=e=>"id"in e&&"source"in e&&"target"in e,Mce=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),$w=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),Rf=(e,t=[0,0])=>{const{width:n,height:i}=pa(e),s=e.origin??t,r=n*s[0],o=i*s[1];return{x:e.position.x-r,y:e.position.y-o}},Rce=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((i,s)=>{const r=typeof s=="string";let o=!t.nodeLookup&&!r?s:void 0;t.nodeLookup&&(o=r?t.nodeLookup.get(s):$w(s)?s:t.nodeLookup.get(s.id));const c=o?Im(o,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return vg(i,c)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return wg(n)},Df=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},i=!1;return e.forEach(s=>{(t.filter===void 0||t.filter(s))&&(n=vg(n,Im(s)),i=!0)}),i?wg(n):{x:0,y:0,width:0,height:0}},qw=(e,t,[n,i,s]=[0,0,1],r=!1,o=!1)=>{const c=(t.x-n)/s,d=(t.y-i)/s,f=t.width/s,m=t.height/s,p=[];for(const b of e.values()){const{measured:y,selectable:x=!0,hidden:v=!1}=b;if(o&&!x||v)continue;const w=y.width??b.width??b.initialWidth??0,k=y.height??b.height??b.initialHeight??0,{x:C,y:S}=b.internals.positionAbsolute,j=mP(c,d,f,m,C,S,w,k),T=w*k,A=r&&j>0;(!b.internals.handleBounds||A||j>=T||b.dragging)&&p.push(b)}return p},Dce=(e,t)=>{const n=new Set;return e.forEach(i=>{n.add(i.id)}),t.filter(i=>n.has(i.source)||n.has(i.target))};function Oce(e,t){const n=new Map,i=t!=null&&t.nodes?new Set(t.nodes.map(s=>s.id)):null;return e.forEach(s=>{s.measured.width&&s.measured.height&&((t==null?void 0:t.includeHiddenNodes)||!s.hidden)&&(!i||i.has(s.id))&&n.set(s.id,s)}),n}async function Lce({nodes:e,width:t,height:n,panZoom:i,minZoom:s,maxZoom:r},o){if(e.size===0)return!0;const c=Oce(e,o),d=Df(c),f=Vw(d,t,n,(o==null?void 0:o.minZoom)??s,(o==null?void 0:o.maxZoom)??r,(o==null?void 0:o.padding)??.1);return await i.setViewport(f,{duration:o==null?void 0:o.duration,ease:o==null?void 0:o.ease,interpolate:o==null?void 0:o.interpolate}),!0}function fP({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:i=[0,0],nodeExtent:s,onError:r}){const o=n.get(e),c=o.parentId?n.get(o.parentId):void 0,{x:d,y:f}=c?c.internals.positionAbsolute:{x:0,y:0},m=o.origin??i;let p=o.extent||s;if(o.extent==="parent"&&!o.expandParent)if(!c)r==null||r("005",ls.error005());else{const y=c.measured.width,x=c.measured.height;y&&x&&(p=[[d,f],[d+y,f+x]])}else c&&xl(o.extent)&&(p=[[o.extent[0][0]+d,o.extent[0][1]+f],[o.extent[1][0]+d,o.extent[1][1]+f]]);const b=xl(p)?bl(t,p,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&(r==null||r("015",ls.error015())),{position:{x:b.x-d+(o.measured.width??0)*m[0],y:b.y-f+(o.measured.height??0)*m[1]},positionAbsolute:b}}async function Ice({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:i,onBeforeDelete:s}){const r=new Set(e.map(b=>b.id)),o=[];for(const b of n){if(b.deletable===!1)continue;const y=r.has(b.id),x=!y&&b.parentId&&o.find(v=>v.id===b.parentId);(y||x)&&o.push(b)}const c=new Set(t.map(b=>b.id)),d=i.filter(b=>b.deletable!==!1),m=Dce(o,d);for(const b of d)c.has(b.id)&&!m.find(x=>x.id===b.id)&&m.push(b);if(!s)return{edges:m,nodes:o};const p=await s({nodes:o,edges:m});return typeof p=="boolean"?p?{edges:m,nodes:o}:{edges:[],nodes:[]}:p}const Qc=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),bl=(e={x:0,y:0},t,n)=>({x:Qc(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:Qc(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function hP(e,t,n){const{width:i,height:s}=pa(n),{x:r,y:o}=n.internals.positionAbsolute;return bl(e,[[r,o],[r+i,o+s]],t)}const oT=(e,t,n)=>e<t?Qc(Math.abs(e-t),1,t)/t:e>n?-Qc(Math.abs(e-n),1,t)/t:0,Hw=(e,t,n=15,i=40)=>{const s=oT(e.x,i,t.width-i)*n,r=oT(e.y,i,t.height-i)*n;return[s,r]},vg=(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)}),F0=({x:e,y:t,width:n,height:i})=>({x:e,y:t,x2:e+n,y2:t+i}),wg=({x:e,y:t,x2:n,y2:i})=>({x:e,y:t,width:n-e,height:i-t}),nf=(e,t=[0,0])=>{var s,r;const{x:n,y:i}=$w(e)?e.internals.positionAbsolute:Rf(e,t);return{x:n,y:i,width:((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0,height:((r=e.measured)==null?void 0:r.height)??e.height??e.initialHeight??0}},Im=(e,t=[0,0])=>{var s,r;const{x:n,y:i}=$w(e)?e.internals.positionAbsolute:Rf(e,t);return{x:n,y:i,x2:n+(((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0),y2:i+(((r=e.measured)==null?void 0:r.height)??e.height??e.initialHeight??0)}},pP=(e,t)=>wg(vg(F0(e),F0(t))),mP=(e,t,n,i,s,r,o,c)=>{const d=Math.max(0,Math.min(e+n,s+o)-Math.max(e,s)),f=Math.max(0,Math.min(t+i,r+c)-Math.max(t,r));return Math.ceil(d*f)},Pm=(e,t)=>mP(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),lT=e=>Xs(e.width)&&Xs(e.height)&&Xs(e.x)&&Xs(e.y),Xs=e=>!isNaN(e)&&isFinite(e),gP=(e,t)=>(n,i)=>{},Of=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Lf=({x:e,y:t},[n,i,s],r=!1,o=[1,1])=>{const c={x:(e-n)/s,y:(t-i)/s};return r?Of(c,o):c},Zc=({x:e,y:t},[n,i,s])=>({x:e*s+n,y:t*s+i});function lc(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function Pce(e,t,n){if(typeof e=="string"||typeof e=="number"){const i=lc(e,n),s=lc(e,t);return{top:i,right:s,bottom:i,left:s,x:s*2,y:i*2}}if(typeof e=="object"){const i=lc(e.top??e.y??0,n),s=lc(e.bottom??e.y??0,n),r=lc(e.left??e.x??0,t),o=lc(e.right??e.x??0,t);return{top:i,right:o,bottom:s,left:r,x:r+o,y:i+s}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function zce(e,t,n,i,s,r){const{x:o,y:c}=Zc(e,[t,n,i]),{x:d,y:f}=Zc({x:e.x+e.width,y:e.y+e.height},[t,n,i]),m=s-d,p=r-f;return{left:Math.floor(o),top:Math.floor(c),right:Math.floor(m),bottom:Math.floor(p)}}const Vw=(e,t,n,i,s,r)=>{const o=Pce(r,t,n),c=(t-o.x)/e.width,d=(n-o.y)/e.height,f=Math.min(c,d),m=Qc(f,i,s),p=e.x+e.width/2,b=e.y+e.height/2,y=t/2-p*m,x=n/2-b*m,v=zce(e,y,x,m,t,n),w={left:Math.min(v.left-o.left,0),top:Math.min(v.top-o.top,0),right:Math.min(v.right-o.right,0),bottom:Math.min(v.bottom-o.bottom,0)};return{x:y-w.left+w.right,y:x-w.top+w.bottom,zoom:m}},sf=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function xl(e){return e!=null&&e!=="parent"}function pa(e){var t,n;return{width:((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth??0,height:((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight??0}}function yP(e){var t,n;return(((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth)!==void 0&&(((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight)!==void 0}function bP(e,t={width:0,height:0},n,i,s){const r={...e},o=i.get(n);if(o){const c=o.origin||s;r.x+=o.internals.positionAbsolute.x-(t.width??0)*c[0],r.y+=o.internals.positionAbsolute.y-(t.height??0)*c[1]}return r}function cT(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function Bce(){let e,t;return{promise:new Promise((i,s)=>{e=i,t=s}),resolve:e,reject:t}}function Uce(e){return{...lP,...e||{}}}function Od(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:i,containerBounds:s}){const{x:r,y:o}=Qs(e),c=Lf({x:r-((s==null?void 0:s.left)??0),y:o-((s==null?void 0:s.top)??0)},i),{x:d,y:f}=n?Of(c,t):c;return{xSnapped:d,ySnapped:f,...c}}const Kw=e=>({width:e.offsetWidth,height:e.offsetHeight}),xP=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},Fce=["INPUT","SELECT","TEXTAREA"];function vP(e){var i,s;const t=((s=(i=e.composedPath)==null?void 0:i.call(e))==null?void 0:s[0])||e.target;return(t==null?void 0:t.nodeType)!==1?!1:Fce.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const wP=e=>"clientX"in e,Qs=(e,t)=>{var r,o;const n=wP(e),i=n?e.clientX:(r=e.touches)==null?void 0:r[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:i-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},uT=(e,t,n,i,s)=>{const r=t.querySelectorAll(`.${e}`);return!r||!r.length?null:Array.from(r).map(o=>{const c=o.getBoundingClientRect();return{id:o.getAttribute("data-handleid"),type:e,nodeId:s,position:o.getAttribute("data-handlepos"),x:(c.left-n.left)/i,y:(c.top-n.top)/i,...Kw(o)}})};function EP({sourceX:e,sourceY:t,targetX:n,targetY:i,sourceControlX:s,sourceControlY:r,targetControlX:o,targetControlY:c}){const d=e*.125+s*.375+o*.375+n*.125,f=t*.125+r*.375+c*.375+i*.125,m=Math.abs(d-e),p=Math.abs(f-t);return[d,f,m,p]}function Ep(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function dT({pos:e,x1:t,y1:n,x2:i,y2:s,c:r}){switch(e){case tt.Left:return[t-Ep(t-i,r),n];case tt.Right:return[t+Ep(i-t,r),n];case tt.Top:return[t,n-Ep(n-s,r)];case tt.Bottom:return[t,n+Ep(s-n,r)]}}function kP({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:s,targetPosition:r=tt.Top,curvature:o=.25}){const[c,d]=dT({pos:n,x1:e,y1:t,x2:i,y2:s,c:o}),[f,m]=dT({pos:r,x1:i,y1:s,x2:e,y2:t,c:o}),[p,b,y,x]=EP({sourceX:e,sourceY:t,targetX:i,targetY:s,sourceControlX:c,sourceControlY:d,targetControlX:f,targetControlY:m});return[`M${e},${t} C${c},${d} ${f},${m} ${i},${s}`,p,b,y,x]}function SP({sourceX:e,sourceY:t,targetX:n,targetY:i}){const s=Math.abs(n-e)/2,r=n<e?n+s:n-s,o=Math.abs(i-t)/2,c=i<t?i+o:i-o;return[r,c,s,o]}function $ce({sourceNode:e,targetNode:t,selected:n=!1,zIndex:i=0,elevateOnSelect:s=!1,zIndexMode:r="basic"}){if(r==="manual")return i;const o=s&&n?i+1e3:i,c=Math.max(e.parentId||s&&e.selected?e.internals.z:0,t.parentId||s&&t.selected?t.internals.z:0);return o+c}function qce({sourceNode:e,targetNode:t,width:n,height:i,transform:s}){const r=vg(Im(e),Im(t));r.x===r.x2&&(r.x2+=1),r.y===r.y2&&(r.y2+=1);const o={x:-s[0]/s[2],y:-s[1]/s[2],width:n/s[2],height:i/s[2]};return Pm(o,wg(r))>0}const NP=({source:e,sourceHandle:t,target:n,targetHandle:i})=>`xy-edge__${e}${t||""}-${n}${i||""}`,Hce=(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)),Vce=(e,t,n={})=>{var r;if(!e.source||!e.target)return(r=n.onError)==null||r.call(n,"006",ls.error006()),t;const i=n.getEdgeId||NP;let s;return dP(e)?s={...e}:s={...e,id:i(e)},Hce(s,t)?t:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,t.concat(s))},Kce=(e,t,n,i={shouldReplaceId:!0})=>{var f,m;const{id:s,...r}=e;if(!t.source||!t.target)return(f=i.onError)==null||f.call(i,"006",ls.error006()),n;if(!n.find(p=>p.id===e.id))return(m=i.onError)==null||m.call(i,"007",ls.error007(s)),n;const c=i.getEdgeId||NP,d={...r,id:i.shouldReplaceId?c(t):s,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle};return n.filter(p=>p.id!==s).concat(d)};function _P({sourceX:e,sourceY:t,targetX:n,targetY:i}){const[s,r,o,c]=SP({sourceX:e,sourceY:t,targetX:n,targetY:i});return[`M ${e},${t}L ${n},${i}`,s,r,o,c]}const fT={[tt.Left]:{x:-1,y:0},[tt.Right]:{x:1,y:0},[tt.Top]:{x:0,y:-1},[tt.Bottom]:{x:0,y:1}},Gce=({source:e,sourcePosition:t=tt.Bottom,target:n})=>t===tt.Left||t===tt.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},hT=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function Wce({source:e,sourcePosition:t=tt.Bottom,target:n,targetPosition:i=tt.Top,center:s,offset:r,stepPosition:o}){const c=fT[t],d=fT[i],f={x:e.x+c.x*r,y:e.y+c.y*r},m={x:n.x+d.x*r,y:n.y+d.y*r},p=Gce({source:f,sourcePosition:t,target:m}),b=p.x!==0?"x":"y",y=p[b];let x=[],v,w;const k={x:0,y:0},C={x:0,y:0},[,,S,j]=SP({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(c[b]*d[b]===-1){b==="x"?(v=s.x??f.x+(m.x-f.x)*o,w=s.y??(f.y+m.y)/2):(v=s.x??(f.x+m.x)/2,w=s.y??f.y+(m.y-f.y)*o);const R=[{x:v,y:f.y},{x:v,y:m.y}],P=[{x:f.x,y:w},{x:m.x,y:w}];c[b]===y?x=b==="x"?R:P:x=b==="x"?P:R}else{const R=[{x:f.x,y:m.y}],P=[{x:m.x,y:f.y}];if(b==="x"?x=c.x===y?P:R:x=c.y===y?R:P,t===i){const D=Math.abs(e[b]-n[b]);if(D<=r){const I=Math.min(r-1,r-D);c[b]===y?k[b]=(f[b]>e[b]?-1:1)*I:C[b]=(m[b]>n[b]?-1:1)*I}}if(t!==i){const D=b==="x"?"y":"x",I=c[b]===d[D],z=f[D]>m[D],W=f[D]<m[D];(c[b]===1&&(!I&&z||I&&W)||c[b]!==1&&(!I&&W||I&&z))&&(x=b==="x"?R:P)}const O={x:f.x+k.x,y:f.y+k.y},B={x:m.x+C.x,y:m.y+C.y},F=Math.max(Math.abs(O.x-x[0].x),Math.abs(B.x-x[0].x)),V=Math.max(Math.abs(O.y-x[0].y),Math.abs(B.y-x[0].y));F>=V?(v=(O.x+B.x)/2,w=x[0].y):(v=x[0].x,w=(O.y+B.y)/2)}const T={x:f.x+k.x,y:f.y+k.y},A={x:m.x+C.x,y:m.y+C.y};return[[e,...T.x!==x[0].x||T.y!==x[0].y?[T]:[],...x,...A.x!==x[x.length-1].x||A.y!==x[x.length-1].y?[A]:[],n],v,w,S,j]}function Yce(e,t,n,i){const s=Math.min(hT(e,t)/2,hT(t,n)/2,i),{x:r,y:o}=t;if(e.x===r&&r===n.x||e.y===o&&o===n.y)return`L${r} ${o}`;if(e.y===o){const f=e.x<n.x?-1:1,m=e.y<n.y?1:-1;return`L ${r+s*f},${o}Q ${r},${o} ${r},${o+s*m}`}const c=e.x<n.x?1:-1,d=e.y<n.y?-1:1;return`L ${r},${o+s*d}Q ${r},${o} ${r+s*c},${o}`}function $0({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:s,targetPosition:r=tt.Top,borderRadius:o=5,centerX:c,centerY:d,offset:f=20,stepPosition:m=.5}){const[p,b,y,x,v]=Wce({source:{x:e,y:t},sourcePosition:n,target:{x:i,y:s},targetPosition:r,center:{x:c,y:d},offset:f,stepPosition:m});let w=`M${p[0].x} ${p[0].y}`;for(let k=1;k<p.length-1;k++)w+=Yce(p[k-1],p[k],p[k+1],o);return w+=`L${p[p.length-1].x} ${p[p.length-1].y}`,[w,b,y,x,v]}function pT(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Xce(e){var p;const{sourceNode:t,targetNode:n}=e;if(!pT(t)||!pT(n))return null;const i=t.internals.handleBounds||mT(t.handles),s=n.internals.handleBounds||mT(n.handles),r=gT((i==null?void 0:i.source)??[],e.sourceHandle),o=gT(e.connectionMode===Xc.Strict?(s==null?void 0:s.target)??[]:((s==null?void 0:s.target)??[]).concat((s==null?void 0:s.source)??[]),e.targetHandle);if(!r||!o)return(p=e.onError)==null||p.call(e,"008",ls.error008(r?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const c=(r==null?void 0:r.position)||tt.Bottom,d=(o==null?void 0:o.position)||tt.Top,f=vl(t,r,c),m=vl(n,o,d);return{sourceX:f.x,sourceY:f.y,targetX:m.x,targetY:m.y,sourcePosition:c,targetPosition:d}}function mT(e){if(!e)return null;const t=[],n=[];for(const i of e)i.width=i.width??1,i.height=i.height??1,i.type==="source"?t.push(i):i.type==="target"&&n.push(i);return{source:t,target:n}}function vl(e,t,n=tt.Left,i=!1){const s=((t==null?void 0:t.x)??0)+e.internals.positionAbsolute.x,r=((t==null?void 0:t.y)??0)+e.internals.positionAbsolute.y,{width:o,height:c}=t??pa(e);if(i)return{x:s+o/2,y:r+c/2};switch((t==null?void 0:t.position)??n){case tt.Top:return{x:s+o/2,y:r};case tt.Right:return{x:s+o,y:r+c/2};case tt.Bottom:return{x:s+o/2,y:r+c};case tt.Left:return{x:s,y:r+c/2}}}function gT(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function q0(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(i=>`${i}=${e[i]}`).join("&")}`:""}function Qce(e,{id:t,defaultColor:n,defaultMarkerStart:i,defaultMarkerEnd:s}){const r=new Set;return e.reduce((o,c)=>([c.markerStart||i,c.markerEnd||s].forEach(d=>{if(d&&typeof d=="object"){const f=q0(d,t);r.has(f)||(o.push({id:f,color:d.color||n,...d}),r.add(f))}}),o),[]).sort((o,c)=>o.id.localeCompare(c.id))}const CP=1e3,Zce=10,Gw={nodeOrigin:[0,0],nodeExtent:ef,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Jce={...Gw,checkEquality:!0};function Ww(e,t){const n={...e};for(const i in t)t[i]!==void 0&&(n[i]=t[i]);return n}function eue(e,t,n){const i=Ww(Gw,n);for(const s of e.values())if(s.parentId)Xw(s,e,t,i);else{const r=Rf(s,i.nodeOrigin),o=xl(s.extent)?s.extent:i.nodeExtent,c=bl(r,o,pa(s));s.internals.positionAbsolute=c}}function tue(e,t){if(!e.handles)return e.measured?t==null?void 0:t.internals.handleBounds:void 0;const n=[],i=[];for(const s of e.handles){const r={id:s.id,width:s.width??1,height:s.height??1,nodeId:e.id,x:s.x,y:s.y,position:s.position,type:s.type};s.type==="source"?n.push(r):s.type==="target"&&i.push(r)}return{source:n,target:i}}function Yw(e){return e==="manual"}function H0(e,t,n,i={}){var m,p;const s=Ww(Jce,i),r={i:0},o=new Map(t),c=s!=null&&s.elevateNodesOnSelect&&!Yw(s.zIndexMode)?CP:0;let d=e.length>0,f=!1;t.clear(),n.clear();for(const b of e){let y=o.get(b.id);if(s.checkEquality&&b===(y==null?void 0:y.internals.userNode))t.set(b.id,y);else{const x=Rf(b,s.nodeOrigin),v=xl(b.extent)?b.extent:s.nodeExtent,w=bl(x,v,pa(b));y={...s.defaults,...b,measured:{width:(m=b.measured)==null?void 0:m.width,height:(p=b.measured)==null?void 0:p.height},internals:{positionAbsolute:w,handleBounds:tue(b,y),z:jP(b,c,s.zIndexMode),userNode:b}},t.set(b.id,y)}(y.measured===void 0||y.measured.width===void 0||y.measured.height===void 0)&&!y.hidden&&(d=!1),b.parentId&&Xw(y,t,n,i,r),f||(f=b.selected??!1)}return{nodesInitialized:d,hasSelectedNodes:f}}function nue(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function Xw(e,t,n,i,s){const{elevateNodesOnSelect:r,nodeOrigin:o,nodeExtent:c,zIndexMode:d}=Ww(Gw,i),f=e.parentId,m=t.get(f);if(!m){console.warn(`Parent node ${f} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}nue(e,n),s&&!m.parentId&&m.internals.rootParentIndex===void 0&&d==="auto"&&(m.internals.rootParentIndex=++s.i,m.internals.z=m.internals.z+s.i*Zce),s&&m.internals.rootParentIndex!==void 0&&(s.i=m.internals.rootParentIndex);const p=r&&!Yw(d)?CP:0,{x:b,y,z:x}=iue(e,m,o,c,p,d),{positionAbsolute:v}=e.internals,w=b!==v.x||y!==v.y;(w||x!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:w?{x:b,y}:v,z:x}})}function jP(e,t,n){const i=Xs(e.zIndex)?e.zIndex:0;return Yw(n)?i:i+(e.selected?t:0)}function iue(e,t,n,i,s,r){const{x:o,y:c}=t.internals.positionAbsolute,d=pa(e),f=Rf(e,n),m=xl(e.extent)?bl(f,e.extent,d):f;let p=bl({x:o+m.x,y:c+m.y},i,d);e.extent==="parent"&&(p=hP(p,d,t));const b=jP(e,s,r),y=t.internals.z??0;return{x:p.x,y:p.y,z:y>=b?y+1:b}}function Qw(e,t,n,i=[0,0]){var o;const s=[],r=new Map;for(const c of e){const d=t.get(c.parentId);if(!d)continue;const f=((o=r.get(c.parentId))==null?void 0:o.expandedRect)??nf(d),m=pP(f,c.rect);r.set(c.parentId,{expandedRect:m,parent:d})}return r.size>0&&r.forEach(({expandedRect:c,parent:d},f)=>{var S;const m=d.internals.positionAbsolute,p=pa(d),b=d.origin??i,y=c.x<m.x?Math.round(Math.abs(m.x-c.x)):0,x=c.y<m.y?Math.round(Math.abs(m.y-c.y)):0,v=Math.max(p.width,Math.round(c.width)),w=Math.max(p.height,Math.round(c.height)),k=(v-p.width)*b[0],C=(w-p.height)*b[1];(y>0||x>0||k||C)&&(s.push({id:f,type:"position",position:{x:d.position.x-y+k,y:d.position.y-x+C}}),(S=n.get(f))==null||S.forEach(j=>{e.some(T=>T.id===j.id)||s.push({id:j.id,type:"position",position:{x:j.position.x+y,y:j.position.y+x}})})),(p.width<c.width||p.height<c.height||y||x)&&s.push({id:f,type:"dimensions",setAttributes:!0,dimensions:{width:v+(y?b[0]*y-k:0),height:w+(x?b[1]*x-C:0)}})}),s}function sue(e,t,n,i,s,r,o){const c=i==null?void 0:i.querySelector(".xyflow__viewport");let d=!1;if(!c)return{changes:[],updatedInternals:d};const f=[],m=window.getComputedStyle(c),{m22:p}=new window.DOMMatrixReadOnly(m.transform),b=[];for(const y of e.values()){const x=t.get(y.id);if(!x)continue;if(x.hidden){t.set(x.id,{...x,internals:{...x.internals,handleBounds:void 0}}),d=!0;continue}const v=Kw(y.nodeElement),w=x.measured.width!==v.width||x.measured.height!==v.height;if(!!(v.width&&v.height&&(w||!x.internals.handleBounds||y.force))){const C=y.nodeElement.getBoundingClientRect(),S=xl(x.extent)?x.extent:r;let{positionAbsolute:j}=x.internals;x.parentId&&x.extent==="parent"?j=hP(j,v,t.get(x.parentId)):S&&(j=bl(j,S,v));const T={...x,measured:v,internals:{...x.internals,positionAbsolute:j,handleBounds:{source:uT("source",y.nodeElement,C,p,x.id),target:uT("target",y.nodeElement,C,p,x.id)}}};t.set(x.id,T),x.parentId&&Xw(T,t,n,{nodeOrigin:s,zIndexMode:o}),d=!0,w&&(f.push({id:x.id,type:"dimensions",dimensions:v}),x.expandParent&&x.parentId&&b.push({id:x.id,parentId:x.parentId,rect:nf(T,s)}))}}if(b.length>0){const y=Qw(b,t,n,s);f.push(...y)}return{changes:f,updatedInternals:d}}async function rue({delta:e,panZoom:t,transform:n,translateExtent:i,width:s,height:r}){if(!t||!e.x&&!e.y)return!1;const o=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[s,r]],i);return!!o&&(o.x!==n[0]||o.y!==n[1]||o.k!==n[2])}function yT(e,t,n,i,s,r){let o=s;const c=i.get(o)||new Map;i.set(o,c.set(n,t)),o=`${s}-${e}`;const d=i.get(o)||new Map;if(i.set(o,d.set(n,t)),r){o=`${s}-${e}-${r}`;const f=i.get(o)||new Map;i.set(o,f.set(n,t))}}function TP(e,t,n){e.clear(),t.clear();for(const i of n){const{source:s,target:r,sourceHandle:o=null,targetHandle:c=null}=i,d={edgeId:i.id,source:s,target:r,sourceHandle:o,targetHandle:c},f=`${s}-${o}--${r}-${c}`,m=`${r}-${c}--${s}-${o}`;yT("source",d,m,e,s,o),yT("target",d,f,e,r,c),t.set(i.id,i)}}function AP(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:AP(n,t):!1}function bT(e,t,n){var s;let i=e;do{if((s=i==null?void 0:i.matches)!=null&&s.call(i,t))return!0;if(i===n)return!1;i=i==null?void 0:i.parentElement}while(i);return!1}function aue(e,t,n,i){const s=new Map;for(const[r,o]of e)if((o.selected||o.id===i)&&(!o.parentId||!AP(o,e))&&(o.draggable||t&&typeof o.draggable>"u")){const c=e.get(r);c&&s.set(r,{id:r,position:c.position||{x:0,y:0},distance:{x:n.x-c.internals.positionAbsolute.x,y:n.y-c.internals.positionAbsolute.y},extent:c.extent,parentId:c.parentId,origin:c.origin,expandParent:c.expandParent,internals:{positionAbsolute:c.internals.positionAbsolute||{x:0,y:0}},measured:{width:c.measured.width??0,height:c.measured.height??0}})}return s}function Gx({nodeId:e,dragItems:t,nodeLookup:n,dragging:i=!0}){var o,c,d;const s=[];for(const[f,m]of t){const p=(o=n.get(f))==null?void 0:o.internals.userNode;p&&s.push({...p,position:m.position,dragging:i})}if(!e)return[s[0],s];const r=(c=n.get(e))==null?void 0:c.internals.userNode;return[r?{...r,position:((d=t.get(e))==null?void 0:d.position)||r.position,dragging:i}:s[0],s]}function oue({dragItems:e,snapGrid:t,x:n,y:i}){const s=e.values().next().value;if(!s)return null;const r={x:n-s.distance.x,y:i-s.distance.y},o=Of(r,t);return{x:o.x-r.x,y:o.y-r.y}}function lue({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:i,onDragStop:s}){let r={x:null,y:null},o=0,c=new Map,d=!1,f={x:0,y:0},m=null,p=!1,b=null,y=!1,x=!1,v=null;function w({noDragClassName:C,handleSelector:S,domNode:j,isSelectable:T,nodeId:A,nodeClickDistance:M=0}){b=ss(j);function R({x:F,y:V}){const{nodeLookup:D,nodeExtent:I,snapGrid:z,snapToGrid:W,nodeOrigin:X,onNodeDrag:G,onSelectionDrag:U,onError:q,updateNodePositions:Y}=t();r={x:F,y:V};let $=!1;const ie=c.size>1,be=ie&&I?F0(Df(c)):null,ce=ie&&W?oue({dragItems:c,snapGrid:z,x:F,y:V}):null;for(const[_e,le]of c){if(!D.has(_e))continue;let pe={x:F-le.distance.x,y:V-le.distance.y};W&&(pe=ce?{x:Math.round(pe.x+ce.x),y:Math.round(pe.y+ce.y)}:Of(pe,z));let Te=null;if(ie&&I&&!le.extent&&be){const{positionAbsolute:xe}=le.internals,fe=xe.x-be.x+I[0][0],te=xe.x+le.measured.width-be.x2+I[1][0],we=xe.y-be.y+I[0][1],Fe=xe.y+le.measured.height-be.y2+I[1][1];Te=[[fe,we],[te,Fe]]}const{position:ne,positionAbsolute:oe}=fP({nodeId:_e,nextPosition:pe,nodeLookup:D,nodeExtent:Te||I,nodeOrigin:X,onError:q});$=$||le.position.x!==ne.x||le.position.y!==ne.y,le.position=ne,le.internals.positionAbsolute=oe}if(x=x||$,!!$&&(Y(c,!0),v&&(i||G||!A&&U))){const[_e,le]=Gx({nodeId:A,dragItems:c,nodeLookup:D});i==null||i(v,c,_e,le),G==null||G(v,_e,le),A||U==null||U(v,le)}}async function P(){if(!m)return;const{transform:F,panBy:V,autoPanSpeed:D,autoPanOnNodeDrag:I}=t();if(!I){d=!1,cancelAnimationFrame(o);return}const[z,W]=Hw(f,m,D);(z!==0||W!==0)&&(r.x=(r.x??0)-z/F[2],r.y=(r.y??0)-W/F[2],await V({x:z,y:W})&&R(r)),o=requestAnimationFrame(P)}function O(F){var ie;const{nodeLookup:V,multiSelectionActive:D,nodesDraggable:I,transform:z,snapGrid:W,snapToGrid:X,selectNodesOnDrag:G,onNodeDragStart:U,onSelectionDragStart:q,unselectNodesAndEdges:Y}=t();p=!0,(!G||!T)&&!D&&A&&((ie=V.get(A))!=null&&ie.selected||Y()),T&&G&&A&&(e==null||e(A));const $=Od(F.sourceEvent,{transform:z,snapGrid:W,snapToGrid:X,containerBounds:m});if(r=$,c=aue(V,I,$,A),c.size>0&&(n||U||!A&&q)){const[be,ce]=Gx({nodeId:A,dragItems:c,nodeLookup:V});n==null||n(F.sourceEvent,c,be,ce),U==null||U(F.sourceEvent,be,ce),A||q==null||q(F.sourceEvent,ce)}}const B=VI().clickDistance(M).on("start",F=>{const{domNode:V,nodeDragThreshold:D,transform:I,snapGrid:z,snapToGrid:W}=t();m=(V==null?void 0:V.getBoundingClientRect())||null,y=!1,x=!1,v=F.sourceEvent,D===0&&O(F),r=Od(F.sourceEvent,{transform:I,snapGrid:z,snapToGrid:W,containerBounds:m}),f=Qs(F.sourceEvent,m)}).on("drag",F=>{const{autoPanOnNodeDrag:V,transform:D,snapGrid:I,snapToGrid:z,nodeDragThreshold:W,nodeLookup:X}=t(),G=Od(F.sourceEvent,{transform:D,snapGrid:I,snapToGrid:z,containerBounds:m});if(v=F.sourceEvent,(F.sourceEvent.type==="touchmove"&&F.sourceEvent.touches.length>1||A&&!X.has(A))&&(y=!0),!y){if(!d&&V&&p&&(d=!0,P()),!p){const U=Qs(F.sourceEvent,m),q=U.x-f.x,Y=U.y-f.y;Math.sqrt(q*q+Y*Y)>W&&O(F)}(r.x!==G.xSnapped||r.y!==G.ySnapped)&&c&&p&&(f=Qs(F.sourceEvent,m),R(G))}}).on("end",F=>{if(!p||y){y&&c.size>0&&t().updateNodePositions(c,!1);return}if(d=!1,p=!1,cancelAnimationFrame(o),c.size>0){const{nodeLookup:V,updateNodePositions:D,onNodeDragStop:I,onSelectionDragStop:z}=t();if(x&&(D(c,!1),x=!1),s||I||!A&&z){const[W,X]=Gx({nodeId:A,dragItems:c,nodeLookup:V,dragging:!1});s==null||s(F.sourceEvent,c,W,X),I==null||I(F.sourceEvent,W,X),A||z==null||z(F.sourceEvent,X)}}}).filter(F=>{const V=F.target;return!F.button&&(!C||!bT(V,`.${C}`,j))&&(!S||bT(V,S,j))});b.call(B)}function k(){b==null||b.on(".drag",null)}return{update:w,destroy:k}}function cue(e,t,n){const i=[],s={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const r of t.values())Pm(s,nf(r))>0&&i.push(r);return i}const uue=250;function due(e,t,n,i){var c,d;let s=[],r=1/0;const o=cue(e,n,t+uue);for(const f of o){const m=[...((c=f.internals.handleBounds)==null?void 0:c.source)??[],...((d=f.internals.handleBounds)==null?void 0:d.target)??[]];for(const p of m){if(i.nodeId===p.nodeId&&i.type===p.type&&i.id===p.id)continue;const{x:b,y}=vl(f,p,p.position,!0),x=Math.sqrt(Math.pow(b-e.x,2)+Math.pow(y-e.y,2));x>t||(x<r?(s=[{...p,x:b,y}],r=x):x===r&&s.push({...p,x:b,y}))}}if(!s.length)return null;if(s.length>1){const f=i.type==="source"?"target":"source";return s.find(m=>m.type===f)??s[0]}return s[0]}function MP(e,t,n,i,s,r=!1){var f,m,p;const o=i.get(e);if(!o)return null;const c=s==="strict"?(f=o.internals.handleBounds)==null?void 0:f[t]:[...((m=o.internals.handleBounds)==null?void 0:m.source)??[],...((p=o.internals.handleBounds)==null?void 0:p.target)??[]],d=(n?c==null?void 0:c.find(b=>b.id===n):c==null?void 0:c[0])??null;return d&&r?{...d,...vl(o,d,d.position,!0)}:d}function RP(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function fue(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const DP=()=>!0;function hue(e,{connectionMode:t,connectionRadius:n,handleId:i,nodeId:s,edgeUpdaterType:r,isTarget:o,domNode:c,nodeLookup:d,lib:f,autoPanOnConnect:m,flowId:p,panBy:b,cancelConnection:y,onConnectStart:x,onConnect:v,onConnectEnd:w,isValidConnection:k=DP,onReconnectEnd:C,updateConnection:S,getTransform:j,getFromHandle:T,autoPanSpeed:A,dragThreshold:M=1,handleDomNode:R}){const P=xP(e.target);let O=0,B;const{x:F,y:V}=Qs(e),D=RP(r,R),I=c==null?void 0:c.getBoundingClientRect();let z=!1;if(!I||!D)return;const W=MP(s,D,i,d,t);if(!W)return;let X=Qs(e,I),G=!1,U=null,q=!1,Y=null;function $(){if(!m||!I)return;const[ne,oe]=Hw(X,I,A);b({x:ne,y:oe}),O=requestAnimationFrame($)}const ie={...W,nodeId:s,type:D,position:W.position},be=d.get(s);let _e={inProgress:!0,isValid:null,from:vl(be,ie,tt.Left,!0),fromHandle:ie,fromPosition:ie.position,fromNode:be,to:X,toHandle:null,toPosition:aT[ie.position],toNode:null,pointer:X};function le(){z=!0,S(_e),x==null||x(e,{nodeId:s,handleId:i,handleType:D})}M===0&&le();function pe(ne){if(!z){const{x:Fe,y:Le}=Qs(ne),pt=Fe-F,nt=Le-V;if(!(pt*pt+nt*nt>M*M))return;le()}if(!T()||!ie){Te(ne);return}const oe=j();X=Qs(ne,I),B=due(Lf(X,oe,!1,[1,1]),n,d,ie),G||($(),G=!0);const xe=OP(ne,{handle:B,connectionMode:t,fromNodeId:s,fromHandleId:i,fromType:o?"target":"source",isValidConnection:k,doc:P,lib:f,flowId:p,nodeLookup:d});Y=xe.handleDomNode,U=xe.connection,q=fue(!!B,xe.isValid);const fe=d.get(s),te=fe?vl(fe,ie,tt.Left,!0):_e.from,we={..._e,from:te,isValid:q,to:xe.toHandle&&q?Zc({x:xe.toHandle.x,y:xe.toHandle.y},oe):X,toHandle:xe.toHandle,toPosition:q&&xe.toHandle?xe.toHandle.position:aT[ie.position],toNode:xe.toHandle?d.get(xe.toHandle.nodeId):null,pointer:X};S(we),_e=we}function Te(ne){if(!("touches"in ne&&ne.touches.length>0)){if(z){(B||Y)&&U&&q&&(v==null||v(U));const{inProgress:oe,...xe}=_e,fe={...xe,toPosition:_e.toHandle?_e.toPosition:null};w==null||w(ne,fe),r&&(C==null||C(ne,fe))}y(),cancelAnimationFrame(O),G=!1,q=!1,U=null,Y=null,P.removeEventListener("mousemove",pe),P.removeEventListener("mouseup",Te),P.removeEventListener("touchmove",pe),P.removeEventListener("touchend",Te)}}P.addEventListener("mousemove",pe),P.addEventListener("mouseup",Te),P.addEventListener("touchmove",pe),P.addEventListener("touchend",Te)}function OP(e,{handle:t,connectionMode:n,fromNodeId:i,fromHandleId:s,fromType:r,doc:o,lib:c,flowId:d,isValidConnection:f=DP,nodeLookup:m}){const p=r==="target",b=t?o.querySelector(`.${c}-flow__handle[data-id="${d}-${t==null?void 0:t.nodeId}-${t==null?void 0:t.id}-${t==null?void 0:t.type}"]`):null,{x:y,y:x}=Qs(e),v=o.elementFromPoint(y,x),w=v!=null&&v.classList.contains(`${c}-flow__handle`)?v:b,k={handleDomNode:w,isValid:!1,connection:null,toHandle:null};if(w){const C=RP(void 0,w),S=w.getAttribute("data-nodeid"),j=w.getAttribute("data-handleid"),T=w.classList.contains("connectable"),A=w.classList.contains("connectableend");if(!S||!C)return k;const M={source:p?S:i,sourceHandle:p?j:s,target:p?i:S,targetHandle:p?s:j};k.connection=M;const P=T&&A&&(n===Xc.Strict?p&&C==="source"||!p&&C==="target":S!==i||j!==s);k.isValid=P&&f(M),k.toHandle=MP(S,C,j,m,n,!0)}return k}const V0={onPointerDown:hue,isValid:OP};function pue({domNode:e,panZoom:t,getTransform:n,getViewScale:i}){const s=ss(e);function r({translateExtent:c,width:d,height:f,zoomStep:m=1,pannable:p=!0,zoomable:b=!0,inversePan:y=!1}){const x=S=>{if(S.sourceEvent.type!=="wheel"||!t)return;const j=n(),T=S.sourceEvent.ctrlKey&&sf()?10:1,A=-S.sourceEvent.deltaY*(S.sourceEvent.deltaMode===1?.05:S.sourceEvent.deltaMode?1:.002)*m,M=j[2]*Math.pow(2,A*T);t.scaleTo(M)};let v=[0,0];const w=S=>{(S.sourceEvent.type==="mousedown"||S.sourceEvent.type==="touchstart")&&(v=[S.sourceEvent.clientX??S.sourceEvent.touches[0].clientX,S.sourceEvent.clientY??S.sourceEvent.touches[0].clientY])},k=S=>{const j=n();if(S.sourceEvent.type!=="mousemove"&&S.sourceEvent.type!=="touchmove"||!t)return;const T=[S.sourceEvent.clientX??S.sourceEvent.touches[0].clientX,S.sourceEvent.clientY??S.sourceEvent.touches[0].clientY],A=[T[0]-v[0],T[1]-v[1]];v=T;const M=i()*Math.max(j[2],Math.log(j[2]))*(y?-1:1),R={x:j[0]-A[0]*M,y:j[1]-A[1]*M},P=[[0,0],[d,f]];t.setViewportConstrained({x:R.x,y:R.y,zoom:j[2]},P,c)},C=aP().on("start",w).on("zoom",p?k:null).on("zoom.wheel",b?x:null);s.call(C,{})}function o(){s.on("zoom",null)}return{update:r,destroy:o,pointer:Gs}}const Eg=e=>({x:e.x,y:e.y,zoom:e.k}),Wx=({x:e,y:t,zoom:n})=>xg.translate(e,t).scale(n),vc=(e,t)=>e.target.closest(`.${t}`),LP=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),mue=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Yx=(e,t=0,n=mue,i=()=>{})=>{const s=typeof t=="number"&&t>0;return s||i(),s?e.transition().duration(t).ease(n).on("end",i):e},IP=e=>{const t=e.ctrlKey&&sf()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function gue({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:i,panOnScrollMode:s,panOnScrollSpeed:r,zoomOnPinch:o,onPanZoomStart:c,onPanZoom:d,onPanZoomEnd:f}){return m=>{if(vc(m,t))return m.ctrlKey&&m.preventDefault(),!1;m.preventDefault(),m.stopImmediatePropagation();const p=n.property("__zoom").k||1;if(m.ctrlKey&&o){const w=Gs(m),k=IP(m),C=p*Math.pow(2,k);i.scaleTo(n,C,w,m);return}const b=m.deltaMode===1?20:1;let y=s===ul.Vertical?0:m.deltaX*b,x=s===ul.Horizontal?0:m.deltaY*b;!sf()&&m.shiftKey&&s!==ul.Vertical&&(y=m.deltaY*b,x=0),i.translateBy(n,-(y/p)*r,-(x/p)*r,{internal:!0});const v=Eg(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(d==null||d(m,v),e.panScrollTimeout=setTimeout(()=>{f==null||f(m,v),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,c==null||c(m,v))}}function yue({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(i,s){const r=i.type==="wheel",o=!t&&r&&!i.ctrlKey,c=vc(i,e);if(i.ctrlKey&&r&&c&&i.preventDefault(),o||c)return null;i.preventDefault(),n.call(this,i,s)}}function bue({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return i=>{var r,o,c;if((r=i.sourceEvent)!=null&&r.internal)return;const s=Eg(i.transform);e.mouseButton=((o=i.sourceEvent)==null?void 0:o.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=s,((c=i.sourceEvent)==null?void 0:c.type)==="mousedown"&&t(!0),n&&(n==null||n(i.sourceEvent,s))}}function xue({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:i,onPanZoom:s}){return r=>{var o,c;e.usedRightMouseButton=!!(n&&LP(t,e.mouseButton??0)),(o=r.sourceEvent)!=null&&o.sync||i([r.transform.x,r.transform.y,r.transform.k]),s&&!((c=r.sourceEvent)!=null&&c.internal)&&(s==null||s(r.sourceEvent,Eg(r.transform)))}}function vue({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:i,onPanZoomEnd:s,onPaneContextMenu:r}){return o=>{var c;if(!((c=o.sourceEvent)!=null&&c.internal)&&(e.isZoomingOrPanning=!1,r&&LP(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&r(o.sourceEvent),e.usedRightMouseButton=!1,i(!1),s)){const d=Eg(o.transform);e.prevViewport=d,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s==null||s(o.sourceEvent,d)},n?150:0)}}}function wue({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:i,panOnScroll:s,zoomOnDoubleClick:r,userSelectionActive:o,noWheelClassName:c,noPanClassName:d,lib:f,connectionInProgress:m}){return p=>{var w;const b=e||t,y=n&&p.ctrlKey,x=p.type==="wheel";if(p.button===1&&p.type==="mousedown"&&(vc(p,`${f}-flow__node`)||vc(p,`${f}-flow__edge`)))return!0;if(!i&&!b&&!s&&!r&&!n||o||m&&!x||vc(p,c)&&x||vc(p,d)&&(!x||s&&x&&!e)||!n&&p.ctrlKey&&x)return!1;if(!n&&p.type==="touchstart"&&((w=p.touches)==null?void 0:w.length)>1)return p.preventDefault(),!1;if(!b&&!s&&!y&&x||!i&&(p.type==="mousedown"||p.type==="touchstart")||Array.isArray(i)&&!i.includes(p.button)&&p.type==="mousedown")return!1;const v=Array.isArray(i)&&i.includes(p.button)||!p.button||p.button<=1;return(!p.ctrlKey||x)&&v}}function Eue({domNode:e,minZoom:t,maxZoom:n,translateExtent:i,viewport:s,onPanZoom:r,onPanZoomStart:o,onPanZoomEnd:c,onDraggingChange:d}){const f={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},m=e.getBoundingClientRect(),p=aP().scaleExtent([t,n]).translateExtent(i),b=ss(e).call(p);C({x:s.x,y:s.y,zoom:Qc(s.zoom,t,n)},[[0,0],[m.width,m.height]],i);const y=b.on("wheel.zoom"),x=b.on("dblclick.zoom");p.wheelDelta(IP);async function v(B,F){return b?new Promise(V=>{p==null||p.interpolate((F==null?void 0:F.interpolate)==="linear"?Dd:Gp).transform(Yx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}function w({noWheelClassName:B,noPanClassName:F,onPaneContextMenu:V,userSelectionActive:D,panOnScroll:I,panOnDrag:z,panOnScrollMode:W,panOnScrollSpeed:X,preventScrolling:G,zoomOnPinch:U,zoomOnScroll:q,zoomOnDoubleClick:Y,zoomActivationKeyPressed:$,lib:ie,onTransformChange:be,connectionInProgress:ce,paneClickDistance:_e,selectionOnDrag:le}){D&&!f.isZoomingOrPanning&&k();const pe=I&&!$&&!D;p.clickDistance(le?1/0:!Xs(_e)||_e<0?0:_e);const Te=pe?gue({zoomPanValues:f,noWheelClassName:B,d3Selection:b,d3Zoom:p,panOnScrollMode:W,panOnScrollSpeed:X,zoomOnPinch:U,onPanZoomStart:o,onPanZoom:r,onPanZoomEnd:c}):yue({noWheelClassName:B,preventScrolling:G,d3ZoomHandler:y});b.on("wheel.zoom",Te,{passive:!1});const ne=bue({zoomPanValues:f,onDraggingChange:d,onPanZoomStart:o});p.on("start",ne);const oe=xue({zoomPanValues:f,panOnDrag:z,onPaneContextMenu:!!V,onPanZoom:r,onTransformChange:be});p.on("zoom",oe);const xe=vue({zoomPanValues:f,panOnDrag:z,panOnScroll:I,onPaneContextMenu:V,onPanZoomEnd:c,onDraggingChange:d});p.on("end",xe);const fe=wue({zoomActivationKeyPressed:$,panOnDrag:z,zoomOnScroll:q,panOnScroll:I,zoomOnDoubleClick:Y,zoomOnPinch:U,userSelectionActive:D,noPanClassName:F,noWheelClassName:B,lib:ie,connectionInProgress:ce});p.filter(fe),Y?b.on("dblclick.zoom",x):b.on("dblclick.zoom",null)}function k(){p.on("zoom",null)}async function C(B,F,V){const D=Wx(B),I=p==null?void 0:p.constrain()(D,F,V);return I&&await v(I),I}async function S(B,F){const V=Wx(B);return await v(V,F),V}function j(B){if(b){const F=Wx(B),V=b.property("__zoom");(V.k!==B.zoom||V.x!==B.x||V.y!==B.y)&&(p==null||p.transform(b,F,null,{sync:!0}))}}function T(){const B=b?rP(b.node()):{x:0,y:0,k:1};return{x:B.x,y:B.y,zoom:B.k}}async function A(B,F){return b?new Promise(V=>{p==null||p.interpolate((F==null?void 0:F.interpolate)==="linear"?Dd:Gp).scaleTo(Yx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}async function M(B,F){return b?new Promise(V=>{p==null||p.interpolate((F==null?void 0:F.interpolate)==="linear"?Dd:Gp).scaleBy(Yx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}function R(B){p==null||p.scaleExtent(B)}function P(B){p==null||p.translateExtent(B)}function O(B){const F=!Xs(B)||B<0?0:B;p==null||p.clickDistance(F)}return{update:w,destroy:k,setViewport:S,setViewportConstrained:C,getViewport:T,scaleTo:A,scaleBy:M,setScaleExtent:R,setTranslateExtent:P,syncViewport:j,setClickDistance:O}}var Jc;(function(e){e.Line="line",e.Handle="handle"})(Jc||(Jc={}));function kue({width:e,prevWidth:t,height:n,prevHeight:i,affectsX:s,affectsY:r}){const o=e-t,c=n-i,d=[o>0?1:o<0?-1:0,c>0?1:c<0?-1:0];return o&&s&&(d[0]=d[0]*-1),c&&r&&(d[1]=d[1]*-1),d}function xT(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),i=e.includes("left"),s=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:i,affectsY:s}}function Ua(e,t){return Math.max(0,t-e)}function Fa(e,t){return Math.max(0,e-t)}function kp(e,t,n){return Math.max(0,t-e,e-n)}function vT(e,t){return e?!t:t}function Sue(e,t,n,i,s,r,o,c){let{affectsX:d,affectsY:f}=t;const{isHorizontal:m,isVertical:p}=t,b=m&&p,{xSnapped:y,ySnapped:x}=n,{minWidth:v,maxWidth:w,minHeight:k,maxHeight:C}=i,{x:S,y:j,width:T,height:A,aspectRatio:M}=e;let R=Math.floor(m?y-e.pointerX:0),P=Math.floor(p?x-e.pointerY:0);const O=T+(d?-R:R),B=A+(f?-P:P),F=-r[0]*T,V=-r[1]*A;let D=kp(O,v,w),I=kp(B,k,C);if(o){let X=0,G=0;d&&R<0?X=Ua(S+R+F,o[0][0]):!d&&R>0&&(X=Fa(S+O+F,o[1][0])),f&&P<0?G=Ua(j+P+V,o[0][1]):!f&&P>0&&(G=Fa(j+B+V,o[1][1])),D=Math.max(D,X),I=Math.max(I,G)}if(c){let X=0,G=0;d&&R>0?X=Fa(S+R,c[0][0]):!d&&R<0&&(X=Ua(S+O,c[1][0])),f&&P>0?G=Fa(j+P,c[0][1]):!f&&P<0&&(G=Ua(j+B,c[1][1])),D=Math.max(D,X),I=Math.max(I,G)}if(s){if(m){const X=kp(O/M,k,C)*M;if(D=Math.max(D,X),o){let G=0;!d&&!f||d&&!f&&b?G=Fa(j+V+O/M,o[1][1])*M:G=Ua(j+V+(d?R:-R)/M,o[0][1])*M,D=Math.max(D,G)}if(c){let G=0;!d&&!f||d&&!f&&b?G=Ua(j+O/M,c[1][1])*M:G=Fa(j+(d?R:-R)/M,c[0][1])*M,D=Math.max(D,G)}}if(p){const X=kp(B*M,v,w)/M;if(I=Math.max(I,X),o){let G=0;!d&&!f||f&&!d&&b?G=Fa(S+B*M+F,o[1][0])/M:G=Ua(S+(f?P:-P)*M+F,o[0][0])/M,I=Math.max(I,G)}if(c){let G=0;!d&&!f||f&&!d&&b?G=Ua(S+B*M,c[1][0])/M:G=Fa(S+(f?P:-P)*M,c[0][0])/M,I=Math.max(I,G)}}}P=P+(P<0?I:-I),R=R+(R<0?D:-D),s&&(b?O>B*M?P=(vT(d,f)?-R:R)/M:R=(vT(d,f)?-P:P)*M:m?(P=R/M,f=d):(R=P*M,d=f));const z=d?S+R:S,W=f?j+P:j;return{width:T+(d?-R:R),height:A+(f?-P:P),x:r[0]*R*(d?-1:1)+z,y:r[1]*P*(f?-1:1)+W}}const PP={width:0,height:0,x:0,y:0},Nue={...PP,pointerX:0,pointerY:0,aspectRatio:1};function _ue(e,t,n){const i=t.position.x+e.position.x,s=t.position.y+e.position.y,r=e.measured.width??0,o=e.measured.height??0,c=n[0]*r,d=n[1]*o;return[[i-c,s-d],[i+r-c,s+o-d]]}function Cue({domNode:e,nodeId:t,getStoreItems:n,onChange:i,onEnd:s}){const r=ss(e);let o={controlDirection:xT("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function c({controlPosition:f,boundaries:m,keepAspectRatio:p,resizeDirection:b,onResizeStart:y,onResize:x,onResizeEnd:v,shouldResize:w}){let k={...PP},C={...Nue};o={boundaries:m,resizeDirection:b,keepAspectRatio:p,controlDirection:xT(f)};let S,j=null,T=[],A,M,R,P=!1;const O=VI().on("start",B=>{const{nodeLookup:F,transform:V,snapGrid:D,snapToGrid:I,nodeOrigin:z,paneDomNode:W}=n();if(S=F.get(t),!S)return;j=(W==null?void 0:W.getBoundingClientRect())??null;const{xSnapped:X,ySnapped:G}=Od(B.sourceEvent,{transform:V,snapGrid:D,snapToGrid:I,containerBounds:j});k={width:S.measured.width??0,height:S.measured.height??0,x:S.position.x??0,y:S.position.y??0},C={...k,pointerX:X,pointerY:G,aspectRatio:k.width/k.height},A=void 0,M=xl(S.extent)?S.extent:void 0,S.parentId&&(S.extent==="parent"||S.expandParent)&&(A=F.get(S.parentId)),A&&S.extent==="parent"&&(M=[[0,0],[A.measured.width,A.measured.height]]),T=[],R=void 0;for(const[U,q]of F)if(q.parentId===t&&(T.push({id:U,position:{...q.position},extent:q.extent}),q.extent==="parent"||q.expandParent)){const Y=_ue(q,S,q.origin??z);R?R=[[Math.min(Y[0][0],R[0][0]),Math.min(Y[0][1],R[0][1])],[Math.max(Y[1][0],R[1][0]),Math.max(Y[1][1],R[1][1])]]:R=Y}y==null||y(B,{...k})}).on("drag",B=>{const{transform:F,snapGrid:V,snapToGrid:D,nodeOrigin:I}=n(),z=Od(B.sourceEvent,{transform:F,snapGrid:V,snapToGrid:D,containerBounds:j}),W=[];if(!S)return;const{x:X,y:G,width:U,height:q}=k,Y={},$=S.origin??I,{width:ie,height:be,x:ce,y:_e}=Sue(C,o.controlDirection,z,o.boundaries,o.keepAspectRatio,$,M,R),le=ie!==U,pe=be!==q,Te=ce!==X&&le,ne=_e!==G&&pe;if(!Te&&!ne&&!le&&!pe)return;if((Te||ne||$[0]===1||$[1]===1)&&(Y.x=Te?ce:k.x,Y.y=ne?_e:k.y,k.x=Y.x,k.y=Y.y,T.length>0)){const te=ce-X,we=_e-G;for(const Fe of T)Fe.position={x:Fe.position.x-te+$[0]*(ie-U),y:Fe.position.y-we+$[1]*(be-q)},W.push(Fe)}if((le||pe)&&(Y.width=le&&(!o.resizeDirection||o.resizeDirection==="horizontal")?ie:k.width,Y.height=pe&&(!o.resizeDirection||o.resizeDirection==="vertical")?be:k.height,k.width=Y.width,k.height=Y.height),A&&S.expandParent){const te=$[0]*(Y.width??0);Y.x&&Y.x<te&&(k.x=te,C.x=C.x-(Y.x-te));const we=$[1]*(Y.height??0);Y.y&&Y.y<we&&(k.y=we,C.y=C.y-(Y.y-we))}const oe=kue({width:k.width,prevWidth:U,height:k.height,prevHeight:q,affectsX:o.controlDirection.affectsX,affectsY:o.controlDirection.affectsY}),xe={...k,direction:oe};(w==null?void 0:w(B,xe))!==!1&&(P=!0,x==null||x(B,xe),i(Y,W))}).on("end",B=>{P&&(v==null||v(B,{...k}),s==null||s({...k}),P=!1)});r.call(O)}function d(){r.on(".drag",null)}return{update:c,destroy:d}}var Xx={exports:{}},Qx={},Zx={exports:{}},Jx={};/**
844
844
  * @license React
845
845
  * use-sync-external-store-shim.production.js
846
846
  *
@@ -864,4 +864,4 @@ description: ...
864
864
  `)),m=f.reduce((p,b)=>p.concat(...b),[]);return[f,m]}return[[],[]]},[e]);return _.useEffect(()=>{const d=(t==null?void 0:t.target)??RT,f=(t==null?void 0:t.actInsideInputWithModifier)??!0;if(e!==null){const m=y=>{var w,k;if(s.current=y.ctrlKey||y.metaKey||y.shiftKey||y.altKey,(!s.current||s.current&&!f)&&vP(y))return!1;const v=OT(y.code,c);if(r.current.add(y[v]),DT(o,r.current,!1)){const C=((k=(w=y.composedPath)==null?void 0:w.call(y))==null?void 0:k[0])||y.target,S=(C==null?void 0:C.nodeName)==="BUTTON"||(C==null?void 0:C.nodeName)==="A";t.preventDefault!==!1&&(s.current||!S)&&y.preventDefault(),i(!0)}},p=y=>{const x=OT(y.code,c);DT(o,r.current,!0)?(i(!1),r.current.clear()):r.current.delete(y[x]),y.key==="Meta"&&r.current.clear(),s.current=!1},b=()=>{r.current.clear(),i(!1)};return d==null||d.addEventListener("keydown",m),d==null||d.addEventListener("keyup",p),window.addEventListener("blur",b),window.addEventListener("contextmenu",b),()=>{d==null||d.removeEventListener("keydown",m),d==null||d.removeEventListener("keyup",p),window.removeEventListener("blur",b),window.removeEventListener("contextmenu",b)}}},[e,i]),n}function DT(e,t,n){return e.filter(i=>n||i.length===t.size).some(i=>i.every(s=>t.has(s)))}function OT(e,t){return t.includes(e)?"code":"key"}const sde=()=>{const e=Nn();return _.useMemo(()=>({zoomIn:async t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):!1},zoomOut:async t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):!1},zoomTo:async(t,n)=>{const{panZoom:i}=e.getState();return i?i.scaleTo(t,n):!1},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[i,s,r],panZoom:o}=e.getState();return o?(await o.setViewport({x:t.x??i,y:t.y??s,zoom:t.zoom??r},n),!0):!1},getViewport:()=>{const[t,n,i]=e.getState().transform;return{x:t,y:n,zoom:i}},setCenter:async(t,n,i)=>e.getState().setCenter(t,n,i),fitBounds:async(t,n)=>{const{width:i,height:s,minZoom:r,maxZoom:o,panZoom:c}=e.getState(),d=Vw(t,i,s,r,o,(n==null?void 0:n.padding)??.1);return c?(await c.setViewport(d,{duration:n==null?void 0:n.duration,ease:n==null?void 0:n.ease,interpolate:n==null?void 0:n.interpolate}),!0):!1},screenToFlowPosition:(t,n={})=>{const{transform:i,snapGrid:s,snapToGrid:r,domNode:o}=e.getState();if(!o)return t;const{x:c,y:d}=o.getBoundingClientRect(),f={x:t.x-c,y:t.y-d},m=n.snapGrid??s,p=n.snapToGrid??r;return Lf(f,i,p,m)},flowToScreenPosition:t=>{const{transform:n,domNode:i}=e.getState();if(!i)return t;const{x:s,y:r}=i.getBoundingClientRect(),o=Zc(t,n);return{x:o.x+s,y:o.y+r}}}),[])};function qP(e,t){const n=[],i=new Map,s=[];for(const r of e)if(r.type==="add"){s.push(r);continue}else if(r.type==="remove"||r.type==="replace")i.set(r.id,[r]);else{const o=i.get(r.id);o?o.push(r):i.set(r.id,[r])}for(const r of t){const o=i.get(r.id);if(!o){n.push(r);continue}if(o[0].type==="remove")continue;if(o[0].type==="replace"){n.push({...o[0].item});continue}const c={...r};for(const d of o)rde(d,c);n.push(c)}return s.length&&s.forEach(r=>{r.index!==void 0?n.splice(r.index,0,{...r.item}):n.push({...r.item})}),n}function rde(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(t.resizing=e.resizing);break}}}function HP(e,t){return qP(e,t)}function VP(e,t){return qP(e,t)}function Uo(e,t){return{id:e,type:"select",selected:t}}function wc(e,t=new Set,n=!1){const i=[];for(const[s,r]of e){const o=t.has(s);!(r.selected===void 0&&!o)&&r.selected!==o&&(n&&(r.selected=o),i.push(Uo(r.id,o)))}return i}function LT({items:e=[],lookup:t}){var s;const n=[],i=new Map(e.map(r=>[r.id,r]));for(const[r,o]of e.entries()){const c=t.get(o.id),d=((s=c==null?void 0:c.internals)==null?void 0:s.userNode)??c;d!==void 0&&d!==o&&n.push({id:o.id,item:o,type:"replace"}),d===void 0&&n.push({item:o,type:"add",index:r})}for(const[r]of t)i.get(r)===void 0&&n.push({id:r,type:"remove"});return n}function IT(e){return{id:e.id,type:"remove"}}const KP=gP();function GP(e,t,n={}){return Vce(e,t,{...n,onError:n.onError??KP})}function ade(e,t,n,i={shouldReplaceId:!0}){return Kce(e,t,n,{...i,onError:i.onError??KP})}const PT=e=>Mce(e),ode=e=>dP(e);function WP(e){return _.forwardRef(e)}const lde=typeof window<"u"?_.useLayoutEffect:_.useEffect;function zT(e){const[t,n]=_.useState(BigInt(0)),[i]=_.useState(()=>cde(()=>n(s=>s+BigInt(1))));return lde(()=>{const s=i.get();s.length&&(e(s),i.reset())},[t]),i}function cde(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const YP=_.createContext(null);function ude({children:e}){const t=Nn(),n=_.useCallback(c=>{const{nodes:d=[],setNodes:f,hasDefaultNodes:m,onNodesChange:p,nodeLookup:b,fitViewQueued:y,onNodesChangeMiddlewareMap:x}=t.getState();let v=d;for(const k of c)v=typeof k=="function"?k(v):k;let w=LT({items:v,lookup:b});for(const k of x.values())w=k(w);m&&f(v),w.length>0?p==null||p(w):y&&window.requestAnimationFrame(()=>{const{fitViewQueued:k,nodes:C,setNodes:S}=t.getState();k&&S(C)})},[]),i=zT(n),s=_.useCallback(c=>{const{edges:d=[],setEdges:f,hasDefaultEdges:m,onEdgesChange:p,edgeLookup:b}=t.getState();let y=d;for(const x of c)y=typeof x=="function"?x(y):x;m?f(y):p&&p(LT({items:y,lookup:b}))},[]),r=zT(s),o=_.useMemo(()=>({nodeQueue:i,edgeQueue:r}),[]);return u.jsx(YP.Provider,{value:o,children:e})}function dde(){const e=_.useContext(YP);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const fde=e=>!!e.panZoom;function Ng(){const e=sde(),t=Nn(),n=dde(),i=Ut(fde),s=_.useMemo(()=>{const r=p=>t.getState().nodeLookup.get(p),o=p=>{n.nodeQueue.push(p)},c=p=>{n.edgeQueue.push(p)},d=p=>{var k,C;const{nodeLookup:b,nodeOrigin:y}=t.getState(),x=PT(p)?p:b.get(p.id),v=x.parentId?bP(x.position,x.measured,x.parentId,b,y):x.position,w={...x,position:v,width:((k=x.measured)==null?void 0:k.width)??x.width,height:((C=x.measured)==null?void 0:C.height)??x.height};return nf(w)},f=(p,b,y={replace:!1})=>{o(x=>x.map(v=>{if(v.id===p){const w=typeof b=="function"?b(v):b;return y.replace&&PT(w)?w:{...v,...w}}return v}))},m=(p,b,y={replace:!1})=>{c(x=>x.map(v=>{if(v.id===p){const w=typeof b=="function"?b(v):b;return y.replace&&ode(w)?w:{...v,...w}}return v}))};return{getNodes:()=>t.getState().nodes.map(p=>({...p})),getNode:p=>{var b;return(b=r(p))==null?void 0:b.internals.userNode},getInternalNode:r,getEdges:()=>{const{edges:p=[]}=t.getState();return p.map(b=>({...b}))},getEdge:p=>t.getState().edgeLookup.get(p),setNodes:o,setEdges:c,addNodes:p=>{const b=Array.isArray(p)?p:[p];n.nodeQueue.push(y=>[...y,...b])},addEdges:p=>{const b=Array.isArray(p)?p:[p];n.edgeQueue.push(y=>[...y,...b])},toObject:()=>{const{nodes:p=[],edges:b=[],transform:y}=t.getState(),[x,v,w]=y;return{nodes:p.map(k=>({...k})),edges:b.map(k=>({...k})),viewport:{x,y:v,zoom:w}}},deleteElements:async({nodes:p=[],edges:b=[]})=>{const{nodes:y,edges:x,onNodesDelete:v,onEdgesDelete:w,triggerNodeChanges:k,triggerEdgeChanges:C,onDelete:S,onBeforeDelete:j}=t.getState(),{nodes:T,edges:A}=await Ice({nodesToRemove:p,edgesToRemove:b,nodes:y,edges:x,onBeforeDelete:j}),M=A.length>0,R=T.length>0;if(M){const P=A.map(IT);w==null||w(A),C(P)}if(R){const P=T.map(IT);v==null||v(T),k(P)}return(R||M)&&(S==null||S({nodes:T,edges:A})),{deletedNodes:T,deletedEdges:A}},getIntersectingNodes:(p,b=!0,y)=>{const x=lT(p),v=x?p:d(p),w=y!==void 0;return v?(y||t.getState().nodes).filter(k=>{const C=t.getState().nodeLookup.get(k.id);if(C&&!x&&(k.id===p.id||!C.internals.positionAbsolute))return!1;const S=nf(w?k:C),j=Pm(S,v);return b&&j>0||j>=S.width*S.height||j>=v.width*v.height}):[]},isNodeIntersecting:(p,b,y=!0)=>{const v=lT(p)?p:d(p);if(!v)return!1;const w=Pm(v,b);return y&&w>0||w>=b.width*b.height||w>=v.width*v.height},updateNode:f,updateNodeData:(p,b,y={replace:!1})=>{f(p,x=>{const v=typeof b=="function"?b(x):b;return y.replace?{...x,data:v}:{...x,data:{...x.data,...v}}},y)},updateEdge:m,updateEdgeData:(p,b,y={replace:!1})=>{m(p,x=>{const v=typeof b=="function"?b(x):b;return y.replace?{...x,data:v}:{...x,data:{...x.data,...v}}},y)},getNodesBounds:p=>{const{nodeLookup:b,nodeOrigin:y}=t.getState();return Rce(p,{nodeLookup:b,nodeOrigin:y})},getHandleConnections:({type:p,id:b,nodeId:y})=>{var x;return Array.from(((x=t.getState().connectionLookup.get(`${y}-${p}${b?`-${b}`:""}`))==null?void 0:x.values())??[])},getNodeConnections:({type:p,handleId:b,nodeId:y})=>{var x;return Array.from(((x=t.getState().connectionLookup.get(`${y}${p?b?`-${p}-${b}`:`-${p}`:""}`))==null?void 0:x.values())??[])},fitView:async p=>{const b=t.getState().fitViewResolver??Bce();return t.setState({fitViewQueued:!0,fitViewOptions:p,fitViewResolver:b}),n.nodeQueue.push(y=>[...y]),b.promise}}},[]);return _.useMemo(()=>({...s,...e,viewportInitialized:i}),[i])}const BT=e=>e.selected,hde=typeof window<"u"?window:void 0;function pde({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=Nn(),{deleteElements:i}=Ng(),s=rf(e,{actInsideInputWithModifier:!1}),r=rf(t,{target:hde});_.useEffect(()=>{if(s){const{edges:o,nodes:c}=n.getState();i({nodes:c.filter(BT),edges:o.filter(BT)}),n.setState({nodesSelectionActive:!1})}},[s]),_.useEffect(()=>{n.setState({multiSelectionActive:r})},[r])}function mde(e){const t=Nn();_.useEffect(()=>{const n=()=>{var s,r,o,c;if(!e.current||!(((r=(s=e.current).checkVisibility)==null?void 0:r.call(s))??!0))return!1;const i=Kw(e.current);(i.height===0||i.width===0)&&((c=(o=t.getState()).onError)==null||c.call(o,"004",ls.error004())),t.setState({width:i.width||500,height:i.height||500})};if(e.current){n(),window.addEventListener("resize",n);const i=new ResizeObserver(()=>n());return i.observe(e.current),()=>{window.removeEventListener("resize",n),i&&e.current&&i.unobserve(e.current)}}},[])}const _g={position:"absolute",width:"100%",height:"100%",top:0,left:0},gde=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function yde({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:i=!1,panOnScrollSpeed:s=.5,panOnScrollMode:r=ul.Free,zoomOnDoubleClick:o=!0,panOnDrag:c=!0,defaultViewport:d,translateExtent:f,minZoom:m,maxZoom:p,zoomActivationKeyCode:b,preventScrolling:y=!0,children:x,noWheelClassName:v,noPanClassName:w,onViewportChange:k,isControlledViewport:C,paneClickDistance:S,selectionOnDrag:j}){const T=Nn(),A=_.useRef(null),{userSelectionActive:M,lib:R,connectionInProgress:P}=Ut(gde,Sn),O=rf(b),B=_.useRef();mde(A);const F=_.useCallback(V=>{k==null||k({x:V[0],y:V[1],zoom:V[2]}),C||T.setState({transform:V})},[k,C]);return _.useEffect(()=>{if(A.current){B.current=Eue({domNode:A.current,minZoom:m,maxZoom:p,translateExtent:f,viewport:d,onDraggingChange:z=>T.setState(W=>W.paneDragging===z?W:{paneDragging:z}),onPanZoomStart:(z,W)=>{const{onViewportChangeStart:X,onMoveStart:G}=T.getState();G==null||G(z,W),X==null||X(W)},onPanZoom:(z,W)=>{const{onViewportChange:X,onMove:G}=T.getState();G==null||G(z,W),X==null||X(W)},onPanZoomEnd:(z,W)=>{const{onViewportChangeEnd:X,onMoveEnd:G}=T.getState();G==null||G(z,W),X==null||X(W)}});const{x:V,y:D,zoom:I}=B.current.getViewport();return T.setState({panZoom:B.current,transform:[V,D,I],domNode:A.current.closest(".react-flow")}),()=>{var z;(z=B.current)==null||z.destroy()}}},[]),_.useEffect(()=>{var V;(V=B.current)==null||V.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:i,panOnScrollSpeed:s,panOnScrollMode:r,zoomOnDoubleClick:o,panOnDrag:c,zoomActivationKeyPressed:O,preventScrolling:y,noPanClassName:w,userSelectionActive:M,noWheelClassName:v,lib:R,onTransformChange:F,connectionInProgress:P,selectionOnDrag:j,paneClickDistance:S})},[e,t,n,i,s,r,o,c,O,y,w,M,v,R,F,P,j,S]),u.jsx("div",{className:"react-flow__renderer",ref:A,style:_g,children:x})}const bde=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function xde(){const{userSelectionActive:e,userSelectionRect:t}=Ut(bde,Sn);return e&&t?u.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}const ev=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},vde=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging,panBy:e.panBy,autoPanSpeed:e.autoPanSpeed});function wde({isSelecting:e,selectionKeyPressed:t,selectionMode:n=tf.Full,panOnDrag:i,autoPanOnSelection:s,paneClickDistance:r,selectionOnDrag:o,onSelectionStart:c,onSelectionEnd:d,onPaneClick:f,onPaneContextMenu:m,onPaneScroll:p,onPaneMouseEnter:b,onPaneMouseMove:y,onPaneMouseLeave:x,children:v}){const w=_.useRef(0),k=Nn(),{userSelectionActive:C,elementsSelectable:S,dragging:j,panBy:T,autoPanSpeed:A}=Ut(vde,Sn),M=S&&(e||C),R=_.useRef(null),P=_.useRef(),O=_.useRef(new Set),B=_.useRef(new Set),F=_.useRef(!1),V=_.useRef(!1),D=_.useRef({x:0,y:0}),I=_.useRef(!1),z=le=>{if(V.current||F.current||k.getState().connection.inProgress){V.current=!1,F.current=!1;return}f==null||f(le),k.getState().resetSelectedElements(),k.setState({nodesSelectionActive:!1})},W=le=>{if(Array.isArray(i)&&(i!=null&&i.includes(2))){le.preventDefault();return}m==null||m(le)},X=p?le=>p(le):void 0,G=le=>{V.current&&(le.stopPropagation(),V.current=!1)},U=le=>{var Fe,Le;const{domNode:pe,transform:Te}=k.getState();if(P.current=pe==null?void 0:pe.getBoundingClientRect(),!P.current)return;const ne=le.target===R.current;if(!ne&&!!le.target.closest(".nokey")||!e||!(o&&ne||t)||le.button!==0||!le.isPrimary)return;(Le=(Fe=le.target)==null?void 0:Fe.setPointerCapture)==null||Le.call(Fe,le.pointerId),V.current=!1;const{x:fe,y:te}=Qs(le.nativeEvent,P.current),we=Lf({x:fe,y:te},Te);k.setState({userSelectionRect:{width:0,height:0,startX:we.x,startY:we.y,x:fe,y:te}}),ne||(le.stopPropagation(),le.preventDefault())};function q(le,pe){const{userSelectionRect:Te}=k.getState();if(!Te)return;const{transform:ne,nodeLookup:oe,edgeLookup:xe,connectionLookup:fe,triggerNodeChanges:te,triggerEdgeChanges:we,defaultEdgeOptions:Fe}=k.getState(),Le={x:Te.startX,y:Te.startY},{x:pt,y:nt}=Zc(Le,ne),Mt={startX:Le.x,startY:Le.y,x:le<pt?le:pt,y:pe<nt?pe:nt,width:Math.abs(le-pt),height:Math.abs(pe-nt)},Nt=O.current,mt=B.current;O.current=new Set(qw(oe,Mt,ne,n===tf.Partial,!0).map(We=>We.id)),B.current=new Set;const Re=(Fe==null?void 0:Fe.selectable)??!0;for(const We of O.current){const se=fe.get(We);if(se)for(const{edgeId:Ee}of se.values()){const De=xe.get(Ee);De&&(De.selectable??Re)&&B.current.add(Ee)}}if(!cT(Nt,O.current)){const We=wc(oe,O.current,!0);te(We)}if(!cT(mt,B.current)){const We=wc(xe,B.current);we(We)}k.setState({userSelectionRect:Mt,userSelectionActive:!0,nodesSelectionActive:!1})}function Y(){if(!s||!P.current)return;const[le,pe]=Hw(D.current,P.current,A);T({x:le,y:pe}).then(Te=>{if(!V.current||!Te){w.current=requestAnimationFrame(Y);return}const{x:ne,y:oe}=D.current;q(ne,oe),w.current=requestAnimationFrame(Y)})}const $=()=>{cancelAnimationFrame(w.current),w.current=0,I.current=!1};_.useEffect(()=>()=>$(),[]);const ie=le=>{const{userSelectionRect:pe,transform:Te,resetSelectedElements:ne}=k.getState();if(!P.current||!pe)return;const{x:oe,y:xe}=Qs(le.nativeEvent,P.current);D.current={x:oe,y:xe};const fe=Zc({x:pe.startX,y:pe.startY},Te);if(!V.current){const te=t?0:r;if(Math.hypot(oe-fe.x,xe-fe.y)<=te)return;ne(),c==null||c(le)}V.current=!0,I.current||(Y(),I.current=!0),q(oe,xe)},be=le=>{var pe,Te;if(!M){le.target===R.current&&k.getState().connection.inProgress&&(F.current=!0);return}le.button===0&&((Te=(pe=le.target)==null?void 0:pe.releasePointerCapture)==null||Te.call(pe,le.pointerId),!C&&le.target===R.current&&k.getState().userSelectionRect&&(z==null||z(le)),k.setState({userSelectionActive:!1,userSelectionRect:null}),V.current&&(d==null||d(le),k.setState({nodesSelectionActive:O.current.size>0})),$())},ce=le=>{var pe,Te;(Te=(pe=le.target)==null?void 0:pe.releasePointerCapture)==null||Te.call(pe,le.pointerId),$()},_e=i===!0||Array.isArray(i)&&i.includes(0);return u.jsxs("div",{className:Wn(["react-flow__pane",{draggable:_e,dragging:j,selection:e}]),onClick:M?void 0:ev(z,R),onContextMenu:ev(W,R),onWheel:ev(X,R),onPointerEnter:M?void 0:b,onPointerMove:M?ie:y,onPointerUp:be,onPointerCancel:M?ce:void 0,onPointerDownCapture:M?U:void 0,onClickCapture:M?G:void 0,onPointerLeave:x,ref:R,style:_g,children:[v,u.jsx(xde,{})]})}function K0({id:e,store:t,unselect:n=!1,nodeRef:i}){const{addSelectedNodes:s,unselectNodesAndEdges:r,multiSelectionActive:o,nodeLookup:c,onError:d}=t.getState(),f=c.get(e);if(!f){d==null||d("012",ls.error012(e));return}t.setState({nodesSelectionActive:!1}),f.selected?(n||f.selected&&o)&&(r({nodes:[f],edges:[]}),requestAnimationFrame(()=>{var m;return(m=i==null?void 0:i.current)==null?void 0:m.blur()})):s([e])}function XP({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:i,nodeId:s,isSelectable:r,nodeClickDistance:o}){const c=Nn(),[d,f]=_.useState(!1),m=_.useRef();return _.useEffect(()=>{m.current=lue({getStoreItems:()=>c.getState(),onNodeMouseDown:p=>{K0({id:p,store:c,nodeRef:e})},onDragStart:()=>{f(!0)},onDragStop:()=>{f(!1)}})},[]),_.useEffect(()=>{if(!(t||!e.current||!m.current))return m.current.update({noDragClassName:n,handleSelector:i,domNode:e.current,isSelectable:r,nodeId:s,nodeClickDistance:o}),()=>{var p;(p=m.current)==null||p.destroy()}},[n,i,t,r,e,s,o]),d}const Ede=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function QP(){const e=Nn();return _.useCallback(n=>{const{nodeExtent:i,snapToGrid:s,snapGrid:r,nodesDraggable:o,onError:c,updateNodePositions:d,nodeLookup:f,nodeOrigin:m}=e.getState(),p=new Map,b=Ede(o),y=s?r[0]:5,x=s?r[1]:5,v=n.direction.x*y*n.factor,w=n.direction.y*x*n.factor;for(const[,k]of f){if(!b(k))continue;let C={x:k.internals.positionAbsolute.x+v,y:k.internals.positionAbsolute.y+w};s&&(C=Of(C,r));const{position:S,positionAbsolute:j}=fP({nodeId:k.id,nextPosition:C,nodeLookup:f,nodeExtent:i,nodeOrigin:m,onError:c});k.position=S,k.internals.positionAbsolute=j,p.set(k.id,k)}d(p)},[])}const Zw=_.createContext(null),kde=Zw.Provider;Zw.Consumer;const ZP=()=>_.useContext(Zw),Sde=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),JP=_.createContext(null);function Nde({children:e}){const t=Ut(Sde,Sn);return u.jsx(JP.Provider,{value:t,children:e})}function _de(){const e=_.useContext(JP);if(!e)throw new Error("useHandleConfig must be used within a HandleConfigProvider");return e}const Cde={connectingFrom:!1,connectingTo:!1,clickConnecting:!1,isPossibleEndHandle:!0,connectionInProcess:!1,clickConnectionInProcess:!1,valid:!1},jde=(e,t,n)=>i=>{const{connectionClickStartHandle:s,connectionMode:r,connection:o}=i,{fromHandle:c,toHandle:d,isValid:f}=o;if(!c&&!s)return Cde;const m=(d==null?void 0:d.nodeId)===e&&(d==null?void 0:d.id)===t&&(d==null?void 0:d.type)===n;return{connectingFrom:(c==null?void 0:c.nodeId)===e&&(c==null?void 0:c.id)===t&&(c==null?void 0:c.type)===n,connectingTo:m,clickConnecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.id)===t&&(s==null?void 0:s.type)===n,isPossibleEndHandle:r===Xc.Strict?(c==null?void 0:c.type)!==n:e!==(c==null?void 0:c.nodeId)||t!==(c==null?void 0:c.id),connectionInProcess:!!c,clickConnectionInProcess:!!s,valid:m&&f}};function Tde({type:e="source",position:t=tt.Top,isValidConnection:n,isConnectable:i=!0,isConnectableStart:s=!0,isConnectableEnd:r=!0,id:o,onConnect:c,children:d,className:f,onMouseDown:m,onTouchStart:p,...b},y){var I,z;const x=o||null,v=e==="target",w=Nn(),k=ZP(),{connectOnClick:C,noPanClassName:S,rfId:j}=_de(),{connectingFrom:T,connectingTo:A,clickConnecting:M,isPossibleEndHandle:R,connectionInProcess:P,clickConnectionInProcess:O,valid:B}=Ut(jde(k,x,e),Sn);k||(z=(I=w.getState()).onError)==null||z.call(I,"010",ls.error010());const F=W=>{const{defaultEdgeOptions:X,onConnect:G,hasDefaultEdges:U}=w.getState(),q={...X,...W};if(U){const{edges:Y,setEdges:$,onError:ie}=w.getState();$(GP(q,Y,{onError:ie}))}G==null||G(q),c==null||c(q)},V=W=>{if(!k)return;const X=wP(W.nativeEvent);if(s&&(X&&W.button===0||!X)){const G=w.getState();V0.onPointerDown(W.nativeEvent,{handleDomNode:W.currentTarget,autoPanOnConnect:G.autoPanOnConnect,connectionMode:G.connectionMode,connectionRadius:G.connectionRadius,domNode:G.domNode,nodeLookup:G.nodeLookup,lib:G.lib,isTarget:v,handleId:x,nodeId:k,flowId:G.rfId,panBy:G.panBy,cancelConnection:G.cancelConnection,onConnectStart:G.onConnectStart,onConnectEnd:(...U)=>{var q,Y;return(Y=(q=w.getState()).onConnectEnd)==null?void 0:Y.call(q,...U)},updateConnection:G.updateConnection,onConnect:F,isValidConnection:n||((...U)=>{var q,Y;return((Y=(q=w.getState()).isValidConnection)==null?void 0:Y.call(q,...U))??!0}),getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,autoPanSpeed:G.autoPanSpeed,dragThreshold:G.connectionDragThreshold})}X?m==null||m(W):p==null||p(W)},D=W=>{const{onClickConnectStart:X,onClickConnectEnd:G,connectionClickStartHandle:U,connectionMode:q,isValidConnection:Y,lib:$,rfId:ie,nodeLookup:be,connection:ce}=w.getState();if(!k||!U&&!s)return;if(!U){X==null||X(W.nativeEvent,{nodeId:k,handleId:x,handleType:e}),w.setState({connectionClickStartHandle:{nodeId:k,type:e,id:x}});return}const _e=xP(W.target),le=n||Y,{connection:pe,isValid:Te}=V0.isValid(W.nativeEvent,{handle:{nodeId:k,id:x,type:e},connectionMode:q,fromNodeId:U.nodeId,fromHandleId:U.id||null,fromType:U.type,isValidConnection:le,flowId:ie,doc:_e,lib:$,nodeLookup:be});Te&&pe&&F(pe);const ne=structuredClone(ce);delete ne.inProgress,ne.toPosition=ne.toHandle?ne.toHandle.position:null,G==null||G(W,ne),w.setState({connectionClickStartHandle:null})};return u.jsx("div",{"data-handleid":x,"data-nodeid":k,"data-handlepos":t,"data-id":`${j}-${k}-${x}-${e}`,className:Wn(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",S,f,{source:!v,target:v,connectable:i,connectablestart:s,connectableend:r,clickconnecting:M,connectingfrom:T,connectingto:A,valid:B,connectionindicator:i&&(!P||R)&&(P||O?r:s)}]),onMouseDown:V,onTouchStart:V,onClick:C?D:void 0,ref:y,...b,children:d})}const no=_.memo(WP(Tde));function Ade({data:e,isConnectable:t,sourcePosition:n=tt.Bottom}){return u.jsxs(u.Fragment,{children:[e==null?void 0:e.label,u.jsx(no,{type:"source",position:n,isConnectable:t})]})}function Mde({data:e,isConnectable:t,targetPosition:n=tt.Top,sourcePosition:i=tt.Bottom}){return u.jsxs(u.Fragment,{children:[u.jsx(no,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,u.jsx(no,{type:"source",position:i,isConnectable:t})]})}function Rde(){return null}function Dde({data:e,isConnectable:t,targetPosition:n=tt.Top}){return u.jsxs(u.Fragment,{children:[u.jsx(no,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label]})}const zm={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},UT={input:Ade,default:Mde,output:Dde,group:Rde};function Ode(e){var t,n,i,s;return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??((t=e.style)==null?void 0:t.width),height:e.height??e.initialHeight??((n=e.style)==null?void 0:n.height)}:{width:e.width??((i=e.style)==null?void 0:i.width),height:e.height??((s=e.style)==null?void 0:s.height)}}const Lde=e=>{const{width:t,height:n,x:i,y:s}=Df(e.nodeLookup,{filter:r=>!!r.selected});return{width:Xs(t)?t:null,height:Xs(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${i}px,${s}px)`}};function Ide({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const i=Nn(),{width:s,height:r,transformString:o,userSelectionActive:c}=Ut(Lde,Sn),d=QP(),f=_.useRef(null);_.useEffect(()=>{var y;n||(y=f.current)==null||y.focus({preventScroll:!0})},[n]);const m=!c&&s!==null&&r!==null;if(XP({nodeRef:f,disabled:!m}),!m)return null;const p=e?y=>{const x=i.getState().nodes.filter(v=>v.selected);e(y,x)}:void 0,b=y=>{Object.prototype.hasOwnProperty.call(zm,y.key)&&(y.preventDefault(),d({direction:zm[y.key],factor:y.shiftKey?4:1}))};return u.jsx("div",{className:Wn(["react-flow__nodesselection","react-flow__container",t]),style:{transform:o},children:u.jsx("div",{ref:f,className:"react-flow__nodesselection-rect",onContextMenu:p,tabIndex:n?void 0:-1,onKeyDown:n?void 0:b,style:{width:s,height:r}})})}const FT=typeof window<"u"?window:void 0,Pde=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function e3({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:i,onPaneMouseLeave:s,onPaneContextMenu:r,onPaneScroll:o,paneClickDistance:c,deleteKeyCode:d,selectionKeyCode:f,selectionOnDrag:m,selectionMode:p,onSelectionStart:b,onSelectionEnd:y,multiSelectionKeyCode:x,panActivationKeyCode:v,zoomActivationKeyCode:w,elementsSelectable:k,zoomOnScroll:C,zoomOnPinch:S,panOnScroll:j,panOnScrollSpeed:T,panOnScrollMode:A,zoomOnDoubleClick:M,panOnDrag:R,autoPanOnSelection:P,defaultViewport:O,translateExtent:B,minZoom:F,maxZoom:V,preventScrolling:D,onSelectionContextMenu:I,noWheelClassName:z,noPanClassName:W,disableKeyboardA11y:X,onViewportChange:G,isControlledViewport:U}){const{nodesSelectionActive:q,userSelectionActive:Y}=Ut(Pde,Sn),$=rf(f,{target:FT}),ie=rf(v,{target:FT}),be=ie||R,ce=ie||j,_e=m&&be!==!0,le=$||Y||_e;return pde({deleteKeyCode:d,multiSelectionKeyCode:x}),u.jsx(yde,{onPaneContextMenu:r,elementsSelectable:k,zoomOnScroll:C,zoomOnPinch:S,panOnScroll:ce,panOnScrollSpeed:T,panOnScrollMode:A,zoomOnDoubleClick:M,panOnDrag:!$&&be,defaultViewport:O,translateExtent:B,minZoom:F,maxZoom:V,zoomActivationKeyCode:w,preventScrolling:D,noWheelClassName:z,noPanClassName:W,onViewportChange:G,isControlledViewport:U,paneClickDistance:c,selectionOnDrag:_e,children:u.jsxs(wde,{onSelectionStart:b,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:i,onPaneMouseLeave:s,onPaneContextMenu:r,onPaneScroll:o,panOnDrag:be,autoPanOnSelection:P,isSelecting:!!le,selectionMode:p,selectionKeyPressed:$,paneClickDistance:c,selectionOnDrag:_e,children:[e,q&&u.jsx(Ide,{onSelectionContextMenu:I,noPanClassName:W,disableKeyboardA11y:X})]})})}e3.displayName="FlowRenderer";const zde=_.memo(e3),Bde=e=>t=>e?qw(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(n=>n.id):Array.from(t.nodeLookup.keys());function Ude(e){return Ut(_.useCallback(Bde(e),[e]),Sn)}const Fde=e=>e.updateNodeInternals;function $de(){const e=Ut(Fde),[t]=_.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const i=new Map;n.forEach(s=>{const r=s.target.getAttribute("data-id");i.set(r,{id:r,nodeElement:s.target,force:!0})}),e(i)}));return _.useEffect(()=>()=>{t==null||t.disconnect()},[t]),t}function qde({node:e,nodeType:t,hasDimensions:n,resizeObserver:i}){const s=Nn(),r=_.useRef(null),o=_.useRef(null),c=_.useRef(e.sourcePosition),d=_.useRef(e.targetPosition),f=_.useRef(t),m=n&&!!e.internals.handleBounds;return _.useEffect(()=>{r.current&&!e.hidden&&(!m||o.current!==r.current)&&(o.current&&(i==null||i.unobserve(o.current)),i==null||i.observe(r.current),o.current=r.current)},[m,e.hidden]),_.useEffect(()=>()=>{o.current&&(i==null||i.unobserve(o.current),o.current=null)},[]),_.useEffect(()=>{if(r.current){const p=f.current!==t,b=c.current!==e.sourcePosition,y=d.current!==e.targetPosition;(p||b||y)&&(f.current=t,c.current=e.sourcePosition,d.current=e.targetPosition,s.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:r.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),r}function Hde({id:e,onClick:t,onMouseEnter:n,onMouseMove:i,onMouseLeave:s,onContextMenu:r,onDoubleClick:o,nodesDraggable:c,elementsSelectable:d,nodesConnectable:f,nodesFocusable:m,resizeObserver:p,noDragClassName:b,noPanClassName:y,disableKeyboardA11y:x,rfId:v,nodeTypes:w,nodeClickDistance:k,onError:C}){const{node:S,internals:j,isParent:T}=Ut(le=>{const pe=le.nodeLookup.get(e),Te=le.parentLookup.has(e);return{node:pe,internals:pe.internals,isParent:Te}},Sn);let A=S.type||"default",M=(w==null?void 0:w[A])||UT[A];M===void 0&&(C==null||C("003",ls.error003(A)),A="default",M=(w==null?void 0:w.default)||UT.default);const R=!!(S.draggable||c&&typeof S.draggable>"u"),P=!!(S.selectable||d&&typeof S.selectable>"u"),O=!!(S.connectable||f&&typeof S.connectable>"u"),B=!!(S.focusable||m&&typeof S.focusable>"u"),F=Nn(),V=yP(S),D=qde({node:S,nodeType:A,hasDimensions:V,resizeObserver:p}),I=XP({nodeRef:D,disabled:S.hidden||!R,noDragClassName:b,handleSelector:S.dragHandle,nodeId:e,isSelectable:P,nodeClickDistance:k}),z=QP();if(S.hidden)return null;const W=pa(S),X=Ode(S),G=P||R||t||n||i||s,U=n?le=>n(le,{...j.userNode}):void 0,q=i?le=>i(le,{...j.userNode}):void 0,Y=s?le=>s(le,{...j.userNode}):void 0,$=r?le=>r(le,{...j.userNode}):void 0,ie=o?le=>o(le,{...j.userNode}):void 0,be=le=>{const{selectNodesOnDrag:pe,nodeDragThreshold:Te}=F.getState();P&&(!pe||!R||Te>0)&&K0({id:e,store:F,nodeRef:D}),t&&t(le,{...j.userNode})},ce=le=>{if(!(vP(le.nativeEvent)||x)){if(oP.includes(le.key)&&P){const pe=le.key==="Escape";K0({id:e,store:F,unselect:pe,nodeRef:D})}else if(R&&S.selected&&Object.prototype.hasOwnProperty.call(zm,le.key)){le.preventDefault();const{ariaLabelConfig:pe}=F.getState();F.setState({ariaLiveMessage:pe["node.a11yDescription.ariaLiveMessage"]({direction:le.key.replace("Arrow","").toLowerCase(),x:~~j.positionAbsolute.x,y:~~j.positionAbsolute.y})}),z({direction:zm[le.key],factor:le.shiftKey?4:1})}}},_e=()=>{var fe;if(x||!((fe=D.current)!=null&&fe.matches(":focus-visible")))return;const{transform:le,width:pe,height:Te,autoPanOnNodeFocus:ne,setCenter:oe}=F.getState();if(!ne)return;qw(new Map([[e,S]]),{x:0,y:0,width:pe,height:Te},le,!0).length>0||oe(S.position.x+W.width/2,S.position.y+W.height/2,{zoom:le[2]})};return u.jsx("div",{className:Wn(["react-flow__node",`react-flow__node-${A}`,{[y]:R},S.className,{selected:S.selected,selectable:P,parent:T,draggable:R,dragging:I}]),ref:D,style:{zIndex:j.z,transform:`translate(${j.positionAbsolute.x}px,${j.positionAbsolute.y}px)`,pointerEvents:G?"all":"none",visibility:V?"visible":"hidden",...S.style,...X},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:U,onMouseMove:q,onMouseLeave:Y,onContextMenu:$,onClick:be,onDoubleClick:ie,onKeyDown:B?ce:void 0,tabIndex:B?0:void 0,onFocus:B?_e:void 0,role:S.ariaRole??(B?"group":void 0),"aria-roledescription":"node","aria-describedby":x?void 0:`${UP}-${v}`,"aria-label":S.ariaLabel,...S.domAttributes,children:u.jsx(kde,{value:e,children:u.jsx(M,{id:e,data:S.data,type:A,positionAbsoluteX:j.positionAbsolute.x,positionAbsoluteY:j.positionAbsolute.y,selected:S.selected??!1,selectable:P,draggable:R,deletable:S.deletable??!0,isConnectable:O,sourcePosition:S.sourcePosition,targetPosition:S.targetPosition,dragging:I,dragHandle:S.dragHandle,zIndex:j.z,parentId:S.parentId,...W})})})}var Vde=_.memo(Hde);const Kde=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function t3(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:i,elementsSelectable:s,onError:r}=Ut(Kde,Sn),o=Ude(e.onlyRenderVisibleElements),c=$de();return u.jsx("div",{className:"react-flow__nodes",style:_g,children:o.map(d=>u.jsx(Vde,{id:d,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:c,nodesDraggable:t,nodesConnectable:n,nodesFocusable:i,elementsSelectable:s,nodeClickDistance:e.nodeClickDistance,onError:r},d))})}t3.displayName="NodeRenderer";const Gde=_.memo(t3);function Wde(e){return Ut(_.useCallback(n=>{if(!e)return n.edges.map(s=>s.id);const i=[];if(n.width&&n.height)for(const s of n.edges){const r=n.nodeLookup.get(s.source),o=n.nodeLookup.get(s.target);r&&o&&qce({sourceNode:r,targetNode:o,width:n.width,height:n.height,transform:n.transform})&&i.push(s.id)}return i},[e]),Sn)}const Yde=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return u.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},Xde=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return u.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},$T={[Lm.Arrow]:Yde,[Lm.ArrowClosed]:Xde};function Qde(e){const t=Nn();return _.useMemo(()=>{var s,r;return Object.prototype.hasOwnProperty.call($T,e)?$T[e]:((r=(s=t.getState()).onError)==null||r.call(s,"009",ls.error009(e)),null)},[e])}const Zde=({id:e,type:t,color:n,width:i=12.5,height:s=12.5,markerUnits:r="strokeWidth",strokeWidth:o,orient:c="auto-start-reverse"})=>{const d=Qde(t);return d?u.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${i}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:r,orient:c,refX:"0",refY:"0",children:u.jsx(d,{color:n,strokeWidth:o})}):null},n3=({defaultColor:e,rfId:t})=>{const n=Ut(r=>r.edges),i=Ut(r=>r.defaultEdgeOptions),s=_.useMemo(()=>Qce(n,{id:t,defaultColor:e,defaultMarkerStart:i==null?void 0:i.markerStart,defaultMarkerEnd:i==null?void 0:i.markerEnd}),[n,i,t,e]);return s.length?u.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:u.jsx("defs",{children:s.map(r=>u.jsx(Zde,{id:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient},r.id))})}):null};n3.displayName="MarkerDefinitions";var Jde=_.memo(n3);function i3({x:e,y:t,label:n,labelStyle:i,labelShowBg:s=!0,labelBgStyle:r,labelBgPadding:o=[2,4],labelBgBorderRadius:c=2,children:d,className:f,...m}){const[p,b]=_.useState({x:1,y:0,width:0,height:0}),y=Wn(["react-flow__edge-textwrapper",f]),x=_.useRef(null);return _.useEffect(()=>{if(x.current){const v=x.current.getBBox();b({x:v.x,y:v.y,width:v.width,height:v.height})}},[n]),n?u.jsxs("g",{transform:`translate(${e-p.width/2} ${t-p.height/2})`,className:y,visibility:p.width?"visible":"hidden",...m,children:[s&&u.jsx("rect",{width:p.width+2*o[0],x:-o[0],y:-o[1],height:p.height+2*o[1],className:"react-flow__edge-textbg",style:r,rx:c,ry:c}),u.jsx("text",{className:"react-flow__edge-text",y:p.height/2,dy:"0.3em",ref:x,style:i,children:n}),d]}):null}i3.displayName="EdgeText";const efe=_.memo(i3);function Cg({path:e,labelX:t,labelY:n,label:i,labelStyle:s,labelShowBg:r,labelBgStyle:o,labelBgPadding:c,labelBgBorderRadius:d,interactionWidth:f=20,...m}){return u.jsxs(u.Fragment,{children:[u.jsx("path",{...m,d:e,fill:"none",className:Wn(["react-flow__edge-path",m.className])}),f?u.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}):null,i&&Xs(t)&&Xs(n)?u.jsx(efe,{x:t,y:n,label:i,labelStyle:s,labelShowBg:r,labelBgStyle:o,labelBgPadding:c,labelBgBorderRadius:d}):null]})}function qT({pos:e,x1:t,y1:n,x2:i,y2:s}){return e===tt.Left||e===tt.Right?[.5*(t+i),n]:[t,.5*(n+s)]}function s3({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:s,targetPosition:r=tt.Top}){const[o,c]=qT({pos:n,x1:e,y1:t,x2:i,y2:s}),[d,f]=qT({pos:r,x1:i,y1:s,x2:e,y2:t}),[m,p,b,y]=EP({sourceX:e,sourceY:t,targetX:i,targetY:s,sourceControlX:o,sourceControlY:c,targetControlX:d,targetControlY:f});return[`M${e},${t} C${o},${c} ${d},${f} ${i},${s}`,m,p,b,y]}function r3(e){return _.memo(({id:t,sourceX:n,sourceY:i,targetX:s,targetY:r,sourcePosition:o,targetPosition:c,label:d,labelStyle:f,labelShowBg:m,labelBgStyle:p,labelBgPadding:b,labelBgBorderRadius:y,style:x,markerEnd:v,markerStart:w,interactionWidth:k})=>{const[C,S,j]=s3({sourceX:n,sourceY:i,sourcePosition:o,targetX:s,targetY:r,targetPosition:c}),T=e.isInternal?void 0:t;return u.jsx(Cg,{id:T,path:C,labelX:S,labelY:j,label:d,labelStyle:f,labelShowBg:m,labelBgStyle:p,labelBgPadding:b,labelBgBorderRadius:y,style:x,markerEnd:v,markerStart:w,interactionWidth:k})})}const tfe=r3({isInternal:!1}),a3=r3({isInternal:!0});tfe.displayName="SimpleBezierEdge";a3.displayName="SimpleBezierEdgeInternal";function o3(e){return _.memo(({id:t,sourceX:n,sourceY:i,targetX:s,targetY:r,label:o,labelStyle:c,labelShowBg:d,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:p,style:b,sourcePosition:y=tt.Bottom,targetPosition:x=tt.Top,markerEnd:v,markerStart:w,pathOptions:k,interactionWidth:C})=>{const[S,j,T]=$0({sourceX:n,sourceY:i,sourcePosition:y,targetX:s,targetY:r,targetPosition:x,borderRadius:k==null?void 0:k.borderRadius,offset:k==null?void 0:k.offset,stepPosition:k==null?void 0:k.stepPosition}),A=e.isInternal?void 0:t;return u.jsx(Cg,{id:A,path:S,labelX:j,labelY:T,label:o,labelStyle:c,labelShowBg:d,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:p,style:b,markerEnd:v,markerStart:w,interactionWidth:C})})}const l3=o3({isInternal:!1}),c3=o3({isInternal:!0});l3.displayName="SmoothStepEdge";c3.displayName="SmoothStepEdgeInternal";function u3(e){return _.memo(({id:t,...n})=>{var s;const i=e.isInternal?void 0:t;return u.jsx(l3,{...n,id:i,pathOptions:_.useMemo(()=>{var r;return{borderRadius:0,offset:(r=n.pathOptions)==null?void 0:r.offset}},[(s=n.pathOptions)==null?void 0:s.offset])})})}const nfe=u3({isInternal:!1}),d3=u3({isInternal:!0});nfe.displayName="StepEdge";d3.displayName="StepEdgeInternal";function f3(e){return _.memo(({id:t,sourceX:n,sourceY:i,targetX:s,targetY:r,label:o,labelStyle:c,labelShowBg:d,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:p,style:b,markerEnd:y,markerStart:x,interactionWidth:v})=>{const[w,k,C]=_P({sourceX:n,sourceY:i,targetX:s,targetY:r}),S=e.isInternal?void 0:t;return u.jsx(Cg,{id:S,path:w,labelX:k,labelY:C,label:o,labelStyle:c,labelShowBg:d,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:p,style:b,markerEnd:y,markerStart:x,interactionWidth:v})})}const ife=f3({isInternal:!1}),h3=f3({isInternal:!0});ife.displayName="StraightEdge";h3.displayName="StraightEdgeInternal";function p3(e){return _.memo(({id:t,sourceX:n,sourceY:i,targetX:s,targetY:r,sourcePosition:o=tt.Bottom,targetPosition:c=tt.Top,label:d,labelStyle:f,labelShowBg:m,labelBgStyle:p,labelBgPadding:b,labelBgBorderRadius:y,style:x,markerEnd:v,markerStart:w,pathOptions:k,interactionWidth:C})=>{const[S,j,T]=kP({sourceX:n,sourceY:i,sourcePosition:o,targetX:s,targetY:r,targetPosition:c,curvature:k==null?void 0:k.curvature}),A=e.isInternal?void 0:t;return u.jsx(Cg,{id:A,path:S,labelX:j,labelY:T,label:d,labelStyle:f,labelShowBg:m,labelBgStyle:p,labelBgPadding:b,labelBgBorderRadius:y,style:x,markerEnd:v,markerStart:w,interactionWidth:C})})}const sfe=p3({isInternal:!1}),m3=p3({isInternal:!0});sfe.displayName="BezierEdge";m3.displayName="BezierEdgeInternal";const HT={default:m3,straight:h3,step:d3,smoothstep:c3,simplebezier:a3},VT={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null,zIndex:void 0},rfe=(e,t,n)=>n===tt.Left?e-t:n===tt.Right?e+t:e,afe=(e,t,n)=>n===tt.Top?e-t:n===tt.Bottom?e+t:e,KT="react-flow__edgeupdater";function GT({position:e,centerX:t,centerY:n,radius:i=10,onMouseDown:s,onMouseEnter:r,onMouseOut:o,type:c}){return u.jsx("circle",{onMouseDown:s,onMouseEnter:r,onMouseOut:o,className:Wn([KT,`${KT}-${c}`]),cx:rfe(t,i,e),cy:afe(n,i,e),r:i,stroke:"transparent",fill:"transparent"})}function ofe({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:i,sourceY:s,targetX:r,targetY:o,sourcePosition:c,targetPosition:d,onReconnect:f,onReconnectStart:m,onReconnectEnd:p,setReconnecting:b,setUpdateHover:y}){const x=Nn(),v=(j,T)=>{if(j.button!==0)return;const{autoPanOnConnect:A,domNode:M,connectionMode:R,connectionRadius:P,lib:O,onConnectStart:B,cancelConnection:F,nodeLookup:V,rfId:D,panBy:I,updateConnection:z}=x.getState(),W=T.type==="target",X=(q,Y)=>{b(!1),p==null||p(q,n,T.type,Y)},G=q=>f==null?void 0:f(n,q),U=(q,Y)=>{b(!0),m==null||m(j,n,T.type),B==null||B(q,Y)};V0.onPointerDown(j.nativeEvent,{autoPanOnConnect:A,connectionMode:R,connectionRadius:P,domNode:M,handleId:T.id,nodeId:T.nodeId,nodeLookup:V,isTarget:W,edgeUpdaterType:T.type,lib:O,flowId:D,cancelConnection:F,panBy:I,isValidConnection:(...q)=>{var Y,$;return(($=(Y=x.getState()).isValidConnection)==null?void 0:$.call(Y,...q))??!0},onConnect:G,onConnectStart:U,onConnectEnd:(...q)=>{var Y,$;return($=(Y=x.getState()).onConnectEnd)==null?void 0:$.call(Y,...q)},onReconnectEnd:X,updateConnection:z,getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,dragThreshold:x.getState().connectionDragThreshold,handleDomNode:j.currentTarget})},w=j=>v(j,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),k=j=>v(j,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),C=()=>y(!0),S=()=>y(!1);return u.jsxs(u.Fragment,{children:[(e===!0||e==="source")&&u.jsx(GT,{position:c,centerX:i,centerY:s,radius:t,onMouseDown:w,onMouseEnter:C,onMouseOut:S,type:"source"}),(e===!0||e==="target")&&u.jsx(GT,{position:d,centerX:r,centerY:o,radius:t,onMouseDown:k,onMouseEnter:C,onMouseOut:S,type:"target"})]})}function lfe({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:i,onClick:s,onDoubleClick:r,onContextMenu:o,onMouseEnter:c,onMouseMove:d,onMouseLeave:f,reconnectRadius:m,onReconnect:p,onReconnectStart:b,onReconnectEnd:y,rfId:x,edgeTypes:v,noPanClassName:w,onError:k,disableKeyboardA11y:C}){let S=Ut(oe=>oe.edgeLookup.get(e));const j=Ut(oe=>oe.defaultEdgeOptions);S=j?{...j,...S}:S;let T=S.type||"default",A=(v==null?void 0:v[T])||HT[T];A===void 0&&(k==null||k("011",ls.error011(T)),T="default",A=(v==null?void 0:v.default)||HT.default);const M=!!(S.focusable||t&&typeof S.focusable>"u"),R=typeof p<"u"&&(S.reconnectable||n&&typeof S.reconnectable>"u"),P=!!(S.selectable||i&&typeof S.selectable>"u"),O=_.useRef(null),[B,F]=_.useState(!1),[V,D]=_.useState(!1),I=Nn(),{zIndex:z=S.zIndex,sourceX:W,sourceY:X,targetX:G,targetY:U,sourcePosition:q,targetPosition:Y}=Ut(_.useCallback(oe=>{const xe=oe.nodeLookup.get(S.source),fe=oe.nodeLookup.get(S.target);if(!xe||!fe)return VT;const te=Xce({id:e,sourceNode:xe,targetNode:fe,sourceHandle:S.sourceHandle||null,targetHandle:S.targetHandle||null,connectionMode:oe.connectionMode,onError:k}),we=$ce({selected:S.selected,zIndex:S.zIndex,sourceNode:xe,targetNode:fe,elevateOnSelect:oe.elevateEdgesOnSelect,zIndexMode:oe.zIndexMode});return{...te||VT,zIndex:we}},[S.source,S.target,S.sourceHandle,S.targetHandle,S.selected,S.zIndex]),Sn),$=_.useMemo(()=>S.markerStart?`url('#${q0(S.markerStart,x)}')`:void 0,[S.markerStart,x]),ie=_.useMemo(()=>S.markerEnd?`url('#${q0(S.markerEnd,x)}')`:void 0,[S.markerEnd,x]);if(S.hidden||W===null||X===null||G===null||U===null)return null;const be=oe=>{var we;const{addSelectedEdges:xe,unselectNodesAndEdges:fe,multiSelectionActive:te}=I.getState();P&&(I.setState({nodesSelectionActive:!1}),S.selected&&te?(fe({nodes:[],edges:[S]}),(we=O.current)==null||we.blur()):xe([e])),s&&s(oe,S)},ce=r?oe=>{r(oe,{...S})}:void 0,_e=o?oe=>{o(oe,{...S})}:void 0,le=c?oe=>{c(oe,{...S})}:void 0,pe=d?oe=>{d(oe,{...S})}:void 0,Te=f?oe=>{f(oe,{...S})}:void 0,ne=oe=>{var xe;if(!C&&oP.includes(oe.key)&&P){const{unselectNodesAndEdges:fe,addSelectedEdges:te}=I.getState();oe.key==="Escape"?((xe=O.current)==null||xe.blur(),fe({edges:[S]})):te([e])}};return u.jsx("svg",{style:{zIndex:z},children:u.jsxs("g",{className:Wn(["react-flow__edge",`react-flow__edge-${T}`,S.className,w,{selected:S.selected,animated:S.animated,inactive:!P&&!s,updating:B,selectable:P}]),onClick:be,onDoubleClick:ce,onContextMenu:_e,onMouseEnter:le,onMouseMove:pe,onMouseLeave:Te,onKeyDown:M?ne:void 0,tabIndex:M?0:void 0,role:S.ariaRole??(M?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":S.ariaLabel===null?void 0:S.ariaLabel||`Edge from ${S.source} to ${S.target}`,"aria-describedby":M?`${FP}-${x}`:void 0,ref:O,...S.domAttributes,children:[!V&&u.jsx(A,{id:e,source:S.source,target:S.target,type:S.type,selected:S.selected,animated:S.animated,selectable:P,deletable:S.deletable??!0,label:S.label,labelStyle:S.labelStyle,labelShowBg:S.labelShowBg,labelBgStyle:S.labelBgStyle,labelBgPadding:S.labelBgPadding,labelBgBorderRadius:S.labelBgBorderRadius,sourceX:W,sourceY:X,targetX:G,targetY:U,sourcePosition:q,targetPosition:Y,data:S.data,style:S.style,sourceHandleId:S.sourceHandle,targetHandleId:S.targetHandle,markerStart:$,markerEnd:ie,pathOptions:"pathOptions"in S?S.pathOptions:void 0,interactionWidth:S.interactionWidth}),R&&u.jsx(ofe,{edge:S,isReconnectable:R,reconnectRadius:m,onReconnect:p,onReconnectStart:b,onReconnectEnd:y,sourceX:W,sourceY:X,targetX:G,targetY:U,sourcePosition:q,targetPosition:Y,setUpdateHover:F,setReconnecting:D})]})})}var cfe=_.memo(lfe);const ufe=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function g3({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:i,noPanClassName:s,onReconnect:r,onEdgeContextMenu:o,onEdgeMouseEnter:c,onEdgeMouseMove:d,onEdgeMouseLeave:f,onEdgeClick:m,reconnectRadius:p,onEdgeDoubleClick:b,onReconnectStart:y,onReconnectEnd:x,disableKeyboardA11y:v}){const{edgesFocusable:w,edgesReconnectable:k,elementsSelectable:C,onError:S}=Ut(ufe,Sn),j=Wde(t);return u.jsxs("div",{className:"react-flow__edges",children:[u.jsx(Jde,{defaultColor:e,rfId:n}),j.map(T=>u.jsx(cfe,{id:T,edgesFocusable:w,edgesReconnectable:k,elementsSelectable:C,noPanClassName:s,onReconnect:r,onContextMenu:o,onMouseEnter:c,onMouseMove:d,onMouseLeave:f,onClick:m,reconnectRadius:p,onDoubleClick:b,onReconnectStart:y,onReconnectEnd:x,rfId:n,onError:S,edgeTypes:i,disableKeyboardA11y:v},T))]})}g3.displayName="EdgeRenderer";const dfe=_.memo(g3),ffe=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function hfe({children:e}){const t=Ut(ffe);return u.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function pfe(e){const t=Ng(),n=_.useRef(!1);_.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const mfe=e=>{var t;return(t=e.panZoom)==null?void 0:t.syncViewport};function gfe(e){const t=Ut(mfe),n=Nn();return _.useEffect(()=>{e&&(t==null||t(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function yfe(e){return e.connection.inProgress?{...e.connection,to:Lf(e.connection.to,e.transform)}:{...e.connection}}function bfe(e){return yfe}function xfe(e){const t=bfe();return Ut(t,Sn)}const vfe=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function wfe({containerStyle:e,style:t,type:n,component:i}){const{nodesConnectable:s,width:r,height:o,isValid:c,inProgress:d}=Ut(vfe,Sn);return!(r&&s&&d)?null:u.jsx("svg",{style:e,width:r,height:o,className:"react-flow__connectionline react-flow__container",children:u.jsx("g",{className:Wn(["react-flow__connection",uP(c)]),children:u.jsx(y3,{style:t,type:n,CustomComponent:i,isValid:c})})})}const y3=({style:e,type:t=Va.Bezier,CustomComponent:n,isValid:i})=>{const{inProgress:s,from:r,fromNode:o,fromHandle:c,fromPosition:d,to:f,toNode:m,toHandle:p,toPosition:b,pointer:y}=xfe();if(!s)return;if(n)return u.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:o,fromHandle:c,fromX:r.x,fromY:r.y,toX:f.x,toY:f.y,fromPosition:d,toPosition:b,connectionStatus:uP(i),toNode:m,toHandle:p,pointer:y});let x="";const v={sourceX:r.x,sourceY:r.y,sourcePosition:d,targetX:f.x,targetY:f.y,targetPosition:b};switch(t){case Va.Bezier:[x]=kP(v);break;case Va.SimpleBezier:[x]=s3(v);break;case Va.Step:[x]=$0({...v,borderRadius:0});break;case Va.SmoothStep:[x]=$0(v);break;default:[x]=_P(v)}return u.jsx("path",{d:x,fill:"none",className:"react-flow__connection-path",style:e})};y3.displayName="ConnectionLine";const Efe={};function WT(e=Efe){_.useRef(e),Nn(),_.useEffect(()=>{},[e])}function kfe(){Nn(),_.useRef(!1),_.useEffect(()=>{},[])}function b3({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:i,onEdgeClick:s,onNodeDoubleClick:r,onEdgeDoubleClick:o,onNodeMouseEnter:c,onNodeMouseMove:d,onNodeMouseLeave:f,onNodeContextMenu:m,onSelectionContextMenu:p,onSelectionStart:b,onSelectionEnd:y,connectionLineType:x,connectionLineStyle:v,connectionLineComponent:w,connectionLineContainerStyle:k,selectionKeyCode:C,selectionOnDrag:S,selectionMode:j,multiSelectionKeyCode:T,panActivationKeyCode:A,zoomActivationKeyCode:M,deleteKeyCode:R,onlyRenderVisibleElements:P,elementsSelectable:O,defaultViewport:B,translateExtent:F,minZoom:V,maxZoom:D,preventScrolling:I,defaultMarkerColor:z,zoomOnScroll:W,zoomOnPinch:X,panOnScroll:G,panOnScrollSpeed:U,panOnScrollMode:q,zoomOnDoubleClick:Y,panOnDrag:$,autoPanOnSelection:ie,onPaneClick:be,onPaneMouseEnter:ce,onPaneMouseMove:_e,onPaneMouseLeave:le,onPaneScroll:pe,onPaneContextMenu:Te,paneClickDistance:ne,nodeClickDistance:oe,onEdgeContextMenu:xe,onEdgeMouseEnter:fe,onEdgeMouseMove:te,onEdgeMouseLeave:we,reconnectRadius:Fe,onReconnect:Le,onReconnectStart:pt,onReconnectEnd:nt,noDragClassName:Mt,noWheelClassName:Nt,noPanClassName:mt,disableKeyboardA11y:Re,nodeExtent:We,rfId:se,viewport:Ee,onViewportChange:De}){return WT(e),WT(t),kfe(),pfe(n),gfe(Ee),u.jsx(zde,{onPaneClick:be,onPaneMouseEnter:ce,onPaneMouseMove:_e,onPaneMouseLeave:le,onPaneContextMenu:Te,onPaneScroll:pe,paneClickDistance:ne,deleteKeyCode:R,selectionKeyCode:C,selectionOnDrag:S,selectionMode:j,onSelectionStart:b,onSelectionEnd:y,multiSelectionKeyCode:T,panActivationKeyCode:A,zoomActivationKeyCode:M,elementsSelectable:O,zoomOnScroll:W,zoomOnPinch:X,zoomOnDoubleClick:Y,panOnScroll:G,panOnScrollSpeed:U,panOnScrollMode:q,panOnDrag:$,autoPanOnSelection:ie,defaultViewport:B,translateExtent:F,minZoom:V,maxZoom:D,onSelectionContextMenu:p,preventScrolling:I,noDragClassName:Mt,noWheelClassName:Nt,noPanClassName:mt,disableKeyboardA11y:Re,onViewportChange:De,isControlledViewport:!!Ee,children:u.jsxs(hfe,{children:[u.jsx(dfe,{edgeTypes:t,onEdgeClick:s,onEdgeDoubleClick:o,onReconnect:Le,onReconnectStart:pt,onReconnectEnd:nt,onlyRenderVisibleElements:P,onEdgeContextMenu:xe,onEdgeMouseEnter:fe,onEdgeMouseMove:te,onEdgeMouseLeave:we,reconnectRadius:Fe,defaultMarkerColor:z,noPanClassName:mt,disableKeyboardA11y:Re,rfId:se}),u.jsx(wfe,{style:v,type:x,component:w,containerStyle:k}),u.jsx("div",{className:"react-flow__edgelabel-renderer"}),u.jsx(Gde,{nodeTypes:e,onNodeClick:i,onNodeDoubleClick:r,onNodeMouseEnter:c,onNodeMouseMove:d,onNodeMouseLeave:f,onNodeContextMenu:m,nodeClickDistance:oe,onlyRenderVisibleElements:P,noPanClassName:mt,noDragClassName:Mt,disableKeyboardA11y:Re,nodeExtent:We,rfId:se}),u.jsx("div",{className:"react-flow__viewport-portal"})]})})}b3.displayName="GraphView";const Sfe=_.memo(b3),Nfe=gP(),YT=({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:s,height:r,fitView:o,fitViewOptions:c,minZoom:d=.5,maxZoom:f=2,nodeOrigin:m,nodeExtent:p,zIndexMode:b="basic"}={})=>{const y=new Map,x=new Map,v=new Map,w=new Map,k=i??t??[],C=n??e??[],S=m??[0,0],j=p??ef;TP(v,w,k);const{nodesInitialized:T}=H0(C,y,x,{nodeOrigin:S,nodeExtent:j,zIndexMode:b});let A=[0,0,1];if(o&&s&&r){const M=Df(y,{filter:B=>!!((B.width||B.initialWidth)&&(B.height||B.initialHeight))}),{x:R,y:P,zoom:O}=Vw(M,s,r,d,f,(c==null?void 0:c.padding)??.1);A=[R,P,O]}return{rfId:"1",width:s??0,height:r??0,transform:A,nodes:C,nodesInitialized:T,nodeLookup:y,parentLookup:x,edges:k,edgeLookup:w,connectionLookup:v,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:i!==void 0,panZoom:null,minZoom:d,maxZoom:f,translateExtent:ef,nodeExtent:j,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Xc.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:S,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:o??!1,fitViewOptions:c,fitViewResolver:null,connection:{...cP},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Nfe,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:lP,zIndexMode:b,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},_fe=({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:s,height:r,fitView:o,fitViewOptions:c,minZoom:d,maxZoom:f,nodeOrigin:m,nodeExtent:p,zIndexMode:b})=>Bue((y,x)=>{async function v(){const{nodeLookup:w,panZoom:k,fitViewOptions:C,fitViewResolver:S,width:j,height:T,minZoom:A,maxZoom:M}=x();k&&(await Lce({nodes:w,width:j,height:T,panZoom:k,minZoom:A,maxZoom:M},C),S==null||S.resolve(!0),y({fitViewResolver:null}))}return{...YT({nodes:e,edges:t,width:s,height:r,fitView:o,fitViewOptions:c,minZoom:d,maxZoom:f,nodeOrigin:m,nodeExtent:p,defaultNodes:n,defaultEdges:i,zIndexMode:b}),setNodes:w=>{const{nodeLookup:k,parentLookup:C,nodeOrigin:S,elevateNodesOnSelect:j,fitViewQueued:T,zIndexMode:A,nodesSelectionActive:M}=x(),{nodesInitialized:R,hasSelectedNodes:P}=H0(w,k,C,{nodeOrigin:S,nodeExtent:p,elevateNodesOnSelect:j,checkEquality:!0,zIndexMode:A}),O=M&&P;T&&R?(v(),y({nodes:w,nodesInitialized:R,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:O})):y({nodes:w,nodesInitialized:R,nodesSelectionActive:O})},setEdges:w=>{const{connectionLookup:k,edgeLookup:C}=x();TP(k,C,w),y({edges:w})},setDefaultNodesAndEdges:(w,k)=>{if(w){const{setNodes:C}=x();C(w),y({hasDefaultNodes:!0})}if(k){const{setEdges:C}=x();C(k),y({hasDefaultEdges:!0})}},updateNodeInternals:w=>{const{triggerNodeChanges:k,nodeLookup:C,parentLookup:S,domNode:j,nodeOrigin:T,nodeExtent:A,debug:M,fitViewQueued:R,zIndexMode:P}=x(),{changes:O,updatedInternals:B}=sue(w,C,S,j,T,A,P);B&&(eue(C,S,{nodeOrigin:T,nodeExtent:A,zIndexMode:P}),R?(v(),y({fitViewQueued:!1,fitViewOptions:void 0})):y({}),(O==null?void 0:O.length)>0&&(M&&console.log("React Flow: trigger node changes",O),k==null||k(O)))},updateNodePositions:(w,k=!1)=>{const C=[];let S=[];const{nodeLookup:j,triggerNodeChanges:T,connection:A,updateConnection:M,onNodesChangeMiddlewareMap:R}=x();for(const[P,O]of w){const B=j.get(P),F=!!(B!=null&&B.expandParent&&(B!=null&&B.parentId)&&(O!=null&&O.position)),V={id:P,type:"position",position:F?{x:Math.max(0,O.position.x),y:Math.max(0,O.position.y)}:O.position,dragging:k};if(B&&A.inProgress&&A.fromNode.id===B.id){const D=vl(B,A.fromHandle,tt.Left,!0);M({...A,from:D})}F&&B.parentId&&C.push({id:P,parentId:B.parentId,rect:{...O.internals.positionAbsolute,width:O.measured.width??0,height:O.measured.height??0}}),S.push(V)}if(C.length>0){const{parentLookup:P,nodeOrigin:O}=x(),B=Qw(C,j,P,O);S.push(...B)}for(const P of R.values())S=P(S);T(S)},triggerNodeChanges:w=>{const{onNodesChange:k,setNodes:C,nodes:S,hasDefaultNodes:j,debug:T}=x();if(w!=null&&w.length){if(j){const A=HP(w,S);C(A)}T&&console.log("React Flow: trigger node changes",w),k==null||k(w)}},triggerEdgeChanges:w=>{const{onEdgesChange:k,setEdges:C,edges:S,hasDefaultEdges:j,debug:T}=x();if(w!=null&&w.length){if(j){const A=VP(w,S);C(A)}T&&console.log("React Flow: trigger edge changes",w),k==null||k(w)}},addSelectedNodes:w=>{const{multiSelectionActive:k,edgeLookup:C,nodeLookup:S,triggerNodeChanges:j,triggerEdgeChanges:T}=x();if(k){const A=w.map(M=>Uo(M,!0));j(A);return}j(wc(S,new Set([...w]),!0)),T(wc(C))},addSelectedEdges:w=>{const{multiSelectionActive:k,edgeLookup:C,nodeLookup:S,triggerNodeChanges:j,triggerEdgeChanges:T}=x();if(k){const A=w.map(M=>Uo(M,!0));T(A);return}T(wc(C,new Set([...w]))),j(wc(S,new Set,!0))},unselectNodesAndEdges:({nodes:w,edges:k}={})=>{const{edges:C,nodes:S,nodeLookup:j,triggerNodeChanges:T,triggerEdgeChanges:A}=x(),M=w||S,R=k||C,P=[];for(const B of M){if(!B.selected)continue;const F=j.get(B.id);F&&(F.selected=!1),P.push(Uo(B.id,!1))}const O=[];for(const B of R)B.selected&&O.push(Uo(B.id,!1));T(P),A(O)},setMinZoom:w=>{const{panZoom:k,maxZoom:C}=x();k==null||k.setScaleExtent([w,C]),y({minZoom:w})},setMaxZoom:w=>{const{panZoom:k,minZoom:C}=x();k==null||k.setScaleExtent([C,w]),y({maxZoom:w})},setTranslateExtent:w=>{var k;(k=x().panZoom)==null||k.setTranslateExtent(w),y({translateExtent:w})},resetSelectedElements:()=>{const{edges:w,nodes:k,triggerNodeChanges:C,triggerEdgeChanges:S,elementsSelectable:j}=x();if(!j)return;const T=k.reduce((M,R)=>R.selected?[...M,Uo(R.id,!1)]:M,[]),A=w.reduce((M,R)=>R.selected?[...M,Uo(R.id,!1)]:M,[]);C(T),S(A)},setNodeExtent:w=>{const{nodes:k,nodeLookup:C,parentLookup:S,nodeOrigin:j,elevateNodesOnSelect:T,nodeExtent:A,zIndexMode:M}=x();w[0][0]===A[0][0]&&w[0][1]===A[0][1]&&w[1][0]===A[1][0]&&w[1][1]===A[1][1]||(H0(k,C,S,{nodeOrigin:j,nodeExtent:w,elevateNodesOnSelect:T,checkEquality:!1,zIndexMode:M}),y({nodeExtent:w}))},panBy:w=>{const{transform:k,width:C,height:S,panZoom:j,translateExtent:T}=x();return rue({delta:w,panZoom:j,transform:k,translateExtent:T,width:C,height:S})},setCenter:async(w,k,C)=>{const{width:S,height:j,maxZoom:T,panZoom:A}=x();if(!A)return!1;const M=typeof(C==null?void 0:C.zoom)<"u"?C.zoom:T;return await A.setViewport({x:S/2-w*M,y:j/2-k*M,zoom:M},{duration:C==null?void 0:C.duration,ease:C==null?void 0:C.ease,interpolate:C==null?void 0:C.interpolate}),!0},cancelConnection:()=>{y({connection:{...cP}})},updateConnection:w=>{y({connection:w})},reset:()=>y({...YT()})}},Object.is);function x3({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:i,initialWidth:s,initialHeight:r,initialMinZoom:o,initialMaxZoom:c,initialFitViewOptions:d,fitView:f,nodeOrigin:m,nodeExtent:p,zIndexMode:b,children:y}){const[x]=_.useState(()=>_fe({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:s,height:r,fitView:f,minZoom:o,maxZoom:c,fitViewOptions:d,nodeOrigin:m,nodeExtent:p,zIndexMode:b}));return u.jsx(Uue,{value:x,children:u.jsx(ude,{children:u.jsx(Nde,{children:y})})})}function Cfe({children:e,nodes:t,edges:n,defaultNodes:i,defaultEdges:s,width:r,height:o,fitView:c,fitViewOptions:d,minZoom:f,maxZoom:m,nodeOrigin:p,nodeExtent:b,zIndexMode:y}){return _.useContext(kg)?u.jsx(u.Fragment,{children:e}):u.jsx(x3,{initialNodes:t,initialEdges:n,defaultNodes:i,defaultEdges:s,initialWidth:r,initialHeight:o,fitView:c,initialFitViewOptions:d,initialMinZoom:f,initialMaxZoom:m,nodeOrigin:p,nodeExtent:b,zIndexMode:y,children:e})}const jfe={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function Tfe({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,className:s,nodeTypes:r,edgeTypes:o,onNodeClick:c,onEdgeClick:d,onInit:f,onMove:m,onMoveStart:p,onMoveEnd:b,onConnect:y,onConnectStart:x,onConnectEnd:v,onClickConnectStart:w,onClickConnectEnd:k,onNodeMouseEnter:C,onNodeMouseMove:S,onNodeMouseLeave:j,onNodeContextMenu:T,onNodeDoubleClick:A,onNodeDragStart:M,onNodeDrag:R,onNodeDragStop:P,onNodesDelete:O,onEdgesDelete:B,onDelete:F,onSelectionChange:V,onSelectionDragStart:D,onSelectionDrag:I,onSelectionDragStop:z,onSelectionContextMenu:W,onSelectionStart:X,onSelectionEnd:G,onBeforeDelete:U,connectionMode:q,connectionLineType:Y=Va.Bezier,connectionLineStyle:$,connectionLineComponent:ie,connectionLineContainerStyle:be,deleteKeyCode:ce="Backspace",selectionKeyCode:_e="Shift",selectionOnDrag:le=!1,selectionMode:pe=tf.Full,panActivationKeyCode:Te="Space",multiSelectionKeyCode:ne=sf()?"Meta":"Control",zoomActivationKeyCode:oe=sf()?"Meta":"Control",snapToGrid:xe,snapGrid:fe,onlyRenderVisibleElements:te=!1,selectNodesOnDrag:we,nodesDraggable:Fe,autoPanOnNodeFocus:Le,nodesConnectable:pt,nodesFocusable:nt,nodeOrigin:Mt=$P,edgesFocusable:Nt,edgesReconnectable:mt,elementsSelectable:Re=!0,defaultViewport:We=Jue,minZoom:se=.5,maxZoom:Ee=2,translateExtent:De=ef,preventScrolling:ye=!0,nodeExtent:et,defaultMarkerColor:Pt="#b1b1b7",zoomOnScroll:Wt=!0,zoomOnPinch:me=!0,panOnScroll:ae=!1,panOnScrollSpeed:je=.5,panOnScrollMode:Ae=ul.Free,zoomOnDoubleClick:Qe=!0,panOnDrag:rt=!0,onPaneClick:Ue,onPaneMouseEnter:it,onPaneMouseMove:qt,onPaneMouseLeave:Qt,onPaneScroll:Ot,onPaneContextMenu:Q,paneClickDistance:ke=1,nodeClickDistance:Pe=0,children:ct,onReconnect:Zt,onReconnectStart:Ht,onReconnectEnd:He,onEdgeContextMenu:$e,onEdgeDoubleClick:at,onEdgeMouseEnter:hn,onEdgeMouseMove:on,onEdgeMouseLeave:ki,reconnectRadius:ds=10,onNodesChange:fs,onEdgesChange:Di,noDragClassName:pn="nodrag",noWheelClassName:In="nowheel",noPanClassName:Yn="nopan",fitView:Ds,fitViewOptions:Mr,connectOnClick:Os,attributionPosition:Rr,proOptions:hs,defaultEdgeOptions:Dr,elevateNodesOnSelect:Xn=!0,elevateEdgesOnSelect:Ki=!1,disableKeyboardA11y:Si=!1,autoPanOnConnect:ps,autoPanOnNodeDrag:wn,autoPanOnSelection:Or=!0,autoPanSpeed:Qn,connectionRadius:An,isValidConnection:Me,onError:Xe,style:xt,id:zt,nodeDragThreshold:gn,connectionDragThreshold:Fn,viewport:ci,onViewportChange:ti,width:Vt,height:ni,colorMode:Lr="light",debug:ii,onScroll:si,ariaLabelConfig:Ls,zIndexMode:ma="basic",...ri},Gi){const yi=zt||"1",Is=ide(Lr),Mn=_.useCallback(rr=>{rr.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),si==null||si(rr)},[si]);return u.jsx("div",{"data-testid":"rf__wrapper",...ri,onScroll:Mn,style:{...xt,...jfe},ref:Gi,className:Wn(["react-flow",s,Is]),id:zt,role:"application",children:u.jsxs(Cfe,{nodes:e,edges:t,width:Vt,height:ni,fitView:Ds,fitViewOptions:Mr,minZoom:se,maxZoom:Ee,nodeOrigin:Mt,nodeExtent:et,zIndexMode:ma,children:[u.jsx(nde,{nodes:e,edges:t,defaultNodes:n,defaultEdges:i,onConnect:y,onConnectStart:x,onConnectEnd:v,onClickConnectStart:w,onClickConnectEnd:k,nodesDraggable:Fe,autoPanOnNodeFocus:Le,nodesConnectable:pt,nodesFocusable:nt,edgesFocusable:Nt,edgesReconnectable:mt,elementsSelectable:Re,elevateNodesOnSelect:Xn,elevateEdgesOnSelect:Ki,minZoom:se,maxZoom:Ee,nodeExtent:et,onNodesChange:fs,onEdgesChange:Di,snapToGrid:xe,snapGrid:fe,connectionMode:q,translateExtent:De,connectOnClick:Os,defaultEdgeOptions:Dr,fitView:Ds,fitViewOptions:Mr,onNodesDelete:O,onEdgesDelete:B,onDelete:F,onNodeDragStart:M,onNodeDrag:R,onNodeDragStop:P,onSelectionDrag:I,onSelectionDragStart:D,onSelectionDragStop:z,onMove:m,onMoveStart:p,onMoveEnd:b,noPanClassName:Yn,nodeOrigin:Mt,rfId:yi,autoPanOnConnect:ps,autoPanOnNodeDrag:wn,autoPanSpeed:Qn,onError:Xe,connectionRadius:An,isValidConnection:Me,selectNodesOnDrag:we,nodeDragThreshold:gn,connectionDragThreshold:Fn,onBeforeDelete:U,debug:ii,ariaLabelConfig:Ls,zIndexMode:ma}),u.jsx(Sfe,{onInit:f,onNodeClick:c,onEdgeClick:d,onNodeMouseEnter:C,onNodeMouseMove:S,onNodeMouseLeave:j,onNodeContextMenu:T,onNodeDoubleClick:A,nodeTypes:r,edgeTypes:o,connectionLineType:Y,connectionLineStyle:$,connectionLineComponent:ie,connectionLineContainerStyle:be,selectionKeyCode:_e,selectionOnDrag:le,selectionMode:pe,deleteKeyCode:ce,multiSelectionKeyCode:ne,panActivationKeyCode:Te,zoomActivationKeyCode:oe,onlyRenderVisibleElements:te,defaultViewport:We,translateExtent:De,minZoom:se,maxZoom:Ee,preventScrolling:ye,zoomOnScroll:Wt,zoomOnPinch:me,zoomOnDoubleClick:Qe,panOnScroll:ae,panOnScrollSpeed:je,panOnScrollMode:Ae,panOnDrag:rt,autoPanOnSelection:Or,onPaneClick:Ue,onPaneMouseEnter:it,onPaneMouseMove:qt,onPaneMouseLeave:Qt,onPaneScroll:Ot,onPaneContextMenu:Q,paneClickDistance:ke,nodeClickDistance:Pe,onSelectionContextMenu:W,onSelectionStart:X,onSelectionEnd:G,onReconnect:Zt,onReconnectStart:Ht,onReconnectEnd:He,onEdgeContextMenu:$e,onEdgeDoubleClick:at,onEdgeMouseEnter:hn,onEdgeMouseMove:on,onEdgeMouseLeave:ki,reconnectRadius:ds,defaultMarkerColor:Pt,noDragClassName:pn,noWheelClassName:In,noPanClassName:Yn,rfId:yi,disableKeyboardA11y:Si,nodeExtent:et,viewport:ci,onViewportChange:ti}),u.jsx(Zue,{onSelectionChange:V}),ct,u.jsx(Gue,{proOptions:hs,position:Rr}),u.jsx(Kue,{rfId:yi,disableKeyboardA11y:Si})]})})}var Afe=WP(Tfe);function Mfe(e){const[t,n]=_.useState(e),i=_.useCallback(s=>n(r=>HP(s,r)),[]);return[t,n,i]}function Rfe(e){const[t,n]=_.useState(e),i=_.useCallback(s=>n(r=>VP(s,r)),[]);return[t,n,i]}function Dfe({dimensions:e,lineWidth:t,variant:n,className:i}){return u.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Wn(["react-flow__background-pattern",n,i])})}function Ofe({radius:e,className:t}){return u.jsx("circle",{cx:e,cy:e,r:e,className:Wn(["react-flow__background-pattern","dots",t])})}var ca;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(ca||(ca={}));const Lfe={[ca.Dots]:1,[ca.Lines]:1,[ca.Cross]:6},Ife=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function v3({id:e,variant:t=ca.Dots,gap:n=20,size:i,lineWidth:s=1,offset:r=0,color:o,bgColor:c,style:d,className:f,patternClassName:m}){const p=_.useRef(null),{transform:b,patternId:y}=Ut(Ife,Sn),x=i||Lfe[t],v=t===ca.Dots,w=t===ca.Cross,k=Array.isArray(n)?n:[n,n],C=[k[0]*b[2]||1,k[1]*b[2]||1],S=x*b[2],j=Array.isArray(r)?r:[r,r],T=w?[S,S]:C,A=[j[0]*b[2]||1+T[0]/2,j[1]*b[2]||1+T[1]/2],M=`${y}${e||""}`;return u.jsxs("svg",{className:Wn(["react-flow__background",f]),style:{...d,..._g,"--xy-background-color-props":c,"--xy-background-pattern-color-props":o},ref:p,"data-testid":"rf__background",children:[u.jsx("pattern",{id:M,x:b[0]%C[0],y:b[1]%C[1],width:C[0],height:C[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${A[0]},-${A[1]})`,children:v?u.jsx(Ofe,{radius:S/2,className:m}):u.jsx(Dfe,{dimensions:T,lineWidth:s,variant:t,className:m})}),u.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${M})`})]})}v3.displayName="Background";const Pfe=_.memo(v3);function zfe(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:u.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function Bfe(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:u.jsx("path",{d:"M0 0h32v4.2H0z"})})}function Ufe(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:u.jsx("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 Ffe(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:u.jsx("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 $fe(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:u.jsx("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"})})}function kd({children:e,className:t,...n}){return u.jsx("button",{type:"button",className:Wn(["react-flow__controls-button",t]),...n,children:e})}const qfe=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function w3({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:i=!0,fitViewOptions:s,onZoomIn:r,onZoomOut:o,onFitView:c,onInteractiveChange:d,className:f,children:m,position:p="bottom-left",orientation:b="vertical","aria-label":y}){const x=Nn(),{isInteractive:v,minZoomReached:w,maxZoomReached:k,ariaLabelConfig:C}=Ut(qfe,Sn),{zoomIn:S,zoomOut:j,fitView:T}=Ng(),A=()=>{S(),r==null||r()},M=()=>{j(),o==null||o()},R=()=>{T(s),c==null||c()},P=()=>{x.setState({nodesDraggable:!v,nodesConnectable:!v,elementsSelectable:!v}),d==null||d(!v)},O=b==="horizontal"?"horizontal":"vertical";return u.jsxs(Sg,{className:Wn(["react-flow__controls",O,f]),position:p,style:e,"data-testid":"rf__controls","aria-label":y??C["controls.ariaLabel"],children:[t&&u.jsxs(u.Fragment,{children:[u.jsx(kd,{onClick:A,className:"react-flow__controls-zoomin",title:C["controls.zoomIn.ariaLabel"],"aria-label":C["controls.zoomIn.ariaLabel"],disabled:k,children:u.jsx(zfe,{})}),u.jsx(kd,{onClick:M,className:"react-flow__controls-zoomout",title:C["controls.zoomOut.ariaLabel"],"aria-label":C["controls.zoomOut.ariaLabel"],disabled:w,children:u.jsx(Bfe,{})})]}),n&&u.jsx(kd,{className:"react-flow__controls-fitview",onClick:R,title:C["controls.fitView.ariaLabel"],"aria-label":C["controls.fitView.ariaLabel"],children:u.jsx(Ufe,{})}),i&&u.jsx(kd,{className:"react-flow__controls-interactive",onClick:P,title:C["controls.interactive.ariaLabel"],"aria-label":C["controls.interactive.ariaLabel"],children:v?u.jsx($fe,{}):u.jsx(Ffe,{})}),m]})}w3.displayName="Controls";const Hfe=_.memo(w3);function Vfe({id:e,x:t,y:n,width:i,height:s,style:r,color:o,strokeColor:c,strokeWidth:d,className:f,borderRadius:m,shapeRendering:p,selected:b,onClick:y}){const{background:x,backgroundColor:v}=r||{},w=o||x||v;return u.jsx("rect",{className:Wn(["react-flow__minimap-node",{selected:b},f]),x:t,y:n,rx:m,ry:m,width:i,height:s,style:{fill:w,stroke:c,strokeWidth:d},shapeRendering:p,onClick:y?k=>y(k,e):void 0})}const Kfe=_.memo(Vfe),Gfe=e=>e.nodes.map(t=>t.id),tv=e=>e instanceof Function?e:()=>e;function Wfe({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:i=5,nodeStrokeWidth:s,nodeComponent:r=Kfe,onClick:o}){const c=Ut(Gfe,Sn),d=tv(t),f=tv(e),m=tv(n),p=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return u.jsx(u.Fragment,{children:c.map(b=>u.jsx(Xfe,{id:b,nodeColorFunc:d,nodeStrokeColorFunc:f,nodeClassNameFunc:m,nodeBorderRadius:i,nodeStrokeWidth:s,NodeComponent:r,onClick:o,shapeRendering:p},b))})}function Yfe({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:i,nodeBorderRadius:s,nodeStrokeWidth:r,shapeRendering:o,NodeComponent:c,onClick:d}){const{node:f,x:m,y:p,width:b,height:y}=Ut(x=>{const v=x.nodeLookup.get(e);if(!v)return{node:void 0,x:0,y:0,width:0,height:0};const w=v.internals.userNode,{x:k,y:C}=v.internals.positionAbsolute,{width:S,height:j}=pa(w);return{node:w,x:k,y:C,width:S,height:j}},Sn);return!f||f.hidden||!yP(f)?null:u.jsx(c,{x:m,y:p,width:b,height:y,style:f.style,selected:!!f.selected,className:i(f),color:t(f),borderRadius:s,strokeColor:n(f),strokeWidth:r,shapeRendering:o,onClick:d,id:f.id})}const Xfe=_.memo(Yfe);var Qfe=_.memo(Wfe);const Zfe=200,Jfe=150,ehe=e=>!e.hidden,the=e=>{const t={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:t,boundingRect:e.nodeLookup.size>0?pP(Df(e.nodeLookup,{filter:ehe}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},nhe="react-flow__minimap-desc";function E3({style:e,className:t,nodeStrokeColor:n,nodeColor:i,nodeClassName:s="",nodeBorderRadius:r=5,nodeStrokeWidth:o,nodeComponent:c,bgColor:d,maskColor:f,maskStrokeColor:m,maskStrokeWidth:p,position:b="bottom-right",onClick:y,onNodeClick:x,pannable:v=!1,zoomable:w=!1,ariaLabel:k,inversePan:C,zoomStep:S=1,offsetScale:j=5}){const T=Nn(),A=_.useRef(null),{boundingRect:M,viewBB:R,rfId:P,panZoom:O,translateExtent:B,flowWidth:F,flowHeight:V,ariaLabelConfig:D}=Ut(the,Sn),I=(e==null?void 0:e.width)??Zfe,z=(e==null?void 0:e.height)??Jfe,W=M.width/I,X=M.height/z,G=Math.max(W,X),U=G*I,q=G*z,Y=j*G,$=M.x-(U-M.width)/2-Y,ie=M.y-(q-M.height)/2-Y,be=U+Y*2,ce=q+Y*2,_e=`${nhe}-${P}`,le=_.useRef(0),pe=_.useRef();le.current=G,_.useEffect(()=>{if(A.current&&O)return pe.current=pue({domNode:A.current,panZoom:O,getTransform:()=>T.getState().transform,getViewScale:()=>le.current}),()=>{var xe;(xe=pe.current)==null||xe.destroy()}},[O]),_.useEffect(()=>{var xe;(xe=pe.current)==null||xe.update({translateExtent:B,width:F,height:V,inversePan:C,pannable:v,zoomStep:S,zoomable:w})},[v,w,C,S,B,F,V]);const Te=y?xe=>{var we;const[fe,te]=((we=pe.current)==null?void 0:we.pointer(xe))||[0,0];y(xe,{x:fe,y:te})}:void 0,ne=x?_.useCallback((xe,fe)=>{const te=T.getState().nodeLookup.get(fe).internals.userNode;x(xe,te)},[]):void 0,oe=k??D["minimap.ariaLabel"];return u.jsx(Sg,{position:b,style:{...e,"--xy-minimap-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-background-color-props":typeof f=="string"?f:void 0,"--xy-minimap-mask-stroke-color-props":typeof m=="string"?m:void 0,"--xy-minimap-mask-stroke-width-props":typeof p=="number"?p*G:void 0,"--xy-minimap-node-background-color-props":typeof i=="string"?i:void 0,"--xy-minimap-node-stroke-color-props":typeof n=="string"?n:void 0,"--xy-minimap-node-stroke-width-props":typeof o=="number"?o:void 0},className:Wn(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:u.jsxs("svg",{width:I,height:z,viewBox:`${$} ${ie} ${be} ${ce}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":_e,ref:A,onClick:Te,children:[oe&&u.jsx("title",{id:_e,children:oe}),u.jsx(Qfe,{onClick:ne,nodeColor:i,nodeStrokeColor:n,nodeBorderRadius:r,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:c}),u.jsx("path",{className:"react-flow__minimap-mask",d:`M${$-Y},${ie-Y}h${be+Y*2}v${ce+Y*2}h${-be-Y*2}z
865
865
  M${R.x},${R.y}h${R.width}v${R.height}h${-R.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}E3.displayName="MiniMap";_.memo(E3);const ihe=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,she={[Jc.Line]:"right",[Jc.Handle]:"bottom-right"};function rhe({nodeId:e,position:t,variant:n=Jc.Handle,className:i,style:s=void 0,children:r,color:o,minWidth:c=10,minHeight:d=10,maxWidth:f=Number.MAX_VALUE,maxHeight:m=Number.MAX_VALUE,keepAspectRatio:p=!1,resizeDirection:b,autoScale:y=!0,shouldResize:x,onResizeStart:v,onResize:w,onResizeEnd:k}){const C=ZP(),S=typeof e=="string"?e:C,j=Nn(),T=_.useRef(null),A=n===Jc.Handle,M=Ut(_.useCallback(ihe(A&&y),[A,y]),Sn),R=_.useRef(null),P=t??she[n];_.useEffect(()=>{if(!(!T.current||!S))return R.current||(R.current=Cue({domNode:T.current,nodeId:S,getStoreItems:()=>{const{nodeLookup:B,transform:F,snapGrid:V,snapToGrid:D,nodeOrigin:I,domNode:z}=j.getState();return{nodeLookup:B,transform:F,snapGrid:V,snapToGrid:D,nodeOrigin:I,paneDomNode:z}},onChange:(B,F)=>{const{triggerNodeChanges:V,nodeLookup:D,parentLookup:I,nodeOrigin:z}=j.getState(),W=[],X={x:B.x,y:B.y},G=D.get(S);if(G&&G.expandParent&&G.parentId){const U=G.origin??z,q=B.width??G.measured.width??0,Y=B.height??G.measured.height??0,$={id:G.id,parentId:G.parentId,rect:{width:q,height:Y,...bP({x:B.x??G.position.x,y:B.y??G.position.y},{width:q,height:Y},G.parentId,D,U)}},ie=Qw([$],D,I,z);W.push(...ie),X.x=B.x?Math.max(U[0]*q,B.x):void 0,X.y=B.y?Math.max(U[1]*Y,B.y):void 0}if(X.x!==void 0&&X.y!==void 0){const U={id:S,type:"position",position:{...X}};W.push(U)}if(B.width!==void 0&&B.height!==void 0){const q={id:S,type:"dimensions",resizing:!0,setAttributes:b?b==="horizontal"?"width":"height":!0,dimensions:{width:B.width,height:B.height}};W.push(q)}for(const U of F){const q={...U,type:"position"};W.push(q)}V(W)},onEnd:({width:B,height:F})=>{const V={id:S,type:"dimensions",resizing:!1,dimensions:{width:B,height:F}};j.getState().triggerNodeChanges([V])}})),R.current.update({controlPosition:P,boundaries:{minWidth:c,minHeight:d,maxWidth:f,maxHeight:m},keepAspectRatio:p,resizeDirection:b,onResizeStart:v,onResize:w,onResizeEnd:k,shouldResize:x}),()=>{var B;(B=R.current)==null||B.destroy()}},[P,c,d,f,m,p,v,w,k,x]);const O=P.split("-");return u.jsx("div",{className:Wn(["react-flow__resize-control","nodrag",...O,n,i]),ref:T,style:{...s,scale:M,...o&&{[A?"backgroundColor":"borderColor"]:o}},children:r})}_.memo(rhe);function ahe(e){return wt(`/api/projects/${encodeURIComponent(e)}/flow`)}function ohe(e,t){return bf(`/api/projects/${encodeURIComponent(e)}/flow`,t)}const lhe=new Set(["NEEDS-FIX","STALE-UPSTREAM","BLOCKED","CONFLICT","ACK-TIMEOUT"]),XT="AI-PIPELINE",G0={done:"var(--color-running)",doing:"var(--color-running)",todo:"var(--color-text-subtle)",stuck:"var(--color-crashed)"},QT=["var(--color-accent-mint)","var(--color-accent-pink)","var(--color-accent-purple)","var(--color-accent-yellow)","var(--color-running-bg)","var(--color-idle-bg)"];function che(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)>>>0;return QT[t%QT.length]}const Np={width:9,height:9,background:"var(--color-bg)",border:"1px solid var(--color-border-light)"},uhe=_.memo(function({id:t,data:n,selected:i}){const s=n,r=s.skills.split(",").map(d=>d.trim()).filter(Boolean),o=(s.labels??"").split(",").map(d=>d.trim()).filter(Boolean),c=o.filter(d=>lhe.has(d));return u.jsxs("div",{className:`flow-node-glow${i?" is-selected":""}${s.status==="doing"?" is-running":""}`,children:[u.jsx(no,{id:"l",type:"target",position:tt.Left,style:Np}),u.jsx(no,{id:"t",type:"target",position:tt.Top,style:Np}),u.jsxs("div",{className:"rounded-2xl border border-[var(--color-border-light)] bg-[var(--color-bg-soft)] overflow-hidden cursor-pointer flex flex-col",style:{width:260,height:158,boxShadow:"var(--surface-card-border) 0 0 0 1px inset"},children:[u.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-[var(--color-border-light)]",style:{background:che(t)},children:[u.jsxs("span",{className:"font-[family-name:var(--font-mono)] text-xs font-bold text-[var(--color-text)]",children:["#",s.seq]}),s.kind&&s.kind!=="worker"&&u.jsx("span",{className:"font-[family-name:var(--font-mono)] text-[10px] px-1 rounded bg-[var(--color-bg)] text-[var(--color-text-subtle)] truncate max-w-[7rem]",title:s.tool??s.kind,children:s.kind==="tool"?`⚙ ${s.tool??"tool"}`:`⇥ ${s.kind}`}),u.jsxs("span",{className:"relative shrink-0 ml-auto flex items-center justify-center w-2.5 h-2.5",title:s.status,children:[s.status==="doing"&&u.jsx("span",{className:"absolute inline-flex w-full h-full rounded-full animate-ping opacity-60",style:{background:G0.doing}}),u.jsx("span",{className:"relative w-2.5 h-2.5 rounded-full",style:{background:G0[s.status]??"var(--color-text-subtle)"}})]})]}),u.jsxs("div",{className:"px-2.5 py-2 flex-1 min-h-0 overflow-hidden",children:[u.jsx("p",{className:"text-[13px] font-semibold text-[var(--color-text)] leading-snug line-clamp-3",children:s.title||"任务"}),!o.includes(XT)&&u.jsxs("div",{className:"mt-1.5 text-[10px] font-[family-name:var(--font-mono)] text-[var(--color-crashed)]",children:["无 ",XT," · 不会被派"]}),c.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mt-1.5",children:c.map(d=>u.jsx("span",{className:"text-[10px] font-[family-name:var(--font-mono)] px-1.5 py-0.5 rounded border border-[var(--color-crashed)] text-[var(--color-crashed)]",children:d},d))}),r.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mt-2 max-h-[46px] overflow-hidden",children:r.slice(0,6).map(d=>u.jsx("span",{className:"text-[10px] font-[family-name:var(--font-mono)] px-1.5 py-0.5 rounded bg-[var(--surface-code)] text-[var(--color-text)]",children:d},d))})]})]}),u.jsx(no,{id:"r",type:"source",position:tt.Right,style:Np}),u.jsx(no,{id:"b",type:"source",position:tt.Bottom,style:Np})]})});function dhe(e){if(!e)return"";const t=e.split(`
866
866
  `),n=t.findIndex(s=>/^##\s+描述\s*$/.test(s));if(n===-1)return"";let i=t.length;for(let s=n+1;s<t.length;s+=1)if(/^##\s+/.test(t[s]??"")){i=s;break}return t.slice(n+1,i).join(`
867
- `).trim()}function fhe(e,t){return t.includes("NEEDS-FIX")?"stuck":e==="Done"?"done":e==="Inprogress"?"doing":"todo"}function hhe({project:e,seq:t,onClose:n,onChanged:i,onDelete:s}){var Te,ne;const r=Ye(),[o,c]=_.useState(!0),[d,f]=_.useState(!1),[m,p]=_.useState(""),[b,y]=_.useState(""),[x,v]=_.useState(new Set),[w,k]=_.useState(""),[C,S]=_.useState("todo"),[j,T]=_.useState(null),[A,M]=_.useState(""),[R,P]=_.useState(void 0),[O,B]=_.useState(void 0),[F,V]=_.useState(void 0),[D,I]=_.useState(void 0),[z,W]=_.useState({value:null,error:"",dirty:!1}),[X,G]=_.useState(null),[U,q]=_.useState(null),Y=U??R,$=Y==="tool"||Y==="join",ie=Je({queryKey:["skills-all",e],queryFn:()=>fg(e),enabled:!$}),be=((Te=ie.data)==null?void 0:Te.data)??[],ce=Je({queryKey:["capabilities",e],queryFn:()=>Rw(e),enabled:$});_.useEffect(()=>{const oe=xe=>{xe.key==="Escape"&&n()};return window.addEventListener("keydown",oe),()=>window.removeEventListener("keydown",oe)},[n]),_.useEffect(()=>{let oe=!1;return c(!0),mI(e,t).then(xe=>{oe||(p(xe.title),v(new Set(xe.skills??[])),y(dhe(xe.body)),k(xe.state),S(fhe(xe.state,xe.labels??[])),T(typeof xe.order=="number"?xe.order:null),P(xe.kind),B(xe.tool),G(null),q(null),V(xe.input),I(xe.toolResult))}).catch(()=>{}).finally(()=>{oe||c(!1)}),()=>{oe=!0}},[e,t]);const _e=oe=>{v(xe=>{const fe=new Set(xe);return fe.has(oe)?fe.delete(oe):fe.add(oe),fe})},le=async()=>{if(M(""),$&&z.error){M(z.error);return}f(!0);try{await _m(e,t,{title:m.trim()||r("flow.node.default"),...U?{kind:U}:{},...$?{...X||U==="tool"?{tool:X??O??"art.inspect"}:{},...z.dirty||U==="tool"?{input:z.value??{in:""}}:{}}:{description:b,skills:[...x]}}),i(),n()}catch(oe){M(oe instanceof Error?oe.message:String(oe)),f(!1)}},pe=()=>s(t);return u.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-40 flex items-center justify-center p-4 md:p-6 bg-black/30 overflow-hidden",onClick:n,children:u.jsxs("div",{className:"nb-card w-full max-w-4xl flex flex-col bg-[var(--color-bg)]",style:{maxHeight:"calc(100vh - 48px)"},onClick:oe=>oe.stopPropagation(),children:[u.jsxs("header",{className:"flex items-start justify-between gap-4 mb-4 flex-shrink-0",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold text-xs px-2 py-0.5 bg-[var(--color-accent-purple)] border-2 border-[var(--color-text)] rounded-full",children:["#",t]}),w&&u.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs px-2 py-0.5 border-2 border-[var(--color-text)] rounded-full font-semibold",children:[u.jsx("span",{className:"w-2.5 h-2.5 rounded-full inline-block border border-[var(--color-text)]",style:{background:G0[C]??"gray"}}),w]}),j!=null&&u.jsx("span",{className:"font-[family-name:var(--font-mono)] text-xs px-2 py-0.5 bg-[var(--color-accent-mint)] border-2 border-[var(--color-text)] rounded-full font-semibold",title:r("flow.lane.orderTip"),children:r("flow.lane.wave",{n:j})})]}),u.jsx("button",{onClick:n,className:"nb-btn nb-btn-mint p-2 flex-shrink-0","aria-label":r("flow.node.close"),type:"button",children:u.jsx(vn,{size:14,strokeWidth:3})})]}),o?u.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--color-text-muted)] py-10 justify-center",children:[u.jsx(ht,{size:16,className:"animate-spin"})," …"]}):u.jsxs(u.Fragment,{children:[A&&u.jsx("div",{className:"text-sm text-[var(--color-crashed)] mb-3",children:A}),u.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[u.jsx("span",{className:"text-sm font-bold",children:r("card.kind.label")}),["worker","tool"].map(oe=>u.jsx("button",{type:"button",onClick:()=>q(oe===(R??"worker")?null:oe),"aria-pressed":Y===oe||oe==="worker"&&!$,className:["px-2.5 py-1 text-xs rounded-full border-2 transition-all font-[family-name:var(--font-mono)]",(oe==="tool"?$:!$)?"bg-[var(--color-accent-mint)] border-[var(--color-text)] font-bold":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),children:r(oe==="tool"?"card.kind.tool":"card.kind.worker")},oe)),U&&u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:r("card.kind.pending")})]}),$&&(z.dirty||X)&&D&&u.jsxs("div",{className:"mb-3 text-xs text-[var(--color-text-muted)]",children:["⚠️ ",r("tool.card.staleWarn")]}),u.jsxs("div",{className:$?"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pr-1":"grid min-h-0 flex-1 grid-cols-1 gap-4 overflow-y-auto pr-1 md:grid-cols-[minmax(0,1fr)_minmax(260px,340px)] md:overflow-hidden md:pr-0",children:[u.jsxs("label",{className:$?"flex flex-col gap-1.5":"hidden",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),u.jsx("input",{className:"nb-input w-full text-base font-semibold",value:m,onChange:oe=>p(oe.target.value)})]}),$&&u.jsx(Nm,{tool:X??O,input:F,toolResult:D,capabilities:((ne=ce.data)==null?void 0:ne.data)??[],onChange:W,onToolChange:G}),!$&&u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex min-h-0 flex-col gap-4 md:overflow-y-auto md:pr-1",children:[u.jsxs("label",{className:"flex flex-col gap-1.5",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),u.jsx("input",{className:"nb-input w-full text-base font-semibold",value:m,onChange:oe=>p(oe.target.value),autoFocus:!0})]}),u.jsxs("label",{className:"flex flex-1 min-h-0 flex-col gap-1.5",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.desc")}),u.jsx("textarea",{className:"nb-input w-full flex-1 min-h-0",style:{minHeight:200,resize:"vertical"},value:b,onChange:oe=>y(oe.target.value)})]})]}),u.jsxs("section",{className:"flex min-h-[200px] flex-col gap-2 md:min-h-0 md:overflow-hidden",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.skills")}),u.jsx("div",{className:"scroll-frame min-h-0 flex-1 rounded-lg border-2 border-[var(--color-border-light)] bg-[var(--color-bg-cream)]",children:u.jsxs("div",{className:"scroll-frame-body h-full p-2",children:[ie.isLoading&&u.jsx(ht,{size:14,className:"animate-spin text-[var(--color-text-muted)]"}),be.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:be.map(oe=>{const xe=x.has(oe.name);return u.jsx("button",{type:"button",onClick:()=>_e(oe.name),className:["max-w-full break-all px-2.5 py-1 text-left text-xs font-[family-name:var(--font-mono)] rounded-full border-2 transition-all",xe?"bg-[var(--color-accent-mint)] border-[var(--color-text)] shadow-[2px_2px_0_var(--color-text)] font-bold":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),"aria-pressed":xe,children:oe.name},oe.name)})})]})}),x.size>0&&u.jsx("p",{className:"max-h-14 overflow-y-auto break-words text-xs text-[var(--color-text-muted)]",children:[...x].join(", ")})]})]})]}),u.jsxs("div",{className:"flex gap-2 justify-between mt-4 pt-3 border-t-2 border-dashed border-[var(--color-text)] flex-shrink-0",children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-danger",onClick:()=>void pe(),disabled:d,children:[u.jsx(us,{size:14,strokeWidth:2.4})," ",r("flow.node.delete")]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta",onClick:()=>void le(),disabled:d||$&&z.error!=="",children:[d?u.jsx(ht,{size:14,className:"animate-spin"}):null,r("flow.node.save")]})]})]})]})})}const phe=_.memo(function({data:t}){const n=t;return u.jsxs("div",{className:"relative w-full h-full rounded-2xl border-2 border-dashed border-[var(--color-text)]",children:[u.jsx("div",{className:"absolute inset-0 rounded-2xl",style:{background:n.color,opacity:.16}}),u.jsxs("span",{className:"absolute top-1.5 left-2.5 inline-flex items-center gap-1.5 px-2 py-0.5 text-[11px] font-bold rounded-md border-2 border-[var(--color-text)] bg-[var(--color-bg)] text-[var(--color-text)] whitespace-nowrap max-w-[90%]",children:[u.jsx("span",{className:"truncate",children:n.label}),n.sub&&u.jsx("span",{className:"font-normal text-[var(--color-text-muted)]",children:n.sub})]})]})});function mhe(e){const t=e;if(typeof t.seq=="number")return t.seq;const n=/#(\d+)/.exec(t.output??"");return n?Number(n[1]):null}const ghe={task:uhe,waveBox:phe},ZT="sps.flow.lastProject",JT="sps.flow.mode";function eA(e){return(e.labels??[]).includes("NEEDS-FIX")?"stuck":e.state==="Done"?"done":e.state==="Inprogress"?"doing":"todo"}function yhe(e){return e==="done"?{animated:!1,style:{stroke:"var(--color-running)",strokeWidth:2.5}}:e==="doing"?{animated:!1,className:"arrange-flow-edge-working",style:{stroke:"var(--color-running)",strokeWidth:3,strokeDasharray:"8 6"}}:e==="stuck"?{animated:!1,style:{stroke:"var(--color-crashed)",strokeWidth:2.5,strokeDasharray:"6 4"}}:{animated:!1,style:{stroke:"var(--color-accent-yellow)",strokeWidth:2.5,strokeDasharray:"6 4"}}}const dl=260,fl=158,Bm=28,_p=dl+120,nv=fl+28,tA=16,nA=44,Cp=60,iv=100,iA=["var(--color-accent-mint)","var(--color-accent-pink)","var(--color-accent-yellow)","var(--color-accent-purple)","var(--color-running-bg)","var(--color-idle-bg)"];function md(e){const t=new Map;for(const n of e){const i=t.get(n.order)??[];i.push(n),t.set(n.order,i)}return[...t.entries()].sort((n,i)=>n[0]-i[0]).map(([,n])=>n.sort((i,s)=>i.seq-s.seq))}function bhe(e,t){return Math.abs(e.x-t.x)<dl+Bm&&Math.abs(e.y-t.y)<fl+Bm}function xhe(e){for(let t=0;t<80;t+=1)for(let n=0;n<8;n+=1){const i={x:60+n*(dl+Bm),y:60+t*(fl+Bm)};if(!e.some(s=>bhe(i,s)))return i}return{x:60,y:60}}function sA(e){return{x:e.position.x+dl/2,y:e.position.y+fl/2}}function vhe(e,t,n){const i=n.x-t.x,s=n.y-t.y,r=i*i+s*s;if(r===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=((e.x-t.x)*i+(e.y-t.y)*s)/r;return o=Math.max(0,Math.min(1,o)),Math.hypot(e.x-(t.x+o*i),e.y-(t.y+o*s))}function whe(){var ye,et,Pt,Wt;const e=Ye(),t=Xt(),n=wl(),{confirm:i}=Un(),{screenToFlowPosition:s,fitView:r}=Ng(),o=_.useRef([]),[c,d]=_.useState(()=>localStorage.getItem(ZT)??""),[f,m]=_.useState(()=>localStorage.getItem(JT)==="lanes"?"lanes":"free"),[p,b]=_.useState(!1),[y,x,v]=Mfe([]),[w,k,C]=Rfe([]),[S,j]=_.useState(null),[T,A]=_.useState(null),[M,R]=_.useState(!1),[P,O]=_.useState(""),[B,F]=_.useState(null),[V,D]=_.useState(null),[I,z]=_.useState(0),W=_.useRef({}),X=_.useRef(w);X.current=w;const G=_.useRef(y);G.current=y;const U=_.useRef(null),q=_.useRef(null),Y=_.useRef(new Set),$=_.useRef(""),ie=_.useRef(null);bI(c||null);const be=Je({queryKey:["cards",c],queryFn:()=>pI(c),enabled:!!c,refetchInterval:3e3}),ce=((ye=be.data)==null?void 0:ye.data)??[],le=((Wt=(Pt=(et=Je({queryKey:["projects"],queryFn:fo,refetchInterval:3e3}).data)==null?void 0:et.data)==null?void 0:Pt.find(me=>me.name===c))==null?void 0:Wt.pipelineStatus)==="running",pe=_.useMemo(()=>{const me={};for(const ae of ce)me[String(ae.seq)]=eA(ae);return me},[ce]),Te=_.useMemo(()=>{if(f!=="lanes")return[];const me=md(ce),ae=[];for(let je=1;je<me.length;je+=1)for(const Ae of me[je-1]??[])for(const Qe of me[je]??[])ae.push({id:`w${Ae.seq}-${Qe.seq}`,source:String(Ae.seq),target:String(Qe.seq),sourceHandle:"r",targetHandle:"l",animated:!1,selectable:!1,deletable:!1});return ae},[f,ce]),ne=_.useMemo(()=>(f==="lanes"?Te:w).map(me=>{const ae=yhe(pe[me.target]);return me.selected?{...me,...ae,style:{...ae.style,strokeWidth:6}}:{...me,...ae}}),[f,Te,w,pe]),oe=_.useCallback(()=>{t.invalidateQueries({queryKey:["cards",c]})},[t,c]),xe=_.useCallback(()=>{!c||U.current!==c||(ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>{ohe(c,{positions:W.current,edges:X.current.map(me=>({id:me.id,source:me.source,target:me.target,sourceHandle:me.sourceHandle??null,targetHandle:me.targetHandle??null}))}).catch(()=>{})},600))},[c]);_.useEffect(()=>{if(U.current=null,j(null),D(null),W.current={},Y.current=new Set,$.current="",x([]),k([]),!c)return;localStorage.setItem(ZT,c);let me=!1;return ahe(c).then(ae=>{me||(W.current=ae.positions??{},k((ae.edges??[]).map(je=>({id:je.id,source:je.source,target:je.target,sourceHandle:je.sourceHandle??void 0,targetHandle:je.targetHandle??void 0,animated:!1}))))}).catch(()=>{}).finally(()=>{me||(U.current=c,z(ae=>ae+1))}),()=>{me=!0}},[c,x,k]),_.useEffect(()=>{if(!c||U.current!==c)return;const me=`${f}|`+ce.map(Ue=>`${Ue.seq}:${Ue.title}:${Ue.state}:${Ue.order}:${(Ue.skills??[]).join("|")}`).join(",");if(me===$.current)return;$.current=me;const ae=Ue=>({seq:String(Ue.seq),title:Ue.title,skills:(Ue.skills??[]).join(", "),labels:(Ue.labels??[]).join(", "),status:eA(Ue),label:Ue.title,desc:"",...Ue.kind?{kind:Ue.kind}:{},...Ue.tool?{tool:Ue.tool}:{}});if(f==="lanes"){const Ue=md(ce),it=Ue.map((Qt,Ot)=>({id:`wave-${Ot}`,type:"waveBox",position:{x:Cp+Ot*_p-tA,y:iv-nA},data:{label:e("flow.lane.wave",{n:Ot+1}),sub:Qt.length>1?e("flow.lane.parallel",{n:Qt.length}):"",color:iA[Ot%iA.length]},style:{width:dl+tA*2,height:nA+(Qt.length-1)*nv+fl+14},draggable:!1,selectable:!1,zIndex:0})),qt=Ue.flatMap((Qt,Ot)=>Qt.map((Q,ke)=>({id:String(Q.seq),type:"task",position:{x:Cp+Ot*_p,y:iv+ke*nv},deletable:!1,zIndex:1,data:ae(Q)})));x([...it,...qt]);return}const je=new Map(G.current.map(Ue=>[Ue.id,Ue.position])),Ae=[];for(const Ue of ce){const it=je.get(String(Ue.seq))??W.current[String(Ue.seq)];it&&Ae.push(it)}let Qe=!1;const rt=ce.map(Ue=>{const it=String(Ue.seq);let qt=je.get(it)??W.current[it];return qt||(qt=xhe(Ae),Ae.push(qt),Qe=!0),W.current[it]=qt,{id:it,type:"task",position:qt,deletable:!1,data:ae(Ue)}});x(rt),Qe&&xe()},[ce,c,f,I,x,xe,e]),_.useEffect(()=>{if(U.current!==c)return;const me=new Set(ce.map(ae=>String(ae.seq)));k(ae=>{const je=ae.filter(Ae=>me.has(Ae.source)&&me.has(Ae.target));return je.length!==ae.length&&xe(),je.length===ae.length?ae:je})},[ce,c,k,xe]),_.useEffect(()=>{if(!c||U.current!==c||f!=="free"||ce.length<2)return;const me=md(ce),ae=[];for(let Qe=1;Qe<me.length;Qe+=1)for(const rt of me[Qe-1]??[])for(const Ue of me[Qe]??[])ae.push({id:`seed-${rt.seq}-${Ue.seq}`,source:String(rt.seq),target:String(Ue.seq),sourceHandle:"r",targetHandle:"l",animated:!1});const je=X.current,Ae=q.current!==c;if(q.current=c,Ae&&je.length===0)ae.length>0&&(k(ae),xe());else{const Qe=new Set;for(const it of je)Qe.add(it.source),Qe.add(it.target);const rt=new Set(je.map(it=>`${it.source}->${it.target}`)),Ue=new Set(ce.map(it=>String(it.seq)).filter(it=>!Y.current.has(it)&&!Qe.has(it)));if(Ue.size>0){const it=ae.filter(qt=>(Ue.has(qt.source)||Ue.has(qt.target))&&!rt.has(`${qt.source}->${qt.target}`));it.length>0&&(k([...je,...it]),xe())}}Y.current=new Set(ce.map(Qe=>String(Qe.seq)))},[ce,c,f,I,k,xe]);const fe=_.useCallback(me=>{if(v(me),f!=="free")return;let ae=!1;for(const je of me)je.type==="position"&&je.position&&(W.current[je.id]=je.position,ae=!0);ae&&xe()},[v,xe,f]),te=_.useCallback(me=>{f==="free"&&(k(ae=>GP({...me,animated:!1},ae)),xe())},[k,xe,f]),we=_.useCallback(()=>{if(f!=="free"||ce.length===0)return;const me=md(ce),ae={},je=[];me.forEach((Ae,Qe)=>{if(Ae.forEach((rt,Ue)=>{ae[String(rt.seq)]={x:Cp+Qe*_p,y:iv+Ue*nv}}),Qe>0)for(const rt of me[Qe-1]??[])for(const Ue of Ae)je.push({id:`seed-${rt.seq}-${Ue.seq}`,source:String(rt.seq),target:String(Ue.seq),sourceHandle:"r",targetHandle:"l",animated:!1})}),W.current={...W.current,...ae},x(Ae=>Ae.map(Qe=>ae[Qe.id]?{...Qe,position:ae[Qe.id]}:Qe)),k(je),xe(),setTimeout(()=>r({padding:.2,duration:300}),60)},[f,ce,x,k,xe,r]),Fe=_.useCallback(async me=>{if(!await i({title:e("flow.confirm.deleteTitle"),body:e("flow.confirm.deleteBody",{seq:me}),danger:!0,confirm:e("flow.node.delete")}))return;O("");const je=X.current.filter(Ae=>Ae.source===String(me)||Ae.target===String(me)).map(Ae=>({...Ae}));try{await gI(c,me),o.current.push({seq:me,edges:je})}catch(Ae){O(Ae instanceof Error?Ae.message:String(Ae))}finally{j(Ae=>Ae===me?null:Ae),A(Ae=>Ae===me?null:Ae),$.current="",z(Ae=>Ae+1),oe()}},[c,i,e,oe]),Le=_.useCallback(async()=>{const me=o.current.pop();if(me){O("");try{await Hie(c,me.seq),k(ae=>{const je=new Set(ae.map(Ae=>Ae.id));return[...ae,...me.edges.filter(Ae=>!je.has(Ae.id))]}),xe(),oe()}catch(ae){O(ae instanceof Error?ae.message:String(ae))}}},[c,k,xe,oe]),pt=_.useCallback((me,ae)=>{var rt;if(f!=="free"||ae.isValid)return;const je=ae.fromNode;if(!je||!c)return;const Ae="changedTouches"in me?me.changedTouches[0]:me;if(!Ae)return;const Qe=s({x:Ae.clientX,y:Ae.clientY});F({fromId:je.id,fromHandle:((rt=ae.fromHandle)==null?void 0:rt.id)??null,clientX:Ae.clientX,clientY:Ae.clientY,flowX:Qe.x,flowY:Qe.y})},[f,c,s]),nt=_.useCallback(async()=>{const me=B;if(F(null),!(!me||!c))try{const ae=await C0(c,{title:`${e("flow.node.default")} ${ce.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),je=mhe(ae);if(je==null)return;const Ae=String(je);W.current[Ae]={x:me.flowX-dl/2,y:me.flowY-fl/2},k(Qe=>[...Qe,{id:`e-${me.fromId}-${Ae}-drop`,source:me.fromId,target:Ae,sourceHandle:me.fromHandle??void 0,animated:!1}]),xe(),oe()}catch(ae){O(ae instanceof Error?ae.message:String(ae))}},[B,c,ce.length,k,xe,e,oe]);_.useEffect(()=>{if(!B)return;const me=ae=>{ae.key==="Escape"&&F(null)};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[B]);const Mt=_.useCallback((me,ae)=>{f==="free"&&(k(je=>ade(me,ae,je)),xe())},[f,k,xe]);_.useEffect(()=>{const me=ae=>{if(ae.key!=="Delete"&&ae.key!=="Backspace"||T!=null)return;const je=ae.target;je&&(je.tagName==="INPUT"||je.tagName==="TEXTAREA"||je.isContentEditable)||S!=null&&(ae.preventDefault(),Fe(S))};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[S,T,Fe]),_.useEffect(()=>{const me=ae=>{if(!(ae.metaKey||ae.ctrlKey)||ae.key!=="z"&&ae.key!=="Z"||T!=null)return;const je=ae.target;je&&(je.tagName==="INPUT"||je.tagName==="TEXTAREA"||je.isContentEditable)||(ae.preventDefault(),Le())};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[T,Le]);const Nt=_.useCallback(async me=>{if(c){b(!0),O("");try{const ae=new Map(ce.map(je=>[je.seq,je.order]));for(let je=0;je<me.length;je+=1)for(const Ae of me[je]??[])ae.get(Ae)!==je+1&&await _m(c,Ae,{order:je+1});oe()}catch(ae){O(ae instanceof Error?ae.message:String(ae))}finally{b(!1)}}},[c,ce,oe]),mt=_.useCallback(me=>{const ae=Number(me.id);if(!Number.isInteger(ae))return;const je=md(ce).map(Ue=>Ue.map(it=>it.seq)),Ae=(me.position.x-Cp)/_p,Qe=Math.round(Ae),rt=je.map(Ue=>Ue.filter(it=>it!==ae));if(Qe>=0&&Qe<je.length&&Math.abs(Ae-Qe)<=.35)rt[Qe].push(ae);else{const Ue=Math.max(0,Math.min(rt.length,Math.ceil(Ae)));rt.splice(Ue,0,[ae])}Nt(rt.filter(Ue=>Ue.length>0)).finally(()=>{$.current="",z(Ue=>Ue+1)})},[ce,Nt]),Re=_.useCallback((me,ae)=>{if(f==="lanes"){mt(ae);return}const je=new Map(G.current.map(it=>[it.id,it])),Ae={x:ae.position.x+dl/2,y:ae.position.y+fl/2};let Qe=null,rt=40;for(const it of X.current){if(it.source===ae.id||it.target===ae.id)continue;const qt=je.get(it.source),Qt=je.get(it.target);if(!qt||!Qt)continue;const Ot=vhe(Ae,sA(qt),sA(Qt));Ot<rt&&(rt=Ot,Qe=it)}if(!Qe)return;const Ue=Qe;k(it=>[...it.filter(qt=>qt.id!==Ue.id),{id:`e-${Ue.source}-${ae.id}-${Ue.id}`,source:Ue.source,target:ae.id,animated:!1},{id:`e-${ae.id}-${Ue.target}-${Ue.id}`,source:ae.id,target:Ue.target,animated:!1}]),xe()},[f,mt,k,xe]),We=_.useCallback(me=>{m(me),localStorage.setItem(JT,me)},[]);_.useEffect(()=>{const me=setTimeout(()=>{r({padding:.2,duration:300})},80);return()=>clearTimeout(me)},[f,r]);const se=async()=>{if(c){O("");try{await C0(c,{title:`${e("flow.node.default")} ${ce.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),oe()}catch(me){O(me instanceof Error?me.message:String(me))}}},Ee=async()=>{if(O(""),D(null),!c)return O(e("flow.err.noProject"));if(ce.length===0)return O(e("flow.err.noNodes"));R(!0);try{const me=ce.filter(Ae=>Ae.state==="Planning"),ae=me.length;let je=0;D({phase:"creating",made:je,total:ae});for(const Ae of me)await _m(c,Ae.seq,{state:"Backlog",labels:Array.from(new Set([...Ae.labels??[],"AI-PIPELINE"]))}),je+=1,D({phase:"creating",made:je,total:ae});D({phase:"starting",made:je,total:ae}),await yI(c),oe(),D({phase:"done",made:je,total:ae})}catch(me){O(me instanceof Error?me.message:String(me))}finally{R(!1)}},De=be.isLoading&&!!c;return u.jsxs("div",{className:"flex flex-col h-full",children:[u.jsxs("header",{className:"flex items-center gap-3 flex-wrap px-4 py-3 border-b border-[var(--surface-card-border)]",children:[u.jsxs("h1",{className:"text-lg font-[family-name:var(--font-heading)] flex items-center gap-2",children:[u.jsx(o_,{size:18,strokeWidth:2.4}),e("nav.arrange")]}),u.jsx(wI,{current:c,onChange:d}),u.jsxs("div",{className:"flex gap-1",role:"group","aria-label":e("flow.mode.aria"),children:[u.jsxs("button",{type:"button",className:["nb-btn",f==="free"?"nb-btn-primary":""].join(" "),"aria-pressed":f==="free",onClick:()=>We("free"),children:[u.jsx(o_,{size:14,strokeWidth:2.4})," ",e("flow.mode.free")]}),u.jsxs("button",{type:"button",className:["nb-btn",f==="lanes"?"nb-btn-primary":""].join(" "),"aria-pressed":f==="lanes",onClick:()=>We("lanes"),children:[u.jsx(LU,{size:14,strokeWidth:2.4})," ",e("flow.mode.lanes")]})]}),De&&u.jsx(ht,{size:15,className:"animate-spin text-[var(--color-text-muted)]"}),u.jsxs("button",{type:"button",className:"nb-btn",onClick:()=>void se(),disabled:!c||De,children:[u.jsx(Bn,{size:15,strokeWidth:2.4})," ",e("flow.addNode")]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta ml-auto",onClick:()=>void Ee(),disabled:M||le||De||!c,title:le?e("flow.pipelineRunning"):void 0,children:[M||le?u.jsx(ht,{size:15,className:"animate-spin"}):u.jsx($m,{size:15,strokeWidth:2.4}),e(M?"flow.running":le?"flow.pipelineRunning":"flow.run")]})]}),!c&&u.jsx("div",{className:"px-4 py-2 text-sm text-[var(--color-text-muted)] border-b border-[var(--surface-card-border)]",children:e("flow.pickProject")}),P&&u.jsx("div",{className:"px-4 py-2 text-sm text-[var(--color-crashed)] bg-[var(--color-crashed-bg)] border-b border-[var(--surface-card-border)]",children:P}),V&&u.jsxs("div",{className:"px-4 py-2 text-sm flex items-center gap-3 bg-[var(--surface-input)] border-b border-[var(--surface-card-border)]",children:[V.phase==="creating"&&u.jsxs("span",{children:[e("flow.status.creating")," ",V.made,"/",V.total,"…"]}),V.phase==="starting"&&u.jsx("span",{children:e("flow.status.starting")}),V.phase==="done"&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-[var(--color-running)] font-bold",children:["✓ ",e("flow.status.done").replace("{n}",String(V.made))]}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>n(`/board?project=${encodeURIComponent(c)}`),children:e("flow.goBoard")})]})]}),u.jsx("div",{className:"flex-1 min-h-0 arrange-flow-shell",children:u.jsxs(Afe,{nodes:y,edges:ne,nodeTypes:ghe,connectionRadius:160,nodesConnectable:f==="free",edgesReconnectable:f==="free",deleteKeyCode:T!=null?null:["Delete","Backspace"],onNodesChange:fe,onEdgesChange:me=>{f==="free"&&(C(me),xe())},onConnect:te,onConnectEnd:pt,onReconnect:Mt,onNodeClick:(me,ae)=>{const je=Number(ae.id);Number.isInteger(je)&&A(je)},onNodeDragStop:Re,onSelectionChange:({nodes:me})=>{const ae=me[0]?Number(me[0].id):null;j(ae!=null&&Number.isInteger(ae)?ae:null)},fitView:!0,children:[u.jsx(Pfe,{variant:ca.Dots,gap:18,size:1}),u.jsx(Hfe,{children:f==="free"&&u.jsx(kd,{onClick:we,title:e("flow.tidy"),"aria-label":e("flow.tidy"),children:u.jsx(cM,{size:14,strokeWidth:2.4})})})]})}),B&&u.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>F(null),children:u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta absolute -translate-x-1/2 -translate-y-1/2",style:{left:B.clientX,top:B.clientY},onClick:me=>{me.stopPropagation(),nt()},children:[u.jsx(Bn,{size:14,strokeWidth:2.4})," ",e("flow.pending.create")]})}),p&&u.jsxs("div",{className:"px-4 py-1 text-xs text-[var(--color-text-muted)] border-t border-[var(--surface-card-border)] flex items-center gap-2",children:[u.jsx(ht,{size:12,className:"animate-spin"})," ",e("flow.lane.applying")]}),u.jsx("footer",{className:"px-4 py-2 text-xs text-[var(--color-text-muted)] border-t border-[var(--surface-card-border)]",children:e(f==="free"?"flow.hint":"flow.lane.hint")}),T!=null&&c&&u.jsx(hhe,{project:c,seq:T,onClose:()=>A(null),onChanged:oe,onDelete:me=>void Fe(me)})]})}function Ehe(){return u.jsx(x3,{children:u.jsx(whe,{})})}function khe(){const e=Ye();return u.jsxs("div",{className:"nb-card max-w-2xl mt-12",children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold mb-2",children:e("notFound.title")}),u.jsx("p",{className:"text-[var(--color-text-muted)] mb-6",children:e("notFound.body")}),u.jsx(Fc,{to:"/",className:"nb-btn nb-btn-mint inline-flex",children:e("notFound.home")})]})}const She=_.lazy(()=>sU(()=>import("./ShowcasePage-B191_5uD.js"),__vite__mapDeps([0,1])));function Nhe(){return u.jsx(l$,{children:u.jsxs(EB,{children:[u.jsx(oi,{path:"/showcase",element:u.jsx(_.Suspense,{fallback:null,children:u.jsx(She,{})})}),u.jsxs(oi,{element:u.jsx(d_,{contentMode:"workspace"}),children:[u.jsx(oi,{index:!0,element:u.jsx(Cx,{})}),u.jsx(oi,{path:"/projects",element:u.jsx(Tj,{})}),u.jsx(oi,{path:"/projects/:name",element:u.jsx(Tj,{})}),u.jsx(oi,{path:"/board",element:u.jsx(dse,{})}),u.jsx(oi,{path:"/prompts",element:u.jsx(Nse,{})}),u.jsx(oi,{path:"/chat",element:u.jsx(Cx,{})}),u.jsx(oi,{path:"/chat/:sessionId",element:u.jsx(Cx,{})}),u.jsx(oi,{path:"/arrange",element:u.jsx(Ehe,{})})]}),u.jsxs(oi,{element:u.jsx(d_,{contentMode:"document"}),children:[u.jsx(oi,{path:"/projects/new",element:u.jsx(hI,{})}),u.jsx(oi,{path:"/skills",element:u.jsx(bse,{})}),u.jsx(oi,{path:"/system",element:u.jsx(qse,{})}),u.jsx(oi,{path:"/memory",element:u.jsx(tre,{})}),u.jsx(oi,{path:"/plugins",element:u.jsx(zre,{})}),u.jsx(oi,{path:"*",element:u.jsx(khe,{})})]})]})})}function _he(){const e=[b0("plugin.config",{owner:"sps",order:0,match:({pluginKey:t})=>t==="memory",render:()=>u.jsx(Bre,{})}),b0("plugin.config",{owner:"sps",order:0,match:({pluginKey:t})=>t==="im",render:()=>u.jsx(Kre,{})})];return()=>{for(const t of e)t()}}function Che(){_he(),cre(),(async()=>{try{const e=await CI();await Promise.all(e.filter(t=>t.clientFormat==="sps"&&!t.disabled).map(t=>ure(t.key)))}catch(e){console.error("插件前端加载失败(不影响 console 本体):",e)}})()}o$();DF();Che();const jhe=new u5({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!1}}}),k3=document.getElementById("root");if(!k3)throw new Error("#root not found");B4.createRoot(k3).render(u.jsx(_.StrictMode,{children:u.jsx(kF,{children:u.jsx(d5,{client:jhe,children:u.jsx(GB,{children:u.jsx(WY,{children:u.jsx(Nhe,{})})})})})}));export{eM as A,RU as C,rM as E,Fc as L,u1 as P,Ev as S,hU as a,ze as c,u as j,_ as r,bM as u};
867
+ `).trim()}function fhe(e,t){return t.includes("NEEDS-FIX")?"stuck":e==="Done"?"done":e==="Inprogress"?"doing":"todo"}function hhe({project:e,seq:t,onClose:n,onChanged:i,onDelete:s}){var Te,ne;const r=Ye(),[o,c]=_.useState(!0),[d,f]=_.useState(!1),[m,p]=_.useState(""),[b,y]=_.useState(""),[x,v]=_.useState(new Set),[w,k]=_.useState(""),[C,S]=_.useState("todo"),[j,T]=_.useState(null),[A,M]=_.useState(""),[R,P]=_.useState(void 0),[O,B]=_.useState(void 0),[F,V]=_.useState(void 0),[D,I]=_.useState(void 0),[z,W]=_.useState({value:null,error:"",dirty:!1}),[X,G]=_.useState(null),[U,q]=_.useState(null),Y=U??R,$=Y==="tool"||Y==="join",ie=Je({queryKey:["skills-all",e],queryFn:()=>fg(e),enabled:!$}),be=((Te=ie.data)==null?void 0:Te.data)??[],ce=Je({queryKey:["capabilities",e],queryFn:()=>Rw(e),enabled:$});_.useEffect(()=>{const oe=xe=>{xe.key==="Escape"&&n()};return window.addEventListener("keydown",oe),()=>window.removeEventListener("keydown",oe)},[n]),_.useEffect(()=>{let oe=!1;return c(!0),mI(e,t).then(xe=>{oe||(p(xe.title),v(new Set(xe.skills??[])),y(dhe(xe.body)),k(xe.state),S(fhe(xe.state,xe.labels??[])),T(typeof xe.order=="number"?xe.order:null),P(xe.kind),B(xe.tool),G(null),q(null),V(xe.input),I(xe.toolResult))}).catch(()=>{}).finally(()=>{oe||c(!1)}),()=>{oe=!0}},[e,t]);const _e=oe=>{v(xe=>{const fe=new Set(xe);return fe.has(oe)?fe.delete(oe):fe.add(oe),fe})},le=async()=>{if(M(""),$&&z.error){M(z.error);return}f(!0);try{await _m(e,t,{title:m.trim()||r("flow.node.default"),...U?{kind:U}:{},...$?{...X||U==="tool"?{tool:X??O??"art.inspect"}:{},...z.dirty||U==="tool"?{input:z.value??{in:""}}:{}}:{description:b,skills:[...x]}}),i(),n()}catch(oe){M(oe instanceof Error?oe.message:String(oe)),f(!1)}},pe=()=>s(t);return u.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-40 flex items-center justify-center p-4 md:p-6 bg-black/30 overflow-hidden",onClick:n,children:u.jsxs("div",{className:"nb-card w-full max-w-4xl flex flex-col bg-[var(--color-bg)]",style:{maxHeight:"calc(100vh - 48px)"},onClick:oe=>oe.stopPropagation(),children:[u.jsxs("header",{className:"flex items-start justify-between gap-4 mb-4 flex-shrink-0",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold text-xs px-2 py-0.5 bg-[var(--color-accent-purple)] border-2 border-[var(--color-text)] rounded-full",children:["#",t]}),w&&u.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs px-2 py-0.5 border-2 border-[var(--color-text)] rounded-full font-semibold",children:[u.jsx("span",{className:"w-2.5 h-2.5 rounded-full inline-block border border-[var(--color-text)]",style:{background:G0[C]??"gray"}}),w]}),j!=null&&u.jsx("span",{className:"font-[family-name:var(--font-mono)] text-xs px-2 py-0.5 bg-[var(--color-accent-mint)] border-2 border-[var(--color-text)] rounded-full font-semibold",title:r("flow.lane.orderTip"),children:r("flow.lane.wave",{n:j})})]}),u.jsx("button",{onClick:n,className:"nb-btn nb-btn-mint p-2 flex-shrink-0","aria-label":r("flow.node.close"),type:"button",children:u.jsx(vn,{size:14,strokeWidth:3})})]}),o?u.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--color-text-muted)] py-10 justify-center",children:[u.jsx(ht,{size:16,className:"animate-spin"})," …"]}):u.jsxs(u.Fragment,{children:[A&&u.jsx("div",{className:"text-sm text-[var(--color-crashed)] mb-3",children:A}),u.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[u.jsx("span",{className:"text-sm font-bold",children:r("card.kind.label")}),["worker","tool"].map(oe=>u.jsx("button",{type:"button",onClick:()=>q(oe===(R??"worker")?null:oe),"aria-pressed":Y===oe||oe==="worker"&&!$,className:["px-2.5 py-1 text-xs rounded-full border-2 transition-all font-[family-name:var(--font-mono)]",(oe==="tool"?$:!$)?"bg-[var(--color-accent-mint)] border-[var(--color-text)] font-bold":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),children:r(oe==="tool"?"card.kind.tool":"card.kind.worker")},oe)),U&&u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:r("card.kind.pending")})]}),$&&(z.dirty||X)&&D&&u.jsxs("div",{className:"mb-3 text-xs text-[var(--color-text-muted)]",children:["⚠️ ",r("tool.card.staleWarn")]}),u.jsxs("div",{className:$?"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pr-1":"grid min-h-0 flex-1 grid-cols-1 gap-4 overflow-y-auto pr-1 md:grid-cols-[minmax(0,1fr)_minmax(260px,340px)] md:overflow-hidden md:pr-0",children:[u.jsxs("label",{className:$?"flex flex-col gap-1.5":"hidden",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),u.jsx("input",{className:"nb-input w-full text-base font-semibold",value:m,onChange:oe=>p(oe.target.value)})]}),$&&u.jsx(Nm,{tool:X??O,input:F,toolResult:D,capabilities:((ne=ce.data)==null?void 0:ne.data)??[],onChange:W,onToolChange:G}),!$&&u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex min-h-0 flex-col gap-4 md:overflow-y-auto md:pr-1",children:[u.jsxs("label",{className:"flex flex-col gap-1.5",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),u.jsx("input",{className:"nb-input w-full text-base font-semibold",value:m,onChange:oe=>p(oe.target.value),autoFocus:!0})]}),u.jsxs("label",{className:"flex flex-1 min-h-0 flex-col gap-1.5",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.desc")}),u.jsx("textarea",{className:"nb-input w-full flex-1 min-h-0",style:{minHeight:200,resize:"vertical"},value:b,onChange:oe=>y(oe.target.value)})]})]}),u.jsxs("section",{className:"flex min-h-[200px] flex-col gap-2 md:min-h-0 md:overflow-hidden",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.skills")}),u.jsx("div",{className:"scroll-frame min-h-0 flex-1 rounded-lg border-2 border-[var(--color-border-light)] bg-[var(--color-bg-cream)]",children:u.jsxs("div",{className:"scroll-frame-body h-full p-2",children:[ie.isLoading&&u.jsx(ht,{size:14,className:"animate-spin text-[var(--color-text-muted)]"}),be.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:be.map(oe=>{const xe=x.has(oe.name);return u.jsx("button",{type:"button",onClick:()=>_e(oe.name),className:["max-w-full break-all px-2.5 py-1 text-left text-xs font-[family-name:var(--font-mono)] rounded-full border-2 transition-all",xe?"bg-[var(--color-accent-mint)] border-[var(--color-text)] shadow-[2px_2px_0_var(--color-text)] font-bold":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),"aria-pressed":xe,children:oe.name},oe.name)})})]})}),x.size>0&&u.jsx("p",{className:"max-h-14 overflow-y-auto break-words text-xs text-[var(--color-text-muted)]",children:[...x].join(", ")})]})]})]}),u.jsxs("div",{className:"flex gap-2 justify-between mt-4 pt-3 border-t-2 border-dashed border-[var(--color-text)] flex-shrink-0",children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-danger",onClick:()=>void pe(),disabled:d,children:[u.jsx(us,{size:14,strokeWidth:2.4})," ",r("flow.node.delete")]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta",onClick:()=>void le(),disabled:d||$&&z.error!=="",children:[d?u.jsx(ht,{size:14,className:"animate-spin"}):null,r("flow.node.save")]})]})]})]})})}const phe=_.memo(function({data:t}){const n=t;return u.jsxs("div",{className:"relative w-full h-full rounded-2xl border-2 border-dashed border-[var(--color-text)]",children:[u.jsx("div",{className:"absolute inset-0 rounded-2xl",style:{background:n.color,opacity:.16}}),u.jsxs("span",{className:"absolute top-1.5 left-2.5 inline-flex items-center gap-1.5 px-2 py-0.5 text-[11px] font-bold rounded-md border-2 border-[var(--color-text)] bg-[var(--color-bg)] text-[var(--color-text)] whitespace-nowrap max-w-[90%]",children:[u.jsx("span",{className:"truncate",children:n.label}),n.sub&&u.jsx("span",{className:"font-normal text-[var(--color-text-muted)]",children:n.sub})]})]})});function mhe(e){const t=e;if(typeof t.seq=="number")return t.seq;const n=/#(\d+)/.exec(t.output??"");return n?Number(n[1]):null}const ghe={task:uhe,waveBox:phe},ZT="sps.flow.lastProject",JT="sps.flow.mode";function eA(e){return(e.labels??[]).includes("NEEDS-FIX")?"stuck":e.state==="Done"?"done":e.state==="Inprogress"?"doing":"todo"}function yhe(e){return e==="done"?{animated:!1,style:{stroke:"var(--color-running)",strokeWidth:2.5}}:e==="doing"?{animated:!1,className:"arrange-flow-edge-working",style:{stroke:"var(--color-running)",strokeWidth:3,strokeDasharray:"8 6"}}:e==="stuck"?{animated:!1,style:{stroke:"var(--color-crashed)",strokeWidth:2.5,strokeDasharray:"6 4"}}:{animated:!1,style:{stroke:"var(--color-accent-yellow)",strokeWidth:2.5,strokeDasharray:"6 4"}}}const dl=260,fl=158,Bm=28,_p=dl+120,nv=fl+28,tA=16,nA=44,Cp=60,iv=100,iA=["var(--color-accent-mint)","var(--color-accent-pink)","var(--color-accent-yellow)","var(--color-accent-purple)","var(--color-running-bg)","var(--color-idle-bg)"];function md(e){const t=new Map;for(const n of e){const i=t.get(n.order)??[];i.push(n),t.set(n.order,i)}return[...t.entries()].sort((n,i)=>n[0]-i[0]).map(([,n])=>n.sort((i,s)=>i.seq-s.seq))}function bhe(e,t){return Math.abs(e.x-t.x)<dl+Bm&&Math.abs(e.y-t.y)<fl+Bm}function xhe(e){for(let t=0;t<80;t+=1)for(let n=0;n<8;n+=1){const i={x:60+n*(dl+Bm),y:60+t*(fl+Bm)};if(!e.some(s=>bhe(i,s)))return i}return{x:60,y:60}}function sA(e){return{x:e.position.x+dl/2,y:e.position.y+fl/2}}function vhe(e,t,n){const i=n.x-t.x,s=n.y-t.y,r=i*i+s*s;if(r===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=((e.x-t.x)*i+(e.y-t.y)*s)/r;return o=Math.max(0,Math.min(1,o)),Math.hypot(e.x-(t.x+o*i),e.y-(t.y+o*s))}function whe(){var ye,et,Pt,Wt;const e=Ye(),t=Xt(),n=wl(),{confirm:i}=Un(),{screenToFlowPosition:s,fitView:r}=Ng(),o=_.useRef([]),[c,d]=_.useState(()=>localStorage.getItem(ZT)??""),[f,m]=_.useState(()=>localStorage.getItem(JT)==="lanes"?"lanes":"free"),[p,b]=_.useState(!1),[y,x,v]=Mfe([]),[w,k,C]=Rfe([]),[S,j]=_.useState(null),[T,A]=_.useState(null),[M,R]=_.useState(!1),[P,O]=_.useState(""),[B,F]=_.useState(null),[V,D]=_.useState(null),[I,z]=_.useState(0),W=_.useRef({}),X=_.useRef(w);X.current=w;const G=_.useRef(y);G.current=y;const U=_.useRef(null),q=_.useRef(null),Y=_.useRef(new Set),$=_.useRef(""),ie=_.useRef(null);bI(c||null);const be=Je({queryKey:["cards",c],queryFn:()=>pI(c),enabled:!!c,refetchInterval:3e3}),ce=((ye=be.data)==null?void 0:ye.data)??[],le=((Wt=(Pt=(et=Je({queryKey:["projects"],queryFn:fo,refetchInterval:3e3}).data)==null?void 0:et.data)==null?void 0:Pt.find(me=>me.name===c))==null?void 0:Wt.pipelineStatus)==="running",pe=_.useMemo(()=>{const me={};for(const ae of ce)me[String(ae.seq)]=eA(ae);return me},[ce]),Te=_.useMemo(()=>{if(f!=="lanes")return[];const me=md(ce),ae=[];for(let je=1;je<me.length;je+=1)for(const Ae of me[je-1]??[])for(const Qe of me[je]??[])ae.push({id:`w${Ae.seq}-${Qe.seq}`,source:String(Ae.seq),target:String(Qe.seq),sourceHandle:"r",targetHandle:"l",animated:!1,selectable:!1,deletable:!1});return ae},[f,ce]),ne=_.useMemo(()=>(f==="lanes"?Te:w).map(me=>{const ae=yhe(pe[me.target]);return me.selected?{...me,...ae,style:{...ae.style,strokeWidth:6}}:{...me,...ae}}),[f,Te,w,pe]),oe=_.useCallback(()=>{t.invalidateQueries({queryKey:["cards",c]})},[t,c]),xe=_.useCallback(()=>{!c||U.current!==c||(ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>{ohe(c,{positions:W.current,edges:X.current.map(me=>({id:me.id,source:me.source,target:me.target,sourceHandle:me.sourceHandle??null,targetHandle:me.targetHandle??null}))}).catch(()=>{})},600))},[c]);_.useEffect(()=>{if(U.current=null,j(null),D(null),W.current={},Y.current=new Set,$.current="",x([]),k([]),!c)return;localStorage.setItem(ZT,c);let me=!1;return ahe(c).then(ae=>{me||(W.current=ae.positions??{},k((ae.edges??[]).map(je=>({id:je.id,source:je.source,target:je.target,sourceHandle:je.sourceHandle??void 0,targetHandle:je.targetHandle??void 0,animated:!1}))))}).catch(()=>{}).finally(()=>{me||(U.current=c,z(ae=>ae+1))}),()=>{me=!0}},[c,x,k]),_.useEffect(()=>{if(!c||U.current!==c)return;const me=`${f}|`+ce.map(Ue=>`${Ue.seq}:${Ue.title}:${Ue.state}:${Ue.order}:${(Ue.skills??[]).join("|")}`).join(",");if(me===$.current)return;$.current=me;const ae=Ue=>({seq:String(Ue.seq),title:Ue.title,skills:(Ue.skills??[]).join(", "),labels:(Ue.labels??[]).join(", "),status:eA(Ue),label:Ue.title,desc:"",...Ue.kind?{kind:Ue.kind}:{},...Ue.tool?{tool:Ue.tool}:{}});if(f==="lanes"){const Ue=md(ce),it=Ue.map((Qt,Ot)=>({id:`wave-${Ot}`,type:"waveBox",position:{x:Cp+Ot*_p-tA,y:iv-nA},data:{label:e("flow.lane.wave",{n:Ot+1}),sub:Qt.length>1?e("flow.lane.parallel",{n:Qt.length}):"",color:iA[Ot%iA.length]},style:{width:dl+tA*2,height:nA+(Qt.length-1)*nv+fl+14},draggable:!1,selectable:!1,zIndex:0})),qt=Ue.flatMap((Qt,Ot)=>Qt.map((Q,ke)=>({id:String(Q.seq),type:"task",position:{x:Cp+Ot*_p,y:iv+ke*nv},deletable:!1,zIndex:1,data:ae(Q)})));x([...it,...qt]);return}const je=new Map(G.current.map(Ue=>[Ue.id,Ue.position])),Ae=[];for(const Ue of ce){const it=je.get(String(Ue.seq))??W.current[String(Ue.seq)];it&&Ae.push(it)}let Qe=!1;const rt=ce.map(Ue=>{const it=String(Ue.seq);let qt=je.get(it)??W.current[it];return qt||(qt=xhe(Ae),Ae.push(qt),Qe=!0),W.current[it]=qt,{id:it,type:"task",position:qt,deletable:!1,data:ae(Ue)}});x(rt),Qe&&xe()},[ce,c,f,I,x,xe,e]),_.useEffect(()=>{if(U.current!==c)return;const me=new Set(ce.map(ae=>String(ae.seq)));k(ae=>{const je=ae.filter(Ae=>me.has(Ae.source)&&me.has(Ae.target));return je.length!==ae.length&&xe(),je.length===ae.length?ae:je})},[ce,c,k,xe]),_.useEffect(()=>{if(!c||U.current!==c||f!=="free"||ce.length<2)return;const me=md(ce),ae=[];for(let Qe=1;Qe<me.length;Qe+=1)for(const rt of me[Qe-1]??[])for(const Ue of me[Qe]??[])ae.push({id:`seed-${rt.seq}-${Ue.seq}`,source:String(rt.seq),target:String(Ue.seq),sourceHandle:"r",targetHandle:"l",animated:!1});const je=X.current,Ae=q.current!==c;if(q.current=c,Ae&&je.length===0)ae.length>0&&(k(ae),xe());else{const Qe=new Set;for(const it of je)Qe.add(it.source),Qe.add(it.target);const rt=new Set(je.map(it=>`${it.source}->${it.target}`)),Ue=new Set(ce.map(it=>String(it.seq)).filter(it=>!Y.current.has(it)&&!Qe.has(it)));if(Ue.size>0){const it=ae.filter(qt=>(Ue.has(qt.source)||Ue.has(qt.target))&&!rt.has(`${qt.source}->${qt.target}`));it.length>0&&(k([...je,...it]),xe())}}Y.current=new Set(ce.map(Qe=>String(Qe.seq)))},[ce,c,f,I,k,xe]);const fe=_.useCallback(me=>{if(v(me),f!=="free")return;let ae=!1;for(const je of me)je.type==="position"&&je.position&&(W.current[je.id]=je.position,ae=!0);ae&&xe()},[v,xe,f]),te=_.useCallback(me=>{f==="free"&&(k(ae=>GP({...me,animated:!1},ae)),xe())},[k,xe,f]),we=_.useCallback(()=>{if(f!=="free"||ce.length===0)return;const me=md(ce),ae={},je=[];me.forEach((Ae,Qe)=>{if(Ae.forEach((rt,Ue)=>{ae[String(rt.seq)]={x:Cp+Qe*_p,y:iv+Ue*nv}}),Qe>0)for(const rt of me[Qe-1]??[])for(const Ue of Ae)je.push({id:`seed-${rt.seq}-${Ue.seq}`,source:String(rt.seq),target:String(Ue.seq),sourceHandle:"r",targetHandle:"l",animated:!1})}),W.current={...W.current,...ae},x(Ae=>Ae.map(Qe=>ae[Qe.id]?{...Qe,position:ae[Qe.id]}:Qe)),k(je),xe(),setTimeout(()=>r({padding:.2,duration:300}),60)},[f,ce,x,k,xe,r]),Fe=_.useCallback(async me=>{if(!await i({title:e("flow.confirm.deleteTitle"),body:e("flow.confirm.deleteBody",{seq:me}),danger:!0,confirm:e("flow.node.delete")}))return;O("");const je=X.current.filter(Ae=>Ae.source===String(me)||Ae.target===String(me)).map(Ae=>({...Ae}));try{await gI(c,me),o.current.push({seq:me,edges:je})}catch(Ae){O(Ae instanceof Error?Ae.message:String(Ae))}finally{j(Ae=>Ae===me?null:Ae),A(Ae=>Ae===me?null:Ae),$.current="",z(Ae=>Ae+1),oe()}},[c,i,e,oe]),Le=_.useCallback(async()=>{const me=o.current.pop();if(me){O("");try{await Hie(c,me.seq),k(ae=>{const je=new Set(ae.map(Ae=>Ae.id));return[...ae,...me.edges.filter(Ae=>!je.has(Ae.id))]}),xe(),oe()}catch(ae){O(ae instanceof Error?ae.message:String(ae))}}},[c,k,xe,oe]),pt=_.useCallback((me,ae)=>{var rt;if(f!=="free"||ae.isValid)return;const je=ae.fromNode;if(!je||!c)return;const Ae="changedTouches"in me?me.changedTouches[0]:me;if(!Ae)return;const Qe=s({x:Ae.clientX,y:Ae.clientY});F({fromId:je.id,fromHandle:((rt=ae.fromHandle)==null?void 0:rt.id)??null,clientX:Ae.clientX,clientY:Ae.clientY,flowX:Qe.x,flowY:Qe.y})},[f,c,s]),nt=_.useCallback(async()=>{const me=B;if(F(null),!(!me||!c))try{const ae=await C0(c,{title:`${e("flow.node.default")} ${ce.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),je=mhe(ae);if(je==null)return;const Ae=String(je);W.current[Ae]={x:me.flowX-dl/2,y:me.flowY-fl/2},k(Qe=>[...Qe,{id:`e-${me.fromId}-${Ae}-drop`,source:me.fromId,target:Ae,sourceHandle:me.fromHandle??void 0,animated:!1}]),xe(),oe()}catch(ae){O(ae instanceof Error?ae.message:String(ae))}},[B,c,ce.length,k,xe,e,oe]);_.useEffect(()=>{if(!B)return;const me=ae=>{ae.key==="Escape"&&F(null)};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[B]);const Mt=_.useCallback((me,ae)=>{f==="free"&&(k(je=>ade(me,ae,je)),xe())},[f,k,xe]);_.useEffect(()=>{const me=ae=>{if(ae.key!=="Delete"&&ae.key!=="Backspace"||T!=null)return;const je=ae.target;je&&(je.tagName==="INPUT"||je.tagName==="TEXTAREA"||je.isContentEditable)||S!=null&&(ae.preventDefault(),Fe(S))};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[S,T,Fe]),_.useEffect(()=>{const me=ae=>{if(!(ae.metaKey||ae.ctrlKey)||ae.key!=="z"&&ae.key!=="Z"||T!=null)return;const je=ae.target;je&&(je.tagName==="INPUT"||je.tagName==="TEXTAREA"||je.isContentEditable)||(ae.preventDefault(),Le())};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[T,Le]);const Nt=_.useCallback(async me=>{if(c){b(!0),O("");try{const ae=new Map(ce.map(je=>[je.seq,je.order]));for(let je=0;je<me.length;je+=1)for(const Ae of me[je]??[])ae.get(Ae)!==je+1&&await _m(c,Ae,{order:je+1});oe()}catch(ae){O(ae instanceof Error?ae.message:String(ae))}finally{b(!1)}}},[c,ce,oe]),mt=_.useCallback(me=>{const ae=Number(me.id);if(!Number.isInteger(ae))return;const je=md(ce).map(Ue=>Ue.map(it=>it.seq)),Ae=(me.position.x-Cp)/_p,Qe=Math.round(Ae),rt=je.map(Ue=>Ue.filter(it=>it!==ae));if(Qe>=0&&Qe<je.length&&Math.abs(Ae-Qe)<=.35)rt[Qe].push(ae);else{const Ue=Math.max(0,Math.min(rt.length,Math.ceil(Ae)));rt.splice(Ue,0,[ae])}Nt(rt.filter(Ue=>Ue.length>0)).finally(()=>{$.current="",z(Ue=>Ue+1)})},[ce,Nt]),Re=_.useCallback((me,ae)=>{if(f==="lanes"){mt(ae);return}const je=new Map(G.current.map(it=>[it.id,it])),Ae={x:ae.position.x+dl/2,y:ae.position.y+fl/2};let Qe=null,rt=40;for(const it of X.current){if(it.source===ae.id||it.target===ae.id)continue;const qt=je.get(it.source),Qt=je.get(it.target);if(!qt||!Qt)continue;const Ot=vhe(Ae,sA(qt),sA(Qt));Ot<rt&&(rt=Ot,Qe=it)}if(!Qe)return;const Ue=Qe;k(it=>[...it.filter(qt=>qt.id!==Ue.id),{id:`e-${Ue.source}-${ae.id}-${Ue.id}`,source:Ue.source,target:ae.id,animated:!1},{id:`e-${ae.id}-${Ue.target}-${Ue.id}`,source:ae.id,target:Ue.target,animated:!1}]),xe()},[f,mt,k,xe]),We=_.useCallback(me=>{m(me),localStorage.setItem(JT,me)},[]);_.useEffect(()=>{const me=setTimeout(()=>{r({padding:.2,duration:300})},80);return()=>clearTimeout(me)},[f,r]);const se=async()=>{if(c){O("");try{await C0(c,{title:`${e("flow.node.default")} ${ce.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),oe()}catch(me){O(me instanceof Error?me.message:String(me))}}},Ee=async()=>{if(O(""),D(null),!c)return O(e("flow.err.noProject"));if(ce.length===0)return O(e("flow.err.noNodes"));R(!0);try{const me=ce.filter(Ae=>Ae.state==="Planning"),ae=me.length;let je=0;D({phase:"creating",made:je,total:ae});for(const Ae of me)await _m(c,Ae.seq,{state:"Backlog",labels:Array.from(new Set([...Ae.labels??[],"AI-PIPELINE"]))}),je+=1,D({phase:"creating",made:je,total:ae});D({phase:"starting",made:je,total:ae}),await yI(c),oe(),D({phase:"done",made:je,total:ae})}catch(me){O(me instanceof Error?me.message:String(me))}finally{R(!1)}},De=be.isLoading&&!!c;return u.jsxs("div",{className:"flex flex-col h-full",children:[u.jsxs("header",{className:"flex items-center gap-3 flex-wrap px-4 py-3 border-b border-[var(--surface-card-border)]",children:[u.jsxs("h1",{className:"text-lg font-[family-name:var(--font-heading)] flex items-center gap-2",children:[u.jsx(o_,{size:18,strokeWidth:2.4}),e("nav.arrange")]}),u.jsx(wI,{current:c,onChange:d}),u.jsxs("div",{className:"flex gap-1",role:"group","aria-label":e("flow.mode.aria"),children:[u.jsxs("button",{type:"button",className:["nb-btn",f==="free"?"nb-btn-primary":""].join(" "),"aria-pressed":f==="free",onClick:()=>We("free"),children:[u.jsx(o_,{size:14,strokeWidth:2.4})," ",e("flow.mode.free")]}),u.jsxs("button",{type:"button",className:["nb-btn",f==="lanes"?"nb-btn-primary":""].join(" "),"aria-pressed":f==="lanes",onClick:()=>We("lanes"),children:[u.jsx(LU,{size:14,strokeWidth:2.4})," ",e("flow.mode.lanes")]})]}),De&&u.jsx(ht,{size:15,className:"animate-spin text-[var(--color-text-muted)]"}),u.jsxs("button",{type:"button",className:"nb-btn",onClick:()=>void se(),disabled:!c||De,children:[u.jsx(Bn,{size:15,strokeWidth:2.4})," ",e("flow.addNode")]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta ml-auto",onClick:()=>void Ee(),disabled:M||le||De||!c,title:le?e("flow.pipelineRunning"):void 0,children:[M||le?u.jsx(ht,{size:15,className:"animate-spin"}):u.jsx($m,{size:15,strokeWidth:2.4}),e(M?"flow.running":le?"flow.pipelineRunning":"flow.run")]})]}),!c&&u.jsx("div",{className:"px-4 py-2 text-sm text-[var(--color-text-muted)] border-b border-[var(--surface-card-border)]",children:e("flow.pickProject")}),P&&u.jsx("div",{className:"px-4 py-2 text-sm text-[var(--color-crashed)] bg-[var(--color-crashed-bg)] border-b border-[var(--surface-card-border)]",children:P}),V&&u.jsxs("div",{className:"px-4 py-2 text-sm flex items-center gap-3 bg-[var(--surface-input)] border-b border-[var(--surface-card-border)]",children:[V.phase==="creating"&&u.jsxs("span",{children:[e("flow.status.creating")," ",V.made,"/",V.total,"…"]}),V.phase==="starting"&&u.jsx("span",{children:e("flow.status.starting")}),V.phase==="done"&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-[var(--color-running)] font-bold",children:["✓ ",e("flow.status.done").replace("{n}",String(V.made))]}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>n(`/board?project=${encodeURIComponent(c)}`),children:e("flow.goBoard")})]})]}),u.jsx("div",{className:"flex-1 min-h-0 arrange-flow-shell",children:u.jsxs(Afe,{nodes:y,edges:ne,nodeTypes:ghe,connectionRadius:160,nodesConnectable:f==="free",edgesReconnectable:f==="free",deleteKeyCode:T!=null?null:["Delete","Backspace"],onNodesChange:fe,onEdgesChange:me=>{f==="free"&&(C(me),xe())},onConnect:te,onConnectEnd:pt,onReconnect:Mt,onNodeClick:(me,ae)=>{const je=Number(ae.id);Number.isInteger(je)&&A(je)},onNodeDragStop:Re,onSelectionChange:({nodes:me})=>{const ae=me[0]?Number(me[0].id):null;j(ae!=null&&Number.isInteger(ae)?ae:null)},fitView:!0,children:[u.jsx(Pfe,{variant:ca.Dots,gap:18,size:1}),u.jsx(Hfe,{children:f==="free"&&u.jsx(kd,{onClick:we,title:e("flow.tidy"),"aria-label":e("flow.tidy"),children:u.jsx(cM,{size:14,strokeWidth:2.4})})})]})}),B&&u.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>F(null),children:u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta absolute -translate-x-1/2 -translate-y-1/2",style:{left:B.clientX,top:B.clientY},onClick:me=>{me.stopPropagation(),nt()},children:[u.jsx(Bn,{size:14,strokeWidth:2.4})," ",e("flow.pending.create")]})}),p&&u.jsxs("div",{className:"px-4 py-1 text-xs text-[var(--color-text-muted)] border-t border-[var(--surface-card-border)] flex items-center gap-2",children:[u.jsx(ht,{size:12,className:"animate-spin"})," ",e("flow.lane.applying")]}),u.jsx("footer",{className:"px-4 py-2 text-xs text-[var(--color-text-muted)] border-t border-[var(--surface-card-border)]",children:e(f==="free"?"flow.hint":"flow.lane.hint")}),T!=null&&c&&u.jsx(hhe,{project:c,seq:T,onClose:()=>A(null),onChanged:oe,onDelete:me=>void Fe(me)})]})}function Ehe(){return u.jsx(x3,{children:u.jsx(whe,{})})}function khe(){const e=Ye();return u.jsxs("div",{className:"nb-card max-w-2xl mt-12",children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold mb-2",children:e("notFound.title")}),u.jsx("p",{className:"text-[var(--color-text-muted)] mb-6",children:e("notFound.body")}),u.jsx(Fc,{to:"/",className:"nb-btn nb-btn-mint inline-flex",children:e("notFound.home")})]})}const She=_.lazy(()=>sU(()=>import("./ShowcasePage-Hrjahug0.js"),__vite__mapDeps([0,1])));function Nhe(){return u.jsx(l$,{children:u.jsxs(EB,{children:[u.jsx(oi,{path:"/showcase",element:u.jsx(_.Suspense,{fallback:null,children:u.jsx(She,{})})}),u.jsxs(oi,{element:u.jsx(d_,{contentMode:"workspace"}),children:[u.jsx(oi,{index:!0,element:u.jsx(Cx,{})}),u.jsx(oi,{path:"/projects",element:u.jsx(Tj,{})}),u.jsx(oi,{path:"/projects/:name",element:u.jsx(Tj,{})}),u.jsx(oi,{path:"/board",element:u.jsx(dse,{})}),u.jsx(oi,{path:"/prompts",element:u.jsx(Nse,{})}),u.jsx(oi,{path:"/chat",element:u.jsx(Cx,{})}),u.jsx(oi,{path:"/chat/:sessionId",element:u.jsx(Cx,{})}),u.jsx(oi,{path:"/arrange",element:u.jsx(Ehe,{})})]}),u.jsxs(oi,{element:u.jsx(d_,{contentMode:"document"}),children:[u.jsx(oi,{path:"/projects/new",element:u.jsx(hI,{})}),u.jsx(oi,{path:"/skills",element:u.jsx(bse,{})}),u.jsx(oi,{path:"/system",element:u.jsx(qse,{})}),u.jsx(oi,{path:"/memory",element:u.jsx(tre,{})}),u.jsx(oi,{path:"/plugins",element:u.jsx(zre,{})}),u.jsx(oi,{path:"*",element:u.jsx(khe,{})})]})]})})}function _he(){const e=[b0("plugin.config",{owner:"sps",order:0,match:({pluginKey:t})=>t==="memory",render:()=>u.jsx(Bre,{})}),b0("plugin.config",{owner:"sps",order:0,match:({pluginKey:t})=>t==="im",render:()=>u.jsx(Kre,{})})];return()=>{for(const t of e)t()}}function Che(){_he(),cre(),(async()=>{try{const e=await CI();await Promise.all(e.filter(t=>t.clientFormat==="sps"&&!t.disabled).map(t=>ure(t.key)))}catch(e){console.error("插件前端加载失败(不影响 console 本体):",e)}})()}o$();DF();Che();const jhe=new u5({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!1}}}),k3=document.getElementById("root");if(!k3)throw new Error("#root not found");B4.createRoot(k3).render(u.jsx(_.StrictMode,{children:u.jsx(kF,{children:u.jsx(d5,{client:jhe,children:u.jsx(GB,{children:u.jsx(WY,{children:u.jsx(Nhe,{})})})})})}));export{eM as A,RU as C,rM as E,Fc as L,u1 as P,Ev as S,hU as a,ze as c,u as j,_ as r,bM as u};